From 939a3c90d8594ef2a36cb9d2f843daea1ccefeaf Mon Sep 17 00:00:00 2001 From: Michael Heap Date: Tue, 7 Jan 2025 17:37:08 +0000 Subject: [PATCH] Check if the running Gateway is licensed before fetching Consumer Groups --- cmd/common.go | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/cmd/common.go b/cmd/common.go index 7eab9becc..72ccc58a7 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -228,7 +228,14 @@ func syncMain(ctx context.Context, filenames []string, dry bool, parallelism, return fmt.Errorf("parsing Kong version: %w", err) } - isKongEnterprise := v.IsKongGatewayEnterprise() + // Check if there's an active license for Consumer Group checks + isLicensedKongEnterprise := false + if v.IsKongGatewayEnterprise() { + isLicensedKongEnterprise, err = isLicensed(ctx, wsConfig) + if err != nil { + return fmt.Errorf("checking if Kong is licensed: %w", err) + } + } if parsedKongVersion.GTE(reconcilerUtils.Kong300Version) && targetContent.FormatVersion != utils.FormatVersion30 { @@ -264,7 +271,7 @@ func syncMain(ctx context.Context, filenames []string, dry bool, parallelism, } // Consumer groups are an enterprise 3.4+ feature - if parsedKongVersion.GTE(reconcilerUtils.Kong340Version) && isKongEnterprise { + if parsedKongVersion.GTE(reconcilerUtils.Kong340Version) && isLicensedKongEnterprise { dumpConfig.LookUpSelectorTagsConsumerGroups, err = determineLookUpSelectorTagsConsumerGroups(*targetContent) if err != nil { return fmt.Errorf("error determining lookup selector tags for consumer groups: %w", err) @@ -561,6 +568,28 @@ func performDiff(ctx context.Context, currentState, targetState *state.KongState return int(totalOps), nil } +func isLicensed(ctx context.Context, config reconcilerUtils.KongClientConfig) (bool, error) { + client, err := reconcilerUtils.GetKongClient(config) + + req, err := http.NewRequest("GET", + reconcilerUtils.CleanAddress(config.Address)+"/", + nil) + if err != nil { + return false, err + } + var resp map[string]interface{} + _, err = client.Do(ctx, req, &resp) + if err != nil { + return false, err + } + _, ok := resp["license"] + if !ok { + return false, nil + } + + return true, nil +} + func fetchKongVersion(ctx context.Context, config reconcilerUtils.KongClientConfig) (string, error) { var version string