From ae4642e0329a57424c739cc7ef1614fef4ef09ad Mon Sep 17 00:00:00 2001 From: Romuald Lemesle Date: Mon, 16 Nov 2026 17:17:24 +0100 Subject: [PATCH 1/2] refactor(inject): fetch an AI target token with the inject authorisation code Co-Authored-By: Claude Opus 5.5 --- pyoaev/apis/inject.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pyoaev/apis/inject.py b/pyoaev/apis/inject.py index 829e8e05..07b9f4f8 100644 --- a/pyoaev/apis/inject.py +++ b/pyoaev/apis/inject.py @@ -35,6 +35,21 @@ def execution_reception( result = self.openaev.http_post(path, post_data=data, **kwargs) return result + @exc.on_http_error(exc.OpenAEVGetError) + def resolve_ai_target_token( + self, inject_id: str, asset_id: str, authorisation: str, **kwargs: Any + ) -> Optional[str]: + """Return the token of an AI target the running inject targets, or None. + + Must be called while the inject is being executed, with the + authorisation code received with the job. + """ + path = f"{self.path}/{inject_id}/targets/{asset_id}/ai-token" + result = self.openaev.http_post( + path, post_data={"authorisation": authorisation}, **kwargs + ) + return result.get("value") if isinstance(result, dict) else None + def resolve_attachment_secret( self, inject_id: str, attachment_id: str, authorisation: str, **kwargs: Any ) -> Dict[str, Any]: From 57f81cb0d690a91e33b707d6136f0989ab00d4fa Mon Sep 17 00:00:00 2001 From: Romuald Lemesle Date: Mon, 16 Nov 2026 18:37:19 +0100 Subject: [PATCH 2/2] feat(credential): add the API token credential type Co-Authored-By: Claude Opus 5.5 --- pyoaev/apis/inject.py | 15 --------------- pyoaev/credential/__init__.py | 2 ++ pyoaev/credential/resolved.py | 10 ++++++++++ pyoaev/credential/types.py | 2 ++ test/credential/test_credential_resolved.py | 5 +++++ test/credential/test_credential_types.py | 1 + 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/pyoaev/apis/inject.py b/pyoaev/apis/inject.py index 07b9f4f8..829e8e05 100644 --- a/pyoaev/apis/inject.py +++ b/pyoaev/apis/inject.py @@ -35,21 +35,6 @@ def execution_reception( result = self.openaev.http_post(path, post_data=data, **kwargs) return result - @exc.on_http_error(exc.OpenAEVGetError) - def resolve_ai_target_token( - self, inject_id: str, asset_id: str, authorisation: str, **kwargs: Any - ) -> Optional[str]: - """Return the token of an AI target the running inject targets, or None. - - Must be called while the inject is being executed, with the - authorisation code received with the job. - """ - path = f"{self.path}/{inject_id}/targets/{asset_id}/ai-token" - result = self.openaev.http_post( - path, post_data={"authorisation": authorisation}, **kwargs - ) - return result.get("value") if isinstance(result, dict) else None - def resolve_attachment_secret( self, inject_id: str, attachment_id: str, authorisation: str, **kwargs: Any ) -> Dict[str, Any]: diff --git a/pyoaev/credential/__init__.py b/pyoaev/credential/__init__.py index 574dfd01..d488653b 100644 --- a/pyoaev/credential/__init__.py +++ b/pyoaev/credential/__init__.py @@ -15,6 +15,7 @@ ) from .materializer import CredentialCleanupError, MaterializedCredential, materialize from .resolved import ( + ApiTokenSecret, AwsAccessKeySecret, AwsAssumeRoleSecret, AzureManagedIdentitySecret, @@ -39,6 +40,7 @@ def build_single_referenced_credential_element(provider_name: str): __all__ = [ + "ApiTokenSecret", "AwsAccessKeySecret", "AwsAssumeRoleSecret", "AwsSourceIdentityType", diff --git a/pyoaev/credential/resolved.py b/pyoaev/credential/resolved.py index 5c6ec06e..261996cc 100644 --- a/pyoaev/credential/resolved.py +++ b/pyoaev/credential/resolved.py @@ -36,6 +36,7 @@ SecretType.AZURE_MANAGED_IDENTITY: CredentialType.CLOUD_AZURE, SecretType.GCP_SERVICE_ACCOUNT: CredentialType.CLOUD_GCP, SecretType.GCP_OAUTH2: CredentialType.CLOUD_GCP, + SecretType.API_TOKEN: CredentialType.API, } @@ -207,6 +208,13 @@ class GcpOAuth2Secret(ResolvedSecret): gcp_custom_oauth_access_token: Optional[str] = _secret(default=None) +@dataclass(frozen=True) +class ApiTokenSecret(ResolvedSecret): + secret_type: ClassVar[SecretType] = SecretType.API_TOKEN + + api_token: str = _secret() + + _RESOLVED_SECRET_CLASSES: Dict[SecretType, Type[ResolvedSecret]] = { cls.secret_type: cls for cls in ( @@ -218,6 +226,7 @@ class GcpOAuth2Secret(ResolvedSecret): AzureManagedIdentitySecret, GcpServiceAccountSecret, GcpOAuth2Secret, + ApiTokenSecret, ) } @@ -308,6 +317,7 @@ def ensure_compatible( __all__ = [ + "ApiTokenSecret", "AwsAccessKeySecret", "AwsAssumeRoleSecret", "AzureManagedIdentitySecret", diff --git a/pyoaev/credential/types.py b/pyoaev/credential/types.py index 4db1c460..732bf4f0 100644 --- a/pyoaev/credential/types.py +++ b/pyoaev/credential/types.py @@ -14,6 +14,7 @@ class CredentialType(str, Enum): CLOUD_AWS = "CLOUD_AWS" CLOUD_AZURE = "CLOUD_AZURE" CLOUD_GCP = "CLOUD_GCP" + API = "API" class SecretType(str, Enum): @@ -27,6 +28,7 @@ class SecretType(str, Enum): AZURE_MANAGED_IDENTITY = "AZURE_MANAGED_IDENTITY" GCP_SERVICE_ACCOUNT = "GCP_SERVICE_ACCOUNT" GCP_OAUTH2 = "GCP_OAUTH2" + API_TOKEN = "API_TOKEN" class AwsSourceIdentityType(str, Enum): diff --git a/test/credential/test_credential_resolved.py b/test/credential/test_credential_resolved.py index 8d8153cb..3b0801e1 100644 --- a/test/credential/test_credential_resolved.py +++ b/test/credential/test_credential_resolved.py @@ -94,6 +94,9 @@ "gcp_oauth_client_secret": SECRET, "gcp_oauth_refresh_token": SECRET, }, + SecretType.API_TOKEN: { + "api_token": SECRET, + }, } EXPECTED_CREDENTIAL_TYPES = { @@ -105,6 +108,7 @@ SecretType.AZURE_MANAGED_IDENTITY: CredentialType.CLOUD_AZURE, SecretType.GCP_SERVICE_ACCOUNT: CredentialType.CLOUD_GCP, SecretType.GCP_OAUTH2: CredentialType.CLOUD_GCP, + SecretType.API_TOKEN: CredentialType.API, } @@ -129,6 +133,7 @@ def test_secret_type_mirrors_platform_labels(self): "AZURE_MANAGED_IDENTITY", "GCP_SERVICE_ACCOUNT", "GCP_OAUTH2", + "API_TOKEN", ], ) diff --git a/test/credential/test_credential_types.py b/test/credential/test_credential_types.py index ed3dca2b..ffff83ab 100644 --- a/test/credential/test_credential_types.py +++ b/test/credential/test_credential_types.py @@ -11,6 +11,7 @@ def test_every_value_matches_the_supported_platform_labels(self): "CLOUD_AWS", "CLOUD_AZURE", "CLOUD_GCP", + "API", } actual_labels = {member.value for member in CredentialType} self.assertEqual(actual_labels, expected_labels)