Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions internal/publisher/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"compress/gzip"
"context"
"fmt"
"maps"
"strconv"
"strings"

Expand Down Expand Up @@ -209,9 +210,7 @@ func cloneAttributesWithCompression(attributes map[string]string, config Compres
}

cloned := make(map[string]string, len(attributes)+1)
for key, value := range attributes {
cloned[key] = value
}
maps.Copy(cloned, attributes)
cloned[config.AttributeName] = string(config.Algorithm)
return cloned
}
26 changes: 13 additions & 13 deletions internal/webhook/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func setHeaderAttr(attrs map[string]string, headers http.Header, attrKey, header
}
}

func parsePayload(contentType string, body []byte) (map[string]interface{}, error) {
func parsePayload(contentType string, body []byte) (map[string]any, error) {
if payload, err := parseJSONPayload(body); err == nil {
return payload, nil
} else if !shouldAttemptFormPayload(contentType, body) {
Expand All @@ -79,15 +79,15 @@ func parsePayload(contentType string, body []byte) (map[string]interface{}, erro
return payload, nil
}

func parseJSONPayload(body []byte) (map[string]interface{}, error) {
var payload map[string]interface{}
func parseJSONPayload(body []byte) (map[string]any, error) {
var payload map[string]any
if err := json.Unmarshal(body, &payload); err != nil {
return nil, err
}
return payload, nil
}

func parseFormPayload(body []byte) (map[string]interface{}, error) {
func parseFormPayload(body []byte) (map[string]any, error) {
values, err := url.ParseQuery(string(body))
if err != nil {
return nil, err
Expand All @@ -110,29 +110,29 @@ func shouldAttemptFormPayload(contentType string, body []byte) bool {
return bytes.HasPrefix(trimmed, []byte("payload="))
}

func extractStringAttr(attrs map[string]string, warnings *[]string, payload map[string]interface{}, attrKey, warning string, paths ...[]string) {
func extractStringAttr(attrs map[string]string, warnings *[]string, payload map[string]any, attrKey, warning string, paths ...[]string) {
if value, ok, invalid := firstStringValue(payload, paths...); ok {
attrs[attrKey] = value
} else if invalid {
*warnings = append(*warnings, warning)
}
}

func extractOptionalStringAttr(attrs map[string]string, payload map[string]interface{}, attrKey string, paths ...[]string) {
func extractOptionalStringAttr(attrs map[string]string, payload map[string]any, attrKey string, paths ...[]string) {
if value, ok, _ := firstStringValue(payload, paths...); ok {
attrs[attrKey] = value
}
}

func extractNumberAttr(attrs map[string]string, warnings *[]string, payload map[string]interface{}, attrKey, warning string, paths ...[]string) {
func extractNumberAttr(attrs map[string]string, warnings *[]string, payload map[string]any, attrKey, warning string, paths ...[]string) {
if value, ok, invalid := firstNumberValue(payload, paths...); ok {
attrs[attrKey] = value
} else if invalid {
*warnings = append(*warnings, warning)
}
}

func firstStringValue(payload map[string]interface{}, paths ...[]string) (string, bool, bool) {
func firstStringValue(payload map[string]any, paths ...[]string) (string, bool, bool) {
invalid := false

for _, path := range paths {
Expand All @@ -148,7 +148,7 @@ func firstStringValue(payload map[string]interface{}, paths ...[]string) (string
return "", false, invalid
}

func firstNumberValue(payload map[string]interface{}, paths ...[]string) (string, bool, bool) {
func firstNumberValue(payload map[string]any, paths ...[]string) (string, bool, bool) {
invalid := false

for _, path := range paths {
Expand All @@ -164,11 +164,11 @@ func firstNumberValue(payload map[string]interface{}, paths ...[]string) (string
return "", false, invalid
}

func lookupStringPath(payload map[string]interface{}, path ...string) (string, lookupStatus) {
func lookupStringPath(payload map[string]any, path ...string) (string, lookupStatus) {
current := any(payload)

for i, key := range path {
m, ok := current.(map[string]interface{})
m, ok := current.(map[string]any)
if !ok {
return "", lookupInvalid
}
Expand Down Expand Up @@ -199,11 +199,11 @@ func lookupStringPath(payload map[string]interface{}, path ...string) (string, l
return "", lookupMissing
}

func lookupNumberPath(payload map[string]interface{}, path ...string) (string, lookupStatus) {
func lookupNumberPath(payload map[string]any, path ...string) (string, lookupStatus) {
current := any(payload)

for i, key := range path {
m, ok := current.(map[string]interface{})
m, ok := current.(map[string]any)
if !ok {
return "", lookupInvalid
}
Expand Down
2 changes: 1 addition & 1 deletion internal/webhook/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func LoadConfig() (*Config, error) {
}

var secrets []string
for _, s := range strings.Split(secretsRaw, ",") {
for s := range strings.SplitSeq(secretsRaw, ",") {
trimmed := strings.TrimSpace(s)
if trimmed != "" {
secrets = append(secrets, trimmed)
Expand Down
Loading