-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ASP-5745] Enable lazy evaluated settings on Jobbergate-cli (#639)
* feat(cli): ensure there is no required setting * fix(cli): implement ContextProtocol to avoid circular imports * Update jobbergate-cli/jobbergate_cli/context.py * feat: remove OIDC_AUDIENCE from core, cli, and agent, following d1fdaa7 * code review * lint(cli): organize imports on subapps.applications.app
- Loading branch information
Showing
28 changed files
with
239 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" | ||
Provides a data object for context passed from the main entry point. | ||
""" | ||
|
||
from dataclasses import dataclass | ||
from functools import cached_property | ||
|
||
from buzz import check_expressions | ||
from httpx import Client | ||
from jobbergate_core.auth.handler import JobbergateAuthHandler | ||
|
||
from jobbergate_cli.auth import show_login_message, track_login_progress | ||
from jobbergate_cli.exceptions import Abort | ||
from jobbergate_cli.config import settings | ||
from jobbergate_cli.schemas import ContextProtocol | ||
|
||
|
||
@dataclass | ||
class JobbergateContext(ContextProtocol): | ||
""" | ||
A data object describing context passed from the main entry point. | ||
""" | ||
|
||
raw_output: bool = False | ||
full_output: bool = False | ||
|
||
@cached_property | ||
def client(self) -> Client: | ||
""" | ||
Client for making requests to the Jobbergate API. | ||
""" | ||
return Client( | ||
base_url=settings.ARMADA_API_BASE, | ||
auth=self.authentication_handler, | ||
timeout=settings.JOBBERGATE_REQUESTS_TIMEOUT, | ||
) | ||
|
||
@cached_property | ||
def authentication_handler(self) -> JobbergateAuthHandler: | ||
""" | ||
The authentication handler for the context. | ||
This is a cached property to ensure that the handler is only created when needed, | ||
so commands that require no authentication face no configuration errors. | ||
""" | ||
with check_expressions( | ||
"The following settings are required to enable authenticated requests:", | ||
raise_exc_class=Abort, | ||
raise_kwargs=dict(support=True, subject="Configuration error"), | ||
) as check: | ||
check(settings.OIDC_DOMAIN, "OIDC_DOMAIN") | ||
check(settings.OIDC_CLIENT_ID, "OIDC_CLIENT_ID") | ||
|
||
protocol = "https" if settings.OIDC_USE_HTTPS else "http" | ||
return JobbergateAuthHandler( | ||
cache_directory=settings.JOBBERGATE_USER_TOKEN_DIR, | ||
login_domain=f"{protocol}://{settings.OIDC_DOMAIN}", | ||
login_client_id=settings.OIDC_CLIENT_ID, | ||
login_client_secret=settings.OIDC_CLIENT_SECRET, | ||
login_url_handler=show_login_message, | ||
login_sequence_handler=track_login_progress, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.