-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathorganization.go
114 lines (94 loc) · 3.52 KB
/
organization.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
110
111
112
113
114
// Package aiven provides a client for using the Aiven API.
package aiven
import (
"context"
"time"
)
//goland:noinspection GoUnusedConst
const (
// OrganizationTierBusiness is the business tier.
OrganizationTierBusiness OrganizationTier = "business"
// OrganizationTierPersonal is the personal tier.
OrganizationTierPersonal OrganizationTier = "personal"
)
type (
// OrganizationHandler is the client which interacts with the Organizations API on Aiven.
OrganizationHandler struct {
// client is the API client to use.
client *Client
}
// OrganizationTier is a type representing the tier of an organization.
OrganizationTier string
// OrganizationInfo is a response from Aiven for a single organization.
OrganizationInfo struct {
APIResponse
// ID is the unique identifier of the organization.
ID string `json:"organization_id"`
// Name is the name of the organization.
Name string `json:"organization_name"`
// Tier is the tier of the organization.
Tier OrganizationTier `json:"tier"`
// DefaultGovernanceUserGroupID is the default governance user group ID.
DefaultGovernanceUserGroupID *string `json:"default_governance_user_group_id,omitempty"`
// AccountID is the unique identifier of the account.
AccountID string `json:"account_id"`
// CreateTime is the time when the organization was created.
CreateTime *time.Time `json:"create_time"`
// UpdateTime is the time when the organization was last updated.
UpdateTime *time.Time `json:"update_time"`
}
// OrganizationCreateRequest are the parameters to create an organization.
OrganizationCreateRequest struct {
// Name is the name of the organization.
Name string `json:"organization_name"`
// Tier is the tier of the organization.
Tier OrganizationTier `json:"tier"`
// PrimaryBillingGroupID is the primary billing group ID.
PrimaryBillingGroupID *string `json:"primary_billing_group_id,omitempty"`
}
// OrganizationUpdateRequest are the parameters to update an organization.
OrganizationUpdateRequest struct {
// Name is the name of the organization.
Name *string `json:"name,omitempty"`
// Tier is the tier of the organization.
Tier *OrganizationTier `json:"tier,omitempty"`
// KafkaGovernanceEnabled is the Kafka governance enabled flag.
KafkaGovernanceEnabled *bool `json:"kafka_governance_enabled,omitempty"`
// DefaultGovernanceUserGroupID is the default governance user group ID.
DefaultGovernanceUserGroupID *string `json:"default_governance_user_group_id,omitempty"`
}
)
// Create creates a new organization.
func (h *OrganizationHandler) Create(ctx context.Context, req OrganizationCreateRequest) (*OrganizationInfo, error) {
path := buildPath("organizations")
bts, err := h.client.doPostRequest(ctx, path, req)
if err != nil {
return nil, err
}
var r OrganizationInfo
return &r, checkAPIResponse(bts, &r)
}
// Get returns information about the specified organization.
func (h *OrganizationHandler) Get(ctx context.Context, id string) (*OrganizationInfo, error) {
path := buildPath("organization", id)
bts, err := h.client.doGetRequest(ctx, path, nil)
if err != nil {
return nil, err
}
var r OrganizationInfo
return &r, checkAPIResponse(bts, &r)
}
// Update updates the specified organization.
func (h *OrganizationHandler) Update(
ctx context.Context,
id string,
req OrganizationUpdateRequest,
) (*OrganizationInfo, error) {
path := buildPath("organization", id)
bts, err := h.client.doPatchRequest(ctx, path, req)
if err != nil {
return nil, err
}
var r OrganizationInfo
return &r, checkAPIResponse(bts, &r)
}