From 58866fb1d5b724019df29b702c6497c703be62ea Mon Sep 17 00:00:00 2001 From: Sivaanand Murugesan Date: Wed, 13 Nov 2024 20:54:38 +0530 Subject: [PATCH] Added role CRUD operations --- client/role.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/client/role.go b/client/role.go index 3d810739..73f42267 100644 --- a/client/role.go +++ b/client/role.go @@ -39,3 +39,37 @@ func (h *V1Client) GetRoleByID(roleUID string) (*models.V1Role, error) { 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) + if err != nil { + return err + } + return nil +} + +// 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) + if err != nil { + return err + } + return nil +}