From 492e7917a193f074a83ae0dbae3ca1a820d5d976 Mon Sep 17 00:00:00 2001 From: checktheroads Date: Tue, 28 Jan 2020 10:06:43 -0700 Subject: [PATCH] allow int or str for primary_asn --- hyperglass/configuration/models/params.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hyperglass/configuration/models/params.py b/hyperglass/configuration/models/params.py index 5ed2135..e5f4c2f 100644 --- a/hyperglass/configuration/models/params.py +++ b/hyperglass/configuration/models/params.py @@ -31,7 +31,7 @@ class Params(HyperglassModel): # Top Level Params debug: StrictBool = False developer_mode: StrictBool = False - primary_asn: StrictStr = "65001" + primary_asn: Union[StrictInt, StrictStr] = "65001" org_name: StrictStr = "The Company" site_title: StrictStr = "hyperglass" site_description: StrictStr = "{org_name} Network Looking Glass" @@ -121,3 +121,17 @@ class Params(HyperglassModel): f'/tmp/hyperglass_{now.strftime(r"%Y%M%d-%H%M%S")}.log' # noqa: S108 ) return value + + @validator("primary_asn") + def validate_primary_asn(cls, value): + """Stringify primary_asn if passed as an integer. + + Arguments: + value {str|int} -- Unvalidated Primary ASN + + Returns: + {str} -- Stringified Primary ASN. + """ + if not isinstance(value, str): + value = str(value) + return value