diff --git a/pyoaev/credential/__init__.py b/pyoaev/credential/__init__.py index 574dfd0..d488653 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 5c6ec06..261996c 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 4db1c46..732bf4f 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 8d8153c..3b0801e 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 ed3dca2..ffff83a 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)