1
0
Fork 1
mirror of https://github.com/thatmattlove/hyperglass.git synced 2026-04-17 21:38:27 +00:00

Merge branch 'thatmattlove:main' into main

This commit is contained in:
WilhelmZA 2025-09-26 08:15:04 +02:00 committed by GitHub
commit f8a836c673
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 31 additions and 21 deletions

View file

@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## [Unreleased]
### Fixed
- [#280](https://github.com/thatmattlove/hyperglass/issues/280): Fix: `condition: None` caused error in directive
- [#306](https://github.com/thatmattlove/hyperglass/issues/306): Fix: allow integer values in ext_community_list_raw field for Arista BGP - @cooperwinser
- [#325](https://github.com/thatmattlove/hyperglass/pull/325): Fix code block padding in the documentation - @jagardaniel
- [#327](https://github.com/thatmattlove/hyperglass/pull/327): Fix huawei bgp route and plugin validation/transform order - @JelsonRodrigues

View file

@ -19,7 +19,7 @@ from .main import MultiModel, HyperglassModel, HyperglassUniqueModel
from .fields import Action
StringOrArray = t.Union[str, t.List[str]]
Condition = t.Union[IPvAnyNetwork, str]
Condition = t.Union[str, None]
RuleValidation = t.Union[t.Literal["ipv4", "ipv6", "pattern"], None]
PassedValidation = t.Union[bool, None]
IPFamily = t.Literal["ipv4", "ipv6"]
@ -264,7 +264,7 @@ class Directive(HyperglassUniqueModel, unique_by=("id", "table_output")):
id: str
name: str
rules: t.List[RuleType] = [RuleWithoutValidation()]
field: t.Union[Text, Select]
field: t.Union[Text, Select, None]
info: t.Optional[FilePath] = None
plugins: t.List[str] = []
table_output: t.Optional[str] = None
@ -282,15 +282,16 @@ class Directive(HyperglassUniqueModel, unique_by=("id", "table_output")):
condition = rule.get("condition")
if condition is None:
out_rules.append(RuleWithoutValidation(**rule))
try:
condition_net = ip_network(condition)
if condition_net.version == 4:
out_rules.append(RuleWithIPv4(**rule))
if condition_net.version == 6:
out_rules.append(RuleWithIPv6(**rule))
except ValueError:
out_rules.append(RuleWithPattern(**rule))
if isinstance(rule, Rule):
else:
try:
condition_net = ip_network(condition)
if condition_net.version == 4:
out_rules.append(RuleWithIPv4(**rule))
if condition_net.version == 6:
out_rules.append(RuleWithIPv6(**rule))
except ValueError:
out_rules.append(RuleWithPattern(**rule))
elif isinstance(rule, Rule):
out_rules.append(rule)
return out_rules
@ -306,7 +307,8 @@ class Directive(HyperglassUniqueModel, unique_by=("id", "table_output")):
@property
def field_type(self) -> t.Literal["text", "select", None]:
"""Get the linked field type."""
if self.field is None:
return None
if self.field.is_select:
return "select"
if self.field.is_text or self.field.is_ip:
@ -337,7 +339,7 @@ class Directive(HyperglassUniqueModel, unique_by=("id", "table_output")):
"name": self.name,
"field_type": self.field_type,
"groups": self.groups,
"description": self.field.description,
"description": self.field.description if self.field is not None else '',
"info": None,
}
@ -345,7 +347,7 @@ class Directive(HyperglassUniqueModel, unique_by=("id", "table_output")):
with self.info.open() as md:
value["info"] = md.read()
if self.field.is_select:
if self.field is not None and self.field.is_select:
value["options"] = [o.export_dict() for o in self.field.options if o is not None]
return value

View file

@ -19,7 +19,7 @@ class UIDirective(HyperglassModel):
id: str
name: str
field_type: str
field_type: t.Union[str, None]
groups: t.List[str]
description: str
info: t.Optional[str] = None

View file

@ -78,10 +78,14 @@ export const LookingGlassForm = (): JSX.Element => {
[],
);
const directive = useMemo<Directive | null>(
() => getDirective(),
[form.queryType, form.queryLocation, getDirective],
);
const directive = useMemo<Directive | null>(() => {
const tmp = getDirective();
if (tmp !== null && tmp.fieldType === null) {
setFormValue('queryTarget', ['null']);
setValue('queryTarget', ['null']);
}
return tmp;
}, [form.queryType, form.queryLocation, getDirective]);
function submitHandler(): void {
if (process.env.NODE_ENV === 'development') {
@ -200,7 +204,11 @@ export const LookingGlassForm = (): JSX.Element => {
<QueryType onChange={handleChange} label={web.text.queryType} />
</FormField>
</SlideFade>
<SlideFade offsetX={100} in={directive !== null} unmountOnExit>
<SlideFade
offsetX={100}
in={directive !== null && directive.fieldType !== null}
unmountOnExit
>
{directive !== null && (
<FormField name="queryTarget" label={web.text.queryTarget}>
<QueryTarget