Skip to content

Commit 51830cd

Browse files
committed
refactor: move path validation to admission controller
1 parent 50361b8 commit 51830cd

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

api/model/api/v4/api.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package v4
1717

1818
import (
1919
"fmt"
20-
"net/url"
2120

2221
"github.com/gravitee-io/gravitee-kubernetes-operator/api/model/api/base"
2322
"github.com/gravitee-io/gravitee-kubernetes-operator/pkg/types/k8s/custom"
@@ -199,13 +198,7 @@ func (api *Api) GetDefinitionVersion() custom.ApiDefinitionVersion {
199198
func (api *Api) GetContextPaths() ([]string, error) {
200199
paths := make([]string, 0)
201200
for _, l := range api.Listeners {
202-
for _, s := range parseListener(l) {
203-
p, err := url.Parse(s)
204-
if err != nil {
205-
return paths, err
206-
}
207-
paths = append(paths, p.String())
208-
}
201+
paths = append(paths, parseListener(l)...)
209202
}
210203
return paths, nil
211204
}

internal/admission/api/v4/validate.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package v4
1616

1717
import (
1818
"context"
19+
"net/url"
1920
"slices"
2021

2122
v4 "github.com/gravitee-io/gravitee-kubernetes-operator/api/model/api/v4"
@@ -61,6 +62,12 @@ func validateNoConflictingPath(ctx context.Context, api custom.ApiDefinitionReso
6162
return errors.NewSevere(err.Error())
6263
}
6364
for _, apiPath := range apiPaths {
65+
if _, pErr := url.Parse(apiPath); pErr != nil {
66+
return errors.NewSevere(
67+
"path [%s] is invalid",
68+
apiPath,
69+
)
70+
}
6471
if slices.Contains(existingPaths, apiPath) {
6572
return errors.NewSevere(
6673
"invalid API context path [%s]. Another API with the same path already exists",

0 commit comments

Comments
 (0)