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,178 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: vspherecredential
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`VSphereCredential` which
|
|
5
|
+
wraps VSphere username/password and/or SSO-token credential
|
|
6
|
+
material for the VSphere venue provisioner.
|
|
7
|
+
|
|
8
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
__author__ = "Myron Walker"
|
|
12
|
+
__copyright__ = "Copyright 2026, Code Craft AI LLC"
|
|
13
|
+
__credits__ = []
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
17
|
+
|
|
18
|
+
import os
|
|
19
|
+
|
|
20
|
+
from ccai.errors.exceptions import ConfigurationError
|
|
21
|
+
|
|
22
|
+
from ccai.credentials.basecredential import BaseCredential
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class VSphereCredential(BaseCredential):
|
|
26
|
+
"""
|
|
27
|
+
The :class:`VSphereCredential` is a container object that wraps the
|
|
28
|
+
VSphere/vCenter SSO authentication material. It carries a username
|
|
29
|
+
plus either a password, an SSO token, or both. VSphere is a
|
|
30
|
+
VM-shaped venue, so the credential is registered under the
|
|
31
|
+
``vm-venue`` category.
|
|
32
|
+
|
|
33
|
+
.. code:: yaml
|
|
34
|
+
"identifier": "vsphere-cred"
|
|
35
|
+
"category": "vm-venue"
|
|
36
|
+
"provider": "vsphere"
|
|
37
|
+
"username": "administrator@vsphere.local"
|
|
38
|
+
"password": "@@&_@@&_LetMeComeIn"
|
|
39
|
+
"sso_token": null
|
|
40
|
+
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
REQUIRED_CATEGORY = "vm-venue"
|
|
44
|
+
|
|
45
|
+
def __init__(self, *, identifier: str, categories: List[str], username: str,
|
|
46
|
+
password: Optional[str] = None, sso_token: Optional[str] = None,
|
|
47
|
+
role: Optional[str] = "priv") -> None:
|
|
48
|
+
"""
|
|
49
|
+
Initializes a :class:`VSphereCredential` 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 username: The VSphere SSO username associated with this credential.
|
|
54
|
+
:param password: The optional VSphere SSO password.
|
|
55
|
+
:param sso_token: The optional pre-minted VSphere SSO session token.
|
|
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 self.REQUIRED_CATEGORY not in categories:
|
|
63
|
+
errmsg_lines = [
|
|
64
|
+
"The VSphereCredential should be given credentials of category 'vm-venue'.",
|
|
65
|
+
"MISSING CATEGORY: {}".format(self.REQUIRED_CATEGORY),
|
|
66
|
+
]
|
|
67
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
68
|
+
raise ConfigurationError(errmsg)
|
|
69
|
+
|
|
70
|
+
if username is None or len(username) == 0:
|
|
71
|
+
raise ConfigurationError("The VSphereCredential constructor requires a non-empty 'username' parameter be provided.")
|
|
72
|
+
|
|
73
|
+
password_present = password is not None and len(password) > 0
|
|
74
|
+
sso_token_present = sso_token is not None and len(sso_token) > 0
|
|
75
|
+
|
|
76
|
+
if not password_present and not sso_token_present:
|
|
77
|
+
errmsg_lines = [
|
|
78
|
+
"The VSphereCredential constructor requires one of 'password' or 'sso_token' to be provided.",
|
|
79
|
+
"PROVIDE: a non-empty 'password' or a non-empty 'sso_token'.",
|
|
80
|
+
]
|
|
81
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
82
|
+
raise ConfigurationError(errmsg)
|
|
83
|
+
|
|
84
|
+
self._username = username
|
|
85
|
+
self._password = password
|
|
86
|
+
self._sso_token = sso_token
|
|
87
|
+
return
|
|
88
|
+
|
|
89
|
+
@property
|
|
90
|
+
def username(self) -> str:
|
|
91
|
+
"""
|
|
92
|
+
Returns the VSphere SSO username associated with this credential.
|
|
93
|
+
|
|
94
|
+
:returns: The username string.
|
|
95
|
+
"""
|
|
96
|
+
return self._username
|
|
97
|
+
|
|
98
|
+
@property
|
|
99
|
+
def password(self) -> Optional[str]:
|
|
100
|
+
"""
|
|
101
|
+
Returns the VSphere SSO password associated with this credential.
|
|
102
|
+
|
|
103
|
+
:returns: The password string, or None.
|
|
104
|
+
"""
|
|
105
|
+
return self._password
|
|
106
|
+
|
|
107
|
+
@property
|
|
108
|
+
def sso_token(self) -> Optional[str]:
|
|
109
|
+
"""
|
|
110
|
+
Returns the pre-minted VSphere SSO session token.
|
|
111
|
+
|
|
112
|
+
:returns: The SSO token string, or None.
|
|
113
|
+
"""
|
|
114
|
+
return self._sso_token
|
|
115
|
+
|
|
116
|
+
@classmethod
|
|
117
|
+
def validate(cls, cred_info: Dict[str, Any]) -> Tuple[List[str], List[str]]:
|
|
118
|
+
"""
|
|
119
|
+
Validates the dictionary describing a VSphere credential.
|
|
120
|
+
|
|
121
|
+
:param cred_info: Credential definition dictionary to validate.
|
|
122
|
+
|
|
123
|
+
:returns: A tuple of lists containing errors and warnings.
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
errors: List[str] = []
|
|
127
|
+
warnings: List[str] = []
|
|
128
|
+
|
|
129
|
+
if "username" not in cred_info:
|
|
130
|
+
errors.append("missing 'username' in vsphere credential.")
|
|
131
|
+
|
|
132
|
+
has_password = "password" in cred_info and cred_info.get("password") not in (None, "")
|
|
133
|
+
has_sso_token = "sso_token" in cred_info and cred_info.get("sso_token") not in (None, "")
|
|
134
|
+
|
|
135
|
+
if not has_password and not has_sso_token:
|
|
136
|
+
errors.append("one of 'password' or 'sso_token' is required in vsphere credential.")
|
|
137
|
+
|
|
138
|
+
return errors, warnings
|
|
139
|
+
|
|
140
|
+
def as_dict(self) -> Dict[str, Any]:
|
|
141
|
+
"""
|
|
142
|
+
Returns a dictionary representation of this credential object.
|
|
143
|
+
|
|
144
|
+
:returns: A dictionary representation of the credential.
|
|
145
|
+
"""
|
|
146
|
+
rtnval = super().as_dict()
|
|
147
|
+
|
|
148
|
+
rtnval["username"] = self._username
|
|
149
|
+
rtnval["password"] = self._password
|
|
150
|
+
rtnval["sso_token"] = self._sso_token
|
|
151
|
+
|
|
152
|
+
return rtnval
|
|
153
|
+
|
|
154
|
+
def __repr__(self) -> str:
|
|
155
|
+
"""
|
|
156
|
+
Returns a debug representation of this credential with secret
|
|
157
|
+
material redacted.
|
|
158
|
+
|
|
159
|
+
:returns: A redacted string representation safe for logs.
|
|
160
|
+
"""
|
|
161
|
+
password_repr = "None"
|
|
162
|
+
if self._password is not None:
|
|
163
|
+
password_repr = "'***'"
|
|
164
|
+
|
|
165
|
+
sso_token_repr = "None"
|
|
166
|
+
if self._sso_token is not None:
|
|
167
|
+
sso_token_repr = "'***'"
|
|
168
|
+
|
|
169
|
+
rtnval = (
|
|
170
|
+
"VSphereCredential("
|
|
171
|
+
"identifier={!r}, categories={!r}, username={!r}, "
|
|
172
|
+
"password={}, sso_token={})"
|
|
173
|
+
).format(
|
|
174
|
+
self._identifier, self._categories, self._username,
|
|
175
|
+
password_repr, sso_token_repr,
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
return rtnval
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: vultrapikeycredential
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`VultrApiKeyCredential` which
|
|
5
|
+
wraps the Vultr venue API-key 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 VultrApiKeyCredential(BaseCredential):
|
|
25
|
+
"""
|
|
26
|
+
The :class:`VultrApiKeyCredential` is a container object that wraps the
|
|
27
|
+
Vultr venue API-key authentication material.
|
|
28
|
+
|
|
29
|
+
.. code:: yaml
|
|
30
|
+
"identifier": "vultr-key"
|
|
31
|
+
"category": "cloud-venue"
|
|
32
|
+
"provider": "vultr"
|
|
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 a :class:`VultrApiKeyCredential` 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 Vultr API key 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 VultrApiKeyCredential 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 VultrApiKeyCredential 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 Vultr API key value.
|
|
69
|
+
|
|
70
|
+
:returns: The API key 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 a Vultr API-key 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 vultr-api-key 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
|
+
"VultrApiKeyCredential("
|
|
110
|
+
"identifier={!r}, categories={!r}, token='***')"
|
|
111
|
+
).format(self._identifier, self._categories)
|
|
112
|
+
|
|
113
|
+
return rtnval
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
|
|
2
|
+
"""
|
|
3
|
+
.. module:: wellknown
|
|
4
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
5
|
+
:synopsis: Module that provides a singleton for the :class:`CredentialManager` and
|
|
6
|
+
declares the well-known credential category constants and umbrella
|
|
7
|
+
membership registry consumed by VPN and venue control planes.
|
|
8
|
+
|
|
9
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
__author__ = "Myron Walker"
|
|
13
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
14
|
+
__credits__ = []
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
from typing import Dict, List, Optional
|
|
18
|
+
|
|
19
|
+
from threading import RLock
|
|
20
|
+
|
|
21
|
+
from ccai.errors.exceptions import SemanticError
|
|
22
|
+
|
|
23
|
+
from ccai.credentials.basecredential import BaseCredential
|
|
24
|
+
from ccai.credentials.credentialmanager import CredentialManager
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
__all__ = [
|
|
28
|
+
"CATEGORY_VPN",
|
|
29
|
+
"CATEGORY_MESH",
|
|
30
|
+
"CATEGORY_CLOUD_VENUE",
|
|
31
|
+
"CATEGORY_VM_VENUE",
|
|
32
|
+
"CATEGORY_HPC_VENUE",
|
|
33
|
+
"WELL_KNOWN_CATEGORY_MEMBERSHIP",
|
|
34
|
+
"CredentialManagerSingleton",
|
|
35
|
+
"get_credentials_by_category",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
CATEGORY_VPN = "vpn"
|
|
40
|
+
CATEGORY_MESH = "mesh"
|
|
41
|
+
CATEGORY_CLOUD_VENUE = "cloud-venue"
|
|
42
|
+
CATEGORY_VM_VENUE = "vm-venue"
|
|
43
|
+
CATEGORY_HPC_VENUE = "hpc-venue"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
WELL_KNOWN_CATEGORY_MEMBERSHIP: Dict[str, List[str]] = {
|
|
47
|
+
CATEGORY_VPN: [
|
|
48
|
+
"tailscale-authkey",
|
|
49
|
+
"tailscale-oauth",
|
|
50
|
+
"twingate-service-account",
|
|
51
|
+
],
|
|
52
|
+
CATEGORY_MESH: [
|
|
53
|
+
"tailscale-authkey",
|
|
54
|
+
"tailscale-oauth",
|
|
55
|
+
"twingate-service-account",
|
|
56
|
+
],
|
|
57
|
+
# The venue credential classes declare the umbrella category itself
|
|
58
|
+
# (``cloud-venue`` / ``vm-venue`` / ``hpc-venue``) rather than a
|
|
59
|
+
# per-provider string, so the umbrella entries must resolve to the
|
|
60
|
+
# umbrella category. The two legacy cloud credential classes
|
|
61
|
+
# (``AwsAccessKeyCredential``, ``AzureClientSecretCredential``) predate
|
|
62
|
+
# that convention and declare per-provider strings, so those remain in
|
|
63
|
+
# the cloud-venue membership list for backward compatibility.
|
|
64
|
+
CATEGORY_CLOUD_VENUE: [
|
|
65
|
+
CATEGORY_CLOUD_VENUE,
|
|
66
|
+
"aws-access-key",
|
|
67
|
+
"azure-client-secret",
|
|
68
|
+
],
|
|
69
|
+
CATEGORY_VM_VENUE: [
|
|
70
|
+
CATEGORY_VM_VENUE,
|
|
71
|
+
],
|
|
72
|
+
CATEGORY_HPC_VENUE: [
|
|
73
|
+
CATEGORY_HPC_VENUE,
|
|
74
|
+
],
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
CREDENTIAL_MANAGER_SINGLETON = None
|
|
79
|
+
|
|
80
|
+
SINGLETON_LOCK = RLock()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def CredentialManagerSingleton(credential_info: Optional[dict] = None, credential_uris: Optional[List[str]] = None) -> CredentialManager:
|
|
84
|
+
"""
|
|
85
|
+
Instantiates and gets a global instance of the :class:`CredentialManager` class. The
|
|
86
|
+
:class:`CredentialManager` provides for management of credentials.
|
|
87
|
+
|
|
88
|
+
:param credential_info: The credential information dictionary used on first call.
|
|
89
|
+
:param credential_uris: The list of source URIs used on first call.
|
|
90
|
+
|
|
91
|
+
:returns: The shared :class:`CredentialManager` instance.
|
|
92
|
+
:raises: SemanticError when the first call omits ``credential_info`` or ``credential_uris``.
|
|
93
|
+
"""
|
|
94
|
+
global CREDENTIAL_MANAGER_SINGLETON
|
|
95
|
+
|
|
96
|
+
if CREDENTIAL_MANAGER_SINGLETON is None:
|
|
97
|
+
|
|
98
|
+
if credential_info is None or credential_uris is None:
|
|
99
|
+
errmsg = "The first call to create the CredentialManagerSingleton must include the credential_info and credential_uris parameters."
|
|
100
|
+
raise SemanticError(errmsg)
|
|
101
|
+
|
|
102
|
+
SINGLETON_LOCK.acquire()
|
|
103
|
+
try:
|
|
104
|
+
# Re-check inside the lock: another thread may have initialised the
|
|
105
|
+
# singleton between the outer check and acquiring the lock. Without
|
|
106
|
+
# this, two concurrent first-callers both build and load a manager,
|
|
107
|
+
# the second overwriting the first.
|
|
108
|
+
if CREDENTIAL_MANAGER_SINGLETON is None:
|
|
109
|
+
credmgr = CredentialManager()
|
|
110
|
+
credmgr.load_credentials(credential_info, source_uris=credential_uris)
|
|
111
|
+
CREDENTIAL_MANAGER_SINGLETON = credmgr
|
|
112
|
+
|
|
113
|
+
finally:
|
|
114
|
+
SINGLETON_LOCK.release()
|
|
115
|
+
|
|
116
|
+
rtnval = CREDENTIAL_MANAGER_SINGLETON
|
|
117
|
+
return rtnval
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _require_initialised_singleton() -> CredentialManager:
|
|
121
|
+
"""
|
|
122
|
+
Returns the initialised :class:`CredentialManager` singleton.
|
|
123
|
+
|
|
124
|
+
:returns: The shared :class:`CredentialManager` instance.
|
|
125
|
+
:raises: SemanticError when the singleton has not been initialised.
|
|
126
|
+
"""
|
|
127
|
+
global CREDENTIAL_MANAGER_SINGLETON
|
|
128
|
+
|
|
129
|
+
if CREDENTIAL_MANAGER_SINGLETON is None:
|
|
130
|
+
errmsg = (
|
|
131
|
+
"CredentialManagerSingleton has not been initialised. "
|
|
132
|
+
"Call CredentialManagerSingleton(credential_info, credential_uris) first."
|
|
133
|
+
)
|
|
134
|
+
raise SemanticError(errmsg)
|
|
135
|
+
|
|
136
|
+
rtnval = CREDENTIAL_MANAGER_SINGLETON
|
|
137
|
+
return rtnval
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def get_credentials_by_category(*, category: str) -> List[BaseCredential]:
|
|
141
|
+
"""
|
|
142
|
+
Returns credentials matching the requested category. Umbrella categories declared
|
|
143
|
+
in :data:`WELL_KNOWN_CATEGORY_MEMBERSHIP` are expanded into their per-provider
|
|
144
|
+
category list before lookup; per-provider categories are looked up directly.
|
|
145
|
+
|
|
146
|
+
:param category: The well-known umbrella category constant or a per-provider category string.
|
|
147
|
+
|
|
148
|
+
:returns: The list of matching :class:`BaseCredential` instances (possibly empty).
|
|
149
|
+
:raises: SemanticError when the credential manager singleton has not been initialised.
|
|
150
|
+
"""
|
|
151
|
+
credmgr = _require_initialised_singleton()
|
|
152
|
+
|
|
153
|
+
targets: List[str] = []
|
|
154
|
+
if category in WELL_KNOWN_CATEGORY_MEMBERSHIP:
|
|
155
|
+
targets = list(WELL_KNOWN_CATEGORY_MEMBERSHIP[category])
|
|
156
|
+
else:
|
|
157
|
+
targets = [category]
|
|
158
|
+
|
|
159
|
+
rtnval = credmgr.get_credentials_by_categories(categories=targets)
|
|
160
|
+
return rtnval
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: wifichoicecredential
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`WifiChoiceCredential` which provides support
|
|
5
|
+
for a list of SSID and password 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 Any, Dict, List, Optional, Tuple
|
|
16
|
+
|
|
17
|
+
from ccai.errors.exceptions import ConfigurationError
|
|
18
|
+
|
|
19
|
+
from ccai.credentials.basecredential import BaseCredential
|
|
20
|
+
|
|
21
|
+
class WifiChoiceCredential(BaseCredential):
|
|
22
|
+
"""
|
|
23
|
+
The :class:`WifiChoiceCredential` is a container object for a list of wifi credential choices.
|
|
24
|
+
|
|
25
|
+
.. code:: yaml
|
|
26
|
+
identifier: "my-wifi-networks"
|
|
27
|
+
category: "wifi-choice"
|
|
28
|
+
networks:
|
|
29
|
+
- ssid: SOMENETWORK
|
|
30
|
+
password: BlahBlah!!
|
|
31
|
+
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
# 'networks' is a list of {ssid, password} dicts whose leaves hold secrets;
|
|
35
|
+
# the field name is not matched by the sensitive field-name heuristic, so the
|
|
36
|
+
# whole value is masked wholesale.
|
|
37
|
+
SECRET_FIELDS = ("networks",)
|
|
38
|
+
|
|
39
|
+
def __init__(self, *, identifier: str, categories: List[str], networks: List[Dict[str, str]], role: Optional[str] = "priv"):
|
|
40
|
+
"""
|
|
41
|
+
Initializes a :class:`WifiChoiceCredential` 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 networks: List of network credentials.
|
|
46
|
+
"""
|
|
47
|
+
super().__init__(identifier=identifier, categories=categories, role=role)
|
|
48
|
+
|
|
49
|
+
if "wifi-choice" not in categories:
|
|
50
|
+
raise ConfigurationError(
|
|
51
|
+
"The WifiChoiceCredential should only be given credentials of category 'wifi-choice'."
|
|
52
|
+
)
|
|
53
|
+
if len(networks) == 0:
|
|
54
|
+
raise ConfigurationError("The WifiChoiceCredential constructor should have at least one network.")
|
|
55
|
+
|
|
56
|
+
self._networks = networks
|
|
57
|
+
return
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def networks(self):
|
|
61
|
+
"""
|
|
62
|
+
Returns the list of wifi network credentials.
|
|
63
|
+
|
|
64
|
+
:returns: A list of dictionaries describing SSIDs and passwords.
|
|
65
|
+
"""
|
|
66
|
+
return self._networks
|
|
67
|
+
|
|
68
|
+
@classmethod
|
|
69
|
+
def validate(cls, cred_info: dict) -> Tuple[List[str], List[str]]:
|
|
70
|
+
"""
|
|
71
|
+
Validates a dictionary describing a wifi-choice credential.
|
|
72
|
+
|
|
73
|
+
:param cred_info: Credential definition dictionary to validate.
|
|
74
|
+
|
|
75
|
+
:returns: A tuple of lists containing errors and warnings.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
errors = []
|
|
79
|
+
warnings = []
|
|
80
|
+
|
|
81
|
+
networks = cred_info.get("networks")
|
|
82
|
+
if networks is None:
|
|
83
|
+
errors.append("missing 'networks' field on wifi-choice credential.")
|
|
84
|
+
networks = []
|
|
85
|
+
elif len(networks) == 0:
|
|
86
|
+
errors.append("empty 'networks' field on wifi-choice credential.")
|
|
87
|
+
|
|
88
|
+
for nidx, network_info in enumerate(networks):
|
|
89
|
+
if "ssid" not in network_info:
|
|
90
|
+
errmsg = "'networks' item {} is missing the 'ssid' field on wifi-choice credential.".format(nidx)
|
|
91
|
+
errors.append(errmsg)
|
|
92
|
+
|
|
93
|
+
if "password" not in network_info:
|
|
94
|
+
errmsg = "'networks' item {} is missing the 'password' field on wifi-choice credential.".format(nidx)
|
|
95
|
+
errors.append(errmsg)
|
|
96
|
+
|
|
97
|
+
return errors, warnings
|
|
98
|
+
|
|
99
|
+
def as_dict(self) -> Dict[str, Any]:
|
|
100
|
+
"""
|
|
101
|
+
Returns a dictionary representation of this credential object.
|
|
102
|
+
"""
|
|
103
|
+
rtnval = super().as_dict()
|
|
104
|
+
|
|
105
|
+
rtnval["networks"] = self._networks
|
|
106
|
+
|
|
107
|
+
return rtnval
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codecraftai-credentials
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: Code Craft AI - Credentials Package
|
|
5
|
+
License-Expression: LicenseRef-CodeCraftAI-Source-Available
|
|
6
|
+
License-File: LICENSE.md
|
|
7
|
+
Keywords: python
|
|
8
|
+
Author: Myron Walker
|
|
9
|
+
Author-email: myron.walker@gmail.com
|
|
10
|
+
Requires-Python: >=3.10,<4.0
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Operating System :: POSIX
|
|
13
|
+
Requires-Dist: codecraftai-foundations (<2.0.0)
|
|
14
|
+
Project-URL: Issues, https://github.com/code-craft-ai-company/codecraftai-credentials/issues
|
|
15
|
+
Project-URL: Repository, https://github.com/code-craft-ai-company/codecraftai-credentials
|
|
16
|
+
Description-Content-Type: text/x-rst
|
|
17
|
+
|
|
18
|
+
============================
|
|
19
|
+
Code Craft AI Credentials
|
|
20
|
+
============================
|
|
21
|
+
|
|
22
|
+
The ``codecraftai-credentials`` package is the credentials vocabulary for the ccai suite. It defines a small hierarchy of credential classes rooted at ``BaseCredential`` and adds concrete types for the authentication styles the rest of the suite has to talk to. A ``CredentialManager`` loads credentials from configuration and exposes them by name so that protocol and REST clients (for example ``codecraftai-protocol-ssh``, ``codecraftai-restclient-github-public``, and ``codecraftai-gitlab``) can request the credential they need without hard-coding authentication details.
|
|
23
|
+
|
|
24
|
+
Highlights
|
|
25
|
+
==========
|
|
26
|
+
|
|
27
|
+
- ``BaseCredential`` root and ``CredentialManager`` for declarative credential lookup by name.
|
|
28
|
+
- SSH-oriented credential types: ``BasicCredential``, ``PublicKeyCredential``, and ``SshCredential``.
|
|
29
|
+
- Token-oriented types: ``ApiTokenCredential``, ``SecretTokenCredential``, ``PersonalApiTokenCredential``.
|
|
30
|
+
- Vendor-specific credentials: ``GithubTokenCredential``, ``GithubAppCredential``, ``AwsAccessKeyCredential``, and ``AzureClientSecretCredential``.
|
|
31
|
+
- ``WifiChoiceCredential`` for network-selection scenarios.
|
|
32
|
+
- Structurally satisfies the ``IBasicCredential`` ``typing.Protocol`` from ``codecraftai-foundations`` (the protocol is structural, so no explicit inheritance or runtime dependency is required).
|
|
33
|
+
|
|
34
|
+
Repository Structure
|
|
35
|
+
====================
|
|
36
|
+
|
|
37
|
+
- ``development/`` - Runtime environment scripts.
|
|
38
|
+
- ``repository-setup/`` - Repository homing and setup scripts.
|
|
39
|
+
- ``source/packages/`` - Package source code.
|
|
40
|
+
- ``source/tests/`` - ``unittest``-based tests.
|
|
41
|
+
- ``specs/`` - Requirements, design, and task documentation.
|
|
42
|
+
- ``userguide/`` - Standards, conventions, and documentation.
|
|
43
|
+
|
|
44
|
+
Environment Setup
|
|
45
|
+
=================
|
|
46
|
+
|
|
47
|
+
When working in a Codex container:
|
|
48
|
+
|
|
49
|
+
.. code-block:: bash
|
|
50
|
+
|
|
51
|
+
./development/setup-agent-container
|
|
52
|
+
|
|
53
|
+
For local development:
|
|
54
|
+
|
|
55
|
+
.. code-block:: bash
|
|
56
|
+
|
|
57
|
+
./repository-setup/rehome-repository
|
|
58
|
+
./development/setup-environment
|
|
59
|
+
|
|
60
|
+
Running Tests
|
|
61
|
+
=============
|
|
62
|
+
|
|
63
|
+
Activate the virtual environment:
|
|
64
|
+
|
|
65
|
+
.. code-block:: bash
|
|
66
|
+
|
|
67
|
+
source .venv/bin/activate
|
|
68
|
+
|
|
69
|
+
Run ``unittest`` tests:
|
|
70
|
+
|
|
71
|
+
.. code-block:: bash
|
|
72
|
+
|
|
73
|
+
python -m unittest discover -s source/tests -p "test_*.py"
|
|
74
|
+
|
|
75
|
+
Standards and Conventions
|
|
76
|
+
=========================
|
|
77
|
+
|
|
78
|
+
- Naming conventions: ``userguide/10-02-naming-conventions.rst``
|
|
79
|
+
- Code organization: ``userguide/10-01-code-organization.rst``
|
|
80
|
+
- Coding standards: ``userguide/10-00-coding-standards.rst``
|
|
81
|
+
|
|
82
|
+
Additional Resources
|
|
83
|
+
====================
|
|
84
|
+
|
|
85
|
+
- User guide entry point: ``userguide/userguide.rst``
|
|
86
|
+
- Design documentation: ``specs/design.md``
|
|
87
|
+
- Requirements: ``specs/requirements.md``
|
|
88
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
ccai/credentials/__init__.py,sha256=PUWnTtRTt9dskSFmK6LERK-3DxwdnI0AjX0H4c2X3Dw,336
|
|
2
|
+
ccai/credentials/apitokencredential.py,sha256=iWl48dVGGj70ay6oMXt9l_ABwY0KDA1DKULij0IpIv0,2875
|
|
3
|
+
ccai/credentials/awsaccesskeycredential.py,sha256=vdmnMvwajLqbF_yXfdekRxOoakwQ67Jq-N7zgUL6ppo,3445
|
|
4
|
+
ccai/credentials/azureclientsecretcredential.py,sha256=PrAI-iK5SBcJ3QolBSjutt2LLumsNAI5QmBrvsM3aTM,3822
|
|
5
|
+
ccai/credentials/azuremanagedidentitycredential.py,sha256=Oe7sn3k34YOjIy5BCczzjfUtr2ViveZNJqvqpHSdaSw,4704
|
|
6
|
+
ccai/credentials/azureserviceprincipalcredential.py,sha256=3or2-enC3h-aQ1w9cPNypG6HsaUWfkg4Our0AYU9gYQ,5435
|
|
7
|
+
ccai/credentials/basecredential.py,sha256=-XZdD0BRcZkaJ1ncUUKVHVDLU1KtQro4yBT8XEhCWwg,6291
|
|
8
|
+
ccai/credentials/basiccredential.py,sha256=yLgG4565own69I5VT9i13tLvdpYtc9WD4dQ6XubaC4o,3472
|
|
9
|
+
ccai/credentials/coreweaveapicredential.py,sha256=WxVfmIG776TIBpxlXkxeGHxBZ9LW4ct8enVweGNpfM8,4338
|
|
10
|
+
ccai/credentials/credentialmanager.py,sha256=kPQgnMZT_KdhBohxH5Ps4GPZ_e6WpUmGyYzc4DljUko,20938
|
|
11
|
+
ccai/credentials/crusoeapikeycredential.py,sha256=lpXm4hIz3ahZevcA33o0D6i2v0jlP14OQMfZMrHJuvs,4499
|
|
12
|
+
ccai/credentials/digitaloceanapitokencredential.py,sha256=pk3L52E7wR-L8mSptNi7ToYvisOFI0oy9npNLGAmTSo,6928
|
|
13
|
+
ccai/credentials/equinixmetalapitokencredential.py,sha256=ecxKVUHo_7ziBCPqDTLpuECyrie9NJ9UZCtcWSMfvDY,3676
|
|
14
|
+
ccai/credentials/gcpserviceaccountkeycredential.py,sha256=JZuih4uTjxIlrwv_EXza17EcqA9ZPWpaf8J5nt5FwqU,7141
|
|
15
|
+
ccai/credentials/gcpworkloadidentitycredential.py,sha256=N-wEYcGAAlW31cm-s8B2uOLAR5ulbbMpMODtGqUoVBo,6616
|
|
16
|
+
ccai/credentials/githubappcredential.py,sha256=QRMDowFwJqSEKVhLknni9asFV-_HtY4zkRY91zAa0J8,6428
|
|
17
|
+
ccai/credentials/githubtokencredential.py,sha256=9IfjcMMEjQ16im5BLCzPPtO5WOBJSbaUEDtTm8R4dCI,3574
|
|
18
|
+
ccai/credentials/hetznerapitokencredential.py,sha256=I_HaGckEP-JXurptYoEMe3lAmPHb7aGPtJSNRufAEIM,3622
|
|
19
|
+
ccai/credentials/lambdalabsapikeycredential.py,sha256=uh03sfPJNDOwWTN5crol0hyaPpcclVgUsqH5N8iR8t4,3618
|
|
20
|
+
ccai/credentials/linodeapitokencredential.py,sha256=QmKRQ4VDogVl5ghBDf-ffoHSRLWXeG3mx6k3KkekM-A,3576
|
|
21
|
+
ccai/credentials/nebiusserviceaccountcredential.py,sha256=fVfGzDOypAFqgbvIy1Aw22E_VUk-vpopffyya6h3EHU,3678
|
|
22
|
+
ccai/credentials/nutanixprismcredential.py,sha256=RNYwex0oxULQkgpbCpfXzm7aeJLqFWMIT_Cy-Lqzvn8,5662
|
|
23
|
+
ccai/credentials/oraclecloudapikeycredential.py,sha256=6eLVQlwEbP58rqH4IttEaz2XbpRnnA4kjYO7gfBDIQk,7843
|
|
24
|
+
ccai/credentials/personalapitokencredential.py,sha256=iFlg3iHChLCVPEeCr-wnhBBAyXtRp171g71R7quLCE0,3425
|
|
25
|
+
ccai/credentials/proxmoxapitokencredential.py,sha256=qceL9nm2xMsBJIXrHJeJ8jUU16miaIoMfQg93zNjpwc,4973
|
|
26
|
+
ccai/credentials/publickeycredential.py,sha256=4_zByZK7zZ7-huiSwYakvMey4ZfB2uo2EprQCXytpfA,3390
|
|
27
|
+
ccai/credentials/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
28
|
+
ccai/credentials/runpodapikeycredential.py,sha256=Eccs2RNnreaHiibYA5LyN0MQJHEmhXTia74QJhZk8FY,3536
|
|
29
|
+
ccai/credentials/secrettokencredential.py,sha256=ru8Q5sHshETd0VoCGwSnfvtlAvxt9Fb9VQFqqem6bdU,3346
|
|
30
|
+
ccai/credentials/sshcredential.py,sha256=4TJBJOJYD0bLA969xNKb0TRyWib-BWppluwtKnPr4n0,8185
|
|
31
|
+
ccai/credentials/tailscaleauthkeycredential.py,sha256=iFQxOIXZnHG7wtKLJViuUjxHhnZB__QVpmSZbQuYMmI,5173
|
|
32
|
+
ccai/credentials/tailscaleoauthcredential.py,sha256=JXXCsmQ82B_yHtkD25AxYGaU5miQDuWZsWWVG8OrHpY,4986
|
|
33
|
+
ccai/credentials/twingateserviceaccountcredential.py,sha256=TD-L-IJYDc-9aolS6maBP8tTlpV0tAmS96PjHRO1ts4,5529
|
|
34
|
+
ccai/credentials/venueregistry.py,sha256=rSojndQdiO7bPIgrlxThWYXIbZTS3YM5teCeh1uuFk8,4004
|
|
35
|
+
ccai/credentials/vspherecredential.py,sha256=fVOR5DCx_VB8bQvpP1SPM41_IuBF1KiZSCrmDomZBj0,6202
|
|
36
|
+
ccai/credentials/vultrapikeycredential.py,sha256=scG4UnRcl10-ZvHftPGzT97_gIx3a3PYdNYKR_PDvEs,3528
|
|
37
|
+
ccai/credentials/wellknown.py,sha256=F5BF6qEQT0v_Z4Pk5hAF_oHHvYnpWLahNwiYUpb432I,5545
|
|
38
|
+
ccai/credentials/wifichoicecredential.py,sha256=gGOLGIU1rPcgmYAJxaMQ6xTgPExn1SgsaQrRjOrzKDA,3782
|
|
39
|
+
codecraftai_credentials-1.2.0.dist-info/METADATA,sha256=xZ7beIDf21TJbOa3adPHEDAiYoDCEB9YRzJZIcxkWek,3333
|
|
40
|
+
codecraftai_credentials-1.2.0.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
|
|
41
|
+
codecraftai_credentials-1.2.0.dist-info/licenses/LICENSE.md,sha256=5tyUZ2kpPxNXbULzrdiT14-ZV-jCBeBFL0xyO-zt1mg,17907
|
|
42
|
+
codecraftai_credentials-1.2.0.dist-info/RECORD,,
|