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,453 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: credentialmanager
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`CredentialManager` which is used to
|
|
5
|
+
load credentials.
|
|
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 Dict, List, Optional, Union
|
|
16
|
+
|
|
17
|
+
import logging
|
|
18
|
+
import os
|
|
19
|
+
|
|
20
|
+
from ccai.errors.exceptions import ConfigurationError
|
|
21
|
+
|
|
22
|
+
from ccai.credentials.apitokencredential import ApiTokenCredential
|
|
23
|
+
from ccai.credentials.awsaccesskeycredential import AwsAccessKeyCredential
|
|
24
|
+
from ccai.credentials.azureclientsecretcredential import AzureClientSecretCredential
|
|
25
|
+
from ccai.credentials.basecredential import BaseCredential
|
|
26
|
+
from ccai.credentials.basiccredential import BasicCredential
|
|
27
|
+
from ccai.credentials.githubappcredential import GithubAppCredential
|
|
28
|
+
from ccai.credentials.githubtokencredential import GithubTokenCredential
|
|
29
|
+
from ccai.credentials.personalapitokencredential import PersonalApiTokenCredential
|
|
30
|
+
from ccai.credentials.publickeycredential import PublicKeyCredential
|
|
31
|
+
from ccai.credentials.secrettokencredential import SecretTokenCredential
|
|
32
|
+
from ccai.credentials.sshcredential import SshCredential
|
|
33
|
+
from ccai.credentials.tailscaleauthkeycredential import TailscaleAuthKeyCredential
|
|
34
|
+
from ccai.credentials.tailscaleoauthcredential import TailscaleOAuthCredential
|
|
35
|
+
from ccai.credentials.twingateserviceaccountcredential import TwingateServiceAccountCredential
|
|
36
|
+
from ccai.credentials.wifichoicecredential import WifiChoiceCredential
|
|
37
|
+
|
|
38
|
+
from ccai.credentials.venueregistry import (
|
|
39
|
+
VENUE_PROVIDER_REGISTRY,
|
|
40
|
+
VENUE_UMBRELLA_CATEGORIES,
|
|
41
|
+
known_providers,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
logger = logging.getLogger(__name__)
|
|
45
|
+
|
|
46
|
+
class CredentialManager:
|
|
47
|
+
"""
|
|
48
|
+
The :class:`CredentialManager` provides for loading credential
|
|
49
|
+
definitions and returning credential objects on demand.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
def __init__(self):
|
|
53
|
+
"""
|
|
54
|
+
Initializes an instance of the :class:`CredentialManager` class.
|
|
55
|
+
|
|
56
|
+
The manager maintains a collection of credential objects loaded from
|
|
57
|
+
configuration sources.
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
self._credentials = {}
|
|
61
|
+
self._source_uris = []
|
|
62
|
+
|
|
63
|
+
return
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def credentials(self):
|
|
67
|
+
"""
|
|
68
|
+
Returns the dictionary of credentials loaded by the manager.
|
|
69
|
+
|
|
70
|
+
:returns: Dictionary mapping credential identifiers to credential objects.
|
|
71
|
+
"""
|
|
72
|
+
return self._credentials
|
|
73
|
+
|
|
74
|
+
def lookup_credential(self, credkey: str) -> Union[ApiTokenCredential,
|
|
75
|
+
AzureClientSecretCredential,
|
|
76
|
+
BasicCredential,
|
|
77
|
+
GithubAppCredential,
|
|
78
|
+
GithubTokenCredential,
|
|
79
|
+
PersonalApiTokenCredential,
|
|
80
|
+
PublicKeyCredential,
|
|
81
|
+
SecretTokenCredential,
|
|
82
|
+
SshCredential,
|
|
83
|
+
WifiChoiceCredential]:
|
|
84
|
+
"""
|
|
85
|
+
Lookup a credential by key.
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
if credkey not in self._credentials:
|
|
89
|
+
|
|
90
|
+
errmsg_lines = [
|
|
91
|
+
f"Error missing credential '{credkey}'."
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
if len(self._source_uris) > 0:
|
|
95
|
+
errmsg_lines.append("CREDENTIAL URIS:")
|
|
96
|
+
|
|
97
|
+
for cfile in self._source_uris:
|
|
98
|
+
errmsg_lines.append(f" {cfile}")
|
|
99
|
+
|
|
100
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
101
|
+
|
|
102
|
+
raise ConfigurationError(errmsg)
|
|
103
|
+
|
|
104
|
+
cred = self._credentials[credkey]
|
|
105
|
+
|
|
106
|
+
return cred
|
|
107
|
+
|
|
108
|
+
def lookup_multiple_credentials(self, credential_keys: List[str]) -> Dict[str, BaseCredential]:
|
|
109
|
+
"""
|
|
110
|
+
Lookup a list of credentials by key and return a dictionary of credential names to
|
|
111
|
+
credentails.
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
cred_table = {}
|
|
115
|
+
|
|
116
|
+
for credkey in credential_keys:
|
|
117
|
+
if credkey not in self._credentials:
|
|
118
|
+
|
|
119
|
+
errmsg_lines = [
|
|
120
|
+
f"Error missing credential '{credkey}'."
|
|
121
|
+
]
|
|
122
|
+
|
|
123
|
+
if len(self._source_uris) > 0:
|
|
124
|
+
errmsg_lines.append("CREDENTIAL URIS:")
|
|
125
|
+
|
|
126
|
+
for cfile in self._source_uris:
|
|
127
|
+
errmsg_lines.append(f" {cfile}")
|
|
128
|
+
|
|
129
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
130
|
+
|
|
131
|
+
raise ConfigurationError(errmsg)
|
|
132
|
+
|
|
133
|
+
cred = self._credentials[credkey]
|
|
134
|
+
|
|
135
|
+
cred_table[credkey] = cred
|
|
136
|
+
|
|
137
|
+
return cred_table
|
|
138
|
+
|
|
139
|
+
def get_credentials_by_categories(self, *, categories: List[str]) -> List[BaseCredential]:
|
|
140
|
+
"""
|
|
141
|
+
Returns the list of loaded credentials whose declared categories intersect the
|
|
142
|
+
requested category list.
|
|
143
|
+
|
|
144
|
+
:param categories: The list of categories to filter the loaded credentials against.
|
|
145
|
+
|
|
146
|
+
:returns: The list of matching :class:`BaseCredential` instances (possibly empty).
|
|
147
|
+
"""
|
|
148
|
+
|
|
149
|
+
category_set = set(categories)
|
|
150
|
+
|
|
151
|
+
matches = []
|
|
152
|
+
|
|
153
|
+
for cred in self._credentials.values():
|
|
154
|
+
cred_categories = set(cred.categories)
|
|
155
|
+
intersection = category_set & cred_categories
|
|
156
|
+
if len(intersection) > 0:
|
|
157
|
+
matches.append(cred)
|
|
158
|
+
|
|
159
|
+
rtnval = matches
|
|
160
|
+
return rtnval
|
|
161
|
+
|
|
162
|
+
def load_credentials(self, credential_info: dict, source_uris: Optional[List[str]] = None):
|
|
163
|
+
"""
|
|
164
|
+
Loads credentials from a dictionary object.
|
|
165
|
+
|
|
166
|
+
:param credential_info: Dictionary containing credential definitions.
|
|
167
|
+
:param source_uris: Optional list of source URIs for the credentials.
|
|
168
|
+
"""
|
|
169
|
+
|
|
170
|
+
if source_uris != None:
|
|
171
|
+
self._source_uris.extend(source_uris)
|
|
172
|
+
|
|
173
|
+
if credential_info is not None and len(credential_info) > 0:
|
|
174
|
+
try:
|
|
175
|
+
credentials_list = credential_info["credentials"]
|
|
176
|
+
errors, warnings = self._validate_credentials(credentials_list)
|
|
177
|
+
|
|
178
|
+
if len(errors) == 0:
|
|
179
|
+
for credential in credentials_list:
|
|
180
|
+
# Copy the credential so if we modify it, we dont modify the
|
|
181
|
+
# original declaration.
|
|
182
|
+
credential = credential.copy()
|
|
183
|
+
|
|
184
|
+
if "identifier" not in credential:
|
|
185
|
+
errmsg = "Credential items in 'environment/credentials' must have an 'identifier' member."
|
|
186
|
+
raise ConfigurationError(errmsg)
|
|
187
|
+
ident = credential["identifier"]
|
|
188
|
+
|
|
189
|
+
if "category" not in credential and "categories" not in credential:
|
|
190
|
+
errmsg = "Credential items in 'environment/credentials' must have an 'category' or categories member."
|
|
191
|
+
raise ConfigurationError(errmsg)
|
|
192
|
+
|
|
193
|
+
# If we find a 'category' or 'categories' parameter we need to pass the categories along as a single
|
|
194
|
+
# list parameter
|
|
195
|
+
categories = []
|
|
196
|
+
if "category" in credential:
|
|
197
|
+
category = credential["category"]
|
|
198
|
+
del credential["category"]
|
|
199
|
+
|
|
200
|
+
if isinstance(category, list):
|
|
201
|
+
categories = category
|
|
202
|
+
else:
|
|
203
|
+
categories = [ category]
|
|
204
|
+
|
|
205
|
+
credential["categories"] = categories
|
|
206
|
+
|
|
207
|
+
elif "categories" in credential:
|
|
208
|
+
categories = credential["categories"]
|
|
209
|
+
|
|
210
|
+
if isinstance(categories, str):
|
|
211
|
+
categories = [ categories ]
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
# If the credential has more than one category, we create a simple `BasicCredential` which has a common set of
|
|
215
|
+
# attributes. The only credential we support with common attributes is a simple 'username' and 'password' credential
|
|
216
|
+
if len(categories) > 1:
|
|
217
|
+
|
|
218
|
+
for category in categories:
|
|
219
|
+
if category not in ['basic', 'ssh', 'rest-basic']:
|
|
220
|
+
errmsg = "The only categories of credentials that can be used together are ['basic', 'ssh (with password)', 'rest-basic']"
|
|
221
|
+
raise ConfigurationError(errmsg)
|
|
222
|
+
|
|
223
|
+
if "username" in credential and "password" in credential:
|
|
224
|
+
|
|
225
|
+
username = credential["username"]
|
|
226
|
+
password = credential["password"]
|
|
227
|
+
|
|
228
|
+
credobj = BasicCredential(identifier=ident, categories=categories, username=username, password=password)
|
|
229
|
+
|
|
230
|
+
self._credentials[ident] = credobj
|
|
231
|
+
|
|
232
|
+
else:
|
|
233
|
+
errmsg = "Multi category credentials must have common attributes. Currently, the only common credential supported is a 'username' and 'password' credential."
|
|
234
|
+
raise ConfigurationError(errmsg)
|
|
235
|
+
|
|
236
|
+
else:
|
|
237
|
+
category = categories[0]
|
|
238
|
+
|
|
239
|
+
if category == "api-token":
|
|
240
|
+
credobj = ApiTokenCredential(**credential)
|
|
241
|
+
self._credentials[ident] = credobj
|
|
242
|
+
|
|
243
|
+
elif category == "aws-access-key":
|
|
244
|
+
credobj = AwsAccessKeyCredential(**credential)
|
|
245
|
+
self._credentials[ident] = credobj
|
|
246
|
+
|
|
247
|
+
elif category == 'azure-client-secret':
|
|
248
|
+
credobj = AzureClientSecretCredential(**credential)
|
|
249
|
+
self._credentials[ident] = credobj
|
|
250
|
+
|
|
251
|
+
elif category == "basic" or category == "rest-basic":
|
|
252
|
+
credobj = BasicCredential(**credential)
|
|
253
|
+
self._credentials[ident] = credobj
|
|
254
|
+
|
|
255
|
+
elif category == "github-app":
|
|
256
|
+
credobj = GithubAppCredential(**credential)
|
|
257
|
+
self._credentials[ident] = credobj
|
|
258
|
+
|
|
259
|
+
elif category == "github-token":
|
|
260
|
+
credobj = GithubTokenCredential(**credential)
|
|
261
|
+
self._credentials[ident] = credobj
|
|
262
|
+
|
|
263
|
+
elif category == "personal-api-token":
|
|
264
|
+
credobj = PersonalApiTokenCredential(**credential)
|
|
265
|
+
self._credentials[ident] = credobj
|
|
266
|
+
|
|
267
|
+
elif category == "public-key":
|
|
268
|
+
credobj = PublicKeyCredential(**credential)
|
|
269
|
+
self._credentials[ident] = credobj
|
|
270
|
+
|
|
271
|
+
elif category == "secret-token":
|
|
272
|
+
credobj = SecretTokenCredential(**credential)
|
|
273
|
+
self._credentials[ident] = credobj
|
|
274
|
+
|
|
275
|
+
elif category == "ssh":
|
|
276
|
+
credobj = SshCredential(**credential)
|
|
277
|
+
self._credentials[ident] = credobj
|
|
278
|
+
|
|
279
|
+
elif category == "tailscale-authkey":
|
|
280
|
+
credobj = TailscaleAuthKeyCredential(**credential)
|
|
281
|
+
self._credentials[ident] = credobj
|
|
282
|
+
|
|
283
|
+
elif category == "tailscale-oauth":
|
|
284
|
+
credobj = TailscaleOAuthCredential(**credential)
|
|
285
|
+
self._credentials[ident] = credobj
|
|
286
|
+
|
|
287
|
+
elif category == "twingate-service-account":
|
|
288
|
+
credobj = TwingateServiceAccountCredential(**credential)
|
|
289
|
+
self._credentials[ident] = credobj
|
|
290
|
+
|
|
291
|
+
elif category == "wifi-choice":
|
|
292
|
+
credobj = WifiChoiceCredential(**credential)
|
|
293
|
+
self._credentials[ident] = credobj
|
|
294
|
+
|
|
295
|
+
elif category in VENUE_UMBRELLA_CATEGORIES:
|
|
296
|
+
# Venue umbrella categories are shared across many
|
|
297
|
+
# providers, so a 'provider' discriminator selects the
|
|
298
|
+
# concrete class. Validation (above) has already
|
|
299
|
+
# guaranteed a known provider is present, so a missing
|
|
300
|
+
# key here is a hard error rather than a silent drop.
|
|
301
|
+
provider = credential.get("provider", None)
|
|
302
|
+
if provider is None or provider not in VENUE_PROVIDER_REGISTRY:
|
|
303
|
+
errmsg = f"Venue credential '{ident}' (category '{category}') requires a known 'provider'. KNOWN PROVIDERS: {known_providers()}"
|
|
304
|
+
raise ConfigurationError(errmsg)
|
|
305
|
+
cred_class = VENUE_PROVIDER_REGISTRY[provider]
|
|
306
|
+
# 'provider' is a manager-level dispatch field, not a
|
|
307
|
+
# constructor argument for the concrete credential class.
|
|
308
|
+
cred_data = dict(credential)
|
|
309
|
+
del cred_data["provider"]
|
|
310
|
+
credobj = cred_class(**cred_data)
|
|
311
|
+
self._credentials[ident] = credobj
|
|
312
|
+
|
|
313
|
+
else:
|
|
314
|
+
errmsg = f"Unknown category '{category}' found in credential '{ident}'. The credential cannot be loaded."
|
|
315
|
+
raise ConfigurationError(errmsg)
|
|
316
|
+
|
|
317
|
+
else:
|
|
318
|
+
errmsg_lines = [
|
|
319
|
+
f"Errors found in credentials.",
|
|
320
|
+
"ERRORS:"
|
|
321
|
+
]
|
|
322
|
+
for err in errors:
|
|
323
|
+
errmsg_lines.append(f" {err}")
|
|
324
|
+
|
|
325
|
+
errmsg_lines.append("WARNINGS:")
|
|
326
|
+
for warn in warnings:
|
|
327
|
+
errmsg_lines.append(f" {warn}")
|
|
328
|
+
|
|
329
|
+
errmsg_lines.append("SOURCE_URIS:")
|
|
330
|
+
for suri in self._source_uris:
|
|
331
|
+
errmsg_lines.append(f" {suri}")
|
|
332
|
+
|
|
333
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
334
|
+
raise ConfigurationError(errmsg)
|
|
335
|
+
|
|
336
|
+
except KeyError:
|
|
337
|
+
errmsg = f"No 'credentials' field found."
|
|
338
|
+
raise ConfigurationError(errmsg)
|
|
339
|
+
|
|
340
|
+
return
|
|
341
|
+
|
|
342
|
+
def _validate_credentials(self, cred_list: List[Dict[str, str]]):
|
|
343
|
+
"""
|
|
344
|
+
Validates a list of credential dictionaries for correctness.
|
|
345
|
+
|
|
346
|
+
:param cred_list: List of credential dictionaries.
|
|
347
|
+
|
|
348
|
+
:returns: A tuple containing a list of error strings and warning strings.
|
|
349
|
+
"""
|
|
350
|
+
|
|
351
|
+
errors = []
|
|
352
|
+
warnings = []
|
|
353
|
+
|
|
354
|
+
identifier_set = set()
|
|
355
|
+
|
|
356
|
+
for cinfo in cred_list:
|
|
357
|
+
if "identifier" in cinfo:
|
|
358
|
+
identifier = cinfo["identifier"]
|
|
359
|
+
if identifier in identifier_set:
|
|
360
|
+
errmsg = f"Duplicate identifer found. identifier={identifier}"
|
|
361
|
+
errors.append(errmsg)
|
|
362
|
+
else:
|
|
363
|
+
identifier_set.add(identifier)
|
|
364
|
+
else:
|
|
365
|
+
errmsg = f"All credentials must have an identifier field. cinfo={cinfo}"
|
|
366
|
+
errors.append(errmsg)
|
|
367
|
+
|
|
368
|
+
if "category" in cinfo or "categories" in cinfo:
|
|
369
|
+
|
|
370
|
+
if 'category' in cinfo and 'categories' in cinfo:
|
|
371
|
+
errmsg = "A credential should not have both a 'category' and 'categories' field. The newest method is to just use a 'categories' field."
|
|
372
|
+
raise ConfigurationError(errmsg)
|
|
373
|
+
|
|
374
|
+
categories = None
|
|
375
|
+
|
|
376
|
+
if "category" in cinfo:
|
|
377
|
+
category = cinfo["category"]
|
|
378
|
+
|
|
379
|
+
if isinstance(category, list):
|
|
380
|
+
categories = category
|
|
381
|
+
else:
|
|
382
|
+
categories = [category]
|
|
383
|
+
|
|
384
|
+
elif "categories" in cinfo:
|
|
385
|
+
categories = cinfo["categories"]
|
|
386
|
+
if isinstance(categories, str):
|
|
387
|
+
categories = [categories]
|
|
388
|
+
|
|
389
|
+
if len(categories) > 1:
|
|
390
|
+
for category in categories:
|
|
391
|
+
if category not in ['basic', 'ssh', 'rest-basic']:
|
|
392
|
+
errmsg = "The only categories of credentials that can be used together are ['basic', 'ssh (with password)', 'rest-basic']"
|
|
393
|
+
raise ConfigurationError(errmsg)
|
|
394
|
+
|
|
395
|
+
if "username" not in cinfo or "password" not in cinfo:
|
|
396
|
+
errmsg = "Multi category credentials must have common attributes. Currently, the only common credential supported is a 'username' and 'password' credential."
|
|
397
|
+
raise ConfigurationError(errmsg)
|
|
398
|
+
|
|
399
|
+
else:
|
|
400
|
+
category = categories[0]
|
|
401
|
+
|
|
402
|
+
if category == "basic" or category == "rest-basic":
|
|
403
|
+
child_errors, child_warnings = BasicCredential.validate(cinfo)
|
|
404
|
+
elif category == "ssh":
|
|
405
|
+
child_errors, child_warnings = SshCredential.validate(cinfo)
|
|
406
|
+
elif category == "api-token":
|
|
407
|
+
child_errors, child_warnings = ApiTokenCredential.validate(cinfo)
|
|
408
|
+
elif category == "aws-access-key":
|
|
409
|
+
child_errors, child_warnings = AwsAccessKeyCredential.validate(cinfo)
|
|
410
|
+
elif category == "azure-client-secret":
|
|
411
|
+
child_errors, child_warnings = AzureClientSecretCredential.validate(cinfo)
|
|
412
|
+
elif category == "github-app":
|
|
413
|
+
child_errors, child_warnings = GithubAppCredential.validate(cinfo)
|
|
414
|
+
elif category == "github-token":
|
|
415
|
+
child_errors, child_warnings = GithubTokenCredential.validate(cinfo)
|
|
416
|
+
elif category == "personal-api-token":
|
|
417
|
+
child_errors, child_warnings = PersonalApiTokenCredential.validate(cinfo)
|
|
418
|
+
elif category == "public-key":
|
|
419
|
+
child_errors, child_warnings = PublicKeyCredential.validate(cinfo)
|
|
420
|
+
elif category == "secret-token":
|
|
421
|
+
child_errors, child_warnings = SecretTokenCredential.validate(cinfo)
|
|
422
|
+
elif category == "tailscale-authkey":
|
|
423
|
+
child_errors, child_warnings = TailscaleAuthKeyCredential.validate(cinfo)
|
|
424
|
+
elif category == "tailscale-oauth":
|
|
425
|
+
child_errors, child_warnings = TailscaleOAuthCredential.validate(cinfo)
|
|
426
|
+
elif category == "twingate-service-account":
|
|
427
|
+
child_errors, child_warnings = TwingateServiceAccountCredential.validate(cinfo)
|
|
428
|
+
elif category == "wifi-choice":
|
|
429
|
+
child_errors, child_warnings = WifiChoiceCredential.validate(cinfo)
|
|
430
|
+
elif category in VENUE_UMBRELLA_CATEGORIES:
|
|
431
|
+
provider = cinfo.get("provider", None)
|
|
432
|
+
if provider is None:
|
|
433
|
+
child_errors = [f"Venue credential (category '{category}') must declare a 'provider'. KNOWN PROVIDERS: {known_providers()}. info={cinfo}"]
|
|
434
|
+
child_warnings = []
|
|
435
|
+
elif provider not in VENUE_PROVIDER_REGISTRY:
|
|
436
|
+
child_errors = [f"Unknown venue provider '{provider}'. KNOWN PROVIDERS: {known_providers()}. info={cinfo}"]
|
|
437
|
+
child_warnings = []
|
|
438
|
+
else:
|
|
439
|
+
cred_class = VENUE_PROVIDER_REGISTRY[provider]
|
|
440
|
+
child_errors, child_warnings = cred_class.validate(cinfo)
|
|
441
|
+
else:
|
|
442
|
+
child_errors = [f"Unknown credential category={category}. info={cinfo}"]
|
|
443
|
+
child_warnings = []
|
|
444
|
+
|
|
445
|
+
errors.extend(child_errors)
|
|
446
|
+
warnings.extend(child_warnings)
|
|
447
|
+
|
|
448
|
+
else:
|
|
449
|
+
errmsg = "Credential info has no category. info=%r" % cinfo
|
|
450
|
+
errors.append(errmsg)
|
|
451
|
+
|
|
452
|
+
return errors, warnings
|
|
453
|
+
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: crusoeapikeycredential
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`CrusoeApiKeyCredential` which
|
|
5
|
+
wraps the two-field Crusoe Cloud API credential 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 CrusoeApiKeyCredential(BaseCredential):
|
|
25
|
+
"""
|
|
26
|
+
The :class:`CrusoeApiKeyCredential` is a container object that wraps the
|
|
27
|
+
two-field Crusoe Cloud API credential material.
|
|
28
|
+
|
|
29
|
+
.. code:: yaml
|
|
30
|
+
"identifier": "crusoe-key"
|
|
31
|
+
"category": "hpc-venue"
|
|
32
|
+
"provider": "crusoe"
|
|
33
|
+
"access_key_id": "..."
|
|
34
|
+
"secret": "..."
|
|
35
|
+
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
def __init__(self, *, identifier: str, categories: List[str], access_key_id: str,
|
|
39
|
+
secret: str, role: Optional[str] = "priv") -> None:
|
|
40
|
+
"""
|
|
41
|
+
Initializes a :class:`CrusoeApiKeyCredential` instance.
|
|
42
|
+
|
|
43
|
+
:param identifier: The identifier that is used to reference this credential. (required)
|
|
44
|
+
:param categories: The categories of authentication that are supported by the credential.
|
|
45
|
+
:param access_key_id: The Crusoe Cloud API access key identifier.
|
|
46
|
+
:param secret: The Crusoe Cloud API secret value.
|
|
47
|
+
:param role: Identifies the role of the credential.
|
|
48
|
+
|
|
49
|
+
:raises: ConfigurationError
|
|
50
|
+
"""
|
|
51
|
+
super().__init__(identifier=identifier, categories=categories, role=role)
|
|
52
|
+
|
|
53
|
+
if "cloud-venue" not in categories and "hpc-venue" not in categories:
|
|
54
|
+
errmsg_lines = [
|
|
55
|
+
"The CrusoeApiKeyCredential should be given credentials of category 'cloud-venue' or 'hpc-venue'.",
|
|
56
|
+
"MISSING CATEGORY: at least one of 'cloud-venue' or 'hpc-venue'",
|
|
57
|
+
]
|
|
58
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
59
|
+
raise ConfigurationError(errmsg)
|
|
60
|
+
|
|
61
|
+
if access_key_id is None or len(access_key_id) == 0:
|
|
62
|
+
raise ConfigurationError("The CrusoeApiKeyCredential constructor requires a non-empty 'access_key_id' parameter be provided.")
|
|
63
|
+
if secret is None or len(secret) == 0:
|
|
64
|
+
raise ConfigurationError("The CrusoeApiKeyCredential constructor requires a non-empty 'secret' parameter be provided.")
|
|
65
|
+
|
|
66
|
+
self._access_key_id = access_key_id
|
|
67
|
+
self._secret = secret
|
|
68
|
+
return
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def access_key_id(self) -> str:
|
|
72
|
+
"""
|
|
73
|
+
Returns the Crusoe Cloud API access key identifier.
|
|
74
|
+
|
|
75
|
+
:returns: The access key identifier string.
|
|
76
|
+
"""
|
|
77
|
+
return self._access_key_id
|
|
78
|
+
|
|
79
|
+
@property
|
|
80
|
+
def secret(self) -> str:
|
|
81
|
+
"""
|
|
82
|
+
Returns the Crusoe Cloud API secret value.
|
|
83
|
+
|
|
84
|
+
:returns: The secret string.
|
|
85
|
+
"""
|
|
86
|
+
return self._secret
|
|
87
|
+
|
|
88
|
+
@classmethod
|
|
89
|
+
def validate(cls, cred_info: Dict[str, Any]) -> Tuple[List[str], List[str]]:
|
|
90
|
+
"""
|
|
91
|
+
Validates the dictionary describing a Crusoe Cloud API-key credential.
|
|
92
|
+
|
|
93
|
+
:param cred_info: Credential definition dictionary to validate.
|
|
94
|
+
|
|
95
|
+
:returns: A tuple of lists containing errors and warnings.
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
errors = []
|
|
99
|
+
warnings = []
|
|
100
|
+
|
|
101
|
+
if "access_key_id" not in cred_info:
|
|
102
|
+
errors.append("missing 'access_key_id' in crusoe-api-key credential.")
|
|
103
|
+
|
|
104
|
+
if "secret" not in cred_info:
|
|
105
|
+
errors.append("missing 'secret' in crusoe-api-key credential.")
|
|
106
|
+
|
|
107
|
+
return errors, warnings
|
|
108
|
+
|
|
109
|
+
def as_dict(self) -> Dict[str, Any]:
|
|
110
|
+
"""
|
|
111
|
+
Returns a dictionary representation of this credential object.
|
|
112
|
+
"""
|
|
113
|
+
rtnval = super().as_dict()
|
|
114
|
+
|
|
115
|
+
rtnval["access_key_id"] = self._access_key_id
|
|
116
|
+
rtnval["secret"] = self._secret
|
|
117
|
+
|
|
118
|
+
return rtnval
|
|
119
|
+
|
|
120
|
+
def __repr__(self) -> str:
|
|
121
|
+
"""
|
|
122
|
+
Returns a debug representation of this credential with the secret redacted.
|
|
123
|
+
|
|
124
|
+
:returns: A redacted string representation safe for logs.
|
|
125
|
+
"""
|
|
126
|
+
rtnval = (
|
|
127
|
+
"CrusoeApiKeyCredential("
|
|
128
|
+
"identifier={!r}, categories={!r}, access_key_id={!r}, secret='***')"
|
|
129
|
+
).format(self._identifier, self._categories, self._access_key_id)
|
|
130
|
+
|
|
131
|
+
return rtnval
|