1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

35 lines
889 B
Python
Raw Normal View History

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