From c0cd6f5106cddaa177aa193f7bbb1db448640683 Mon Sep 17 00:00:00 2001 From: Kian Parvin Date: Thu, 29 Aug 2024 08:56:37 +0200 Subject: [PATCH] return cloud-credentials with empty attribute --- internal/jujuapi/cloud.go | 2 +- internal/jujuapi/cloud_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/internal/jujuapi/cloud.go b/internal/jujuapi/cloud.go index 1adb9b775..5723c9817 100644 --- a/internal/jujuapi/cloud.go +++ b/internal/jujuapi/cloud.go @@ -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) - if err != nil { + if err != nil && errors.ErrorCode(err) != errors.CodeNotFound { return nil, errors.E(err) } mas := make([]jujuparams.ModelAccess, len(c.Models)) diff --git a/internal/jujuapi/cloud_test.go b/internal/jujuapi/cloud_test.go index 58d4144e3..e2fa8a3b8 100644 --- a/internal/jujuapi/cloud_test.go +++ b/internal/jujuapi/cloud_test.go @@ -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 + "/test@canonical.com/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()