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.
Files changed (42) hide show
  1. ccai/credentials/__init__.py +13 -0
  2. ccai/credentials/apitokencredential.py +86 -0
  3. ccai/credentials/awsaccesskeycredential.py +105 -0
  4. ccai/credentials/azureclientsecretcredential.py +116 -0
  5. ccai/credentials/azuremanagedidentitycredential.py +131 -0
  6. ccai/credentials/azureserviceprincipalcredential.py +150 -0
  7. ccai/credentials/basecredential.py +187 -0
  8. ccai/credentials/basiccredential.py +104 -0
  9. ccai/credentials/coreweaveapicredential.py +130 -0
  10. ccai/credentials/credentialmanager.py +453 -0
  11. ccai/credentials/crusoeapikeycredential.py +131 -0
  12. ccai/credentials/digitaloceanapitokencredential.py +181 -0
  13. ccai/credentials/equinixmetalapitokencredential.py +113 -0
  14. ccai/credentials/gcpserviceaccountkeycredential.py +188 -0
  15. ccai/credentials/gcpworkloadidentitycredential.py +173 -0
  16. ccai/credentials/githubappcredential.py +167 -0
  17. ccai/credentials/githubtokencredential.py +106 -0
  18. ccai/credentials/hetznerapitokencredential.py +113 -0
  19. ccai/credentials/lambdalabsapikeycredential.py +113 -0
  20. ccai/credentials/linodeapitokencredential.py +113 -0
  21. ccai/credentials/nebiusserviceaccountcredential.py +113 -0
  22. ccai/credentials/nutanixprismcredential.py +161 -0
  23. ccai/credentials/oraclecloudapikeycredential.py +211 -0
  24. ccai/credentials/personalapitokencredential.py +101 -0
  25. ccai/credentials/proxmoxapitokencredential.py +145 -0
  26. ccai/credentials/publickeycredential.py +104 -0
  27. ccai/credentials/py.typed +0 -0
  28. ccai/credentials/runpodapikeycredential.py +113 -0
  29. ccai/credentials/secrettokencredential.py +103 -0
  30. ccai/credentials/sshcredential.py +221 -0
  31. ccai/credentials/tailscaleauthkeycredential.py +145 -0
  32. ccai/credentials/tailscaleoauthcredential.py +139 -0
  33. ccai/credentials/twingateserviceaccountcredential.py +146 -0
  34. ccai/credentials/venueregistry.py +89 -0
  35. ccai/credentials/vspherecredential.py +178 -0
  36. ccai/credentials/vultrapikeycredential.py +113 -0
  37. ccai/credentials/wellknown.py +160 -0
  38. ccai/credentials/wifichoicecredential.py +107 -0
  39. codecraftai_credentials-1.2.0.dist-info/METADATA +88 -0
  40. codecraftai_credentials-1.2.0.dist-info/RECORD +42 -0
  41. codecraftai_credentials-1.2.0.dist-info/WHEEL +4 -0
  42. codecraftai_credentials-1.2.0.dist-info/licenses/LICENSE.md +204 -0
