@@ -16,10 +16,10 @@ func handleError(w http.ResponseWriter, err error) {
1616 fmt .Fprintf (w , "{\" kind\" : \" Status\" , \" api\" : \" ocgate\" , \" status\" : \" Forbidden\" , \" message\" : \" %s\" ,\" code\" : %d}" , err , http .StatusForbidden )
1717}
1818
19- func validateRequest (httpMethod string , httpPath string , apiPAth string , allowedAPIMethods string , k8sAllowedAPIRegexp * regexp.Regexp ) error {
19+ func validateRequest (httpMethod string , httpPath string , apiPAth string , matchMethod string , matchPathRegexp * regexp.Regexp ) error {
2020 // Validate method
21- if allowedAPIMethods != "" {
22- if ! strings .Contains (allowedAPIMethods , strings .ToLower (httpMethod )) {
21+ if matchMethod != "" {
22+ if ! strings .Contains (strings . ToLower ( matchMethod ) , strings .ToLower (httpMethod )) {
2323 return fmt .Errorf ("%s method not allowedd" , httpMethod )
2424 }
2525 }
@@ -29,7 +29,7 @@ func validateRequest(httpMethod string, httpPath string, apiPAth string, allowed
2929 if len (httpPath ) > len (apiPAth ) &&
3030 httpPath [:len (apiPAth )] == apiPAth &&
3131 httpPath [len (apiPAth ):] != "/.well-known/oauth-authorization-server" &&
32- ! k8sAllowedAPIRegexp .MatchString (httpPath ) {
32+ ! matchPathRegexp .MatchString (httpPath ) {
3333 return fmt .Errorf ("%s path not allowed" , httpPath )
3434 }
3535
@@ -53,18 +53,18 @@ func validateToken(token string, secret []byte, publicKey *rsa.PublicKey, apiPat
5353 }
5454
5555 if claims , ok := tok .Claims .(jwt.MapClaims ); ok && tok .Valid {
56- var allowedAPIMethods string
57- var allowedAPIRegexp string
56+ var matchMethod string
57+ var matchPath string
5858
59- if allowedAPIMethods , ok = claims ["allowedAPIMethods " ].(string ); ! ok {
60- allowedAPIMethods = ""
59+ if matchMethod , ok = claims ["matchMethod " ].(string ); ! ok {
60+ matchMethod = ""
6161 }
62- if allowedAPIRegexp , ok = claims ["allowedAPIRegexp " ].(string ); ! ok {
63- allowedAPIRegexp = ""
62+ if matchPath , ok = claims ["matchPath " ].(string ); ! ok {
63+ matchPath = ""
6464 }
65- k8sAllowedAPIRegexp := regexp .MustCompile (allowedAPIRegexp )
65+ matchPathRegexp := regexp .MustCompile (matchPath )
6666
67- err := validateRequest (httpMethod , httpPath , apiPath , allowedAPIMethods , k8sAllowedAPIRegexp )
67+ err := validateRequest (httpMethod , httpPath , apiPath , matchMethod , matchPathRegexp )
6868 if err != nil {
6969 return nil , err
7070 }
0 commit comments