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,113 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: nebiusserviceaccountcredential
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`NebiusServiceAccountCredential` which
|
|
5
|
+
wraps the Nebius venue service-account 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 NebiusServiceAccountCredential(BaseCredential):
|
|
25
|
+
"""
|
|
26
|
+
The :class:`NebiusServiceAccountCredential` is a container object that wraps the
|
|
27
|
+
Nebius venue service-account authentication material.
|
|
28
|
+
|
|
29
|
+
.. code:: yaml
|
|
30
|
+
"identifier": "nebius-svc"
|
|
31
|
+
"category": "hpc-venue"
|
|
32
|
+
"provider": "nebius"
|
|
33
|
+
"token": "ne1...."
|
|
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:`NebiusServiceAccountCredential` 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 Nebius service-account 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 "hpc-venue" not in categories:
|
|
52
|
+
errmsg_lines = [
|
|
53
|
+
"The NebiusServiceAccountCredential should be given credentials of category 'hpc-venue'.",
|
|
54
|
+
"MISSING CATEGORY: hpc-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 NebiusServiceAccountCredential 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 Nebius service-account token value.
|
|
69
|
+
|
|
70
|
+
:returns: The service-account 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 a Nebius service-account 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 nebius-service-account 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
|
+
"NebiusServiceAccountCredential("
|
|
110
|
+
"identifier={!r}, categories={!r}, token='***')"
|
|
111
|
+
).format(self._identifier, self._categories)
|
|
112
|
+
|
|
113
|
+
return rtnval
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: nutanixprismcredential
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`NutanixPrismCredential` which
|
|
5
|
+
wraps the Nutanix Prism Central 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 NutanixPrismCredential(BaseCredential):
|
|
25
|
+
"""
|
|
26
|
+
The :class:`NutanixPrismCredential` is a container object that wraps the
|
|
27
|
+
Nutanix Prism Central authentication material: username + password plus
|
|
28
|
+
the Prism Central endpoint URL.
|
|
29
|
+
|
|
30
|
+
.. code:: yaml
|
|
31
|
+
"identifier": "nutanix-prism"
|
|
32
|
+
"category": "vm-venue"
|
|
33
|
+
"provider": "nutanix-prism"
|
|
34
|
+
"username": "admin"
|
|
35
|
+
"password": "..."
|
|
36
|
+
"endpoint": "https://prism.example.com:9440"
|
|
37
|
+
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
ALLOWED_ENDPOINT_PREFIXES = ("http://", "https://")
|
|
41
|
+
|
|
42
|
+
def __init__(self, *, identifier: str, categories: List[str], username: str,
|
|
43
|
+
password: str, endpoint: str, role: Optional[str] = "priv") -> None:
|
|
44
|
+
"""
|
|
45
|
+
Initializes a :class:`NutanixPrismCredential` 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 username: The Nutanix Prism Central username.
|
|
50
|
+
:param password: The Nutanix Prism Central password.
|
|
51
|
+
:param endpoint: The Nutanix Prism Central endpoint URL.
|
|
52
|
+
:param role: Identifies the role of the credential.
|
|
53
|
+
|
|
54
|
+
:raises: ConfigurationError
|
|
55
|
+
"""
|
|
56
|
+
super().__init__(identifier=identifier, categories=categories, role=role)
|
|
57
|
+
|
|
58
|
+
if "vm-venue" not in categories:
|
|
59
|
+
errmsg_lines = [
|
|
60
|
+
"The NutanixPrismCredential should be given credentials of category 'vm-venue'.",
|
|
61
|
+
"MISSING CATEGORY: vm-venue",
|
|
62
|
+
]
|
|
63
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
64
|
+
raise ConfigurationError(errmsg)
|
|
65
|
+
|
|
66
|
+
if username is None or len(username) == 0:
|
|
67
|
+
raise ConfigurationError("The NutanixPrismCredential constructor requires a non-empty 'username' parameter be provided.")
|
|
68
|
+
if password is None or len(password) == 0:
|
|
69
|
+
raise ConfigurationError("The NutanixPrismCredential constructor requires a non-empty 'password' parameter be provided.")
|
|
70
|
+
if endpoint is None or len(endpoint) == 0:
|
|
71
|
+
raise ConfigurationError("The NutanixPrismCredential constructor requires a non-empty 'endpoint' parameter be provided.")
|
|
72
|
+
|
|
73
|
+
if not endpoint.startswith(self.ALLOWED_ENDPOINT_PREFIXES):
|
|
74
|
+
errmsg_lines = [
|
|
75
|
+
"The NutanixPrismCredential 'endpoint' parameter has an invalid scheme.",
|
|
76
|
+
"EXPECTED PREFIXES: {}".format(", ".join(self.ALLOWED_ENDPOINT_PREFIXES)),
|
|
77
|
+
"PROVIDED VALUE: {}".format(endpoint),
|
|
78
|
+
]
|
|
79
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
80
|
+
raise ConfigurationError(errmsg)
|
|
81
|
+
|
|
82
|
+
self._username = username
|
|
83
|
+
self._password = password
|
|
84
|
+
self._endpoint = endpoint
|
|
85
|
+
return
|
|
86
|
+
|
|
87
|
+
@property
|
|
88
|
+
def username(self) -> str:
|
|
89
|
+
"""
|
|
90
|
+
Returns the Nutanix Prism Central username.
|
|
91
|
+
|
|
92
|
+
:returns: The username string.
|
|
93
|
+
"""
|
|
94
|
+
return self._username
|
|
95
|
+
|
|
96
|
+
@property
|
|
97
|
+
def password(self) -> str:
|
|
98
|
+
"""
|
|
99
|
+
Returns the Nutanix Prism Central password.
|
|
100
|
+
|
|
101
|
+
:returns: The password string.
|
|
102
|
+
"""
|
|
103
|
+
return self._password
|
|
104
|
+
|
|
105
|
+
@property
|
|
106
|
+
def endpoint(self) -> str:
|
|
107
|
+
"""
|
|
108
|
+
Returns the Nutanix Prism Central endpoint URL.
|
|
109
|
+
|
|
110
|
+
:returns: The endpoint URL string.
|
|
111
|
+
"""
|
|
112
|
+
return self._endpoint
|
|
113
|
+
|
|
114
|
+
@classmethod
|
|
115
|
+
def validate(cls, cred_info: Dict[str, Any]) -> Tuple[List[str], List[str]]:
|
|
116
|
+
"""
|
|
117
|
+
Validates the dictionary describing a Nutanix Prism credential.
|
|
118
|
+
|
|
119
|
+
:param cred_info: Credential definition dictionary to validate.
|
|
120
|
+
|
|
121
|
+
:returns: A tuple of lists containing errors and warnings.
|
|
122
|
+
"""
|
|
123
|
+
|
|
124
|
+
errors = []
|
|
125
|
+
warnings = []
|
|
126
|
+
|
|
127
|
+
if "username" not in cred_info:
|
|
128
|
+
errors.append("missing 'username' in nutanix-prism credential.")
|
|
129
|
+
|
|
130
|
+
if "password" not in cred_info:
|
|
131
|
+
errors.append("missing 'password' in nutanix-prism credential.")
|
|
132
|
+
|
|
133
|
+
if "endpoint" not in cred_info:
|
|
134
|
+
errors.append("missing 'endpoint' in nutanix-prism credential.")
|
|
135
|
+
|
|
136
|
+
return errors, warnings
|
|
137
|
+
|
|
138
|
+
def as_dict(self) -> Dict[str, Any]:
|
|
139
|
+
"""
|
|
140
|
+
Returns a dictionary representation of this credential object.
|
|
141
|
+
"""
|
|
142
|
+
rtnval = super().as_dict()
|
|
143
|
+
|
|
144
|
+
rtnval["username"] = self._username
|
|
145
|
+
rtnval["password"] = self._password
|
|
146
|
+
rtnval["endpoint"] = self._endpoint
|
|
147
|
+
|
|
148
|
+
return rtnval
|
|
149
|
+
|
|
150
|
+
def __repr__(self) -> str:
|
|
151
|
+
"""
|
|
152
|
+
Returns a debug representation of this credential with the password redacted.
|
|
153
|
+
|
|
154
|
+
:returns: A redacted string representation safe for logs.
|
|
155
|
+
"""
|
|
156
|
+
rtnval = (
|
|
157
|
+
"NutanixPrismCredential("
|
|
158
|
+
"identifier={!r}, categories={!r}, username={!r}, password='***', endpoint={!r})"
|
|
159
|
+
).format(self._identifier, self._categories, self._username, self._endpoint)
|
|
160
|
+
|
|
161
|
+
return rtnval
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: oraclecloudapikeycredential
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`OracleCloudApiKeyCredential` which
|
|
5
|
+
wraps the four-field OCI API-key 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 OracleCloudApiKeyCredential(BaseCredential):
|
|
25
|
+
"""
|
|
26
|
+
The :class:`OracleCloudApiKeyCredential` is a container object that wraps the
|
|
27
|
+
four-field Oracle Cloud Infrastructure API-key credential material plus an
|
|
28
|
+
optional passphrase for encrypted keys.
|
|
29
|
+
|
|
30
|
+
.. code:: yaml
|
|
31
|
+
"identifier": "oci-key"
|
|
32
|
+
"category": "cloud-venue"
|
|
33
|
+
"provider": "oracle-cloud"
|
|
34
|
+
"tenancy_ocid": "ocid1.tenancy.oc1..aaaa"
|
|
35
|
+
"user_ocid": "ocid1.user.oc1..bbbb"
|
|
36
|
+
"private_key": "-----BEGIN PRIVATE KEY-----\\n...\\n-----END PRIVATE KEY-----\\n"
|
|
37
|
+
"fingerprint": "aa:bb:cc:dd:ee:ff:00:11:22:33:44:55:66:77:88:99"
|
|
38
|
+
"passphrase": null
|
|
39
|
+
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
TENANCY_OCID_PREFIX = "ocid1.tenancy."
|
|
43
|
+
USER_OCID_PREFIX = "ocid1.user."
|
|
44
|
+
|
|
45
|
+
def __init__(self, *, identifier: str, categories: List[str], tenancy_ocid: str, user_ocid: str,
|
|
46
|
+
private_key: str, fingerprint: str, passphrase: Optional[str] = None,
|
|
47
|
+
role: Optional[str] = "priv") -> None:
|
|
48
|
+
"""
|
|
49
|
+
Initializes an :class:`OracleCloudApiKeyCredential` 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 tenancy_ocid: The OCI tenancy OCID.
|
|
54
|
+
:param user_ocid: The OCI user OCID.
|
|
55
|
+
:param private_key: The PEM body of the OCI API signing key.
|
|
56
|
+
:param fingerprint: The fingerprint of the OCI API signing key.
|
|
57
|
+
:param passphrase: The optional passphrase for an encrypted private key.
|
|
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 OracleCloudApiKeyCredential 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 tenancy_ocid is None or len(tenancy_ocid) == 0:
|
|
73
|
+
raise ConfigurationError("The OracleCloudApiKeyCredential constructor requires a non-empty 'tenancy_ocid' parameter be provided.")
|
|
74
|
+
if user_ocid is None or len(user_ocid) == 0:
|
|
75
|
+
raise ConfigurationError("The OracleCloudApiKeyCredential constructor requires a non-empty 'user_ocid' parameter be provided.")
|
|
76
|
+
if private_key is None or len(private_key) == 0:
|
|
77
|
+
raise ConfigurationError("The OracleCloudApiKeyCredential constructor requires a non-empty 'private_key' parameter be provided.")
|
|
78
|
+
if fingerprint is None or len(fingerprint) == 0:
|
|
79
|
+
raise ConfigurationError("The OracleCloudApiKeyCredential constructor requires a non-empty 'fingerprint' parameter be provided.")
|
|
80
|
+
|
|
81
|
+
if not tenancy_ocid.startswith(self.TENANCY_OCID_PREFIX):
|
|
82
|
+
errmsg_lines = [
|
|
83
|
+
"The OracleCloudApiKeyCredential 'tenancy_ocid' parameter has an invalid OCID prefix.",
|
|
84
|
+
"EXPECTED PREFIX: {}".format(self.TENANCY_OCID_PREFIX),
|
|
85
|
+
"PROVIDED VALUE: {}".format(tenancy_ocid),
|
|
86
|
+
]
|
|
87
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
88
|
+
raise ConfigurationError(errmsg)
|
|
89
|
+
|
|
90
|
+
if not user_ocid.startswith(self.USER_OCID_PREFIX):
|
|
91
|
+
errmsg_lines = [
|
|
92
|
+
"The OracleCloudApiKeyCredential 'user_ocid' parameter has an invalid OCID prefix.",
|
|
93
|
+
"EXPECTED PREFIX: {}".format(self.USER_OCID_PREFIX),
|
|
94
|
+
"PROVIDED VALUE: {}".format(user_ocid),
|
|
95
|
+
]
|
|
96
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
97
|
+
raise ConfigurationError(errmsg)
|
|
98
|
+
|
|
99
|
+
self._tenancy_ocid = tenancy_ocid
|
|
100
|
+
self._user_ocid = user_ocid
|
|
101
|
+
self._private_key = private_key
|
|
102
|
+
self._fingerprint = fingerprint
|
|
103
|
+
self._passphrase = passphrase
|
|
104
|
+
return
|
|
105
|
+
|
|
106
|
+
@property
|
|
107
|
+
def tenancy_ocid(self) -> str:
|
|
108
|
+
"""
|
|
109
|
+
Returns the OCI tenancy OCID.
|
|
110
|
+
|
|
111
|
+
:returns: The tenancy OCID string.
|
|
112
|
+
"""
|
|
113
|
+
return self._tenancy_ocid
|
|
114
|
+
|
|
115
|
+
@property
|
|
116
|
+
def user_ocid(self) -> str:
|
|
117
|
+
"""
|
|
118
|
+
Returns the OCI user OCID.
|
|
119
|
+
|
|
120
|
+
:returns: The user OCID string.
|
|
121
|
+
"""
|
|
122
|
+
return self._user_ocid
|
|
123
|
+
|
|
124
|
+
@property
|
|
125
|
+
def private_key(self) -> str:
|
|
126
|
+
"""
|
|
127
|
+
Returns the PEM body of the OCI API signing key.
|
|
128
|
+
|
|
129
|
+
:returns: The private key string.
|
|
130
|
+
"""
|
|
131
|
+
return self._private_key
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def fingerprint(self) -> str:
|
|
135
|
+
"""
|
|
136
|
+
Returns the fingerprint of the OCI API signing key.
|
|
137
|
+
|
|
138
|
+
:returns: The fingerprint string.
|
|
139
|
+
"""
|
|
140
|
+
return self._fingerprint
|
|
141
|
+
|
|
142
|
+
@property
|
|
143
|
+
def passphrase(self) -> Optional[str]:
|
|
144
|
+
"""
|
|
145
|
+
Returns the passphrase for an encrypted private key.
|
|
146
|
+
|
|
147
|
+
:returns: The passphrase string, or None.
|
|
148
|
+
"""
|
|
149
|
+
return self._passphrase
|
|
150
|
+
|
|
151
|
+
@classmethod
|
|
152
|
+
def validate(cls, cred_info: Dict[str, Any]) -> Tuple[List[str], List[str]]:
|
|
153
|
+
"""
|
|
154
|
+
Validates the dictionary describing an Oracle Cloud API-key credential.
|
|
155
|
+
|
|
156
|
+
:param cred_info: Credential definition dictionary to validate.
|
|
157
|
+
|
|
158
|
+
:returns: A tuple of lists containing errors and warnings.
|
|
159
|
+
"""
|
|
160
|
+
|
|
161
|
+
errors = []
|
|
162
|
+
warnings = []
|
|
163
|
+
|
|
164
|
+
if "tenancy_ocid" not in cred_info:
|
|
165
|
+
errors.append("missing 'tenancy_ocid' in oracle-api-key credential.")
|
|
166
|
+
|
|
167
|
+
if "user_ocid" not in cred_info:
|
|
168
|
+
errors.append("missing 'user_ocid' in oracle-api-key credential.")
|
|
169
|
+
|
|
170
|
+
if "private_key" not in cred_info:
|
|
171
|
+
errors.append("missing 'private_key' in oracle-api-key credential.")
|
|
172
|
+
|
|
173
|
+
if "fingerprint" not in cred_info:
|
|
174
|
+
errors.append("missing 'fingerprint' in oracle-api-key credential.")
|
|
175
|
+
|
|
176
|
+
return errors, warnings
|
|
177
|
+
|
|
178
|
+
def as_dict(self) -> Dict[str, Any]:
|
|
179
|
+
"""
|
|
180
|
+
Returns a dictionary representation of this credential object.
|
|
181
|
+
"""
|
|
182
|
+
rtnval = super().as_dict()
|
|
183
|
+
|
|
184
|
+
rtnval["tenancy_ocid"] = self._tenancy_ocid
|
|
185
|
+
rtnval["user_ocid"] = self._user_ocid
|
|
186
|
+
rtnval["private_key"] = self._private_key
|
|
187
|
+
rtnval["fingerprint"] = self._fingerprint
|
|
188
|
+
rtnval["passphrase"] = self._passphrase
|
|
189
|
+
|
|
190
|
+
return rtnval
|
|
191
|
+
|
|
192
|
+
def __repr__(self) -> str:
|
|
193
|
+
"""
|
|
194
|
+
Returns a debug representation of this credential with key material redacted.
|
|
195
|
+
|
|
196
|
+
:returns: A redacted string representation safe for logs.
|
|
197
|
+
"""
|
|
198
|
+
passphrase_repr = "None"
|
|
199
|
+
if self._passphrase is not None:
|
|
200
|
+
passphrase_repr = "'***'"
|
|
201
|
+
|
|
202
|
+
rtnval = (
|
|
203
|
+
"OracleCloudApiKeyCredential("
|
|
204
|
+
"identifier={!r}, categories={!r}, tenancy_ocid={!r}, user_ocid={!r}, "
|
|
205
|
+
"private_key='***', fingerprint={!r}, passphrase={})"
|
|
206
|
+
).format(
|
|
207
|
+
self._identifier, self._categories, self._tenancy_ocid, self._user_ocid,
|
|
208
|
+
self._fingerprint, passphrase_repr,
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
return rtnval
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: personalapitokencredential
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`PersonalApiTokenCredential` used
|
|
5
|
+
for personal API token authentication.
|
|
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 PersonalApiTokenCredential(BaseCredential):
|
|
22
|
+
"""
|
|
23
|
+
The :class:`PersonalApiTokenCredential` is a container object for a personal api token credential.
|
|
24
|
+
|
|
25
|
+
.. code:: yaml
|
|
26
|
+
"identifier": "jira-token"
|
|
27
|
+
"category": "personal-api-token"
|
|
28
|
+
"username": "some.guy@google.com"
|
|
29
|
+
"token": "B130909CD9744F1E8679755034F9E70B08519F16C3DE46FCBFE82117F2794BA1"
|
|
30
|
+
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, *, identifier: str, categories: List[str], username: str, token: str, role: Optional[str] = "priv"):
|
|
34
|
+
"""
|
|
35
|
+
Initializes a :class:`PersonalApiTokenCredential` instance.
|
|
36
|
+
|
|
37
|
+
:param identifier: The identifier that is used to reference this credential. (required)
|
|
38
|
+
:param categories: The categories of authentication that are supported by the credential
|
|
39
|
+
:param username: The username associated with the personal token.
|
|
40
|
+
:param token: A token that services as an identity and authenticate to allow the use of specific APIs.
|
|
41
|
+
"""
|
|
42
|
+
super().__init__(identifier=identifier, categories=categories, role=role)
|
|
43
|
+
|
|
44
|
+
if "personal-api-token" not in categories:
|
|
45
|
+
raise ConfigurationError("The PersonalApiTokenCredential should only be given credentials of category 'personal-api-token'.")
|
|
46
|
+
if len(token) == 0:
|
|
47
|
+
raise ConfigurationError("The PersonalApiTokenCredential constructor requires a 'token' parameter be provided.")
|
|
48
|
+
|
|
49
|
+
self._username = username
|
|
50
|
+
self._token = token
|
|
51
|
+
return
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def username(self):
|
|
55
|
+
"""
|
|
56
|
+
Returns the username associated with this credential.
|
|
57
|
+
|
|
58
|
+
:returns: The username string.
|
|
59
|
+
"""
|
|
60
|
+
return self._username
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def token(self):
|
|
64
|
+
"""
|
|
65
|
+
Returns the personal API token.
|
|
66
|
+
|
|
67
|
+
:returns: The token string.
|
|
68
|
+
"""
|
|
69
|
+
return self._token
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def validate(cls, cred_info) -> Tuple[List[str], List[str]]:
|
|
73
|
+
"""
|
|
74
|
+
Validates the dictionary describing a personal API token credential.
|
|
75
|
+
|
|
76
|
+
:param cred_info: Credential definition dictionary to validate.
|
|
77
|
+
|
|
78
|
+
:returns: A tuple of lists containing errors and warnings.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
errors = []
|
|
82
|
+
warnings = []
|
|
83
|
+
|
|
84
|
+
if "username" not in cred_info:
|
|
85
|
+
errors.append("missing 'username' in personal api token credential.")
|
|
86
|
+
|
|
87
|
+
if "token" not in cred_info:
|
|
88
|
+
errors.append("missing 'token' in personal 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["username"] = self._username
|
|
99
|
+
rtnval["token"] = self._token
|
|
100
|
+
|
|
101
|
+
return rtnval
|