@@ -0,0 +1,187 @@
1
+ """
2
+ .. module:: basecredential
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module that contains the :class:`BaseCredential` object which is the
5
+ common base class that all other credential objects inherit from.
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
+
20
+ # Substrings (case-insensitive) used to identify secret-bearing fields in a
21
+ # credential's as_dict() output so they can be masked for safe display/logging.
22
+ SENSITIVE_FIELD_SUBSTRINGS = (
23
+ "password",
24
+ "passwd",
25
+ "passphrase",
26
+ "token",
27
+ "secret",
28
+ "private",
29
+ "api_key",
30
+ "apikey",
31
+ "access_key",
32
+ "authkey",
33
+ "auth_key",
34
+ "client_secret",
35
+ )
36
+
37
+ REDACTED_PLACEHOLDER = "***REDACTED***"
38
+
39
+
40
+ def is_sensitive_field(field_name: str) -> bool:
41
+ """
42
+ Indicates whether a credential field name denotes secret material.
43
+
44
+ :param field_name: The credential dictionary key to test.
45
+
46
+ :returns: ``True`` if the field should be redacted for display/logging.
47
+ """
48
+ lowered = field_name.lower()
49
+ rtnval = False
50
+ for marker in SENSITIVE_FIELD_SUBSTRINGS:
51
+ if marker in lowered:
52
+ rtnval = True
53
+ break
54
+ return rtnval
55
+
56
+
57
+ class BaseCredential:
58
+ """
59
+ The :class:`BaseCredential` is the base container object for credentials passed in the landscape
60
+ configuration file.
61
+
62
+ .. code:: yaml
63
+ "identifier": "player-ssh"
64
+ "category": "(category)"
65
+ """
66
+
67
+ # Names of this class's ``as_dict`` fields that carry secret material but are
68
+ # NOT matched by the SENSITIVE_FIELD_SUBSTRINGS name heuristic (e.g. "keyraw",
69
+ # "keys", "networks"). Subclasses declare their own; the values are aggregated
70
+ # across the MRO in as_redacted_dict, so a subclass's declaration never drops a
71
+ # base class's. Redaction is name-based only, so a declared field is masked
72
+ # wholesale (safe for nested list/dict values whose leaves hold secrets).
73
+ SECRET_FIELDS: Tuple[str, ...] = ()
74
+
75
+ def __init__(self, *, identifier: str, categories: List[str], role: Optional[str]="priv"):
76
+ """
77
+ Initializes a :class:`BaseCredential` instance.
78
+
79
+ :param identifier: The identifier that is used to reference this credential. (required)
80
+ :param categories: The categories of authentication that the credential can
81
+ be used for.
82
+ :param role: Identifies the role of the credential
83
+ """
84
+ if len(identifier) == 0:
85
+ raise ConfigurationError("The BaseCredential constructor requires a 'identifier' parameter be provided.")
86
+ if len(categories) == 0:
87
+ raise ConfigurationError("The BaseCredential constructor requires a 'categories' parameter be provided.")
88
+
89
+ self._identifier = identifier
90
+ self._categories = categories
91
+ self._role = role
92
+ return
93
+
94
+ @property
95
+ def categories(self):
96
+ """
97
+ Gets the authentication categories associated with this credential.
98
+
99
+ :returns: A list of category names.
100
+ """
101
+ return self._categories
102
+
103
+ @property
104
+ def identifier(self):
105
+ """
106
+ Gets the identifier of this credential.
107
+
108
+ :returns: The identifier string for the credential.
109
+ """
110
+ return self._identifier
111
+
112
+ @property
113
+ def role(self):
114
+ """
115
+ Gets the role assigned to this credential.
116
+
117
+ :returns: The role name associated with this credential.
118
+ """
119
+ return self._role
120
+
121
+ def as_dict(self) -> Dict[str, Any]:
122
+ """
123
+ Returns a full dictionary representation of this credential object,
124
+ suitable for round-tripping back through the constructor.
125
+
126
+ .. warning::
127
+ The returned dictionary includes raw secret material (passwords,
128
+ tokens, keys, ...) for secret-bearing credential subclasses. Do
129
+ NOT log or persist it as-is. Use :meth:`as_redacted_dict` for any
130
+ display, logging, or diagnostic output.
131
+ """
132
+
133
+ rtnval = {
134
+ "identifier": self._identifier,
135
+ "categories": self._categories,
136
+ "role": self._role
137
+ }
138
+
139
+ return rtnval
140
+
141
+ def as_redacted_dict(self) -> Dict[str, Any]:
142
+ """
143
+ Returns a display/logging-safe dictionary representation of this
144
+ credential with all secret-bearing fields masked.
145
+
146
+ This is derived from :meth:`as_dict` (so it automatically covers every
147
+ subclass's fields) with any sensitive field value replaced by a
148
+ redaction placeholder. Use this anywhere credential data may be logged
149
+ or persisted.
150
+
151
+ :returns: A dictionary with secret fields masked.
152
+ """
153
+ full = self.as_dict()
154
+
155
+ declared_secret_fields = set()
156
+ for klass in type(self).__mro__:
157
+ declared_secret_fields.update(getattr(klass, "SECRET_FIELDS", ()))
158
+
159
+ rtnval = {}
160
+ for key, value in full.items():
161
+ if is_sensitive_field(key) or key in declared_secret_fields:
162
+ rtnval[key] = REDACTED_PLACEHOLDER
163
+ else:
164
+ rtnval[key] = value
165
+
166
+ return rtnval
167
+
168
+ def __repr__(self) -> str:
169
+ """
170
+ Returns a secret-safe debug representation of this credential.
171
+
172
+ The representation is built from :meth:`as_redacted_dict`, so secret
173
+ fields are masked. Subclasses may override with their own redacted
174
+ representation; this default guarantees no credential class falls back
175
+ to a representation that could leak secret material.
176
+
177
+ :returns: A redacted string representation safe for logs.
178
+ """
179
+ redacted = self.as_redacted_dict()
180
+
181
+ field_parts = []
182
+ for key, value in redacted.items():
183
+ field_parts.append(f"{key}={value!r}")
184
+
185
+ field_str = ", ".join(field_parts)
186
+ rtnval = f"{type(self).__name__}({field_str})"
187
+ return rtnval
@@ -0,0 +1,104 @@
1
+ """
2
+ .. module:: basiccredential
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module that contains the :class:`BasicCredential` which is a simple
5
+ username and password based credential.
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 BasicCredential(BaseCredential):
22
+ """
23
+ The :class:`BasicCredential` is a container object for a basic username and password based credential.
24
+
25
+ .. code:: yaml
26
+ "identifier": "basic-login"
27
+ "category": "basic"
28
+ "username": "ubuntu"
29
+ "password": "@@&_@@&_LetMeComeIn"
30
+
31
+ """
32
+
33
+ def __init__(self, *, identifier: str, categories: List[str], username: str, password: str,
34
+ role: Optional[str] = "priv"):
35
+ """
36
+ Initializes a :class:`BasicCredential` instance.
37
+
38
+ :param identifier: The identifier that is used to reference this credential. (required)
39
+ :param categories: The categories of authentication that are supported by the credential
40
+ :param username: The username associated with this credential.
41
+ :param password: The password associated with this credential.
42
+ """
43
+ super().__init__(identifier=identifier, categories=categories, role=role)
44
+
45
+ if "basic" not in categories and "rest-basic" not in categories:
46
+ raise ConfigurationError("The BasicCredential should only be given credentials of category 'basic'.")
47
+ if len(username) == 0:
48
+ raise ConfigurationError("The BasicCredential constructor requires a 'username' parameter be provided.")
49
+ if password is None or len(password) == 0:
50
+ raise ConfigurationError("The BasicCredential constructor requires a 'password' parameter be provided.")
51
+
52
+ self._username = username
53
+ self._password = password
54
+ return
55
+
56
+ @property
57
+ def password(self):
58
+ """
59
+ Returns the password associated with this credential.
60
+
61
+ :returns: The password string.
62
+ """
63
+ return self._password
64
+
65
+ @property
66
+ def username(self):
67
+ """
68
+ Returns the username associated with this credential.
69
+
70
+ :returns: The username string.
71
+ """
72
+ return self._username
73
+
74
+ @classmethod
75
+ def validate(cls, cred_info) -> Tuple[List[str], List[str]]:
76
+ """
77
+ Validates the dictionary describing a basic 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 "password" not in cred_info:
88
+ errors.append("missing 'password' in basic credential.")
89
+
90
+ if "username" not in cred_info:
91
+ errors.append("missing 'username' in basic credential.")
92
+
93
+ return errors, warnings
94
+
95
+ def as_dict(self) -> Dict[str, Any]:
96
+ """
97
+ Returns a dictionary representation of this credential object.
98
+ """
99
+ rtnval = super().as_dict()
100
+
101
+ rtnval["username"] = self._username
102
+ rtnval["password"] = self._password
103
+
104
+ return rtnval
@@ -0,0 +1,130 @@
1
+ """
2
+ .. module:: coreweaveapicredential
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module that contains the :class:`CoreweaveApiCredential` which
5
+ wraps the CoreWeave 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 CoreweaveApiCredential(BaseCredential):
25
+ """
26
+ The :class:`CoreweaveApiCredential` is a container object that wraps the
27
+ CoreWeave venue API-token authentication material plus an optional
28
+ organisation scope. The credential intentionally does not hold a
29
+ kubeconfig; kubeconfig issuance happens inside ``codecraftai-interop-coreweave``
30
+ at use time.
31
+
32
+ .. code:: yaml
33
+ "identifier": "coreweave-token"
34
+ "category": "hpc-venue"
35
+ "provider": "coreweave"
36
+ "token": "..."
37
+ "organization_id": null
38
+
39
+ """
40
+
41
+ def __init__(self, *, identifier: str, categories: List[str], token: str,
42
+ organization_id: Optional[str] = None,
43
+ role: Optional[str] = "priv") -> None:
44
+ """
45
+ Initializes a :class:`CoreweaveApiCredential` instance.
46
+
47
+ :param identifier: The identifier that is used to reference this credential. (required)
48
+ :param categories: The categories of authentication that are supported by the credential.
49
+ :param token: The CoreWeave API token value.
50
+ :param organization_id: The optional CoreWeave organisation scope.
51
+ :param role: Identifies the role of the credential.
52
+
53
+ :raises: ConfigurationError
54
+ """
55
+ super().__init__(identifier=identifier, categories=categories, role=role)
56
+
57
+ if "hpc-venue" not in categories:
58
+ errmsg_lines = [
59
+ "The CoreweaveApiCredential should be given credentials of category 'hpc-venue'.",
60
+ "MISSING CATEGORY: hpc-venue",
61
+ ]
62
+ errmsg = os.linesep.join(errmsg_lines)
63
+ raise ConfigurationError(errmsg)
64
+
65
+ if token is None or len(token) == 0:
66
+ raise ConfigurationError("The CoreweaveApiCredential constructor requires a non-empty 'token' parameter be provided.")
67
+
68
+ self._token = token
69
+ self._organization_id = organization_id
70
+ return
71
+
72
+ @property
73
+ def token(self) -> str:
74
+ """
75
+ Returns the CoreWeave API token value.
76
+
77
+ :returns: The API token string.
78
+ """
79
+ return self._token
80
+
81
+ @property
82
+ def organization_id(self) -> Optional[str]:
83
+ """
84
+ Returns the CoreWeave organisation scope.
85
+
86
+ :returns: The organisation identifier string, or None.
87
+ """
88
+ return self._organization_id
89
+
90
+ @classmethod
91
+ def validate(cls, cred_info: Dict[str, Any]) -> Tuple[List[str], List[str]]:
92
+ """
93
+ Validates the dictionary describing a CoreWeave API credential.
94
+
95
+ :param cred_info: Credential definition dictionary to validate.
96
+
97
+ :returns: A tuple of lists containing errors and warnings.
98
+ """
99
+
100
+ errors = []
101
+ warnings = []
102
+
103
+ if "token" not in cred_info:
104
+ errors.append("missing 'token' in coreweave-api-token credential.")
105
+
106
+ return errors, warnings
107
+
108
+ def as_dict(self) -> Dict[str, Any]:
109
+ """
110
+ Returns a dictionary representation of this credential object.
111
+ """
112
+ rtnval = super().as_dict()
113
+
114
+ rtnval["token"] = self._token
115
+ rtnval["organization_id"] = self._organization_id
116
+
117
+ return rtnval
118
+
119
+ def __repr__(self) -> str:
120
+ """
121
+ Returns a debug representation of this credential with the token redacted.
122
+
123
+ :returns: A redacted string representation safe for logs.
124
+ """
125
+ rtnval = (
126
+ "CoreweaveApiCredential("
127
+ "identifier={!r}, categories={!r}, token='***', organization_id={!r})"
128
+ ).format(self._identifier, self._categories, self._organization_id)
129
+
130
+ return rtnval