codecraftai-credentials 1.2.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.
- ccai/credentials/__init__.py +13 -0
- ccai/credentials/apitokencredential.py +86 -0
- ccai/credentials/awsaccesskeycredential.py +105 -0
- ccai/credentials/azureclientsecretcredential.py +116 -0
- ccai/credentials/azuremanagedidentitycredential.py +131 -0
- ccai/credentials/azureserviceprincipalcredential.py +150 -0
- ccai/credentials/basecredential.py +187 -0
- ccai/credentials/basiccredential.py +104 -0
- ccai/credentials/coreweaveapicredential.py +130 -0
- ccai/credentials/credentialmanager.py +453 -0
- ccai/credentials/crusoeapikeycredential.py +131 -0
- ccai/credentials/digitaloceanapitokencredential.py +181 -0
- ccai/credentials/equinixmetalapitokencredential.py +113 -0
- ccai/credentials/gcpserviceaccountkeycredential.py +188 -0
- ccai/credentials/gcpworkloadidentitycredential.py +173 -0
- ccai/credentials/githubappcredential.py +167 -0
- ccai/credentials/githubtokencredential.py +106 -0
- ccai/credentials/hetznerapitokencredential.py +113 -0
- ccai/credentials/lambdalabsapikeycredential.py +113 -0
- ccai/credentials/linodeapitokencredential.py +113 -0
- ccai/credentials/nebiusserviceaccountcredential.py +113 -0
- ccai/credentials/nutanixprismcredential.py +161 -0
- ccai/credentials/oraclecloudapikeycredential.py +211 -0
- ccai/credentials/personalapitokencredential.py +101 -0
- ccai/credentials/proxmoxapitokencredential.py +145 -0
- ccai/credentials/publickeycredential.py +104 -0
- ccai/credentials/py.typed +0 -0
- ccai/credentials/runpodapikeycredential.py +113 -0
- ccai/credentials/secrettokencredential.py +103 -0
- ccai/credentials/sshcredential.py +221 -0
- ccai/credentials/tailscaleauthkeycredential.py +145 -0
- ccai/credentials/tailscaleoauthcredential.py +139 -0
- ccai/credentials/twingateserviceaccountcredential.py +146 -0
- ccai/credentials/venueregistry.py +89 -0
- ccai/credentials/vspherecredential.py +178 -0
- ccai/credentials/vultrapikeycredential.py +113 -0
- ccai/credentials/wellknown.py +160 -0
- ccai/credentials/wifichoicecredential.py +107 -0
- codecraftai_credentials-1.2.0.dist-info/METADATA +88 -0
- codecraftai_credentials-1.2.0.dist-info/RECORD +42 -0
- codecraftai_credentials-1.2.0.dist-info/WHEEL +4 -0
- codecraftai_credentials-1.2.0.dist-info/licenses/LICENSE.md +204 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: digitaloceanapitokencredential
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`DigitalOceanApiTokenCredential` which
|
|
5
|
+
wraps the DigitalOcean venue personal-access-token authentication material.
|
|
6
|
+
|
|
7
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__author__ = "Myron Walker"
|
|
11
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
12
|
+
__credits__ = []
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
16
|
+
|
|
17
|
+
import os
|
|
18
|
+
|
|
19
|
+
from ccai.errors.exceptions import ConfigurationError
|
|
20
|
+
|
|
21
|
+
from ccai.credentials.basecredential import BaseCredential
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class DigitalOceanApiTokenCredential(BaseCredential):
|
|
25
|
+
"""
|
|
26
|
+
The :class:`DigitalOceanApiTokenCredential` is a container object that wraps the
|
|
27
|
+
DigitalOcean venue personal-access-token authentication material.
|
|
28
|
+
|
|
29
|
+
.. code:: yaml
|
|
30
|
+
"identifier": "digitalocean-token"
|
|
31
|
+
"category": "cloud-venue"
|
|
32
|
+
"provider": "digitalocean"
|
|
33
|
+
"token": "dop_v1_..."
|
|
34
|
+
"spaces_access_key": "DO00..."
|
|
35
|
+
"spaces_secret_key": "..."
|
|
36
|
+
|
|
37
|
+
The Spaces keys are optional and separate from the API token because
|
|
38
|
+
DigitalOcean issues them separately: Spaces is an S3-compatible object
|
|
39
|
+
store authenticated with its own access-key pair, and the
|
|
40
|
+
personal-access token has no authority there. A credential that
|
|
41
|
+
never touches buckets does not need them.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
def __init__(self, *, identifier: str, categories: List[str], token: str,
|
|
45
|
+
spaces_access_key: Optional[str] = None,
|
|
46
|
+
spaces_secret_key: Optional[str] = None,
|
|
47
|
+
role: Optional[str] = "priv") -> None:
|
|
48
|
+
"""
|
|
49
|
+
Initializes a :class:`DigitalOceanApiTokenCredential` instance.
|
|
50
|
+
|
|
51
|
+
:param identifier: The identifier that is used to reference this credential. (required)
|
|
52
|
+
:param categories: The categories of authentication that are supported by the credential.
|
|
53
|
+
:param token: The DigitalOcean personal-access-token value.
|
|
54
|
+
:param spaces_access_key: The S3-compatible Spaces access key, required
|
|
55
|
+
only for bucket operations.
|
|
56
|
+
:param spaces_secret_key: The S3-compatible Spaces secret key, required
|
|
57
|
+
only for bucket operations.
|
|
58
|
+
:param role: Identifies the role of the credential.
|
|
59
|
+
|
|
60
|
+
:raises: ConfigurationError
|
|
61
|
+
"""
|
|
62
|
+
super().__init__(identifier=identifier, categories=categories, role=role)
|
|
63
|
+
|
|
64
|
+
if "cloud-venue" not in categories:
|
|
65
|
+
errmsg_lines = [
|
|
66
|
+
"The DigitalOceanApiTokenCredential should be given credentials of category 'cloud-venue'.",
|
|
67
|
+
"MISSING CATEGORY: cloud-venue",
|
|
68
|
+
]
|
|
69
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
70
|
+
raise ConfigurationError(errmsg)
|
|
71
|
+
|
|
72
|
+
if token is None or len(token) == 0:
|
|
73
|
+
raise ConfigurationError("The DigitalOceanApiTokenCredential constructor requires a non-empty 'token' parameter be provided.")
|
|
74
|
+
|
|
75
|
+
one_spaces_key_missing = (
|
|
76
|
+
(spaces_access_key is None) != (spaces_secret_key is None)
|
|
77
|
+
)
|
|
78
|
+
if one_spaces_key_missing:
|
|
79
|
+
errmsg_lines = [
|
|
80
|
+
"The DigitalOceanApiTokenCredential Spaces keys must be supplied as a pair.",
|
|
81
|
+
"Half a key pair cannot authenticate a bucket operation, and accepting it",
|
|
82
|
+
"here would defer the failure to the first bucket call.",
|
|
83
|
+
f" spaces_access_key: {'set' if spaces_access_key is not None else 'missing'}",
|
|
84
|
+
f" spaces_secret_key: {'set' if spaces_secret_key is not None else 'missing'}",
|
|
85
|
+
]
|
|
86
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
87
|
+
raise ConfigurationError(errmsg)
|
|
88
|
+
|
|
89
|
+
self._token = token
|
|
90
|
+
self._spaces_access_key = spaces_access_key
|
|
91
|
+
self._spaces_secret_key = spaces_secret_key
|
|
92
|
+
return
|
|
93
|
+
|
|
94
|
+
@property
|
|
95
|
+
def token(self) -> str:
|
|
96
|
+
"""
|
|
97
|
+
Returns the DigitalOcean personal-access-token value.
|
|
98
|
+
|
|
99
|
+
:returns: The API token string.
|
|
100
|
+
"""
|
|
101
|
+
return self._token
|
|
102
|
+
|
|
103
|
+
@property
|
|
104
|
+
def spaces_access_key(self) -> Optional[str]:
|
|
105
|
+
"""
|
|
106
|
+
Returns the S3-compatible Spaces access key.
|
|
107
|
+
|
|
108
|
+
:returns: The Spaces access key, or None when the credential carries
|
|
109
|
+
no bucket authority.
|
|
110
|
+
"""
|
|
111
|
+
return self._spaces_access_key
|
|
112
|
+
|
|
113
|
+
@property
|
|
114
|
+
def spaces_secret_key(self) -> Optional[str]:
|
|
115
|
+
"""
|
|
116
|
+
Returns the S3-compatible Spaces secret key.
|
|
117
|
+
|
|
118
|
+
:returns: The Spaces secret key, or None when the credential carries
|
|
119
|
+
no bucket authority.
|
|
120
|
+
"""
|
|
121
|
+
return self._spaces_secret_key
|
|
122
|
+
|
|
123
|
+
@classmethod
|
|
124
|
+
def validate(cls, cred_info: Dict[str, Any]) -> Tuple[List[str], List[str]]:
|
|
125
|
+
"""
|
|
126
|
+
Validates the dictionary describing a DigitalOcean API-token credential.
|
|
127
|
+
|
|
128
|
+
:param cred_info: Credential definition dictionary to validate.
|
|
129
|
+
|
|
130
|
+
:returns: A tuple of lists containing errors and warnings.
|
|
131
|
+
"""
|
|
132
|
+
|
|
133
|
+
errors = []
|
|
134
|
+
warnings = []
|
|
135
|
+
|
|
136
|
+
if "token" not in cred_info:
|
|
137
|
+
errors.append("missing 'token' in digitalocean-api-token credential.")
|
|
138
|
+
|
|
139
|
+
has_access_key = "spaces_access_key" in cred_info
|
|
140
|
+
has_secret_key = "spaces_secret_key" in cred_info
|
|
141
|
+
if has_access_key != has_secret_key:
|
|
142
|
+
present = "spaces_access_key" if has_access_key else "spaces_secret_key"
|
|
143
|
+
absent = "spaces_secret_key" if has_access_key else "spaces_access_key"
|
|
144
|
+
errors.append(
|
|
145
|
+
f"digitalocean-api-token credential declares '{present}' without "
|
|
146
|
+
f"'{absent}'; Spaces keys must be supplied as a pair."
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
return errors, warnings
|
|
150
|
+
|
|
151
|
+
def as_dict(self) -> Dict[str, Any]:
|
|
152
|
+
"""
|
|
153
|
+
Returns a dictionary representation of this credential object.
|
|
154
|
+
"""
|
|
155
|
+
rtnval = super().as_dict()
|
|
156
|
+
|
|
157
|
+
rtnval["token"] = self._token
|
|
158
|
+
|
|
159
|
+
if self._spaces_access_key is not None:
|
|
160
|
+
rtnval["spaces_access_key"] = self._spaces_access_key
|
|
161
|
+
if self._spaces_secret_key is not None:
|
|
162
|
+
rtnval["spaces_secret_key"] = self._spaces_secret_key
|
|
163
|
+
|
|
164
|
+
return rtnval
|
|
165
|
+
|
|
166
|
+
def __repr__(self) -> str:
|
|
167
|
+
"""
|
|
168
|
+
Returns a debug representation of this credential with the secrets redacted.
|
|
169
|
+
|
|
170
|
+
:returns: A redacted string representation safe for logs.
|
|
171
|
+
"""
|
|
172
|
+
spaces = "absent"
|
|
173
|
+
if self._spaces_access_key is not None:
|
|
174
|
+
spaces = "'***'"
|
|
175
|
+
|
|
176
|
+
rtnval = (
|
|
177
|
+
"DigitalOceanApiTokenCredential("
|
|
178
|
+
"identifier={!r}, categories={!r}, token='***', spaces_keys={})"
|
|
179
|
+
).format(self._identifier, self._categories, spaces)
|
|
180
|
+
|
|
181
|
+
return rtnval
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: equinixmetalapitokencredential
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`EquinixMetalApiTokenCredential` which
|
|
5
|
+
wraps the Equinix Metal venue API-token authentication material.
|
|
6
|
+
|
|
7
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__author__ = "Myron Walker"
|
|
11
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
12
|
+
__credits__ = []
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
16
|
+
|
|
17
|
+
import os
|
|
18
|
+
|
|
19
|
+
from ccai.errors.exceptions import ConfigurationError
|
|
20
|
+
|
|
21
|
+
from ccai.credentials.basecredential import BaseCredential
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class EquinixMetalApiTokenCredential(BaseCredential):
|
|
25
|
+
"""
|
|
26
|
+
The :class:`EquinixMetalApiTokenCredential` is a container object that wraps the
|
|
27
|
+
Equinix Metal venue API-token authentication material.
|
|
28
|
+
|
|
29
|
+
.. code:: yaml
|
|
30
|
+
"identifier": "equinix-token"
|
|
31
|
+
"category": "cloud-venue"
|
|
32
|
+
"provider": "equinix-metal"
|
|
33
|
+
"token": "..."
|
|
34
|
+
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(self, *, identifier: str, categories: List[str], token: str,
|
|
38
|
+
role: Optional[str] = "priv") -> None:
|
|
39
|
+
"""
|
|
40
|
+
Initializes an :class:`EquinixMetalApiTokenCredential` instance.
|
|
41
|
+
|
|
42
|
+
:param identifier: The identifier that is used to reference this credential. (required)
|
|
43
|
+
:param categories: The categories of authentication that are supported by the credential.
|
|
44
|
+
:param token: The Equinix Metal API token value.
|
|
45
|
+
:param role: Identifies the role of the credential.
|
|
46
|
+
|
|
47
|
+
:raises: ConfigurationError
|
|
48
|
+
"""
|
|
49
|
+
super().__init__(identifier=identifier, categories=categories, role=role)
|
|
50
|
+
|
|
51
|
+
if "cloud-venue" not in categories:
|
|
52
|
+
errmsg_lines = [
|
|
53
|
+
"The EquinixMetalApiTokenCredential should be given credentials of category 'cloud-venue'.",
|
|
54
|
+
"MISSING CATEGORY: cloud-venue",
|
|
55
|
+
]
|
|
56
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
57
|
+
raise ConfigurationError(errmsg)
|
|
58
|
+
|
|
59
|
+
if token is None or len(token) == 0:
|
|
60
|
+
raise ConfigurationError("The EquinixMetalApiTokenCredential constructor requires a non-empty 'token' parameter be provided.")
|
|
61
|
+
|
|
62
|
+
self._token = token
|
|
63
|
+
return
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def token(self) -> str:
|
|
67
|
+
"""
|
|
68
|
+
Returns the Equinix Metal API token value.
|
|
69
|
+
|
|
70
|
+
:returns: The API token string.
|
|
71
|
+
"""
|
|
72
|
+
return self._token
|
|
73
|
+
|
|
74
|
+
@classmethod
|
|
75
|
+
def validate(cls, cred_info: Dict[str, Any]) -> Tuple[List[str], List[str]]:
|
|
76
|
+
"""
|
|
77
|
+
Validates the dictionary describing an Equinix Metal API-token credential.
|
|
78
|
+
|
|
79
|
+
:param cred_info: Credential definition dictionary to validate.
|
|
80
|
+
|
|
81
|
+
:returns: A tuple of lists containing errors and warnings.
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
errors = []
|
|
85
|
+
warnings = []
|
|
86
|
+
|
|
87
|
+
if "token" not in cred_info:
|
|
88
|
+
errors.append("missing 'token' in equinix-metal-api-token credential.")
|
|
89
|
+
|
|
90
|
+
return errors, warnings
|
|
91
|
+
|
|
92
|
+
def as_dict(self) -> Dict[str, Any]:
|
|
93
|
+
"""
|
|
94
|
+
Returns a dictionary representation of this credential object.
|
|
95
|
+
"""
|
|
96
|
+
rtnval = super().as_dict()
|
|
97
|
+
|
|
98
|
+
rtnval["token"] = self._token
|
|
99
|
+
|
|
100
|
+
return rtnval
|
|
101
|
+
|
|
102
|
+
def __repr__(self) -> str:
|
|
103
|
+
"""
|
|
104
|
+
Returns a debug representation of this credential with the token redacted.
|
|
105
|
+
|
|
106
|
+
:returns: A redacted string representation safe for logs.
|
|
107
|
+
"""
|
|
108
|
+
rtnval = (
|
|
109
|
+
"EquinixMetalApiTokenCredential("
|
|
110
|
+
"identifier={!r}, categories={!r}, token='***')"
|
|
111
|
+
).format(self._identifier, self._categories)
|
|
112
|
+
|
|
113
|
+
return rtnval
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: gcpserviceaccountkeycredential
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`GcpServiceAccountKeyCredential` which
|
|
5
|
+
wraps the contents of a GCP service-account JSON key.
|
|
6
|
+
|
|
7
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__author__ = "Myron Walker"
|
|
11
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
12
|
+
__credits__ = []
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
16
|
+
|
|
17
|
+
import os
|
|
18
|
+
|
|
19
|
+
from ccai.errors.exceptions import ConfigurationError
|
|
20
|
+
|
|
21
|
+
from ccai.credentials.basecredential import BaseCredential
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class GcpServiceAccountKeyCredential(BaseCredential):
|
|
25
|
+
"""
|
|
26
|
+
The :class:`GcpServiceAccountKeyCredential` is a container object that wraps the
|
|
27
|
+
contents of a Google Cloud Platform service-account JSON key.
|
|
28
|
+
|
|
29
|
+
.. code:: yaml
|
|
30
|
+
"identifier": "gcp-sa"
|
|
31
|
+
"category": "cloud-venue"
|
|
32
|
+
"provider": "gcp-service-account"
|
|
33
|
+
"project_id": "my-project"
|
|
34
|
+
"client_email": "svc@my-project.iam.gserviceaccount.com"
|
|
35
|
+
"private_key_id": "abcdef0123456789"
|
|
36
|
+
"private_key": "-----BEGIN PRIVATE KEY-----\\n...\\n-----END PRIVATE KEY-----\\n"
|
|
37
|
+
"token_uri": "https://oauth2.googleapis.com/token"
|
|
38
|
+
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
DEFAULT_TOKEN_URI = "https://oauth2.googleapis.com/token"
|
|
42
|
+
|
|
43
|
+
def __init__(self, *, identifier: str, categories: List[str], project_id: str, client_email: str,
|
|
44
|
+
private_key_id: str, private_key: str, token_uri: Optional[str] = None,
|
|
45
|
+
role: Optional[str] = "priv") -> None:
|
|
46
|
+
"""
|
|
47
|
+
Initializes a :class:`GcpServiceAccountKeyCredential` instance.
|
|
48
|
+
|
|
49
|
+
:param identifier: The identifier that is used to reference this credential. (required)
|
|
50
|
+
:param categories: The categories of authentication that are supported by the credential.
|
|
51
|
+
:param project_id: The GCP project id the service account belongs to.
|
|
52
|
+
:param client_email: The service account client email address.
|
|
53
|
+
:param private_key_id: The identifier of the service account private key.
|
|
54
|
+
:param private_key: The PEM body of the service account private key.
|
|
55
|
+
:param token_uri: The OAuth2 token endpoint; defaults to :data:`DEFAULT_TOKEN_URI`.
|
|
56
|
+
:param role: Identifies the role of the credential.
|
|
57
|
+
|
|
58
|
+
:raises: ConfigurationError
|
|
59
|
+
"""
|
|
60
|
+
super().__init__(identifier=identifier, categories=categories, role=role)
|
|
61
|
+
|
|
62
|
+
if "cloud-venue" not in categories:
|
|
63
|
+
errmsg_lines = [
|
|
64
|
+
"The GcpServiceAccountKeyCredential should be given credentials of category 'cloud-venue'.",
|
|
65
|
+
"MISSING CATEGORY: cloud-venue",
|
|
66
|
+
]
|
|
67
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
68
|
+
raise ConfigurationError(errmsg)
|
|
69
|
+
|
|
70
|
+
if project_id is None or len(project_id) == 0:
|
|
71
|
+
raise ConfigurationError("The GcpServiceAccountKeyCredential constructor requires a non-empty 'project_id' parameter be provided.")
|
|
72
|
+
if client_email is None or len(client_email) == 0:
|
|
73
|
+
raise ConfigurationError("The GcpServiceAccountKeyCredential constructor requires a non-empty 'client_email' parameter be provided.")
|
|
74
|
+
if private_key_id is None or len(private_key_id) == 0:
|
|
75
|
+
raise ConfigurationError("The GcpServiceAccountKeyCredential constructor requires a non-empty 'private_key_id' parameter be provided.")
|
|
76
|
+
if private_key is None or len(private_key) == 0:
|
|
77
|
+
raise ConfigurationError("The GcpServiceAccountKeyCredential constructor requires a non-empty 'private_key' parameter be provided.")
|
|
78
|
+
|
|
79
|
+
effective_token_uri = token_uri
|
|
80
|
+
if effective_token_uri is None or len(effective_token_uri) == 0:
|
|
81
|
+
effective_token_uri = self.DEFAULT_TOKEN_URI
|
|
82
|
+
|
|
83
|
+
self._project_id = project_id
|
|
84
|
+
self._client_email = client_email
|
|
85
|
+
self._private_key_id = private_key_id
|
|
86
|
+
self._private_key = private_key
|
|
87
|
+
self._token_uri = effective_token_uri
|
|
88
|
+
return
|
|
89
|
+
|
|
90
|
+
@property
|
|
91
|
+
def project_id(self) -> str:
|
|
92
|
+
"""
|
|
93
|
+
Returns the GCP project id.
|
|
94
|
+
|
|
95
|
+
:returns: The project id string.
|
|
96
|
+
"""
|
|
97
|
+
return self._project_id
|
|
98
|
+
|
|
99
|
+
@property
|
|
100
|
+
def client_email(self) -> str:
|
|
101
|
+
"""
|
|
102
|
+
Returns the service account client email address.
|
|
103
|
+
|
|
104
|
+
:returns: The client email string.
|
|
105
|
+
"""
|
|
106
|
+
return self._client_email
|
|
107
|
+
|
|
108
|
+
@property
|
|
109
|
+
def private_key_id(self) -> str:
|
|
110
|
+
"""
|
|
111
|
+
Returns the identifier of the service account private key.
|
|
112
|
+
|
|
113
|
+
:returns: The private key id string.
|
|
114
|
+
"""
|
|
115
|
+
return self._private_key_id
|
|
116
|
+
|
|
117
|
+
@property
|
|
118
|
+
def private_key(self) -> str:
|
|
119
|
+
"""
|
|
120
|
+
Returns the PEM body of the service account private key.
|
|
121
|
+
|
|
122
|
+
:returns: The private key string.
|
|
123
|
+
"""
|
|
124
|
+
return self._private_key
|
|
125
|
+
|
|
126
|
+
@property
|
|
127
|
+
def token_uri(self) -> str:
|
|
128
|
+
"""
|
|
129
|
+
Returns the OAuth2 token endpoint URI.
|
|
130
|
+
|
|
131
|
+
:returns: The token URI string.
|
|
132
|
+
"""
|
|
133
|
+
return self._token_uri
|
|
134
|
+
|
|
135
|
+
@classmethod
|
|
136
|
+
def validate(cls, cred_info: Dict[str, Any]) -> Tuple[List[str], List[str]]:
|
|
137
|
+
"""
|
|
138
|
+
Validates the dictionary describing a GCP service account key credential.
|
|
139
|
+
|
|
140
|
+
:param cred_info: Credential definition dictionary to validate.
|
|
141
|
+
|
|
142
|
+
:returns: A tuple of lists containing errors and warnings.
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
errors = []
|
|
146
|
+
warnings = []
|
|
147
|
+
|
|
148
|
+
if "project_id" not in cred_info:
|
|
149
|
+
errors.append("missing 'project_id' in gcp-service-account-key credential.")
|
|
150
|
+
|
|
151
|
+
if "client_email" not in cred_info:
|
|
152
|
+
errors.append("missing 'client_email' in gcp-service-account-key credential.")
|
|
153
|
+
|
|
154
|
+
if "private_key_id" not in cred_info:
|
|
155
|
+
errors.append("missing 'private_key_id' in gcp-service-account-key credential.")
|
|
156
|
+
|
|
157
|
+
if "private_key" not in cred_info:
|
|
158
|
+
errors.append("missing 'private_key' in gcp-service-account-key credential.")
|
|
159
|
+
|
|
160
|
+
return errors, warnings
|
|
161
|
+
|
|
162
|
+
def as_dict(self) -> Dict[str, Any]:
|
|
163
|
+
"""
|
|
164
|
+
Returns a dictionary representation of this credential object.
|
|
165
|
+
"""
|
|
166
|
+
rtnval = super().as_dict()
|
|
167
|
+
|
|
168
|
+
rtnval["project_id"] = self._project_id
|
|
169
|
+
rtnval["client_email"] = self._client_email
|
|
170
|
+
rtnval["private_key_id"] = self._private_key_id
|
|
171
|
+
rtnval["private_key"] = self._private_key
|
|
172
|
+
rtnval["token_uri"] = self._token_uri
|
|
173
|
+
|
|
174
|
+
return rtnval
|
|
175
|
+
|
|
176
|
+
def __repr__(self) -> str:
|
|
177
|
+
"""
|
|
178
|
+
Returns a debug representation of this credential with private key material redacted.
|
|
179
|
+
|
|
180
|
+
:returns: A redacted string representation safe for logs.
|
|
181
|
+
"""
|
|
182
|
+
rtnval = (
|
|
183
|
+
"GcpServiceAccountKeyCredential("
|
|
184
|
+
"identifier={!r}, categories={!r}, project_id={!r}, client_email={!r}, "
|
|
185
|
+
"private_key_id='***', private_key='***', token_uri={!r})"
|
|
186
|
+
).format(self._identifier, self._categories, self._project_id, self._client_email, self._token_uri)
|
|
187
|
+
|
|
188
|
+
return rtnval
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: gcpworkloadidentitycredential
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`GcpWorkloadIdentityCredential` which
|
|
5
|
+
wraps a GCP Workload Identity Federation assertion.
|
|
6
|
+
|
|
7
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__author__ = "Myron Walker"
|
|
11
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
12
|
+
__credits__ = []
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
16
|
+
|
|
17
|
+
import os
|
|
18
|
+
|
|
19
|
+
from ccai.errors.exceptions import ConfigurationError
|
|
20
|
+
|
|
21
|
+
from ccai.credentials.basecredential import BaseCredential
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class GcpWorkloadIdentityCredential(BaseCredential):
|
|
25
|
+
"""
|
|
26
|
+
The :class:`GcpWorkloadIdentityCredential` is a container object that wraps a
|
|
27
|
+
Google Cloud Platform Workload Identity Federation assertion.
|
|
28
|
+
|
|
29
|
+
.. code:: yaml
|
|
30
|
+
"identifier": "gcp-wif"
|
|
31
|
+
"category": "cloud-venue"
|
|
32
|
+
"provider": "gcp-workload-identity"
|
|
33
|
+
"audience": "//iam.googleapis.com/projects/123/locations/global/workloadIdentityPools/pool/providers/provider"
|
|
34
|
+
"subject_token_type": "urn:ietf:params:oauth:token-type:jwt"
|
|
35
|
+
"service_account_email": "svc@my-project.iam.gserviceaccount.com"
|
|
36
|
+
"token_url": "https://sts.googleapis.com/v1/token"
|
|
37
|
+
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
DEFAULT_TOKEN_URL = "https://sts.googleapis.com/v1/token"
|
|
41
|
+
|
|
42
|
+
def __init__(self, *, identifier: str, categories: List[str], audience: str, subject_token_type: str,
|
|
43
|
+
service_account_email: str, token_url: Optional[str] = None,
|
|
44
|
+
role: Optional[str] = "priv") -> None:
|
|
45
|
+
"""
|
|
46
|
+
Initializes a :class:`GcpWorkloadIdentityCredential` instance.
|
|
47
|
+
|
|
48
|
+
:param identifier: The identifier that is used to reference this credential. (required)
|
|
49
|
+
:param categories: The categories of authentication that are supported by the credential.
|
|
50
|
+
:param audience: The workload identity pool provider audience string.
|
|
51
|
+
:param subject_token_type: The subject token type for the federated assertion.
|
|
52
|
+
:param service_account_email: The target service account email to impersonate.
|
|
53
|
+
:param token_url: The security token service endpoint; defaults to :data:`DEFAULT_TOKEN_URL`.
|
|
54
|
+
:param role: Identifies the role of the credential.
|
|
55
|
+
|
|
56
|
+
:raises: ConfigurationError
|
|
57
|
+
"""
|
|
58
|
+
super().__init__(identifier=identifier, categories=categories, role=role)
|
|
59
|
+
|
|
60
|
+
if "cloud-venue" not in categories:
|
|
61
|
+
errmsg_lines = [
|
|
62
|
+
"The GcpWorkloadIdentityCredential should be given credentials of category 'cloud-venue'.",
|
|
63
|
+
"MISSING CATEGORY: cloud-venue",
|
|
64
|
+
]
|
|
65
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
66
|
+
raise ConfigurationError(errmsg)
|
|
67
|
+
|
|
68
|
+
if audience is None or len(audience) == 0:
|
|
69
|
+
raise ConfigurationError("The GcpWorkloadIdentityCredential constructor requires a non-empty 'audience' parameter be provided.")
|
|
70
|
+
if subject_token_type is None or len(subject_token_type) == 0:
|
|
71
|
+
raise ConfigurationError("The GcpWorkloadIdentityCredential constructor requires a non-empty 'subject_token_type' parameter be provided.")
|
|
72
|
+
if service_account_email is None or len(service_account_email) == 0:
|
|
73
|
+
raise ConfigurationError("The GcpWorkloadIdentityCredential constructor requires a non-empty 'service_account_email' parameter be provided.")
|
|
74
|
+
|
|
75
|
+
effective_token_url = token_url
|
|
76
|
+
if effective_token_url is None or len(effective_token_url) == 0:
|
|
77
|
+
effective_token_url = self.DEFAULT_TOKEN_URL
|
|
78
|
+
|
|
79
|
+
self._audience = audience
|
|
80
|
+
self._subject_token_type = subject_token_type
|
|
81
|
+
self._service_account_email = service_account_email
|
|
82
|
+
self._token_url = effective_token_url
|
|
83
|
+
return
|
|
84
|
+
|
|
85
|
+
@property
|
|
86
|
+
def audience(self) -> str:
|
|
87
|
+
"""
|
|
88
|
+
Returns the workload identity pool provider audience.
|
|
89
|
+
|
|
90
|
+
:returns: The audience string.
|
|
91
|
+
"""
|
|
92
|
+
return self._audience
|
|
93
|
+
|
|
94
|
+
@property
|
|
95
|
+
def subject_token_type(self) -> str:
|
|
96
|
+
"""
|
|
97
|
+
Returns the subject token type for the federated assertion.
|
|
98
|
+
|
|
99
|
+
:returns: The subject token type string.
|
|
100
|
+
"""
|
|
101
|
+
return self._subject_token_type
|
|
102
|
+
|
|
103
|
+
@property
|
|
104
|
+
def service_account_email(self) -> str:
|
|
105
|
+
"""
|
|
106
|
+
Returns the target service account email.
|
|
107
|
+
|
|
108
|
+
:returns: The service account email string.
|
|
109
|
+
"""
|
|
110
|
+
return self._service_account_email
|
|
111
|
+
|
|
112
|
+
@property
|
|
113
|
+
def token_url(self) -> str:
|
|
114
|
+
"""
|
|
115
|
+
Returns the security token service endpoint URL.
|
|
116
|
+
|
|
117
|
+
:returns: The token URL string.
|
|
118
|
+
"""
|
|
119
|
+
return self._token_url
|
|
120
|
+
|
|
121
|
+
@classmethod
|
|
122
|
+
def validate(cls, cred_info: Dict[str, Any]) -> Tuple[List[str], List[str]]:
|
|
123
|
+
"""
|
|
124
|
+
Validates the dictionary describing a GCP workload identity credential.
|
|
125
|
+
|
|
126
|
+
:param cred_info: Credential definition dictionary to validate.
|
|
127
|
+
|
|
128
|
+
:returns: A tuple of lists containing errors and warnings.
|
|
129
|
+
"""
|
|
130
|
+
|
|
131
|
+
errors = []
|
|
132
|
+
warnings = []
|
|
133
|
+
|
|
134
|
+
if "audience" not in cred_info:
|
|
135
|
+
errors.append("missing 'audience' in gcp-workload-identity credential.")
|
|
136
|
+
|
|
137
|
+
if "subject_token_type" not in cred_info:
|
|
138
|
+
errors.append("missing 'subject_token_type' in gcp-workload-identity credential.")
|
|
139
|
+
|
|
140
|
+
if "service_account_email" not in cred_info:
|
|
141
|
+
errors.append("missing 'service_account_email' in gcp-workload-identity credential.")
|
|
142
|
+
|
|
143
|
+
return errors, warnings
|
|
144
|
+
|
|
145
|
+
def as_dict(self) -> Dict[str, Any]:
|
|
146
|
+
"""
|
|
147
|
+
Returns a dictionary representation of this credential object.
|
|
148
|
+
"""
|
|
149
|
+
rtnval = super().as_dict()
|
|
150
|
+
|
|
151
|
+
rtnval["audience"] = self._audience
|
|
152
|
+
rtnval["subject_token_type"] = self._subject_token_type
|
|
153
|
+
rtnval["service_account_email"] = self._service_account_email
|
|
154
|
+
rtnval["token_url"] = self._token_url
|
|
155
|
+
|
|
156
|
+
return rtnval
|
|
157
|
+
|
|
158
|
+
def __repr__(self) -> str:
|
|
159
|
+
"""
|
|
160
|
+
Returns a debug representation of this credential.
|
|
161
|
+
|
|
162
|
+
:returns: A string representation safe for logs.
|
|
163
|
+
"""
|
|
164
|
+
rtnval = (
|
|
165
|
+
"GcpWorkloadIdentityCredential("
|
|
166
|
+
"identifier={!r}, categories={!r}, audience={!r}, subject_token_type={!r}, "
|
|
167
|
+
"service_account_email={!r}, token_url={!r})"
|
|
168
|
+
).format(
|
|
169
|
+
self._identifier, self._categories, self._audience, self._subject_token_type,
|
|
170
|
+
self._service_account_email, self._token_url,
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
return rtnval
|