Skip to content

Adding pilot registrations and authentification (Router) #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
fail-fast: false
matrix:
dirac-branch:
- integration
- robin-pilot-registrations
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand All @@ -37,7 +37,7 @@ jobs:
- name: Clone DIRAC
run: |
pip install typer pyyaml gitpython packaging
git clone https://github.com/DIRACGrid/DIRAC.git -b "${{ matrix.dirac-branch }}" /tmp/DIRACRepo
git clone https://github.com/Robin-Van-de-Merghel/DIRAC.git -b "${{ matrix.dirac-branch }}" /tmp/DIRACRepo
echo "Current revision: $(git -C /tmp/DIRACRepo rev-parse HEAD)"
# We need to cd in the directory for the integration_tests.py to work
- name: Prepare environment
Expand Down
1 change: 1 addition & 0 deletions diracx-cli/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dirac = "diracx.cli:app"
[project.entry-points."diracx.cli"]
jobs = "diracx.cli.jobs:app"
config = "diracx.cli.config:app"
pilots = "diracx.cli.pilots:app"

[project.entry-points."diracx.cli.hidden"]
internal = "diracx.cli.internal:app"
Expand Down
66 changes: 66 additions & 0 deletions diracx-cli/src/diracx/cli/pilots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from __future__ import annotations

__all__ = ("app",)

import asyncio
import json
from typing import Annotated, Optional

import typer

from diracx.client.aio import AsyncDiracClient

from .utils import AsyncTyper

app = AsyncTyper()


async def installation_metadata():
async with AsyncDiracClient() as api:
return await api.well_known.get_installation_metadata()


def vo_callback(vo: str | None) -> str:
metadata = asyncio.run(installation_metadata())
vos = list(metadata.virtual_organizations)
if not vo:
raise typer.BadParameter(
f"VO must be specified, available options are: {' '.join(vos)}"
)
if vo not in vos:
raise typer.BadParameter(
f"Unknown VO {vo}, available options are: {' '.join(vos)}"
)
return vo


@app.async_command()
async def generate_pilot_secrets(
vo: Annotated[
str,
typer.Argument(callback=vo_callback, help="Virtual Organization name"),
],
n: Annotated[
int,
typer.Argument(help="Number of secrets to generate."),
],
expiration_minutes: Optional[int] = typer.Option(
60,
help="Expiration in minutes of the secrets.",
),
max_use: Optional[int] = typer.Option(
60,
help="Number of uses max for a secret.",
),
):
async with AsyncDiracClient() as api:
secrets = await api.pilots.create_pilot_secrets(
n=n,
expiration_minutes=expiration_minutes,
pilot_secret_use_count_max=max_use,
vo=vo,
)
# Convert each model to dict
secrets_dict = [secret.as_dict() for secret in secrets]

print(json.dumps(secrets_dict, indent=2))
15 changes: 14 additions & 1 deletion diracx-client/src/diracx/client/_generated/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
from . import models as _models
from ._configuration import DiracConfiguration
from ._utils.serialization import Deserializer, Serializer
from .operations import AuthOperations, ConfigOperations, JobsOperations, WellKnownOperations
from .operations import (
AuthOperations,
ConfigOperations,
JobsOperations,
PilotsInternalOperations,
PilotsOperations,
WellKnownOperations,
)


class Dirac: # pylint: disable=client-accepts-api-version-keyword
Expand All @@ -29,6 +36,10 @@ class Dirac: # pylint: disable=client-accepts-api-version-keyword
:vartype config: _generated.operations.ConfigOperations
:ivar jobs: JobsOperations operations
:vartype jobs: _generated.operations.JobsOperations
:ivar pilots: PilotsOperations operations
:vartype pilots: _generated.operations.PilotsOperations
:ivar pilots_internal: PilotsInternalOperations operations
:vartype pilots_internal: _generated.operations.PilotsInternalOperations
:keyword endpoint: Service URL. Required. Default value is "".
:paramtype endpoint: str
"""
Expand Down Expand Up @@ -65,6 +76,8 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
self.auth = AuthOperations(self._client, self._config, self._serialize, self._deserialize)
self.config = ConfigOperations(self._client, self._config, self._serialize, self._deserialize)
self.jobs = JobsOperations(self._client, self._config, self._serialize, self._deserialize)
self.pilots = PilotsOperations(self._client, self._config, self._serialize, self._deserialize)
self.pilots_internal = PilotsInternalOperations(self._client, self._config, self._serialize, self._deserialize)

def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
"""Runs the network request through the client's chained policies.
Expand Down
15 changes: 14 additions & 1 deletion diracx-client/src/diracx/client/_generated/aio/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
from .. import models as _models
from .._utils.serialization import Deserializer, Serializer
from ._configuration import DiracConfiguration
from .operations import AuthOperations, ConfigOperations, JobsOperations, WellKnownOperations
from .operations import (
AuthOperations,
ConfigOperations,
JobsOperations,
PilotsInternalOperations,
PilotsOperations,
WellKnownOperations,
)


class Dirac: # pylint: disable=client-accepts-api-version-keyword
Expand All @@ -29,6 +36,10 @@ class Dirac: # pylint: disable=client-accepts-api-version-keyword
:vartype config: _generated.aio.operations.ConfigOperations
:ivar jobs: JobsOperations operations
:vartype jobs: _generated.aio.operations.JobsOperations
:ivar pilots: PilotsOperations operations
:vartype pilots: _generated.aio.operations.PilotsOperations
:ivar pilots_internal: PilotsInternalOperations operations
:vartype pilots_internal: _generated.aio.operations.PilotsInternalOperations
:keyword endpoint: Service URL. Required. Default value is "".
:paramtype endpoint: str
"""
Expand Down Expand Up @@ -65,6 +76,8 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
self.auth = AuthOperations(self._client, self._config, self._serialize, self._deserialize)
self.config = ConfigOperations(self._client, self._config, self._serialize, self._deserialize)
self.jobs = JobsOperations(self._client, self._config, self._serialize, self._deserialize)
self.pilots = PilotsOperations(self._client, self._config, self._serialize, self._deserialize)
self.pilots_internal = PilotsInternalOperations(self._client, self._config, self._serialize, self._deserialize)

def send_request(
self, request: HttpRequest, *, stream: bool = False, **kwargs: Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from ._operations import AuthOperations # type: ignore
from ._operations import ConfigOperations # type: ignore
from ._operations import JobsOperations # type: ignore
from ._operations import PilotsOperations # type: ignore
from ._operations import PilotsInternalOperations # type: ignore

from ._patch import __all__ as _patch_all
from ._patch import *
Expand All @@ -24,6 +26,8 @@
"AuthOperations",
"ConfigOperations",
"JobsOperations",
"PilotsOperations",
"PilotsInternalOperations",
]
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
_patch_sdk()
Loading
Loading