Skip to content

Commit

Permalink
add feature online plugins filter flag
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineJac committed Nov 28, 2024
1 parent 43eef06 commit 6125315
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions cmd/gateway_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
var (
validateCmdKongStateFile []string
validateCmdRBACResourcesOnly bool
validateCmdCheckOnlinePluginsOnly bool
validateOnline bool
validateWorkspace string
validateParallelism int
Expand Down Expand Up @@ -237,6 +238,8 @@ this command unless --online flag is used.

validateCmd.Flags().BoolVar(&validateCmdRBACResourcesOnly, "rbac-resources-only",
false, "indicate that the state file(s) contains RBAC resources only (Kong Enterprise only).")
validateCmd.Flags().BoolVar(&validateCmdCheckOnlinePluginsOnly, "check-online-plugins-only",
false, "indicate that the online validation will be done only on plugins.")
if deprecated {
validateCmd.Flags().StringSliceVarP(&validateCmdKongStateFile,
"state", "s", []string{"kong.yaml"}, "file(s) containing Kong's configuration.\n"+
Expand Down Expand Up @@ -284,6 +287,7 @@ func validateWithKong(
Client: kongClient,
Parallelism: validateParallelism,
RBACResourcesOnly: validateCmdRBACResourcesOnly,
CheckOnlinePluginsOnly: validateCmdCheckOnlinePluginsOnly,
}
validator := validate.NewValidator(opts)
return validator.Validate(parsedFormatVersion)
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ func Test_Validate_File(t *testing.T) {
stateFile: "testdata/validate/rbac-resources.yaml",
additionalArgs: []string{"--rbac-resources-only"},
},
{
name: "file validate with --check-online-plugins-only",
stateFile: "testdata/validate/kong3x.yaml",
additionalArgs: []string{"--check-online-plugins-only"},
},
}

for _, tc := range tests {
Expand Down
14 changes: 11 additions & 3 deletions validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Validator struct {
client *kong.Client
parallelism int
rbacResourcesOnly bool
CheckOnlinePluginsOnly bool
}

type ValidatorOpts struct {
Expand All @@ -29,6 +30,7 @@ type ValidatorOpts struct {
Client *kong.Client
Parallelism int
RBACResourcesOnly bool
CheckOnlinePluginsOnly bool
}

func NewValidator(opt ValidatorOpts) *Validator {
Expand All @@ -38,6 +40,7 @@ func NewValidator(opt ValidatorOpts) *Validator {
client: opt.Client,
parallelism: opt.Parallelism,
rbacResourcesOnly: opt.RBACResourcesOnly,
CheckOnlinePluginsOnly: opt.CheckOnlinePluginsOnly,
}
}

Expand Down Expand Up @@ -130,6 +133,14 @@ func (v *Validator) Validate(formatVersion semver.Version) []error {
return allErr
}

// validate Plugins resources then.
if err := v.entities(v.state.Plugins, "plugins"); err != nil {
allErr = append(allErr, err...)
}
if v.CheckOnlinePluginsOnly {
return allErr
}

if err := v.entities(v.state.Services, "services"); err != nil {
allErr = append(allErr, err...)
}
Expand Down Expand Up @@ -163,9 +174,6 @@ func (v *Validator) Validate(formatVersion semver.Version) []error {
if err := v.entities(v.state.Oauth2Creds, "oauth2_credentials"); err != nil {
allErr = append(allErr, err...)
}
if err := v.entities(v.state.Plugins, "plugins"); err != nil {
allErr = append(allErr, err...)
}
if err := v.entities(v.state.Routes, "routes"); err != nil {
allErr = append(allErr, err...)
}
Expand Down

0 comments on commit 6125315

Please sign in to comment.