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

Cannot remove all TAGS associated to API Key or JWT #314

Open
miguel91it opened this issue Apr 14, 2023 · 0 comments
Open

Cannot remove all TAGS associated to API Key or JWT #314

miguel91it opened this issue Apr 14, 2023 · 0 comments

Comments

@miguel91it
Copy link

Issue Description

We are using github.com/kong/go-kong v0.16.0 but i realized the same would occur with the latest version.

We are using API Keys and JWT and we are using the TAGS option to add some labels to our customer keys. I realized i cannot remove all TAGs added to a key through either KeyAuths.Update or JWTAuths.Update functions, even when we explicit pass an empty slice/array to both structs credentials/KeyAuth and credentials/JWTAuth in the Tags field.

Currently, both structs have Tags defined as follow:

Tags      []*string `json:"tags,omitempty" yaml:"tags,omitempty"`

They have the omitempty annotation which make empty Tags slice to be discarded when marshaled to json.

I tested with following values no one worked to remove all tags:

Tags =
- nil -> omitted
- make([]*string, 0, 0) -> omitted
- make([]*string, 0) -> omitted
- []*string{} -> omitted
- []*string{nil} -> error 13 -  "error updating APIKey: failed to update API Key: HTTP status 400 (message: \"schema violation (tags.1: required field missing)\")"
- make([]*string, 1, 0) -> omitted
	*/

In the otther hand, by calling Kong's API directly (PATCH to consumers/{USERNAME_OR_ID}/key-auth/{CRED_ID}) i could remove all tags passing either empty array or null value in the body.

Possible solution tested

I modified Kong's structs and I removed the omitempty annotation from the struct and i realized it worked for me.

Question

Do you have other option to remove all tags or changing the struct annotation is the only option?

As we need to fix that quickly, i'm gonna fork your repo and remove the omitempty. Could I open a PR with that change?

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

No branches or pull requests

1 participant