blob: f3cfb994eea8265e8549c854df958684ab5ea59b [file] [log] [blame]
package apidVerifyApiKey
import (
"encoding/json"
"regexp"
"strings"
)
/*
* Check for the base path (API_Product) match with the path
* received in the Request, via the customized regex, where
* "**" gets de-normalized as ".*" and "*" as everything till
* the next "/".
*/
func validatePath(basePath, requestBase string) bool {
var basePaths []string
json.Unmarshal([]byte(basePath), &basePaths)
for _, a := range basePaths {
str1 := strings.Replace(a, "**", "(.*)", -1)
str2 := strings.Replace(a, "*", "([^/]+)", -1)
if a != str1 {
reg, _ := regexp.Compile(str1)
res := reg.MatchString(requestBase)
if res == true {
return true
}
} else if a != str2 {
reg, _ := regexp.Compile(str2)
res := reg.MatchString(requestBase)
if res == true {
return true
}
} else if requestBase == a {
return true
}
/*
* FIXME: SINGLE_FORWARD_SLASH_PATTERN not supported yet
*/
}
/* if the i/p resource is empty, no checks need to be made */
return len(basePaths) == 0
}