Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't overwrite fields set to empty arrays when default exists #374

Merged
merged 2 commits into from
Oct 17, 2023

Conversation

GGabriele
Copy link
Collaborator

This commit fixes a bug preventing users to set fields to emtpy arrays when a default for those fields exist. For example, imagine we have an openid-connect plugin configured via the UI having the login_tokens set to an empty array (note: this field has a default value of ["id_token"]:

$ http :8001/plugins/$id | jq .config.login_tokens
[]

If we do a deck dump, the configuration will be reflected into a local state file:

$ deck dump --yes

$ cat kong.yaml | grep login_tokens
    login_tokens: []

But, if we now run deck diff we see that decK will detect a difference because of the login_tokens field's default value:

$ deck diff
updating plugin openid-connect (global)  {
   "config": {
     "anonymous": null,
     ...
     ...
     "login_redirect_mode": "fragment",
     "login_redirect_uri": null,
     "login_tokens": [
+      "id_token"
     ],
     "logout_methods": [
       "POST",
       "DELETE"
     ],
     ...
     ...
 }

Summary:
  Created: 0
  Updated: 1
  Deleted: 0

This commit corrects this defect by allowing decK to set empty arrays when default values exist for a given field.

This commit fixes a bug preventing users to set fields to emtpy
arrays when a default for those fields exist. For example, imagine
we have an `openid-connect` plugin configured via the UI having
the `login_tokens` set to an empty array (note: this field has
a default value of `["id_token"]`:

```
$ http :8001/plugins/$id | jq .config.login_tokens
[]
```

If we do a `deck dump`, the configuration will be reflected
into a local state file:

```
$ deck dump --yes

$ cat kong.yaml | grep login_tokens
    login_tokens: []
```

But, if we now run `deck diff` we see that decK will detect
a difference because of the `login_tokens` field's default
value:

```
$ deck diff
updating plugin openid-connect (global)  {
   "config": {
     "anonymous": null,
     ...
     ...
     "login_redirect_mode": "fragment",
     "login_redirect_uri": null,
     "login_tokens": [
+      "id_token"
     ],
     "logout_methods": [
       "POST",
       "DELETE"
     ],
     ...
     ...
 }

Summary:
  Created: 0
  Updated: 1
  Deleted: 0
```

This commit corrects this defect by allowing decK to set empty
arrays when default values exist for a given field.
@GGabriele GGabriele requested a review from a team as a code owner October 17, 2023 10:02
@GGabriele GGabriele requested a review from a team October 17, 2023 10:02
@codecov-commenter
Copy link

codecov-commenter commented Oct 17, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (dc4db7b) 53.06% compared to head (1457275) 53.05%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #374      +/-   ##
==========================================
- Coverage   53.06%   53.05%   -0.01%     
==========================================
  Files          69       69              
  Lines        5201     5200       -1     
==========================================
- Hits         2760     2759       -1     
  Misses       1857     1857              
  Partials      584      584              
Flag Coverage Δ
2.1 33.09% <100.00%> (-0.02%) ⬇️
2.2 33.09% <100.00%> (-11.50%) ⬇️
2.3 45.28% <100.00%> (-0.02%) ⬇️
2.4 45.36% <100.00%> (-0.02%) ⬇️
2.5 33.23% <100.00%> (-12.15%) ⬇️
2.6 45.36% <100.00%> (-0.02%) ⬇️
2.7 46.86% <100.00%> (-0.02%) ⬇️
2.8 46.86% <100.00%> (-0.02%) ⬇️
3.0 50.55% <100.00%> (-0.01%) ⬇️
3.1 52.01% <100.00%> (-0.01%) ⬇️
3.2 52.07% <100.00%> (-0.01%) ⬇️
3.3 52.07% <100.00%> (-0.01%) ⬇️
3.4 52.40% <100.00%> (-0.01%) ⬇️
community 38.23% <100.00%> (-0.02%) ⬇️
enterprise 51.73% <100.00%> (-0.01%) ⬇️
enterprise-nightly 50.75% <100.00%> (-0.01%) ⬇️
integration 53.05% <100.00%> (-0.01%) ⬇️
nightly 37.57% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
kong/utils.go 88.30% <100.00%> (-0.04%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@pmalek pmalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits, but overall 👍

I believe we want to add a changelog entry for this, right?

kong/utils_test.go Outdated Show resolved Hide resolved
kong/utils_test.go Outdated Show resolved Hide resolved
@GGabriele GGabriele requested a review from pmalek October 17, 2023 15:54
@pmalek pmalek merged commit 6881f5b into main Oct 17, 2023
67 checks passed
@pmalek pmalek deleted the fix/set-empty-array-when-default-exists branch October 17, 2023 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants