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

fix feature enable/disable issue

This commit is contained in:
checktheroads
2020-03-23 09:44:50 -07:00
parent e5d13d0254
commit 50f1160a7f
3 changed files with 29 additions and 11 deletions

View File

@@ -86,6 +86,28 @@ class Query(BaseModel):
"""Create SHA256 hash digest of model representation."""
return hashlib.sha256(repr(self).encode()).hexdigest()
@validator("query_type")
def validate_query_type(cls, value):
"""Ensure query_type is enabled.
Arguments:
value {str} -- Query Type
Raises:
InputInvalid: Raised if query_type is disabled.
Returns:
{str} -- Valid query_type
"""
query_type_obj = getattr(params.queries, value)
if not query_type_obj.enable:
raise InputInvalid(
params.messages.feature_not_enabled,
level="warning",
feature=query_type_obj.display_name,
)
return value
@validator("query_location")
def validate_query_location(cls, value):
"""Ensure query_location is defined.

View File

@@ -28,9 +28,9 @@ class Messages(HyperglassModel):
description="Displayed when a query target is implicitly denied by a matched VRF's ACL. `{target}` may be used to display the denied query target.",
)
feature_not_enabled: StrictStr = Field(
"{feature} is not enabled for {device_name}.",
"{feature} is not enabled.",
title="Feature Not Enabled",
description="Displayed when a query type is submitted that is not supported or disabled. The hyperglass UI performs validation of supported query types prior to submitting any requests, so this is primarily relevant to the hyperglass API. `{feature}` and `{device_name}` may be used to display the disabled feature and the selected device/location.",
description="Displayed when a query type is submitted that is not supported or disabled. The hyperglass UI performs validation of supported query types prior to submitting any requests, so this is primarily relevant to the hyperglass API. `{feature}` may be used to display the disabled feature.",
)
invalid_input: StrictStr = Field(
"{target} is not a valid {query_type} target.",

View File

@@ -1,16 +1,12 @@
import React from "react";
import ChakraSelect from "~/components/ChakraSelect";
const buildQueries = queryTypes => {
const queries = [];
queryTypes.map(q => {
queries.push({ value: q.name, label: q.display_name });
});
return queries;
};
export default ({ queryTypes, onChange }) => {
const queries = buildQueries(queryTypes);
const queries = queryTypes
.filter(q => q.enable === true)
.map(q => {
return { value: q.name, label: q.display_name };
});
return (
<ChakraSelect
size="lg"