Simplify validation
diff --git a/cmd/termmapper/main.go b/cmd/termmapper/main.go
index 0f619c1..664471d 100644
--- a/cmd/termmapper/main.go
+++ b/cmd/termmapper/main.go
@@ -161,31 +161,8 @@
// validateInput checks if the input parameters are valid
func validateInput(mapID, dir, foundryA, foundryB, layerA, layerB string, body []byte) error {
- // Check input lengths
- if len(mapID) > maxParamLength {
- return fmt.Errorf("map ID too long (max %d bytes)", maxParamLength)
- }
- if len(dir) > maxParamLength {
- return fmt.Errorf("direction too long (max %d bytes)", maxParamLength)
- }
- if len(foundryA) > maxParamLength {
- return fmt.Errorf("foundryA too long (max %d bytes)", maxParamLength)
- }
- if len(foundryB) > maxParamLength {
- return fmt.Errorf("foundryB too long (max %d bytes)", maxParamLength)
- }
- if len(layerA) > maxParamLength {
- return fmt.Errorf("layerA too long (max %d bytes)", maxParamLength)
- }
- if len(layerB) > maxParamLength {
- return fmt.Errorf("layerB too long (max %d bytes)", maxParamLength)
- }
- if len(body) > maxInputLength {
- return fmt.Errorf("request body too large (max %d bytes)", maxInputLength)
- }
-
- // Check for invalid characters in parameters
- for _, param := range []struct {
+ // Define parameter checks
+ params := []struct {
name string
value string
}{
@@ -195,11 +172,22 @@
{"foundryB", foundryB},
{"layerA", layerA},
{"layerB", layerB},
- } {
+ }
+
+ for _, param := range params {
+ // Check input lengths
+ if len(param.value) > maxParamLength {
+ return fmt.Errorf("%s too long (max %d bytes)", param.name, maxParamLength)
+ }
+ // Check for invalid characters in parameters
if strings.ContainsAny(param.value, "<>{}[]\\") {
return fmt.Errorf("%s contains invalid characters", param.name)
}
}
+ if len(body) > maxInputLength {
+ return fmt.Errorf("request body too large (max %d bytes)", maxInputLength)
+ }
+
return nil
}