Skip to content

Commit

Permalink
PLT-1455: Added support for role management (#141)
Browse files Browse the repository at this point in the history
* Added support to get role by id.

* Added role CRUD operations

* fix
  • Loading branch information
SivaanandM authored Nov 14, 2024
1 parent 1e19102 commit b4855be
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions client/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,43 @@ func (h *V1Client) GetRole(roleName string) (*models.V1Role, error) {

return nil, fmt.Errorf("role '%s' not found", roleName)
}

// GetRoleByID retrieves an existing role by ID.
func (h *V1Client) GetRoleByID(roleUID string) (*models.V1Role, error) {
// ACL scoped to tenant only
params := clientv1.NewV1RolesUIDGetParams().WithUID(roleUID)
resp, err := h.Client.V1RolesUIDGet(params)
if err != nil {
return nil, err
}

return resp.Payload, nil
}

// CreateRole create new role.
func (h *V1Client) CreateRole(role *models.V1Role) (string, error) {
// ACL scoped to tenant only
params := clientv1.NewV1RolesCreateParams().WithBody(role)
resp, err := h.Client.V1RolesCreate(params)
if err != nil {
return "", err
}

return *resp.Payload.UID, nil
}

// UpdateRole Update existing role with ID
func (h *V1Client) UpdateRole(role *models.V1Role, roleUID string) error {
// ACL scoped to tenant only
params := clientv1.NewV1RolesUIDUpdateParams().WithBody(role).WithUID(roleUID)
_, err := h.Client.V1RolesUIDUpdate(params)
return err
}

// DeleteRole Delete existing role with ID
func (h *V1Client) DeleteRole(roleUID string) error {
// ACL scoped to tenant only
params := clientv1.NewV1RolesUIDDeleteParams().WithUID(roleUID)
_, err := h.Client.V1RolesUIDDelete(params)
return err
}

0 comments on commit b4855be

Please sign in to comment.