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

Credential contents api call #1249

Merged
merged 2 commits into from
Jul 12, 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
8 changes: 8 additions & 0 deletions internal/jimm/jimm.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,14 @@ type API interface {
// AllModels allows controller administrators to get the list of all the
// models in the controller.
AllModels(ctx context.Context) (jujuparams.UserModelList, error)

// CredentialContents returns the specified cloud credentials,
// including the secrets if requested.
// If no specific credential name/cloud was passed in, all credentials for this user
// are returned.
// Only credential owner can see its contents as well as what models use it.
// Controller admin has no special superpowers here and is treated the same as all other users.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we keep this comment in one place or duplicate it?

CredentialContents(ctx context.Context, args jujuparams.CloudCredentialArgs) (jujuparams.CredentialContentResults, error)
}

// forEachController runs a given function on multiple controllers
Expand Down
8 changes: 8 additions & 0 deletions internal/jimmtest/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ type API struct {
ListStorageDetails_ func(ctx context.Context) ([]jujuparams.StorageDetails, error)
ListModelSummaries_ func(ctx context.Context, args *jujuparams.ModelSummariesRequest, out *jujuparams.ModelSummaryResults) error
AllModels_ func(ctx context.Context) (jujuparams.UserModelList, error)
CredentialContents_ func(ctx context.Context, args jujuparams.CloudCredentialArgs) (jujuparams.CredentialContentResults, error)
}

func (a *API) CredentialContents(ctx context.Context, args jujuparams.CloudCredentialArgs) (jujuparams.CredentialContentResults, error) {
if a.AllModels_ == nil {
return jujuparams.CredentialContentResults{}, errors.E(errors.CodeNotImplemented)
}
return a.CredentialContents_(ctx, args)
}

func (a *API) AllModels(ctx context.Context) (jujuparams.UserModelList, error) {
Expand Down
24 changes: 24 additions & 0 deletions internal/jujuclient/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,27 @@ func (c Connection) UpdateCloud(ctx context.Context, tag names.CloudTag, cloud j
}
return nil
}

// CredentialContents returns the specified cloud credentials,
// including the secrets if requested.
// If no specific credential name/cloud was passed in, all credentials for this user
// are returned.
// Only credential owner can see its contents as well as what models use it.
// Controller admin has no special superpowers here and is treated the same as all other users.
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't a controller admin be able to see all cloud creds on the controller?

func (c Connection) CredentialContents(ctx context.Context, args jujuparams.CloudCredentialArgs) (jujuparams.CredentialContentResults, error) {
const op = errors.Op("jujuclient.CredentialContents")

resp := jujuparams.CredentialContentResults{
Results: []jujuparams.CredentialContentResult{},
}

err := c.Call(ctx, "Cloud", 7, "", "CredentialContents", &args, &resp)
if err != nil {
return resp, errors.E(op, jujuerrors.Cause(err))
}
if resp.Results[0].Error != nil {
return resp, errors.E(op, resp.Results[0].Error)
}
return resp, nil

}
8 changes: 8 additions & 0 deletions internal/jujuclient/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,3 +464,11 @@ func (s *cloudSuite) TestUpdateCloud(c *gc.C) {
c.Assert(err, gc.Equals, nil)
c.Check(cloud2, jc.DeepEquals, cloud)
}

func (s *cloudSuite) TestCredentialContents(c *gc.C) {
ctx := context.Background()
args := jujuparams.CloudCredentialArgs{}
res, err := s.API.CredentialContents(ctx, args)
c.Assert(err, gc.Equals, nil)
c.Assert(res.Results, gc.HasLen, 1)
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a test that looks up for a specific cloud credential?

Loading