2019-09-11 01:35:31 -07:00
|
|
|
"""
|
|
|
|
Defines models for Credential config variables.
|
|
|
|
|
|
|
|
Imports config variables and overrides default class attributes.
|
|
|
|
|
|
|
|
Validates input for overridden parameters.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Third Party Imports
|
|
|
|
from pydantic import SecretStr
|
|
|
|
|
|
|
|
# Project Imports
|
2019-10-04 16:54:32 -07:00
|
|
|
from hyperglass.configuration.models._utils import HyperglassModel
|
2019-10-09 03:10:52 -07:00
|
|
|
from hyperglass.configuration.models._utils import clean_name
|
2019-09-11 01:35:31 -07:00
|
|
|
|
|
|
|
|
2019-10-04 16:54:32 -07:00
|
|
|
class Credential(HyperglassModel):
|
2019-09-11 01:35:31 -07:00
|
|
|
"""Model for per-credential config in devices.yaml"""
|
|
|
|
|
|
|
|
username: str
|
|
|
|
password: SecretStr
|
|
|
|
|
|
|
|
|
2019-10-04 16:54:32 -07:00
|
|
|
class Credentials(HyperglassModel):
|
2019-09-11 01:35:31 -07:00
|
|
|
"""Base model for credentials class"""
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def import_params(cls, input_params):
|
|
|
|
"""
|
|
|
|
Imports passed dict from YAML config, removes unsupported
|
|
|
|
characters from device names, dynamically sets attributes for
|
|
|
|
the credentials class.
|
|
|
|
"""
|
|
|
|
obj = Credentials()
|
|
|
|
for (credname, params) in input_params.items():
|
|
|
|
cred = clean_name(credname)
|
|
|
|
setattr(Credentials, cred, Credential(**params))
|
|
|
|
return obj
|