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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/jujuapi/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

if err != nil {
if err != nil && errors.ErrorCode(err) != errors.CodeNotFound {
return nil, errors.E(err)
}
mas := make([]jujuparams.ModelAccess, len(c.Models))
Expand Down
27 changes: 27 additions & 0 deletions internal/jujuapi/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,33 @@ func (s *cloudSuite) TestCredentialContents(c *gc.C) {
}})
}

func (s *cloudSuite) TestCredentialContentsWithEmptyAttributes(c *gc.C) {
conn := s.open(c, nil, "test")
defer conn.Close()
client := cloudapi.NewClient(conn)
credentialTag := names.NewCloudCredentialTag(jimmtest.TestCloudName + "/[email protected]/cred3")
err := client.AddCredential(
credentialTag.String(),
cloud.NewCredential(
"certificate",
nil,
),
)
c.Assert(err, gc.Equals, nil)
creds, err := client.CredentialContents(jimmtest.TestCloudName, "cred3", false)
c.Assert(err, gc.Equals, nil)
c.Assert(creds, jc.DeepEquals, []jujuparams.CredentialContentResult{{
Result: &jujuparams.ControllerCredentialInfo{
Content: jujuparams.CredentialContent{
Name: "cred3",
Cloud: jimmtest.TestCloudName,
AuthType: "certificate",
Attributes: nil,
},
},
}})
}

func (s *cloudSuite) TestRemoveCloud(c *gc.C) {
conn := s.open(c, nil, "test")
defer conn.Close()
Expand Down
Loading