From 7b67f927cb472e8ce53c2c648797baa54dac270f Mon Sep 17 00:00:00 2001 From: Rahul Rajesh Date: Sun, 15 Jun 2025 13:34:39 -0400 Subject: [PATCH] expander: add support for vlan tags, truncate iface name Currently, the expander does not support adding a ".100" vlan id to the end of a capture referenced ethernet interface name when creating a vlan interface. Example: "{{ capture.nic.interfaces.0.name }}.100" Resolves: https://issues.redhat.com/browse/NMT-1510 Signed-off-by: Rahul Rajesh --- nmpolicy/internal/expander/state_expander.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/nmpolicy/internal/expander/state_expander.go b/nmpolicy/internal/expander/state_expander.go index 66eca170..3cfd287c 100644 --- a/nmpolicy/internal/expander/state_expander.go +++ b/nmpolicy/internal/expander/state_expander.go @@ -81,24 +81,30 @@ func (c StateExpander) expandMap(mapState map[string]interface{}) (map[string]in } func (c StateExpander) expandString(stringState string) (interface{}, error) { - re := regexp.MustCompile(`^{{ (.*) }}$`) + re := regexp.MustCompile(`^{{ (.*) }}(\.[0-9]+)?$`) submatch := re.FindStringSubmatch(stringState) if len(submatch) == 0 { return stringState, nil } - const captureSubmatchLength = 2 + const captureSubmatchLength = 3 if len(submatch) != captureSubmatchLength { return nil, fmt.Errorf("the capture expression has wrong format %s", stringState) } capturePath := submatch[1] + suffix := submatch[2] resolvedPath, err := c.capResolver.ResolveCaptureEntryPath(capturePath) if err != nil { return nil, err } + switch captureValue := resolvedPath.(type) { + case string: + resolvedPath = captureValue + suffix + } + return resolvedPath, nil }