Skip to content

Commit f29a300

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

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
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
}

docs/api/reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7369,7 +7369,7 @@ Application is the main resource handled by the Kubernetes Operator
73697369
<td><b>clientId</b></td>
73707370
<td>string</td>
73717371
<td>
7372-
The ClientId identifying the application. This field is required when subscribing to an OAUTH2 / JWT plan.<br/>
7372+
The ClientID identifying the application. This field is required when subscribing to an OAUTH2 / JWT plan.<br/>
73737373
</td>
73747374
<td>false</td>
73757375
</tr><tr>
@@ -7551,7 +7551,7 @@ Application settings
75517551
<td><b>client_id</b></td>
75527552
<td>string</td>
75537553
<td>
7554-
ClientId is the client id of the application<br/>
7554+
ClientID is the client id of the application<br/>
75557555
</td>
75567556
<td>false</td>
75577557
</tr></tbody>

helm/gko/crds/gravitee.io_applications.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ spec:
7575
when displaying it on the portal
7676
type: string
7777
clientId:
78-
description: The ClientId identifying the application. This field
78+
description: The ClientID identifying the application. This field
7979
is required when subscribing to an OAUTH2 / JWT plan.
8080
type: string
8181
contextRef:
@@ -164,7 +164,7 @@ spec:
164164
app:
165165
properties:
166166
client_id:
167-
description: ClientId is the client id of the application
167+
description: ClientID is the client id of the application
168168
type: string
169169
type:
170170
description: Application Type

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)