handle unassignment of role

This commit is contained in:
Mike Mason
2023-07-11 22:26:16 +00:00
parent 11fe8f8f2a
commit 2147f0374b
11 changed files with 403 additions and 162 deletions

View File

@@ -45,6 +45,29 @@ func (c *Client) AssignRole(ctx context.Context, roleID gidx.PrefixedID, memberI
return nil
}
func (c *Client) UnassignRole(ctx context.Context, roleID gidx.PrefixedID, memberID gidx.PrefixedID) error {
path := fmt.Sprintf("/api/v1/roles/%s/assignments", roleID.String())
body, err := encodeJSON(RoleAssign{
SubjectID: memberID.String(),
})
if err != nil {
return err
}
var response RoleAssignResponse
if _, err = c.DoRequest(ctx, http.MethodDelete, path, body, &response); err != nil {
return err
}
if !response.Success {
return ErrUnassignmentFailed
}
return nil
}
func (c *Client) ListRoleAssignments(ctx context.Context, roleID gidx.PrefixedID) ([]gidx.PrefixedID, error) {
path := fmt.Sprintf("/api/v1/roles/%s/assignments", roleID.String())