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

Return cloud-credentials with empty attribute #1333

Merged
merged 7 commits into from
Aug 30, 2024

Conversation

kian99
Copy link
Contributor

@kian99 kian99 commented Aug 29, 2024

Description

An issue was found when testing the Juju Terraform provider against JIMM. When requesting a cloud-credential, if the cloud-credential had an empty attribute map, JIMM would return a "not found" error even though the cloud-credential was found.

This is different behaviour from Juju where you can retrieve your cloud-credential even if the attribute map is empty. This 1 line change fixes that and additionally adds a test for it.

Engineering checklist

Check only items that apply

  • Documentation updated
  • Covered by unit tests
  • Covered by integration tests

@kian99 kian99 requested a review from a team as a code owner August 29, 2024 06:58
@@ -321,7 +321,7 @@ func getIdentityCredentials(ctx context.Context, user *openfga.User, j JIMM, arg
}
var err error
content.Attributes, _, err = j.GetCloudCredentialAttributes(ctx, user, c, args.IncludeSecrets)
Copy link
Contributor

@SimoneDutto SimoneDutto Aug 29, 2024

Choose a reason for hiding this comment

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

thinking out loud...

now this map is set to nil, and if you try to access it it will panic, i would prefer j.GetCloudCredentialAttributes to return an empty map without any error. It is even more correct, because we don't want to treat empty attributes as an error.
What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes fair point

@@ -322,7 +322,11 @@ func getIdentityCredentials(ctx context.Context, user *openfga.User, j JIMM, arg
var err error
content.Attributes, _, err = j.GetCloudCredentialAttributes(ctx, user, c, args.IncludeSecrets)
if err != nil {
return nil, errors.E(err)
if errors.ErrorCode(err) == errors.CodeNotFound {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah true actually! Good point

Copy link
Contributor Author

@kian99 kian99 Aug 29, 2024

Choose a reason for hiding this comment

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

I've updated this, seems like a nil map is treated like a nil slice, in the sense that using a nil map e.g. range myMap won't cause a panic even though it is nil.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah good point, fixed.

SimoneDutto
SimoneDutto previously approved these changes Aug 29, 2024
Copy link
Contributor

@SimoneDutto SimoneDutto left a comment

Choose a reason for hiding this comment

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

thank you for the changes

Copy link
Contributor

@ale8k ale8k left a comment

Choose a reason for hiding this comment

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

lgtm

@kian99 kian99 merged commit f8a7174 into canonical:v3 Aug 30, 2024
4 checks passed
kian99 added a commit to kian99/jimm that referenced this pull request Sep 3, 2024
* return cloud-credentials with empty attribute

* set empty map if attributes not found

* change application logic to not return error on empty attributes

* add app layer test

* return empty map rather than nil

* fix test
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