Skip to content

Commit

Permalink
Use existing ToCloudRelation for mapping accesses to relations
Browse files Browse the repository at this point in the history
Signed-off-by: Babak K. Shandiz <[email protected]>
  • Loading branch information
babakks committed Oct 2, 2023
1 parent 72db748 commit 6adda6d
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions internal/jimm/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ func (j *JIMM) doCloudAdmin(ctx context.Context, u *openfga.User, ct names.Cloud
func (j *JIMM) GrantCloudAccess(ctx context.Context, user *openfga.User, ct names.CloudTag, ut names.UserTag, access string) error {
const op = errors.Op("jimm.GrantCloudAccess")

targetRelation, err := cloudAccessToRelation(access)
targetRelation, err := ToCloudRelation(access)
if err != nil {
return errors.E(op, errors.CodeBadRequest, "failed to recognize given access", err)
}
Expand Down Expand Up @@ -608,7 +608,7 @@ func (j *JIMM) GrantCloudAccess(ctx context.Context, user *openfga.User, ct name
func (j *JIMM) RevokeCloudAccess(ctx context.Context, user *openfga.User, ct names.CloudTag, ut names.UserTag, access string) error {
const op = errors.Op("jimm.RevokeCloudAccess")

targetRelation, err := cloudAccessToRelation(access)
targetRelation, err := ToCloudRelation(access)
if err != nil {
return errors.E(op, errors.CodeBadRequest, "failed to recognize given access", err)
}
Expand Down Expand Up @@ -662,15 +662,6 @@ func (j *JIMM) RevokeCloudAccess(ctx context.Context, user *openfga.User, ct nam
return nil
}

func cloudAccessToRelation(access string) (openfga.Relation, error) {
if access == "admin" {
return ofganames.AdministratorRelation, nil
} else if access == "add-model" {
return ofganames.CanAddModelRelation, nil
}
return ofganames.NoRelation, errors.E(fmt.Sprintf("unknown access: %q", access))
}

// RemoveCloud removes the given cloud from JAAS If the cloud is not found
// then an error with the code CodeNotFound is returned. If the
// authenticated user does not have admin access to the cloud then an error
Expand Down

0 comments on commit 6adda6d

Please sign in to comment.