Skip to content

Commit

Permalink
Check if the running Gateway is licensed before fetching Consumer Groups
Browse files Browse the repository at this point in the history
  • Loading branch information
mheap committed Jan 7, 2025
1 parent 4d4a0fd commit 939a3c9
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Check failure on line 572 in cmd/common.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)

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

Expand Down

0 comments on commit 939a3c9

Please sign in to comment.