-
Notifications
You must be signed in to change notification settings - Fork 5
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
Changes from 2 commits
c0cd6f5
eb7eb51
b66f8e6
f594b5f
896f58d
fd97f08
b6af7ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it is even better to return an empty map without any error here: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah true actually! Good point There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, but this will There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah good point, fixed. |
||
content.Attributes = map[string]string{} | ||
} else { | ||
return nil, errors.E(err) | ||
} | ||
} | ||
mas := make([]jujuparams.ModelAccess, len(c.Models)) | ||
for i, m := range c.Models { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes fair point