Skip to content

Commit

Permalink
rm redundant const
Browse files Browse the repository at this point in the history
  • Loading branch information
katherinelc321 committed May 8, 2024
1 parent 1b1974b commit 715bbc5
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions frontend/middleware_validatestatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ import (
"github.com/Azure/ARO-HCP/internal/api/arm"
)

const (
wantedResourceProviderNamespace = "Microsoft.RedHatOpenShift"
resourceTypeHCPOpenshiftCluster = "HcpOpenShiftClusters"
)

// Referenced in https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/resource-name-rules#microsoftresources
var rxResourceGroupName = regexp.MustCompile(`^[-a-z0-9_().]{0,89}[-a-z0-9_()]$`)

func MiddlewareValidateStatic(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
Expand Down Expand Up @@ -52,20 +48,18 @@ func MiddlewareValidateStatic(w http.ResponseWriter, r *http.Request, next http.

if resourceGroupName != "" {
if !rxResourceGroupName.MatchString(resourceGroupName) {
arm.WriteError(w, http.StatusBadRequest, arm.CloudErrorCodeResourceGroupNotFound, "", "Resource group '%s' could not be found.", resourceGroupName)
arm.WriteError(w, http.StatusBadRequest, arm.CloudErrorCodeResourceGroupNotFound, "", "Resource group '%s' is invalid.", resourceGroupName)
return
}
}

if resourceProviderNamespace != "" {
if resourceProviderNamespace != strings.ToLower(wantedResourceProviderNamespace) {
arm.WriteError(w, http.StatusBadRequest, arm.CloudErrorCodeInvalidResourceNamespace, "", "The resource namespace '%s' is invalid.", resourceProviderNamespace)
return
}
if resourceProviderNamespace != strings.ToLower(api.ProviderNamespace) {
arm.WriteError(w, http.StatusBadRequest, arm.CloudErrorCodeInvalidResourceNamespace, "", "The resource namespace '%s' is invalid.", resourceProviderNamespace)
return
}

if resourceType != "" {
if resourceType != strings.ToLower(resourceTypeHCPOpenshiftCluster) {
if resourceType != strings.ToLower(api.ResourceType) {
arm.WriteError(w, http.StatusBadRequest, arm.CloudErrorCodeInvalidResourceType, "", "The resource type '%s' could not be found in the namespace '%s' for api version '%s'.", resourceType, resourceProviderNamespace, apiVersion)
return
}
Expand Down

0 comments on commit 715bbc5

Please sign in to comment.