Skip to content

Commit

Permalink
fix: detect filter chain support from API response (#101)
Browse files Browse the repository at this point in the history
This updates the business logic that is used to decide if (wasm) filter
chains are supported by Kong. Instead of relying on the caller to set
`dump.Config.IsFilterChainsSupported`, we check the error response code
from `GET /filter-chains` and decide how to proceed from there.
  • Loading branch information
flrgh authored Jun 11, 2024
1 parent a0cb138 commit 2947f60
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions pkg/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ type Config struct {

// IsConsumerGroupScopedPluginSupported
IsConsumerGroupScopedPluginSupported bool

// IsFilterChainsSupported
IsFilterChainsSupported bool
}

func deduplicate(stringSlice []string) []string {
Expand Down Expand Up @@ -255,18 +252,25 @@ func getProxyConfiguration(ctx context.Context, group *errgroup.Group,
return nil
})

if config.IsFilterChainsSupported {
group.Go(func() error {
filterChains, err := GetAllFilterChains(ctx, client, config.SelectorTags)
if err != nil {
return fmt.Errorf("filter chains: %w", err)
}
state.FilterChains = filterChains
return nil
})
} else {
group.Go(func() error {
state.FilterChains = make([]*kong.FilterChain, 0)
}
filterChains, err := GetAllFilterChains(ctx, client, config.SelectorTags)
if err != nil {
var kongErr *kong.APIError
if errors.As(err, &kongErr) {
// GET /filter-chains returns:
// -> 200 on success
// -> 404 if Kong version < 3.4
// -> 400 if Kong version >= 3.4 but wasm is not enabled
if kongErr.Code() == http.StatusNotFound || kongErr.Code() == http.StatusBadRequest {
return nil
}
}
return fmt.Errorf("filter chains: %w", err)
}
state.FilterChains = filterChains
return nil
})

group.Go(func() error {
certificates, err := GetAllCertificates(ctx, client, config.SelectorTags)
Expand Down

0 comments on commit 2947f60

Please sign in to comment.