From f0a6c12443c1486193cfd3fc4821726c3f44dea1 Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 00:06:46 +0000 Subject: [PATCH] feat(action): accept semantic alias keys in resolve and reverse actions Co-Authored-By: Virgil --- action.go | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/action.go b/action.go index e474c76..f8d408b 100644 --- a/action.go +++ b/action.go @@ -28,7 +28,10 @@ const ( actionArgBind = "bind" actionArgBindAddress = "bindAddress" actionArgIP = "ip" + actionArgAddress = "address" actionArgName = "name" + actionArgHost = "host" + actionArgHostName = "hostname" actionArgPort = "port" actionArgDNSPort = "dnsPort" actionArgHealthPort = "health_port" @@ -245,7 +248,7 @@ func (service *Service) HandleActionContext(ctx context.Context, name string, va func (service *Service) handleResolveAddress(ctx context.Context, values map[string]any) (any, bool, error) { _ = ctx - host, err := stringActionValue(values, actionArgName) + host, err := stringActionValueFromKeys(values, actionArgName, actionArgHost, actionArgHostName) if err != nil { return nil, false, err } @@ -258,7 +261,7 @@ func (service *Service) handleResolveAddress(ctx context.Context, values map[str func (service *Service) handleResolveTXTRecords(ctx context.Context, values map[string]any) (any, bool, error) { _ = ctx - host, err := stringActionValue(values, actionArgName) + host, err := stringActionValueFromKeys(values, actionArgName, actionArgHost, actionArgHostName) if err != nil { return nil, false, err } @@ -271,7 +274,7 @@ func (service *Service) handleResolveTXTRecords(ctx context.Context, values map[ func (service *Service) handleResolveAll(ctx context.Context, values map[string]any) (any, bool, error) { _ = ctx - host, err := stringActionValue(values, actionArgName) + host, err := stringActionValueFromKeys(values, actionArgName, actionArgHost, actionArgHostName) if err != nil { return nil, false, err } @@ -284,7 +287,7 @@ func (service *Service) handleResolveAll(ctx context.Context, values map[string] func (service *Service) handleReverseLookup(ctx context.Context, values map[string]any) (any, bool, error) { _ = ctx - ip, err := stringActionValue(values, actionArgIP) + ip, err := stringActionValueFromKeys(values, actionArgIP, actionArgAddress) if err != nil { return nil, false, err } @@ -353,6 +356,28 @@ func stringActionValue(values map[string]any, key string) (string, error) { return "", errActionMissingValue } +func stringActionValueFromKeys(values map[string]any, keys ...string) (string, error) { + for _, key := range keys { + value, exists := values[key] + if !exists { + continue + } + + text, ok := value.(string) + if !ok { + return "", fmt.Errorf("%w: %s", errActionMissingValue, key) + } + + text = strings.TrimSpace(text) + if text == "" { + return "", errActionMissingValue + } + return text, nil + } + + return "", errActionMissingValue +} + func stringActionValueOptional(values map[string]any, key string) (string, error) { if values == nil { return "", nil