From 2947f608d3f236a366a3c8b7dd9f61b2c252049f Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Tue, 11 Jun 2024 11:43:23 -0700 Subject: [PATCH] fix: detect filter chain support from API response (#101) 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. --- pkg/dump/dump.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/pkg/dump/dump.go b/pkg/dump/dump.go index 3f75304..4439d81 100644 --- a/pkg/dump/dump.go +++ b/pkg/dump/dump.go @@ -42,9 +42,6 @@ type Config struct { // IsConsumerGroupScopedPluginSupported IsConsumerGroupScopedPluginSupported bool - - // IsFilterChainsSupported - IsFilterChainsSupported bool } func deduplicate(stringSlice []string) []string { @@ -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)