-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ssh key authentication support, closes #81
- Loading branch information
1 parent
6b188e4
commit fbb42e7
Showing
6 changed files
with
94 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,42 @@ | ||
"""Validate credential configuration variables.""" | ||
|
||
# Standard Library | ||
from typing import Optional | ||
|
||
# Third Party | ||
from pydantic import SecretStr, StrictStr | ||
from pydantic import FilePath, SecretStr, StrictStr, constr, root_validator | ||
|
||
# Local | ||
from ..main import HyperglassModel | ||
from ..main import HyperglassModelExtra | ||
|
||
Methods = constr(regex=r"(password|unencrypted_key|encrypted_key)") | ||
|
||
|
||
class Credential(HyperglassModel): | ||
class Credential(HyperglassModelExtra): | ||
"""Model for per-credential config in devices.yaml.""" | ||
|
||
username: StrictStr | ||
password: SecretStr | ||
password: Optional[SecretStr] | ||
key: Optional[FilePath] | ||
|
||
@root_validator | ||
def validate_credential(cls, values): | ||
"""Ensure either a password or an SSH key is set.""" | ||
if values["key"] is None and values["password"] is None: | ||
raise ValueError( | ||
"Either a password or an SSH key must be specified for user '{}'".format( | ||
values["username"] | ||
) | ||
) | ||
return values | ||
|
||
def __init__(self, **kwargs): | ||
"""Set private attribute _method based on validated model.""" | ||
super().__init__(**kwargs) | ||
self._method = None | ||
if self.password is not None and self.key is not None: | ||
self._method = "encrypted_key" | ||
elif self.password is None: | ||
self._method = "unencrypted_key" | ||
elif self.key is None: | ||
self._method = "password" |