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,145 @@
1
+ """
2
+ .. module:: proxmoxapitokencredential
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module that contains the :class:`ProxmoxApiTokenCredential` which
5
+ wraps the Proxmox 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
+ import re
19
+
20
+ from ccai.errors.exceptions import ConfigurationError
21
+
22
+ from ccai.credentials.basecredential import BaseCredential
23
+
24
+
25
+ class ProxmoxApiTokenCredential(BaseCredential):
26
+ """
27
+ The :class:`ProxmoxApiTokenCredential` is a container object that wraps the
28
+ Proxmox venue API-token authentication material. The ``token_id`` carries
29
+ the ``<user>@<realm>!<tokenname>`` form that Proxmox requires.
30
+
31
+ .. code:: yaml
32
+ "identifier": "proxmox-token"
33
+ "category": "vm-venue"
34
+ "provider": "proxmox"
35
+ "token_id": "root@pam!automation"
36
+ "secret": "..."
37
+
38
+ """
39
+
40
+ TOKEN_ID_PATTERN = r"^[^@!]+@[^@!]+![^@!]+$"
41
+
42
+ def __init__(self, *, identifier: str, categories: List[str], token_id: str,
43
+ secret: str, role: Optional[str] = "priv") -> None:
44
+ """
45
+ Initializes a :class:`ProxmoxApiTokenCredential` 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_id: The Proxmox API token id in ``<user>@<realm>!<tokenname>`` form.
50
+ :param secret: The Proxmox API token secret value.
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 "vm-venue" not in categories:
58
+ errmsg_lines = [
59
+ "The ProxmoxApiTokenCredential should be given credentials of category 'vm-venue'.",
60
+ "MISSING CATEGORY: vm-venue",
61
+ ]
62
+ errmsg = os.linesep.join(errmsg_lines)
63
+ raise ConfigurationError(errmsg)
64
+
65
+ if token_id is None or len(token_id) == 0:
66
+ raise ConfigurationError("The ProxmoxApiTokenCredential constructor requires a non-empty 'token_id' parameter be provided.")
67
+ if secret is None or len(secret) == 0:
68
+ raise ConfigurationError("The ProxmoxApiTokenCredential constructor requires a non-empty 'secret' parameter be provided.")
69
+
70
+ matched = re.match(self.TOKEN_ID_PATTERN, token_id)
71
+ if matched is None:
72
+ errmsg_lines = [
73
+ "The ProxmoxApiTokenCredential 'token_id' parameter has an invalid format.",
74
+ "EXPECTED FORMAT: <user>@<realm>!<tokenname>",
75
+ "PROVIDED VALUE: {}".format(token_id),
76
+ ]
77
+ errmsg = os.linesep.join(errmsg_lines)
78
+ raise ConfigurationError(errmsg)
79
+
80
+ self._token_id = token_id
81
+ self._secret = secret
82
+ return
83
+
84
+ @property
85
+ def token_id(self) -> str:
86
+ """
87
+ Returns the Proxmox API token id.
88
+
89
+ :returns: The token id string.
90
+ """
91
+ return self._token_id
92
+
93
+ @property
94
+ def secret(self) -> str:
95
+ """
96
+ Returns the Proxmox API token secret value.
97
+
98
+ :returns: The token secret string.
99
+ """
100
+ return self._secret
101
+
102
+ @classmethod
103
+ def validate(cls, cred_info: Dict[str, Any]) -> Tuple[List[str], List[str]]:
104
+ """
105
+ Validates the dictionary describing a Proxmox API-token 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 "token_id" not in cred_info:
116
+ errors.append("missing 'token_id' in proxmox-api-token credential.")
117
+
118
+ if "secret" not in cred_info:
119
+ errors.append("missing 'secret' in proxmox-api-token credential.")
120
+
121
+ return errors, warnings
122
+
123
+ def as_dict(self) -> Dict[str, Any]:
124
+ """
125
+ Returns a dictionary representation of this credential object.
126
+ """
127
+ rtnval = super().as_dict()
128
+
129
+ rtnval["token_id"] = self._token_id
130
+ rtnval["secret"] = self._secret
131
+
132
+ return rtnval
133
+
134
+ def __repr__(self) -> str:
135
+ """
136
+ Returns a debug representation of this credential with the secret redacted.
137
+
138
+ :returns: A redacted string representation safe for logs.
139
+ """
140
+ rtnval = (
141
+ "ProxmoxApiTokenCredential("
142
+ "identifier={!r}, categories={!r}, token_id={!r}, secret='***')"
143
+ ).format(self._identifier, self._categories, self._token_id)
144
+
145
+ return rtnval
@@ -0,0 +1,104 @@
1
+ """
2
+ .. module:: publickeycredential
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module that contains the :class:`PublicKeyCredential` which represents
5
+ a public and private key pair.
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 PublicKeyCredential(BaseCredential):
22
+ """
23
+ The :class:`PublicKeyCredential` is a container object for a public and private key pair.
24
+
25
+ .. code:: yaml
26
+ "identifier": "somename"
27
+ "category": "public-key"
28
+ "public": "FETD64DUFYLUFY"
29
+ "private": "B130909CD9744F1E8679755034F9E70B08519F16C3DE46FCBFE82117F2794BA1"
30
+
31
+ """
32
+
33
+ def __init__(self, *, identifier: str, categories: List[str], public: str, private: str, role: Optional[str] = "priv"):
34
+ """
35
+ Initializes a :class:`PublicKeyCredential` 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 public: The public key value.
40
+ :param private: The private key value.
41
+ """
42
+ super().__init__(identifier=identifier, categories=categories, role=role)
43
+
44
+ if "public-key" not in categories:
45
+ raise ConfigurationError("The PublicKeyCredential should only be given credentials of category 'public-key'.")
46
+ if len(public) == 0:
47
+ raise ConfigurationError("The PublicKeyCredential constructor requires a 'public' parameter be provided.")
48
+ if len(private) == 0:
49
+ raise ConfigurationError("The PublicKeyCredential constructor requires a 'private' parameter be provided.")
50
+
51
+ self._public = public
52
+ self._private = private
53
+ return
54
+
55
+ @property
56
+ def public(self):
57
+ """
58
+ Returns the public key value.
59
+
60
+ :returns: The public key string.
61
+ """
62
+ return self._public
63
+
64
+ @property
65
+ def private(self):
66
+ """
67
+ Returns the private key value.
68
+
69
+ :returns: The private key string.
70
+ """
71
+ return self._private
72
+
73
+
74
+ @classmethod
75
+ def validate(cls, cred_info) -> Tuple[List[str], List[str]]:
76
+ """
77
+ Validates the dictionary describing a public/private 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 "public" not in cred_info:
88
+ errors.append("missing 'public' in a public key credential.")
89
+
90
+ if "private" not in cred_info:
91
+ errors.append("missing 'private' in a public key 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["public"] = self._public
102
+ rtnval["private"] = self._private
103
+
104
+ return rtnval
File without changes
@@ -0,0 +1,113 @@
1
+ """
2
+ .. module:: runpodapikeycredential
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module that contains the :class:`RunpodApiKeyCredential` which
5
+ wraps the RunPod 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 RunpodApiKeyCredential(BaseCredential):
25
+ """
26
+ The :class:`RunpodApiKeyCredential` is a container object that wraps the
27
+ RunPod venue API-key authentication material.
28
+
29
+ .. code:: yaml
30
+ "identifier": "runpod-key"
31
+ "category": "hpc-venue"
32
+ "provider": "runpod"
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:`RunpodApiKeyCredential` 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 RunPod 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 "hpc-venue" not in categories:
52
+ errmsg_lines = [
53
+ "The RunpodApiKeyCredential 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 RunpodApiKeyCredential 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 RunPod 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 RunPod 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 runpod-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
+ "RunpodApiKeyCredential("
110
+ "identifier={!r}, categories={!r}, token='***')"
111
+ ).format(self._identifier, self._categories)
112
+
113
+ return rtnval
@@ -0,0 +1,103 @@
1
+
2
+ """
3
+ .. module:: secrettokencredential
4
+ :platform: Darwin, Linux, Unix, Windows
5
+ :synopsis: Module that contains the :class:`SecretTokenCredential` used for third party verifications such as hCaptcha.
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 SecretTokenCredential(BaseCredential):
22
+ """
23
+ The :class:`SecretTokenCredential` is a container object for a secret token credential.
24
+
25
+ .. code:: yaml
26
+ "identifier": "hcaptcha"
27
+ "category": "secret-token"
28
+ "endpoint": "https://hcaptcha.com/siteverify"
29
+ "token": "B130909CD9744F1E8679755034F9E70B08519F16C3DE46FCBFE82117F2794BA1"
30
+
31
+ """
32
+
33
+ def __init__(self, *, identifier: str, categories: List[str], endpoint: str, token: str, role: Optional[str] = "priv"):
34
+ """
35
+ Initializes a :class:`SecretTokenCredential` 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 endpoint: The endpoint of a service that has knowledge of the secret token.
40
+ :param token: A token that services as a secret token.
41
+
42
+ """
43
+ super().__init__(identifier=identifier, categories=categories, role=role)
44
+
45
+ if "secret-token" not in categories:
46
+ raise ConfigurationError("The SecretTokenCredential should only be given credentials of category 'secret-token'.")
47
+ if len(token) == 0:
48
+ raise ConfigurationError("The SecretTokenCredential constructor requires a 'token' parameter be provided.")
49
+
50
+ self._endpoint = endpoint
51
+ self._token = token
52
+
53
+ return
54
+
55
+ @property
56
+ def endpoint(self):
57
+ """
58
+ Returns the endpoint of the service that shares the secret token.
59
+
60
+ :returns: The endpoint string.
61
+ """
62
+ return self._endpoint
63
+
64
+ @property
65
+ def token(self):
66
+ """
67
+ Returns the secret token.
68
+
69
+ :returns: The token string.
70
+ """
71
+ return self._token
72
+
73
+ @classmethod
74
+ def validate(cls, cred_info) -> Tuple[List[str], List[str]]:
75
+ """
76
+ Validates the dictionary describing a secret token credential.
77
+
78
+ :param cred_info: Credential definition dictionary to validate.
79
+
80
+ :returns: A tuple of lists containing errors and warnings.
81
+ """
82
+
83
+ errors = []
84
+ warnings = []
85
+
86
+ if "endpoint" not in cred_info:
87
+ errors.append("missing 'endpoint' in secret token credential.")
88
+
89
+ if "token" not in cred_info:
90
+ errors.append("missing 'token' in secret token credential.")
91
+
92
+ return errors, warnings
93
+
94
+ def as_dict(self) -> Dict[str, Any]:
95
+ """
96
+ Returns a dictionary representation of this credential object.
97
+ """
98
+ rtnval = super().as_dict()
99
+
100
+ rtnval["endpoint"] = self._endpoint
101
+ rtnval["token"] = self._token
102
+
103
+ return rtnval
@@ -0,0 +1,221 @@
1
+ """
2
+ .. module:: sshcredential
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module that contains the :class:`SshCredential` which provides support
5
+ for SSH credentials including support for public key based SSH 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, Union
16
+
17
+ import os
18
+
19
+ from ccai.errors.exceptions import ConfigurationError
20
+
21
+ from ccai.credentials.basecredential import BaseCredential
22
+
23
+ class SshCredential(BaseCredential):
24
+ """
25
+ The :class:`SshCredential` is a container object for SSH credentials passed in the landscape
26
+ configuration file.
27
+
28
+ .. code:: yaml
29
+ "identifier": "straw-node"
30
+ "catagories": "ssh"
31
+ "username": "ubuntu"
32
+ "password": "@@&_@@&_LetMeComeIn"
33
+ "keyfile": "~/.ssh/id_blah_rsa"
34
+ "keypasswd": "@@&_@@&_LetMeComeIn"
35
+ "allow_agent": False
36
+ """
37
+
38
+ # 'keyraw' holds raw private-key material and is not matched by the sensitive
39
+ # field-name heuristic; 'password'/'keypasswd' are already caught by it.
40
+ SECRET_FIELDS = ("keyraw",)
41
+
42
+ def __init__(self, *, identifier: str, categories: List[str], username: str, role: Optional[str] = "priv",
43
+ password: Optional[str] = None, keyfile: Optional[str] = None, keyraw: Optional[str] = None,
44
+ keypasswd: Optional[str] = None, allow_agent: bool = False, primitive: bool = False):
45
+ """
46
+ Initializes an :class:`SshCredential` instance.
47
+
48
+ :param identifier: The identifier that is used to reference this credential. (required)
49
+ :param categories: The categories of authentication that are supported by the credential
50
+ :param role: An optional parameter that identifies the role that the credential is assigned to.
51
+ :param username: The username associated with this credential.
52
+ :param password: The password associated with this credential. A password is not required if a
53
+ keyfile parameter is provided or if 'allow_agent' is passed as 'True'.
54
+ :param keyfile: The private key file to use for authentication with this credential. A keyfile
55
+ is not required if a password was passed or if 'allow_agent' is passed as 'True'.
56
+ :param keyraw: The raw private key in base64 or other text encoded format.
57
+ :param keypasswd: The password to decrypt the keyfile if required by the keyfile.
58
+ :param allow_agent: Indicates if the SSH Agent can be used to authenticate connections.
59
+ :param primitive: When True, simulate file transfers and directory services with ssh commands.
60
+ """
61
+ super().__init__(identifier=identifier, categories=categories, role=role)
62
+
63
+ if "ssh" not in categories:
64
+ raise ConfigurationError("The SshCredential should only be given credentials of category 'ssh'.")
65
+ if len(username) == 0:
66
+ raise ConfigurationError("The SshCredential constructor requires a 'username' parameter be provided.")
67
+ if keyfile is not None and keyraw is not None:
68
+ raise ConfigurationError("The SshCredential constructor should only have either a keyfile or keyraw parameter but not both.")
69
+
70
+ if password is None:
71
+ if not allow_agent and keyfile is None and keyraw is None:
72
+ raise ConfigurationError("The SshCredential constructor requires one of: 'password is not None', 'keyfile is not None', 'keyraw is not None', 'allow_agent == True'.")
73
+
74
+ self._username = username
75
+ self._password = password
76
+ self._keyfile = keyfile
77
+ self._keyraw = keyraw
78
+ self._keypasswd = keypasswd
79
+ self._allow_agent = allow_agent
80
+ self._primitive = primitive
81
+ return
82
+
83
+ @property
84
+ def allow_agent(self) -> bool:
85
+ """
86
+ Indicates if the SSH agent is allowed for authentication.
87
+
88
+ :returns: True if the SSH agent can be used.
89
+ """
90
+ return self._allow_agent
91
+
92
+ @property
93
+ def keyfile(self) -> Union[str, None]:
94
+ """
95
+ Gets the path to the private key file used for authentication.
96
+
97
+ :returns: Path to the key file or ``None`` if not specified.
98
+ """
99
+ return self._keyfile
100
+
101
+ @property
102
+ def keyraw(self) -> Union[str, None]:
103
+ """
104
+ Gets the raw private key data used for authentication.
105
+
106
+ :returns: Raw key data or ``None`` if not specified.
107
+ """
108
+ return self._keyraw
109
+
110
+ @property
111
+ def keypasswd(self) -> Union[str, None]:
112
+ """
113
+ Returns the password used to decrypt the private key file if required.
114
+
115
+ :returns: Key password or ``None`` if not specified.
116
+ """
117
+ return self._keypasswd
118
+
119
+ @property
120
+ def password(self) -> Union[str, None]:
121
+ """
122
+ Returns the password used for authentication.
123
+
124
+ :returns: Password string or ``None`` if not provided.
125
+ """
126
+ return self._password
127
+
128
+ @property
129
+ def primitive(self) -> bool:
130
+ """
131
+ Indicates if primitive SSH operations should be used for file transfers.
132
+
133
+ :returns: ``True`` if primitive mode is enabled.
134
+ """
135
+ return self._primitive
136
+
137
+ @property
138
+ def username(self) -> str:
139
+ """
140
+ Returns the username associated with this credential.
141
+
142
+ :returns: The username string.
143
+ """
144
+ return self._username
145
+
146
+ @classmethod
147
+ def validate(cls, cred_info) -> Tuple[List[str], List[str]]:
148
+ """
149
+ Validates a dictionary describing an SSH credential.
150
+
151
+ :param cred_info: Credential definition dictionary to validate.
152
+
153
+ :returns: A tuple of lists containing errors and warnings.
154
+ """
155
+
156
+ errors = []
157
+ warnings = []
158
+
159
+ allow_agent = False
160
+ if "allow_agent" in cred_info:
161
+ allow_agent = cred_info["allow_agent"]
162
+
163
+ if "identifier" not in cred_info:
164
+ errors.append("missing 'identifier' parameter")
165
+
166
+ if "username" not in cred_info:
167
+ errors.append("missing 'username' parameter")
168
+
169
+ if "password" not in cred_info:
170
+ if not allow_agent:
171
+ if "keyfile" not in cred_info and "keyraw" not in cred_info:
172
+ errors.append("missing 'password' or 'keyfile' when allow_agent is 'False'")
173
+
174
+ if "keyfile" in cred_info and "keyraw" in cred_info:
175
+ errors.append("both 'keyfile' and 'keyraw' found in ssh credential.")
176
+
177
+ if "keyfile" in cred_info:
178
+ keyfile = os.path.abspath(os.path.expandvars(os.path.expanduser(cred_info["keyfile"])))
179
+ if not os.path.exists(keyfile):
180
+ errors.append("specified 'keyfile={}' not found.".format(keyfile))
181
+
182
+ return errors, warnings
183
+
184
+ def as_dict(self) -> Dict[str, Any]:
185
+ """
186
+ Returns a dictionary representation of this credential object.
187
+ """
188
+ rtnval = super().as_dict()
189
+
190
+ rtnval["username"] = self._username
191
+ rtnval["allow_agent"] = self._allow_agent
192
+ rtnval["primitive"] = self._primitive
193
+
194
+ if self._password is not None:
195
+ rtnval["password"] = self._password
196
+
197
+ if self._keyfile is not None:
198
+ rtnval["keyfile"] = self._keyfile
199
+
200
+ if self._keypasswd is not None:
201
+ rtnval["keypasswd"] = self._keypasswd
202
+
203
+ if self._keyraw is not None:
204
+ rtnval["keyraw"] = self._keyraw
205
+
206
+ return rtnval
207
+
208
+
209
+ def is_ssh_credential(cred: BaseCredential) -> bool:
210
+ """
211
+ Checks to see if a credential is a credential that has been designated
212
+ for use with SSH.
213
+
214
+ :returns: A boolean value representing if the credential has been marked as an SSH credential.
215
+ """
216
+ rtnval = False
217
+
218
+ if "ssh" in cred.categories:
219
+ rtnval = True
220
+
221
+ return rtnval