2019-12-29 23:57:39 -07:00
|
|
|
"""Validate credential configuration variables."""
|
2019-09-11 01:35:31 -07:00
|
|
|
|
2020-02-03 02:35:11 -07:00
|
|
|
# Third Party
|
2019-09-11 01:35:31 -07:00
|
|
|
from pydantic import SecretStr
|
|
|
|
|
2020-02-03 02:35:11 -07:00
|
|
|
# Project
|
|
|
|
from hyperglass.configuration.models._utils import HyperglassModel, clean_name
|
2019-09-11 01:35:31 -07:00
|
|
|
|
|
|
|
|
2019-10-04 16:54:32 -07:00
|
|
|
class Credential(HyperglassModel):
|
2019-12-29 23:57:39 -07:00
|
|
|
"""Model for per-credential config in devices.yaml."""
|
2019-09-11 01:35:31 -07:00
|
|
|
|
|
|
|
username: str
|
|
|
|
password: SecretStr
|
|
|
|
|
|
|
|
|
2019-10-04 16:54:32 -07:00
|
|
|
class Credentials(HyperglassModel):
|
2019-12-29 23:57:39 -07:00
|
|
|
"""Base model for credentials class."""
|
2019-09-11 01:35:31 -07:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def import_params(cls, input_params):
|
2019-12-31 18:29:43 -07:00
|
|
|
"""Import credentials with corrected field names.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
input_params {dict} -- Credential definition
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
{object} -- Validated credential object
|
2019-09-11 01:35:31 -07:00
|
|
|
"""
|
|
|
|
obj = Credentials()
|
|
|
|
for (credname, params) in input_params.items():
|
|
|
|
cred = clean_name(credname)
|
|
|
|
setattr(Credentials, cred, Credential(**params))
|
|
|
|
return obj
|