Skip to content

Commit

Permalink
Test for addServiceAccount CLI method
Browse files Browse the repository at this point in the history
  • Loading branch information
kian99 committed Jan 29, 2024
1 parent 492a3a1 commit 256ccf8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/jimm.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,5 @@ func (c *Client) MigrateModel(req *params.MigrateModelRequest) (*jujuparams.Init

// AddServiceAccount binds a service account to a user allowing them to manage it.
func (c *Client) AddServiceAccount(req *params.AddServiceAccountRequest) error {
return c.caller.APICall("JIMM", 4, "", "UpdateServiceAccountCredentials", req, nil)
return c.caller.APICall("JIMM", 4, "", "AddServiceAccount", req, nil)
}
2 changes: 1 addition & 1 deletion cmd/serviceaccounts/cmd/addserviceaccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (s *addServiceAccountSuite) TestAddServiceAccount(c *gc.C) {
_, err := cmdtesting.RunCommand(c, cmd.NewAddServiceAccountCommandForTesting(s.ClientStore(), bClient), clientID)
c.Assert(err, gc.IsNil)
tuple := openfga.Tuple{
Object: ofganames.ConvertTag(names.NewUserTag("user-alice@external")),
Object: ofganames.ConvertTag(names.NewUserTag("alice@external")),
Relation: ofganames.AdministratorRelation,
Target: ofganames.ConvertTag(jimmnames.NewServiceAccountTag(clientID)),
}
Expand Down
4 changes: 0 additions & 4 deletions internal/jimm/service_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import (
func (j *JIMM) AddServiceAccount(ctx context.Context, u *openfga.User, clientId string) error {
op := errors.Op("jimm.AddServiceAccount")

if !jimmnames.IsValidServiceAccountId(clientId) {
return errors.E(op, errors.CodeBadRequest, "invalid client ID")
}

svcTag := jimmnames.NewServiceAccountTag(clientId)
key := openfga.Tuple{
Relation: ofganames.AdministratorRelation,
Expand Down
4 changes: 4 additions & 0 deletions internal/jujuapi/jimm.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func init() {
migrateModel := rpc.Method(r.MigrateModel)
addServiceAccountMethod := rpc.Method(r.AddServiceAccount)
updateServiceAccountCredentials := rpc.Method(r.UpdateServiceAccountCredentials)
listServiceAccountCredentials := rpc.Method(r.ListServiceAccountCredentials)
grantServiceAccountAccess := rpc.Method(r.GrantServiceAccountAccess)

// JIMM Generic RPC
r.AddMethod("JIMM", 4, "AddController", addControllerMethod)
Expand Down Expand Up @@ -82,6 +84,8 @@ func init() {
// JIMM Service Accounts
r.AddMethod("JIMM", 4, "AddServiceAccount", addServiceAccountMethod)
r.AddMethod("JIMM", 4, "UpdateServiceAccountCredentials", updateServiceAccountCredentials)
r.AddMethod("JIMM", 4, "ListServiceAccountCredentials", listServiceAccountCredentials)
r.AddMethod("JIMM", 4, "GrantServiceAccountAccess", grantServiceAccountAccess)

return []int{4}
}
Expand Down
4 changes: 4 additions & 0 deletions internal/jujuapi/service_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import (
func (r *controllerRoot) AddServiceAccount(ctx context.Context, req apiparams.AddServiceAccountRequest) error {
const op = errors.Op("jujuapi.AddServiceAccount")

if !jimmnames.IsValidServiceAccountId(req.ClientID) {
return errors.E(op, errors.CodeBadRequest, "invalid client ID")
}

return r.jimm.AddServiceAccount(ctx, r.user, req.ClientID)
}

Expand Down

0 comments on commit 256ccf8

Please sign in to comment.