Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@validator('something')
def check_something(cls, v):
val_calls.append(v)
return v
@validator("structured_output", pre=True, always=True)
def validate_structured_output(cls, value, values):
"""Validate structured output is supported on the device & set a default.
Raises:
ConfigError: Raised if true on a device that doesn't support structured output.
Returns:
{bool} -- True if hyperglass should return structured output for this device.
"""
if value is True and values["nos"] not in SUPPORTED_STRUCTURED_OUTPUT:
raise ConfigError(
"The 'structured_output' field is set to 'true' on device '{d}' with "
+ "NOS '{n}', which does not support structured output",
d=values["name"],
n=values["nos"],
)
@validator("validation_state", pre=True, always=True)
def validate_rpki_state(cls, value):
"""Convert string RPKI state to standard integer mapping."""
return RPKI_STATE_MAP.get(value, 3)
@validator("initial_molecule", pre=True)
def check_initial_molecules(cls, v):
if isinstance(v, (str, dict, Molecule)):
v = [v]
return v
@validator('amount')
def validate_amount(cls, value):
if value > 0:
return value
raise errors.InvalidParamError('Amount for payment must be bigger than 0')
@validator("credential", "proxy", "location")
def clean_name(cls, v): # noqa: N805
"""Remove or replace unsupported characters from field values"""
return clean_name(v)
@validator('default_template')
def theme_templates(cls, v, values, **kwargs):
templates_dir = values['theme_dir'] / 'templates'
if not v or templates_dir.is_dir():
return v
else:
raise ValueError(f'default-template set but template directory "{templates_dir}" does not exist')
@validator("site_description")
def validate_site_description(cls, value, values):
"""Format the site descripion with the org_name field.
Arguments:
value {str} -- site_description
values {str} -- Values before site_description
Returns:
{str} -- Formatted description
"""
return value.format(org_name=values["org_name"])
@validator("method")
def _check_method(cls, v):
return v.lower()
@validator("steps")
def check_steps(cls, v):
if not (all(x < y for x, y in zip(v, v[1:])) or all(x > y for x, y in zip(v, v[1:]))):
raise ValueError("Steps are not strictly monotonically increasing or decreasing.")
v = recursive_normalizer(v)
return v