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,13 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: ccai.credentials
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Package that contains credential helper classes for Code Craft AI.
|
|
5
|
+
|
|
6
|
+
.. moduleauthor:: Myron Walker <myron.walker@gmail.com>
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__author__ = "Myron Walker"
|
|
10
|
+
__copyright__ = "Copyright 2025, Code Craft AI LLC"
|
|
11
|
+
__credits__ = []
|
|
12
|
+
|
|
13
|
+
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: apitokencredential
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`ApiTokenCredential` which is a simple
|
|
5
|
+
container used to hold an API token.
|
|
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 ApiTokenCredential(BaseCredential):
|
|
22
|
+
"""
|
|
23
|
+
The :class:`ApiTokenCredential` is a container object for an api token credential.
|
|
24
|
+
|
|
25
|
+
.. code:: yaml
|
|
26
|
+
"identifier": "jira-token"
|
|
27
|
+
"category": "api-token"
|
|
28
|
+
"token": "B130909CD9744F1E8679755034F9E70B08519F16C3DE46FCBFE82117F2794BA1"
|
|
29
|
+
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def __init__(self, *, identifier: str, categories: List[str], token: str, role: Optional[str] = "priv"):
|
|
33
|
+
"""
|
|
34
|
+
Initializes an :class:`ApiTokenCredential` instance.
|
|
35
|
+
|
|
36
|
+
:param identifier: The identifier that is used to reference this credential. (required)
|
|
37
|
+
:param categories: The categories of authentication that are supported by the credential
|
|
38
|
+
:param token: A token that serves as an identity credential used to authenticate
|
|
39
|
+
access to specific APIs.
|
|
40
|
+
"""
|
|
41
|
+
super().__init__(identifier=identifier, categories=categories, role=role)
|
|
42
|
+
|
|
43
|
+
if "api-token" not in categories:
|
|
44
|
+
raise ConfigurationError("The ApiTokenCredential should only be given credentials of category 'api-token'.")
|
|
45
|
+
if token is None or len(token) == 0:
|
|
46
|
+
raise ConfigurationError("The ApiTokenCredential constructor requires a 'token' parameter be provided.")
|
|
47
|
+
|
|
48
|
+
self._token = token
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def token(self) -> str:
|
|
53
|
+
"""
|
|
54
|
+
Returns the API token string.
|
|
55
|
+
|
|
56
|
+
:returns: The API token value.
|
|
57
|
+
"""
|
|
58
|
+
return self._token
|
|
59
|
+
|
|
60
|
+
@classmethod
|
|
61
|
+
def validate(cls, cred_info: Dict[str, Any]) -> Tuple[List[str], List[str]]:
|
|
62
|
+
"""
|
|
63
|
+
Validates the dictionary describing an API token credential.
|
|
64
|
+
|
|
65
|
+
:param cred_info: The credential information dictionary to validate.
|
|
66
|
+
|
|
67
|
+
:returns: A tuple of lists containing errors and warnings.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
errors = []
|
|
71
|
+
warnings = []
|
|
72
|
+
|
|
73
|
+
if "token" not in cred_info:
|
|
74
|
+
errors.append("missing 'token' in api token credential.")
|
|
75
|
+
|
|
76
|
+
return errors, warnings
|
|
77
|
+
|
|
78
|
+
def as_dict(self) -> Dict[str, Any]:
|
|
79
|
+
"""
|
|
80
|
+
Returns a dictionary representation of this credential object.
|
|
81
|
+
"""
|
|
82
|
+
rtnval = super().as_dict()
|
|
83
|
+
|
|
84
|
+
rtnval["token"] = self._token
|
|
85
|
+
|
|
86
|
+
return rtnval
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: awsaccesskeycredential
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`AwsAccessKeyCredential` which
|
|
5
|
+
represents an AWS access key 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 AwsAccessKeyCredential(BaseCredential):
|
|
22
|
+
"""
|
|
23
|
+
The :class:`AwsAccessKeyCredential` is a container object for an AWS
|
|
24
|
+
access key credential.
|
|
25
|
+
|
|
26
|
+
.. code:: yaml
|
|
27
|
+
"identifier": "aws-cred"
|
|
28
|
+
"category": "aws-access-key"
|
|
29
|
+
"keyid": "FETD64DUFYLUFY"
|
|
30
|
+
"secret": "B130909CD9744F1E8679755034F9E70B08519F16C3DE46FCBFE82117F2794BA1"
|
|
31
|
+
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __init__(self, *, identifier: str, categories: List[str], keyid: str, secret: str, role: Optional[str] = "priv"):
|
|
35
|
+
"""
|
|
36
|
+
Initializes an :class:`AwsAccessKeyCredential` 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 keyid: The AWS key identifier.
|
|
41
|
+
:param secret: The AWS secret key.
|
|
42
|
+
"""
|
|
43
|
+
super().__init__(identifier=identifier, categories=categories, role=role)
|
|
44
|
+
|
|
45
|
+
if "aws-access-key" not in categories:
|
|
46
|
+
raise ConfigurationError("The AwsAccessKeyCredential should only be given credentials of category 'aws-access-key'.")
|
|
47
|
+
if len(keyid) == 0:
|
|
48
|
+
raise ConfigurationError("The AwsAccessKeyCredential constructor requires a 'keyid' parameter be provided.")
|
|
49
|
+
if len(secret) == 0:
|
|
50
|
+
raise ConfigurationError("The AwsAccessKeyCredential constructor requires a 'secret' parameter be provided.")
|
|
51
|
+
|
|
52
|
+
self._keyid = keyid
|
|
53
|
+
self._secret = secret
|
|
54
|
+
return
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def keyid(self):
|
|
58
|
+
"""
|
|
59
|
+
Returns the AWS key identifier associated with this credential.
|
|
60
|
+
|
|
61
|
+
:returns: The key identifier string.
|
|
62
|
+
"""
|
|
63
|
+
return self._keyid
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def secret(self):
|
|
67
|
+
"""
|
|
68
|
+
Returns the AWS secret key.
|
|
69
|
+
|
|
70
|
+
:returns: The secret key string.
|
|
71
|
+
"""
|
|
72
|
+
return self._secret
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def validate(cls, cred_info) -> Tuple[List[str], List[str]]:
|
|
77
|
+
"""
|
|
78
|
+
Validates the dictionary describing an AWS access key credential.
|
|
79
|
+
|
|
80
|
+
:param cred_info: Credential definition dictionary to validate.
|
|
81
|
+
|
|
82
|
+
:returns: A tuple of lists containing errors and warnings.
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
errors = []
|
|
86
|
+
warnings = []
|
|
87
|
+
|
|
88
|
+
if "keyid" not in cred_info:
|
|
89
|
+
errors.append("missing 'keyid' in aws access key credential.")
|
|
90
|
+
|
|
91
|
+
if "secret" not in cred_info:
|
|
92
|
+
errors.append("missing 'secret' in aws access key credential.")
|
|
93
|
+
|
|
94
|
+
return errors, warnings
|
|
95
|
+
|
|
96
|
+
def as_dict(self) -> Dict[str, Any]:
|
|
97
|
+
"""
|
|
98
|
+
Returns a dictionary representation of this credential object.
|
|
99
|
+
"""
|
|
100
|
+
rtnval = super().as_dict()
|
|
101
|
+
|
|
102
|
+
rtnval["keyid"] = self._keyid
|
|
103
|
+
rtnval["secret"] = self._secret
|
|
104
|
+
|
|
105
|
+
return rtnval
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: azureclientsecretcredential
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`AzureClientSecretCredential` which is used
|
|
5
|
+
for application access to Azure.
|
|
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 AzureClientSecretCredential(BaseCredential):
|
|
22
|
+
"""
|
|
23
|
+
The :class:`AzureClientSecretCredential` is a container object for the parameters for a Microsoft Azure 'ClientSecretCredential'.
|
|
24
|
+
|
|
25
|
+
.. code:: yaml
|
|
26
|
+
"identifier": "azure-client"
|
|
27
|
+
"category": "azure-client-secret"
|
|
28
|
+
"tenant_id": ""
|
|
29
|
+
"client_id": ""
|
|
30
|
+
"client_secret": "@@&_@@&_LetMeComeIn"
|
|
31
|
+
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __init__(self, *, identifier: str, categories: List[str], tenant_id: str, client_id: str,
|
|
35
|
+
client_secret: str, role: Optional[str] = "priv"):
|
|
36
|
+
"""
|
|
37
|
+
Initializes an :class:`AzureClientSecretCredential` instance.
|
|
38
|
+
|
|
39
|
+
:param identifier: The identifier that is used to reference this credential. (required)
|
|
40
|
+
:param categories: The categories of authentication that are supported by the credential
|
|
41
|
+
:param tenant_id: The Microsoft Azure tenant id.
|
|
42
|
+
:param client_id: The Microsoft Azure client id.
|
|
43
|
+
:param client_secret: The Microsoft Azure client secret.
|
|
44
|
+
"""
|
|
45
|
+
super().__init__(identifier=identifier, categories=categories, role=role)
|
|
46
|
+
|
|
47
|
+
if "azure-client-secret" not in categories:
|
|
48
|
+
raise ConfigurationError("The AzureClientSecretCredential should only be given credentials of category 'azure-client-secret'.")
|
|
49
|
+
|
|
50
|
+
self._tenant_id = tenant_id
|
|
51
|
+
self._client_id = client_id
|
|
52
|
+
self._client_secret = client_secret
|
|
53
|
+
return
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def client_id(self):
|
|
57
|
+
"""
|
|
58
|
+
Returns the Azure client identifier for this credential.
|
|
59
|
+
|
|
60
|
+
:returns: Azure client identifier.
|
|
61
|
+
"""
|
|
62
|
+
return self._client_id
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def client_secret(self):
|
|
66
|
+
"""
|
|
67
|
+
Returns the Azure client secret.
|
|
68
|
+
|
|
69
|
+
:returns: The client secret string.
|
|
70
|
+
"""
|
|
71
|
+
return self._client_secret
|
|
72
|
+
|
|
73
|
+
@property
|
|
74
|
+
def tenant_id(self):
|
|
75
|
+
"""
|
|
76
|
+
Returns the Azure tenant identifier.
|
|
77
|
+
|
|
78
|
+
:returns: The tenant identifier string.
|
|
79
|
+
"""
|
|
80
|
+
return self._tenant_id
|
|
81
|
+
|
|
82
|
+
@classmethod
|
|
83
|
+
def validate(cls, cred_info) -> Tuple[List[str], List[str]]:
|
|
84
|
+
"""
|
|
85
|
+
Validates a dictionary describing an Azure client secret credential.
|
|
86
|
+
|
|
87
|
+
:param cred_info: Credential definition dictionary to validate.
|
|
88
|
+
|
|
89
|
+
:returns: A tuple of lists containing errors and warnings.
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
errors = []
|
|
93
|
+
warnings = []
|
|
94
|
+
|
|
95
|
+
if "client_id" not in cred_info:
|
|
96
|
+
errors.append("missing 'client_id' in azure-client-secret credential.")
|
|
97
|
+
|
|
98
|
+
if "client_secret" not in cred_info:
|
|
99
|
+
errors.append("missing 'client_secret' in azure-client-secret credential.")
|
|
100
|
+
|
|
101
|
+
if "tenant_id" not in cred_info:
|
|
102
|
+
errors.append("missing 'tenant_id' in azure-client-secret credential.")
|
|
103
|
+
|
|
104
|
+
return errors, warnings
|
|
105
|
+
|
|
106
|
+
def as_dict(self) -> Dict[str, Any]:
|
|
107
|
+
"""
|
|
108
|
+
Returns a dictionary representation of this credential object.
|
|
109
|
+
"""
|
|
110
|
+
rtnval = super().as_dict()
|
|
111
|
+
|
|
112
|
+
rtnval["client_id"] = self._client_id
|
|
113
|
+
rtnval["client_secret"] = self._client_secret
|
|
114
|
+
rtnval["tenant_id"] = self._tenant_id
|
|
115
|
+
|
|
116
|
+
return rtnval
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: azuremanagedidentitycredential
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`AzureManagedIdentityCredential` which
|
|
5
|
+
references an Azure managed identity resolved at use time.
|
|
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 AzureManagedIdentityCredential(BaseCredential):
|
|
25
|
+
"""
|
|
26
|
+
The :class:`AzureManagedIdentityCredential` is a container object that references a
|
|
27
|
+
system-assigned or user-assigned Azure managed identity. No secret material is
|
|
28
|
+
stored; the credential is resolved at use time against the Azure Instance Metadata
|
|
29
|
+
Service from inside an Azure-hosted runtime.
|
|
30
|
+
|
|
31
|
+
.. code:: yaml
|
|
32
|
+
"identifier": "azure-mi"
|
|
33
|
+
"category": "cloud-venue"
|
|
34
|
+
"provider": "azure-managed-identity"
|
|
35
|
+
"client_id": ""
|
|
36
|
+
"resource_id": ""
|
|
37
|
+
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
def __init__(self, *, identifier: str, categories: List[str], client_id: Optional[str] = None,
|
|
41
|
+
resource_id: Optional[str] = None, role: Optional[str] = "priv") -> None:
|
|
42
|
+
"""
|
|
43
|
+
Initializes an :class:`AzureManagedIdentityCredential` instance.
|
|
44
|
+
|
|
45
|
+
:param identifier: The identifier that is used to reference this credential. (required)
|
|
46
|
+
:param categories: The categories of authentication that are supported by the credential.
|
|
47
|
+
:param client_id: The optional client id of a user-assigned managed identity.
|
|
48
|
+
:param resource_id: The optional resource id of a user-assigned managed identity.
|
|
49
|
+
:param role: Identifies the role of the credential.
|
|
50
|
+
|
|
51
|
+
:raises: ConfigurationError
|
|
52
|
+
"""
|
|
53
|
+
super().__init__(identifier=identifier, categories=categories, role=role)
|
|
54
|
+
|
|
55
|
+
if "cloud-venue" not in categories:
|
|
56
|
+
errmsg_lines = [
|
|
57
|
+
"The AzureManagedIdentityCredential should be given credentials of category 'cloud-venue'.",
|
|
58
|
+
"MISSING CATEGORY: cloud-venue",
|
|
59
|
+
]
|
|
60
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
61
|
+
raise ConfigurationError(errmsg)
|
|
62
|
+
|
|
63
|
+
if client_id is None and resource_id is None:
|
|
64
|
+
raise ConfigurationError("The AzureManagedIdentityCredential constructor requires at least one of 'client_id' or 'resource_id' be provided.")
|
|
65
|
+
|
|
66
|
+
self._client_id = client_id
|
|
67
|
+
self._resource_id = resource_id
|
|
68
|
+
return
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def client_id(self) -> Optional[str]:
|
|
72
|
+
"""
|
|
73
|
+
Returns the client id of the referenced user-assigned managed identity.
|
|
74
|
+
|
|
75
|
+
:returns: The client identifier string, or None.
|
|
76
|
+
"""
|
|
77
|
+
return self._client_id
|
|
78
|
+
|
|
79
|
+
@property
|
|
80
|
+
def resource_id(self) -> Optional[str]:
|
|
81
|
+
"""
|
|
82
|
+
Returns the resource id of the referenced user-assigned managed identity.
|
|
83
|
+
|
|
84
|
+
:returns: The resource identifier string, or None.
|
|
85
|
+
"""
|
|
86
|
+
return self._resource_id
|
|
87
|
+
|
|
88
|
+
@classmethod
|
|
89
|
+
def validate(cls, cred_info: Dict[str, Any]) -> Tuple[List[str], List[str]]:
|
|
90
|
+
"""
|
|
91
|
+
Validates the dictionary describing an Azure managed identity 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
|
+
has_client_id = "client_id" in cred_info
|
|
102
|
+
has_resource_id = "resource_id" in cred_info
|
|
103
|
+
|
|
104
|
+
if not has_client_id and not has_resource_id:
|
|
105
|
+
errors.append("at least one of 'client_id' or 'resource_id' must be provided in azure-managed-identity 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["client_id"] = self._client_id
|
|
116
|
+
rtnval["resource_id"] = self._resource_id
|
|
117
|
+
|
|
118
|
+
return rtnval
|
|
119
|
+
|
|
120
|
+
def __repr__(self) -> str:
|
|
121
|
+
"""
|
|
122
|
+
Returns a debug representation of this credential.
|
|
123
|
+
|
|
124
|
+
:returns: A string representation safe for logs.
|
|
125
|
+
"""
|
|
126
|
+
rtnval = (
|
|
127
|
+
"AzureManagedIdentityCredential("
|
|
128
|
+
"identifier={!r}, categories={!r}, client_id={!r}, resource_id={!r})"
|
|
129
|
+
).format(self._identifier, self._categories, self._client_id, self._resource_id)
|
|
130
|
+
|
|
131
|
+
return rtnval
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: azureserviceprincipalcredential
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`AzureServicePrincipalCredential` which
|
|
5
|
+
represents an Azure service principal credential for cloud-venue access.
|
|
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 AzureServicePrincipalCredential(BaseCredential):
|
|
25
|
+
"""
|
|
26
|
+
The :class:`AzureServicePrincipalCredential` is a container object for an Azure
|
|
27
|
+
service principal credential used for application-based access to Azure cloud venues.
|
|
28
|
+
|
|
29
|
+
.. code:: yaml
|
|
30
|
+
"identifier": "azure-sp"
|
|
31
|
+
"category": "cloud-venue"
|
|
32
|
+
"provider": "azure-service-principal"
|
|
33
|
+
"tenant_id": ""
|
|
34
|
+
"client_id": ""
|
|
35
|
+
"client_secret": "@@&_@@&_LetMeComeIn"
|
|
36
|
+
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(self, *, identifier: str, categories: List[str], tenant_id: str, client_id: str,
|
|
40
|
+
client_secret: str, role: Optional[str] = "priv") -> None:
|
|
41
|
+
"""
|
|
42
|
+
Initializes an :class:`AzureServicePrincipalCredential` instance.
|
|
43
|
+
|
|
44
|
+
:param identifier: The identifier that is used to reference this credential. (required)
|
|
45
|
+
:param categories: The categories of authentication that are supported by the credential.
|
|
46
|
+
:param tenant_id: The Microsoft Azure tenant id.
|
|
47
|
+
:param client_id: The Microsoft Azure client (application) id.
|
|
48
|
+
:param client_secret: The Microsoft Azure client secret.
|
|
49
|
+
:param role: Identifies the role of the credential.
|
|
50
|
+
|
|
51
|
+
:raises: ConfigurationError
|
|
52
|
+
"""
|
|
53
|
+
super().__init__(identifier=identifier, categories=categories, role=role)
|
|
54
|
+
|
|
55
|
+
if "cloud-venue" not in categories:
|
|
56
|
+
errmsg_lines = [
|
|
57
|
+
"The AzureServicePrincipalCredential should be given credentials of category 'cloud-venue'.",
|
|
58
|
+
"MISSING CATEGORY: cloud-venue",
|
|
59
|
+
]
|
|
60
|
+
errmsg = os.linesep.join(errmsg_lines)
|
|
61
|
+
raise ConfigurationError(errmsg)
|
|
62
|
+
|
|
63
|
+
if tenant_id is None or len(tenant_id) == 0:
|
|
64
|
+
raise ConfigurationError("The AzureServicePrincipalCredential constructor requires a non-empty 'tenant_id' parameter be provided.")
|
|
65
|
+
if client_id is None or len(client_id) == 0:
|
|
66
|
+
raise ConfigurationError("The AzureServicePrincipalCredential constructor requires a non-empty 'client_id' parameter be provided.")
|
|
67
|
+
if client_secret is None or len(client_secret) == 0:
|
|
68
|
+
raise ConfigurationError("The AzureServicePrincipalCredential constructor requires a non-empty 'client_secret' parameter be provided.")
|
|
69
|
+
|
|
70
|
+
self._tenant_id = tenant_id
|
|
71
|
+
self._client_id = client_id
|
|
72
|
+
self._client_secret = client_secret
|
|
73
|
+
return
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def client_id(self) -> str:
|
|
77
|
+
"""
|
|
78
|
+
Returns the Azure client (application) identifier for this credential.
|
|
79
|
+
|
|
80
|
+
:returns: The Azure client identifier string.
|
|
81
|
+
"""
|
|
82
|
+
return self._client_id
|
|
83
|
+
|
|
84
|
+
@property
|
|
85
|
+
def client_secret(self) -> str:
|
|
86
|
+
"""
|
|
87
|
+
Returns the Azure client secret.
|
|
88
|
+
|
|
89
|
+
:returns: The client secret string.
|
|
90
|
+
"""
|
|
91
|
+
return self._client_secret
|
|
92
|
+
|
|
93
|
+
@property
|
|
94
|
+
def tenant_id(self) -> str:
|
|
95
|
+
"""
|
|
96
|
+
Returns the Azure tenant identifier.
|
|
97
|
+
|
|
98
|
+
:returns: The tenant identifier string.
|
|
99
|
+
"""
|
|
100
|
+
return self._tenant_id
|
|
101
|
+
|
|
102
|
+
@classmethod
|
|
103
|
+
def validate(cls, cred_info: Dict[str, Any]) -> Tuple[List[str], List[str]]:
|
|
104
|
+
"""
|
|
105
|
+
Validates the dictionary describing an Azure service principal credential.
|
|
106
|
+
|
|
107
|
+
:param cred_info: Credential definition dictionary to validate.
|
|
108
|
+
|
|
109
|
+
:returns: A tuple of lists containing errors and warnings.
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
errors = []
|
|
113
|
+
warnings = []
|
|
114
|
+
|
|
115
|
+
if "tenant_id" not in cred_info:
|
|
116
|
+
errors.append("missing 'tenant_id' in azure-service-principal credential.")
|
|
117
|
+
|
|
118
|
+
if "client_id" not in cred_info:
|
|
119
|
+
errors.append("missing 'client_id' in azure-service-principal credential.")
|
|
120
|
+
|
|
121
|
+
if "client_secret" not in cred_info:
|
|
122
|
+
errors.append("missing 'client_secret' in azure-service-principal credential.")
|
|
123
|
+
|
|
124
|
+
return errors, warnings
|
|
125
|
+
|
|
126
|
+
def as_dict(self) -> Dict[str, Any]:
|
|
127
|
+
"""
|
|
128
|
+
Returns a dictionary representation of this credential object.
|
|
129
|
+
"""
|
|
130
|
+
rtnval = super().as_dict()
|
|
131
|
+
|
|
132
|
+
rtnval["tenant_id"] = self._tenant_id
|
|
133
|
+
rtnval["client_id"] = self._client_id
|
|
134
|
+
rtnval["client_secret"] = self._client_secret
|
|
135
|
+
|
|
136
|
+
return rtnval
|
|
137
|
+
|
|
138
|
+
def __repr__(self) -> str:
|
|
139
|
+
"""
|
|
140
|
+
Returns a debug representation of this credential with the client secret redacted.
|
|
141
|
+
|
|
142
|
+
:returns: A redacted string representation safe for logs.
|
|
143
|
+
"""
|
|
144
|
+
rtnval = (
|
|
145
|
+
"AzureServicePrincipalCredential("
|
|
146
|
+
"identifier={!r}, categories={!r}, tenant_id={!r}, client_id={!r}, "
|
|
147
|
+
"client_secret='***')"
|
|
148
|
+
).format(self._identifier, self._categories, self._tenant_id, self._client_id)
|
|
149
|
+
|
|
150
|
+
return rtnval
|