github.com/aiven/aiven-go-client@v1.36.0/organization_user_group.go (about) 1 // Package aiven provides a client for using the Aiven API. 2 package aiven 3 4 type ( 5 // OrganizationUserGroupHandler is the client which interacts with the Organization Users Groups API on Aiven. 6 OrganizationUserGroupHandler struct { 7 // client is the API client to use. 8 client *Client 9 } 10 11 // OrganizationUserGroupRequest is request structure for the Organization Users Groups API on Aiven. 12 OrganizationUserGroupRequest struct { 13 // Name of the user group 14 UserGroupName string `json:"user_group_name,omitempty"` 15 // Optional description of the user group 16 Description string `json:"description,omitempty"` 17 } 18 19 // OrganizationUserGroupResponse is response structure for the Organization Users Groups API on Aiven. 20 OrganizationUserGroupResponse struct { 21 APIResponse 22 23 // ID of the user group 24 UserGroupID string `json:"user_group_id"` 25 // Name of the user group 26 UserGroupName string `json:"user_group_name"` 27 // Description of the user group 28 Description string `json:"description"` 29 // Time when the user group was created 30 CreateTime string `json:"create_time"` 31 // Time when the user group was last updated 32 UpdateTime string `json:"update_time"` 33 } 34 35 // OrganizationUserGroupListResponse is response structure for the Organization Users Groups Members List API on Aiven. 36 OrganizationUserGroupListResponse struct { 37 APIResponse 38 39 UserGroups []OrganizationUserGroupResponse `json:"user_groups"` 40 } 41 ) 42 43 // Get returns data about the specified Organization User Group. 44 func (h *OrganizationUserGroupHandler) Get(orgID, userGroupID string) (*OrganizationUserGroupResponse, error) { 45 path := buildPath("organization", orgID, "user-groups", userGroupID) 46 bts, err := h.client.doGetRequest(path, nil) 47 if err != nil { 48 return nil, err 49 } 50 51 var r OrganizationUserGroupResponse 52 53 return &r, checkAPIResponse(bts, &r) 54 } 55 56 // Create creates Organization User Group. 57 func (h *OrganizationUserGroupHandler) Create(orgID string, req OrganizationUserGroupRequest) (*OrganizationUserGroupResponse, error) { 58 path := buildPath("organization", orgID, "user-groups") 59 bts, err := h.client.doPostRequest(path, req) 60 if err != nil { 61 return nil, err 62 } 63 64 var r OrganizationUserGroupResponse 65 66 return &r, checkAPIResponse(bts, &r) 67 } 68 69 // Delete deletes Organization User Group. 70 func (h *OrganizationUserGroupHandler) Delete(orgID, userGroupID string) error { 71 path := buildPath("organization", orgID, "user-groups", userGroupID) 72 bts, err := h.client.doDeleteRequest(path, nil) 73 if err != nil { 74 return err 75 } 76 77 return checkAPIResponse(bts, nil) 78 } 79 80 // List retrieves a list of Organization User Groups. 81 func (h *OrganizationUserGroupHandler) List(orgID string) (*OrganizationUserGroupListResponse, error) { 82 path := buildPath("organization", orgID, "user-groups") 83 bts, err := h.client.doGetRequest(path, nil) 84 if err != nil { 85 return nil, err 86 } 87 88 var r OrganizationUserGroupListResponse 89 90 return &r, checkAPIResponse(bts, &r) 91 } 92 93 // Update updates Organization User Group. 94 func (h *OrganizationUserGroupHandler) Update(orgID, userGroupID string, req OrganizationUserGroupRequest) (*OrganizationUserGroupResponse, error) { 95 path := buildPath("organization", orgID, "user-groups", userGroupID) 96 bts, err := h.client.doPatchRequest(path, req) 97 if err != nil { 98 return nil, err 99 } 100 101 var r OrganizationUserGroupResponse 102 103 return &r, checkAPIResponse(bts, &r) 104 }