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