capo-codecatalyst 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- capo_codecatalyst/__init__.py +51 -0
- capo_codecatalyst/_async.py +25 -0
- capo_codecatalyst/_auth/_identity.py +14 -0
- capo_codecatalyst/_auth/_providers.py +154 -0
- capo_codecatalyst/_auth/_signers.py +43 -0
- capo_codecatalyst/_auth/_sigv4.py +434 -0
- capo_codecatalyst/_auth/_zapros_handler.py +80 -0
- capo_codecatalyst/_iter.py +113 -0
- capo_codecatalyst/_operations/code_catalyst/create_access_token.py +153 -0
- capo_codecatalyst/_operations/code_catalyst/create_dev_environment.py +165 -0
- capo_codecatalyst/_operations/code_catalyst/create_project.py +158 -0
- capo_codecatalyst/_operations/code_catalyst/create_source_repository.py +159 -0
- capo_codecatalyst/_operations/code_catalyst/create_source_repository_branch.py +165 -0
- capo_codecatalyst/_operations/code_catalyst/delete_access_token.py +146 -0
- capo_codecatalyst/_operations/code_catalyst/delete_dev_environment.py +159 -0
- capo_codecatalyst/_operations/code_catalyst/delete_project.py +155 -0
- capo_codecatalyst/_operations/code_catalyst/delete_source_repository.py +155 -0
- capo_codecatalyst/_operations/code_catalyst/delete_space.py +152 -0
- capo_codecatalyst/_operations/code_catalyst/get_dev_environment.py +159 -0
- capo_codecatalyst/_operations/code_catalyst/get_project.py +153 -0
- capo_codecatalyst/_operations/code_catalyst/get_source_repository.py +156 -0
- capo_codecatalyst/_operations/code_catalyst/get_source_repository_clone_urls.py +157 -0
- capo_codecatalyst/_operations/code_catalyst/get_space.py +152 -0
- capo_codecatalyst/_operations/code_catalyst/get_subscription.py +155 -0
- capo_codecatalyst/_operations/code_catalyst/get_user_details.py +157 -0
- capo_codecatalyst/_operations/code_catalyst/get_workflow.py +159 -0
- capo_codecatalyst/_operations/code_catalyst/get_workflow_run.py +161 -0
- capo_codecatalyst/_operations/code_catalyst/list_access_tokens.py +153 -0
- capo_codecatalyst/_operations/code_catalyst/list_dev_environment_sessions.py +164 -0
- capo_codecatalyst/_operations/code_catalyst/list_dev_environments.py +156 -0
- capo_codecatalyst/_operations/code_catalyst/list_event_logs.py +160 -0
- capo_codecatalyst/_operations/code_catalyst/list_projects.py +158 -0
- capo_codecatalyst/_operations/code_catalyst/list_source_repositories.py +159 -0
- capo_codecatalyst/_operations/code_catalyst/list_source_repository_branches.py +164 -0
- capo_codecatalyst/_operations/code_catalyst/list_spaces.py +155 -0
- capo_codecatalyst/_operations/code_catalyst/list_workflow_runs.py +166 -0
- capo_codecatalyst/_operations/code_catalyst/list_workflows.py +168 -0
- capo_codecatalyst/_operations/code_catalyst/start_dev_environment.py +160 -0
- capo_codecatalyst/_operations/code_catalyst/start_dev_environment_session.py +163 -0
- capo_codecatalyst/_operations/code_catalyst/start_workflow_run.py +160 -0
- capo_codecatalyst/_operations/code_catalyst/stop_dev_environment.py +155 -0
- capo_codecatalyst/_operations/code_catalyst/stop_dev_environment_session.py +156 -0
- capo_codecatalyst/_operations/code_catalyst/update_dev_environment.py +164 -0
- capo_codecatalyst/_operations/code_catalyst/update_project.py +159 -0
- capo_codecatalyst/_operations/code_catalyst/update_space.py +156 -0
- capo_codecatalyst/_operations/code_catalyst/verify_session.py +146 -0
- capo_codecatalyst/_pagination.py +21 -0
- capo_codecatalyst/_protocol/__init__.py +1 -0
- capo_codecatalyst/_protocol/errors.py +93 -0
- capo_codecatalyst/_protocol/eventstream.py +238 -0
- capo_codecatalyst/_protocol/serialize.py +47 -0
- capo_codecatalyst/_protocol/xml.py +33 -0
- capo_codecatalyst/_resources/code_catalyst/access_token.py +359 -0
- capo_codecatalyst/_resources/code_catalyst/space.py +578 -0
- capo_codecatalyst/_rule_engine/__init__.py +0 -0
- capo_codecatalyst/_rule_engine/_aws_partition.py +160 -0
- capo_codecatalyst/_rule_engine/_endpoint_rule_set.py +98 -0
- capo_codecatalyst/_rule_engine/_endpoint_runtime.py +389 -0
- capo_codecatalyst/_services/_aws_config.py +156 -0
- capo_codecatalyst/_services/_pipeline.py +195 -0
- capo_codecatalyst/_services/async_code_catalyst.py +214 -0
- capo_codecatalyst/_services/code_catalyst.py +212 -0
- capo_codecatalyst/errors/__init__.py +33 -0
- capo_codecatalyst/errors/_base.py +94 -0
- capo_codecatalyst/errors/access_denied_exception.py +47 -0
- capo_codecatalyst/errors/conflict_exception.py +45 -0
- capo_codecatalyst/errors/resource_not_found_exception.py +47 -0
- capo_codecatalyst/errors/service_quota_exceeded_exception.py +49 -0
- capo_codecatalyst/errors/throttling_exception.py +45 -0
- capo_codecatalyst/errors/validation_exception.py +45 -0
- capo_codecatalyst/py.typed +0 -0
- capo_codecatalyst/types/_prelude/blob.py +12 -0
- capo_codecatalyst/types/_prelude/timestamp.py +17 -0
- capo_codecatalyst/types/access_token_id.py +5 -0
- capo_codecatalyst/types/access_token_name.py +5 -0
- capo_codecatalyst/types/access_token_secret.py +5 -0
- capo_codecatalyst/types/access_token_summaries.py +31 -0
- capo_codecatalyst/types/access_token_summary.py +54 -0
- capo_codecatalyst/types/client_token.py +5 -0
- capo_codecatalyst/types/comparison_operator.py +5 -0
- capo_codecatalyst/types/create_access_token_request.py +46 -0
- capo_codecatalyst/types/create_access_token_response.py +63 -0
- capo_codecatalyst/types/create_dev_environment_request.py +123 -0
- capo_codecatalyst/types/create_dev_environment_response.py +52 -0
- capo_codecatalyst/types/create_project_request.py +43 -0
- capo_codecatalyst/types/create_project_response.py +49 -0
- capo_codecatalyst/types/create_source_repository_branch_request.py +38 -0
- capo_codecatalyst/types/create_source_repository_branch_response.py +60 -0
- capo_codecatalyst/types/create_source_repository_request.py +38 -0
- capo_codecatalyst/types/create_source_repository_response.py +57 -0
- capo_codecatalyst/types/delete_access_token_request.py +24 -0
- capo_codecatalyst/types/delete_access_token_response.py +18 -0
- capo_codecatalyst/types/delete_dev_environment_request.py +29 -0
- capo_codecatalyst/types/delete_dev_environment_response.py +46 -0
- capo_codecatalyst/types/delete_project_request.py +26 -0
- capo_codecatalyst/types/delete_project_response.py +44 -0
- capo_codecatalyst/types/delete_source_repository_request.py +29 -0
- capo_codecatalyst/types/delete_source_repository_response.py +48 -0
- capo_codecatalyst/types/delete_space_request.py +24 -0
- capo_codecatalyst/types/delete_space_response.py +37 -0
- capo_codecatalyst/types/dev_environment_access_details.py +38 -0
- capo_codecatalyst/types/dev_environment_repository_summaries.py +39 -0
- capo_codecatalyst/types/dev_environment_repository_summary.py +42 -0
- capo_codecatalyst/types/dev_environment_session_configuration.py +56 -0
- capo_codecatalyst/types/dev_environment_session_summary.py +71 -0
- capo_codecatalyst/types/dev_environment_session_type.py +5 -0
- capo_codecatalyst/types/dev_environment_sessions_summary_list.py +37 -0
- capo_codecatalyst/types/dev_environment_status.py +5 -0
- capo_codecatalyst/types/dev_environment_summary.py +163 -0
- capo_codecatalyst/types/dev_environment_summary_list.py +33 -0
- capo_codecatalyst/types/email_address.py +29 -0
- capo_codecatalyst/types/event_log_entries.py +31 -0
- capo_codecatalyst/types/event_log_entry.py +174 -0
- capo_codecatalyst/types/event_payload.py +29 -0
- capo_codecatalyst/types/execute_command_session_configuration.py +53 -0
- capo_codecatalyst/types/execute_command_session_configuration_arguments.py +14 -0
- capo_codecatalyst/types/filter.py +50 -0
- capo_codecatalyst/types/filter_key.py +5 -0
- capo_codecatalyst/types/filters.py +29 -0
- capo_codecatalyst/types/get_dev_environment_request.py +29 -0
- capo_codecatalyst/types/get_dev_environment_response.py +169 -0
- capo_codecatalyst/types/get_project_request.py +26 -0
- capo_codecatalyst/types/get_project_response.py +49 -0
- capo_codecatalyst/types/get_source_repository_clone_urls_request.py +29 -0
- capo_codecatalyst/types/get_source_repository_clone_urls_response.py +28 -0
- capo_codecatalyst/types/get_source_repository_request.py +29 -0
- capo_codecatalyst/types/get_source_repository_response.py +88 -0
- capo_codecatalyst/types/get_space_request.py +24 -0
- capo_codecatalyst/types/get_space_response.py +51 -0
- capo_codecatalyst/types/get_subscription_request.py +24 -0
- capo_codecatalyst/types/get_subscription_response.py +59 -0
- capo_codecatalyst/types/get_user_details_request.py +21 -0
- capo_codecatalyst/types/get_user_details_response.py +60 -0
- capo_codecatalyst/types/get_workflow_request.py +29 -0
- capo_codecatalyst/types/get_workflow_response.py +136 -0
- capo_codecatalyst/types/get_workflow_run_request.py +29 -0
- capo_codecatalyst/types/get_workflow_run_response.py +127 -0
- capo_codecatalyst/types/ide.py +29 -0
- capo_codecatalyst/types/ide_configuration.py +29 -0
- capo_codecatalyst/types/ide_configuration_list.py +31 -0
- capo_codecatalyst/types/ides.py +29 -0
- capo_codecatalyst/types/inactivity_timeout_minutes.py +5 -0
- capo_codecatalyst/types/instance_type.py +5 -0
- capo_codecatalyst/types/list_access_tokens_request.py +29 -0
- capo_codecatalyst/types/list_access_tokens_response.py +45 -0
- capo_codecatalyst/types/list_dev_environment_sessions_request.py +41 -0
- capo_codecatalyst/types/list_dev_environment_sessions_response.py +49 -0
- capo_codecatalyst/types/list_dev_environments_request.py +57 -0
- capo_codecatalyst/types/list_dev_environments_response.py +49 -0
- capo_codecatalyst/types/list_event_logs_request.py +75 -0
- capo_codecatalyst/types/list_event_logs_response.py +45 -0
- capo_codecatalyst/types/list_projects_request.py +53 -0
- capo_codecatalyst/types/list_projects_response.py +42 -0
- capo_codecatalyst/types/list_source_repositories_item.py +81 -0
- capo_codecatalyst/types/list_source_repositories_items.py +35 -0
- capo_codecatalyst/types/list_source_repositories_request.py +38 -0
- capo_codecatalyst/types/list_source_repositories_response.py +48 -0
- capo_codecatalyst/types/list_source_repository_branches_item.py +60 -0
- capo_codecatalyst/types/list_source_repository_branches_items.py +39 -0
- capo_codecatalyst/types/list_source_repository_branches_request.py +41 -0
- capo_codecatalyst/types/list_source_repository_branches_response.py +51 -0
- capo_codecatalyst/types/list_spaces_request.py +23 -0
- capo_codecatalyst/types/list_spaces_response.py +42 -0
- capo_codecatalyst/types/list_workflow_runs_request.py +54 -0
- capo_codecatalyst/types/list_workflow_runs_response.py +44 -0
- capo_codecatalyst/types/list_workflows_request.py +51 -0
- capo_codecatalyst/types/list_workflows_response.py +42 -0
- capo_codecatalyst/types/name_string.py +5 -0
- capo_codecatalyst/types/operation_type.py +5 -0
- capo_codecatalyst/types/persistent_storage.py +26 -0
- capo_codecatalyst/types/persistent_storage_configuration.py +28 -0
- capo_codecatalyst/types/project_description.py +5 -0
- capo_codecatalyst/types/project_display_name.py +5 -0
- capo_codecatalyst/types/project_information.py +29 -0
- capo_codecatalyst/types/project_list_filter.py +54 -0
- capo_codecatalyst/types/project_list_filters.py +31 -0
- capo_codecatalyst/types/project_summaries.py +31 -0
- capo_codecatalyst/types/project_summary.py +38 -0
- capo_codecatalyst/types/region_string.py +5 -0
- capo_codecatalyst/types/repositories_input.py +31 -0
- capo_codecatalyst/types/repository_input.py +40 -0
- capo_codecatalyst/types/sensitive_string.py +5 -0
- capo_codecatalyst/types/source_repository_branch_ref_string.py +5 -0
- capo_codecatalyst/types/source_repository_branch_string.py +5 -0
- capo_codecatalyst/types/source_repository_description_string.py +5 -0
- capo_codecatalyst/types/source_repository_id_string.py +5 -0
- capo_codecatalyst/types/source_repository_name_string.py +5 -0
- capo_codecatalyst/types/space_description.py +5 -0
- capo_codecatalyst/types/space_summaries.py +29 -0
- capo_codecatalyst/types/space_summary.py +51 -0
- capo_codecatalyst/types/start_dev_environment_request.py +63 -0
- capo_codecatalyst/types/start_dev_environment_response.py +54 -0
- capo_codecatalyst/types/start_dev_environment_session_request.py +52 -0
- capo_codecatalyst/types/start_dev_environment_session_response.py +77 -0
- capo_codecatalyst/types/start_workflow_run_request.py +35 -0
- capo_codecatalyst/types/start_workflow_run_response.py +53 -0
- capo_codecatalyst/types/status_reason.py +5 -0
- capo_codecatalyst/types/stop_dev_environment_request.py +29 -0
- capo_codecatalyst/types/stop_dev_environment_response.py +54 -0
- capo_codecatalyst/types/stop_dev_environment_session_request.py +31 -0
- capo_codecatalyst/types/stop_dev_environment_session_response.py +59 -0
- capo_codecatalyst/types/string_list.py +14 -0
- capo_codecatalyst/types/timestamp.py +20 -0
- capo_codecatalyst/types/update_dev_environment_request.py +76 -0
- capo_codecatalyst/types/update_dev_environment_response.py +93 -0
- capo_codecatalyst/types/update_project_request.py +35 -0
- capo_codecatalyst/types/update_project_response.py +46 -0
- capo_codecatalyst/types/update_space_request.py +33 -0
- capo_codecatalyst/types/update_space_response.py +40 -0
- capo_codecatalyst/types/user_identity.py +50 -0
- capo_codecatalyst/types/user_type.py +5 -0
- capo_codecatalyst/types/uuid.py +5 -0
- capo_codecatalyst/types/verify_session_response.py +23 -0
- capo_codecatalyst/types/workflow_definition.py +26 -0
- capo_codecatalyst/types/workflow_definition_summary.py +26 -0
- capo_codecatalyst/types/workflow_run_mode.py +5 -0
- capo_codecatalyst/types/workflow_run_sort_criteria.py +18 -0
- capo_codecatalyst/types/workflow_run_sort_criteria_list.py +35 -0
- capo_codecatalyst/types/workflow_run_status.py +5 -0
- capo_codecatalyst/types/workflow_run_status_reason.py +18 -0
- capo_codecatalyst/types/workflow_run_status_reasons.py +35 -0
- capo_codecatalyst/types/workflow_run_summaries.py +31 -0
- capo_codecatalyst/types/workflow_run_summary.py +119 -0
- capo_codecatalyst/types/workflow_sort_criteria.py +18 -0
- capo_codecatalyst/types/workflow_sort_criteria_list.py +33 -0
- capo_codecatalyst/types/workflow_status.py +5 -0
- capo_codecatalyst/types/workflow_summaries.py +31 -0
- capo_codecatalyst/types/workflow_summary.py +123 -0
- capo_codecatalyst-0.1.0.dist-info/METADATA +82 -0
- capo_codecatalyst-0.1.0.dist-info/RECORD +233 -0
- capo_codecatalyst-0.1.0.dist-info/WHEEL +5 -0
- capo_codecatalyst-0.1.0.dist-info/licenses/LICENSE +21 -0
- capo_codecatalyst-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from . import _iter as _iter
|
|
4
|
+
from . import _protocol as _protocol
|
|
5
|
+
from ._auth._identity import BearerToken as BearerToken
|
|
6
|
+
from ._auth._identity import Identity as Identity
|
|
7
|
+
from ._auth._providers import (
|
|
8
|
+
BearerTokenProvider as BearerTokenProvider,
|
|
9
|
+
)
|
|
10
|
+
from ._auth._providers import (
|
|
11
|
+
CachedProvider as CachedProvider,
|
|
12
|
+
)
|
|
13
|
+
from ._auth._providers import (
|
|
14
|
+
ChainedProvider as ChainedProvider,
|
|
15
|
+
)
|
|
16
|
+
from ._auth._providers import (
|
|
17
|
+
IdentityNotFound as IdentityNotFound,
|
|
18
|
+
)
|
|
19
|
+
from ._auth._providers import (
|
|
20
|
+
IdentityProvider as IdentityProvider,
|
|
21
|
+
)
|
|
22
|
+
from ._auth._providers import (
|
|
23
|
+
SsoTokenCacheProvider as SsoTokenCacheProvider,
|
|
24
|
+
)
|
|
25
|
+
from ._auth._providers import (
|
|
26
|
+
StaticBearerTokenProvider as StaticBearerTokenProvider,
|
|
27
|
+
)
|
|
28
|
+
from ._auth._signers import HttpBearerSigner as HttpBearerSigner
|
|
29
|
+
from ._auth._signers import Signer as Signer
|
|
30
|
+
from ._services._pipeline import (
|
|
31
|
+
AsyncOperationOptions as AsyncOperationOptions,
|
|
32
|
+
)
|
|
33
|
+
from ._services._pipeline import (
|
|
34
|
+
AsyncOperationRequest as AsyncOperationRequest,
|
|
35
|
+
)
|
|
36
|
+
from ._services._pipeline import (
|
|
37
|
+
AsyncOperationResponse as AsyncOperationResponse,
|
|
38
|
+
)
|
|
39
|
+
from ._services._pipeline import (
|
|
40
|
+
OperationOptions as OperationOptions,
|
|
41
|
+
)
|
|
42
|
+
from ._services._pipeline import (
|
|
43
|
+
OperationRequest as OperationRequest,
|
|
44
|
+
)
|
|
45
|
+
from ._services._pipeline import (
|
|
46
|
+
OperationResponse as OperationResponse,
|
|
47
|
+
)
|
|
48
|
+
from ._services.async_code_catalyst import (
|
|
49
|
+
AsyncCodeCatalystClient as AsyncCodeCatalystClient,
|
|
50
|
+
)
|
|
51
|
+
from ._services.code_catalyst import CodeCatalystClient as CodeCatalystClient
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
import trio
|
|
8
|
+
else:
|
|
9
|
+
try:
|
|
10
|
+
import trio
|
|
11
|
+
except ImportError:
|
|
12
|
+
trio = None
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def in_trio_run() -> bool:
|
|
16
|
+
if trio is None:
|
|
17
|
+
return False
|
|
18
|
+
return trio.lowlevel.in_trio_run()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
async def anysleep(delay: float) -> None:
|
|
22
|
+
if in_trio_run():
|
|
23
|
+
await trio.sleep(delay)
|
|
24
|
+
else:
|
|
25
|
+
await asyncio.sleep(delay)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import TypedDict
|
|
5
|
+
|
|
6
|
+
from typing_extensions import NotRequired
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Identity(TypedDict):
|
|
10
|
+
expiration: NotRequired[datetime | None]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class BearerToken(Identity):
|
|
14
|
+
token: str
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from abc import abstractmethod
|
|
5
|
+
from datetime import datetime, timezone
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Generic, TypeVar
|
|
8
|
+
|
|
9
|
+
from capo_codecatalyst._auth._identity import (
|
|
10
|
+
BearerToken,
|
|
11
|
+
Identity,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class IdentityNotFound(Exception):
|
|
16
|
+
"""Raised when a provider cannot resolve an identity. Chain continues."""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
IdentityT = TypeVar("IdentityT", bound="Identity")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class IdentityProvider(Generic[IdentityT]):
|
|
23
|
+
@abstractmethod
|
|
24
|
+
def resolve_identity(self) -> IdentityT:
|
|
25
|
+
raise NotImplementedError
|
|
26
|
+
|
|
27
|
+
async def aresolve_identity(self) -> IdentityT:
|
|
28
|
+
# default: no network I/O, reuse the sync resolution
|
|
29
|
+
return self.resolve_identity()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ChainedProvider(IdentityProvider[IdentityT]):
|
|
33
|
+
"""Try each provider in order; first non-`IdentityNotFound` wins."""
|
|
34
|
+
|
|
35
|
+
def __init__(self, *providers: IdentityProvider[IdentityT]) -> None:
|
|
36
|
+
if not providers:
|
|
37
|
+
raise ValueError("ChainedProvider requires at least one provider")
|
|
38
|
+
self._providers = providers
|
|
39
|
+
|
|
40
|
+
def resolve_identity(self) -> IdentityT:
|
|
41
|
+
errors: list[str] = []
|
|
42
|
+
for p in self._providers:
|
|
43
|
+
try:
|
|
44
|
+
return p.resolve_identity()
|
|
45
|
+
except IdentityNotFound as e:
|
|
46
|
+
errors.append(f"{type(p).__name__}: {e}")
|
|
47
|
+
raise IdentityNotFound("no provider succeeded: " + "; ".join(errors))
|
|
48
|
+
|
|
49
|
+
async def aresolve_identity(self) -> IdentityT:
|
|
50
|
+
errors: list[str] = []
|
|
51
|
+
for p in self._providers:
|
|
52
|
+
try:
|
|
53
|
+
return await p.aresolve_identity()
|
|
54
|
+
except IdentityNotFound as e:
|
|
55
|
+
errors.append(f"{type(p).__name__}: {e}")
|
|
56
|
+
raise IdentityNotFound("no provider succeeded: " + "; ".join(errors))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class CachedProvider(IdentityProvider[IdentityT]):
|
|
60
|
+
"""Cache an identity until its `expiration` (minus skew) elapses."""
|
|
61
|
+
|
|
62
|
+
_SKEW_SECONDS = 60
|
|
63
|
+
|
|
64
|
+
def __init__(self, inner: IdentityProvider[IdentityT]) -> None:
|
|
65
|
+
self._inner = inner
|
|
66
|
+
self._cached: IdentityT | None = None
|
|
67
|
+
|
|
68
|
+
def resolve_identity(self) -> IdentityT:
|
|
69
|
+
if self._cached is not None and not self._expired(self._cached):
|
|
70
|
+
return self._cached
|
|
71
|
+
self._cached = self._inner.resolve_identity()
|
|
72
|
+
return self._cached
|
|
73
|
+
|
|
74
|
+
async def aresolve_identity(self) -> IdentityT:
|
|
75
|
+
if self._cached is not None and not self._expired(self._cached):
|
|
76
|
+
return self._cached
|
|
77
|
+
self._cached = await self._inner.aresolve_identity()
|
|
78
|
+
return self._cached
|
|
79
|
+
|
|
80
|
+
@classmethod
|
|
81
|
+
def _expired(cls, ident: Identity) -> bool:
|
|
82
|
+
exp = ident.get("expiration")
|
|
83
|
+
if exp is None:
|
|
84
|
+
return False
|
|
85
|
+
return (exp - datetime.now(timezone.utc)).total_seconds() <= cls._SKEW_SECONDS
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class BearerTokenProvider(IdentityProvider[BearerToken]):
|
|
89
|
+
"""Base class for providers that resolve a `BearerToken`."""
|
|
90
|
+
|
|
91
|
+
@abstractmethod
|
|
92
|
+
def resolve_identity(self) -> BearerToken:
|
|
93
|
+
raise NotImplementedError
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class StaticBearerTokenProvider(BearerTokenProvider):
|
|
97
|
+
def __init__(self, token: str) -> None:
|
|
98
|
+
self._token: BearerToken = {"token": token}
|
|
99
|
+
|
|
100
|
+
def resolve_identity(self) -> BearerToken:
|
|
101
|
+
return self._token
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class SsoTokenCacheProvider(BearerTokenProvider):
|
|
105
|
+
"""Read a token cached by `aws sso login` from ~/.aws/sso/cache/."""
|
|
106
|
+
|
|
107
|
+
def __init__(
|
|
108
|
+
self, cache_dir: Path | None = None, session_name: str | None = None
|
|
109
|
+
) -> None:
|
|
110
|
+
self._cache_dir = cache_dir or (Path.home() / ".aws" / "sso" / "cache")
|
|
111
|
+
self._session_name = session_name
|
|
112
|
+
|
|
113
|
+
def resolve_identity(self) -> BearerToken:
|
|
114
|
+
if not self._cache_dir.is_dir():
|
|
115
|
+
raise IdentityNotFound(f"SSO cache dir missing: {self._cache_dir}")
|
|
116
|
+
|
|
117
|
+
entry = self._select_entry()
|
|
118
|
+
if entry is None:
|
|
119
|
+
raise IdentityNotFound("no usable SSO cache entry")
|
|
120
|
+
|
|
121
|
+
token = entry.get("accessToken")
|
|
122
|
+
if not isinstance(token, str) or not token:
|
|
123
|
+
raise IdentityNotFound("SSO cache entry has no accessToken")
|
|
124
|
+
|
|
125
|
+
out: BearerToken = {"token": token}
|
|
126
|
+
exp = entry.get("expiresAt")
|
|
127
|
+
if isinstance(exp, str):
|
|
128
|
+
out["expiration"] = _parse_iso8601(exp)
|
|
129
|
+
return out
|
|
130
|
+
|
|
131
|
+
def _select_entry(self) -> dict[str, object] | None:
|
|
132
|
+
candidates: list[tuple[float, dict[str, object]]] = []
|
|
133
|
+
for path in self._cache_dir.glob("*.json"):
|
|
134
|
+
try:
|
|
135
|
+
data: dict[str, object] = json.loads(path.read_text())
|
|
136
|
+
except (OSError, json.JSONDecodeError):
|
|
137
|
+
continue
|
|
138
|
+
if self._session_name and data.get("sessionName") != self._session_name:
|
|
139
|
+
continue
|
|
140
|
+
if "accessToken" not in data:
|
|
141
|
+
continue
|
|
142
|
+
candidates.append((path.stat().st_mtime, data))
|
|
143
|
+
if not candidates:
|
|
144
|
+
return None
|
|
145
|
+
return max(candidates, key=lambda x: x[0])[1]
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _parse_iso8601(value: str) -> datetime:
|
|
149
|
+
# tolerate trailing 'Z'
|
|
150
|
+
return datetime.fromisoformat(value.replace("Z", "+00:00"))
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def default_bearer_token_provider() -> IdentityProvider[BearerToken]:
|
|
154
|
+
return CachedProvider(SsoTokenCacheProvider())
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from typing import Generic, TypeVar
|
|
5
|
+
|
|
6
|
+
from zapros import Request
|
|
7
|
+
|
|
8
|
+
from capo_codecatalyst._auth._identity import BearerToken, Identity
|
|
9
|
+
from capo_codecatalyst._auth._providers import IdentityProvider
|
|
10
|
+
|
|
11
|
+
IdentityT = TypeVar("IdentityT", bound="Identity")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Signer(ABC, Generic[IdentityT]):
|
|
15
|
+
"""Per-request request signer. Holds an IdentityProvider plus static config."""
|
|
16
|
+
|
|
17
|
+
def __init__(self, provider: IdentityProvider[IdentityT]) -> None:
|
|
18
|
+
self.provider = provider
|
|
19
|
+
|
|
20
|
+
@abstractmethod
|
|
21
|
+
async def asign(self, req: Request) -> Request: ...
|
|
22
|
+
@abstractmethod
|
|
23
|
+
def sign(self, req: Request) -> Request: ...
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class HttpBearerSigner(Signer[BearerToken]):
|
|
27
|
+
"""smithy.api#httpBearerAuth — RFC 6750 ``Authorization: Bearer <token>``."""
|
|
28
|
+
|
|
29
|
+
async def asign(self, req: Request) -> Request:
|
|
30
|
+
t = await self.provider.aresolve_identity()
|
|
31
|
+
headers = req.headers.copy()
|
|
32
|
+
headers["Authorization"] = f"Bearer {t['token']}"
|
|
33
|
+
return Request(
|
|
34
|
+
req.url, req.method, headers, body=req.body or b"", context=req.context
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
def sign(self, req: Request) -> Request:
|
|
38
|
+
t = self.provider.resolve_identity()
|
|
39
|
+
headers = req.headers.copy()
|
|
40
|
+
headers["Authorization"] = f"Bearer {t['token']}"
|
|
41
|
+
return Request(
|
|
42
|
+
req.url, req.method, headers, body=req.body or b"", context=req.context
|
|
43
|
+
)
|