forked from aiven/aiven-go-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
service_integration.go
147 lines (125 loc) · 5.54 KB
/
service_integration.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright (c) 2018 Aiven, Helsinki, Finland. https://aiven.io/
package aiven
type (
// NewServiceIntegration defines partial set of service integration fields used
// when passing integration as part of service creation call
NewServiceIntegration struct {
DestinationEndpointID *string `json:"dest_endpoint_id"`
DestinationService *string `json:"dest_service"`
IntegrationType string `json:"integration_type"`
SourceService *string `json:"source_service"`
SourceEndpointID *string `json:"source_endpoint_id"`
UserConfig map[string]interface{} `json:"user_config"`
}
// ServiceIntegration represents a service integration endpoint,
// like parameters for integration to Datadog
ServiceIntegration struct {
Active bool `json:"active"`
Description string `json:"description"`
DestinationProject *string `json:"dest_project"`
DestinationService *string `json:"dest_service"`
DestinationEndpointID *string `json:"dest_endpoint_id"`
DestinationEndpointName *string `json:"dest_endpoint"`
DestinationServiceType *string `json:"dest_service_type"`
Enabled bool `json:"enabled"`
IntegrationType string `json:"integration_type"`
IntegrationStatus map[string]interface{} `json:"integration_status"`
ServiceIntegrationID string `json:"service_integration_id"`
SourceProject *string `json:"source_project"`
SourceService *string `json:"source_service"`
SourceEndpointID *string `json:"source_endpoint_id"`
SourceEndpointName *string `json:"source_endpoint"`
SourceServiceType *string `json:"source_service_type"`
UserConfig map[string]interface{} `json:"user_config"`
}
// ServiceIntegrationsHandler is the client that interacts
// with the Service Integration Endpoints API endpoints on Aiven.
ServiceIntegrationsHandler struct {
client *Client
}
// CreateServiceIntegrationRequest are the parameters to create a Service Integration.
CreateServiceIntegrationRequest struct {
DestinationService *string `json:"dest_service,omitempty"`
DestinationEndpointID *string `json:"dest_endpoint_id,omitempty"`
IntegrationType string `json:"integration_type"`
SourceService *string `json:"source_service,omitempty"`
SourceEndpointID *string `json:"source_endpoint_id,omitempty"`
UserConfig map[string]interface{} `json:"user_config,omitempty"`
}
// UpdateServiceIntegrationRequest are the parameters to update a Service Integration.
UpdateServiceIntegrationRequest struct {
UserConfig map[string]interface{} `json:"user_config,omitempty"`
}
// ServiceIntegrationResponse represents the response from Aiven
// after interacting with the Service Integration API.
ServiceIntegrationResponse struct {
APIResponse
ServiceIntegration *ServiceIntegration `json:"service_integration"`
}
// ServiceIntegrationListResponse represents the response from Aiven
// for listing service integrations.
ServiceIntegrationListResponse struct {
APIResponse
ServiceIntegrations []*ServiceIntegration `json:"service_integrations"`
}
)
// Create the given Service Integration on Aiven.
func (h *ServiceIntegrationsHandler) Create(
project string,
req CreateServiceIntegrationRequest,
) (*ServiceIntegration, error) {
path := buildPath("project", project, "integration")
bts, err := h.client.doPostRequest(path, req)
if err != nil {
return nil, err
}
var r ServiceIntegrationResponse
errR := checkAPIResponse(bts, &r)
return r.ServiceIntegration, errR
}
// Get a specific service integration endpoint from Aiven.
func (h *ServiceIntegrationsHandler) Get(project, integrationID string) (*ServiceIntegration, error) {
path := buildPath("project", project, "integration", integrationID)
bts, err := h.client.doGetRequest(path, nil)
if err != nil {
return nil, err
}
var r ServiceIntegrationResponse
errR := checkAPIResponse(bts, &r)
return r.ServiceIntegration, errR
}
// Update the given service integration with the given parameters.
func (h *ServiceIntegrationsHandler) Update(
project string,
integrationID string,
req UpdateServiceIntegrationRequest,
) (*ServiceIntegration, error) {
path := buildPath("project", project, "integration", integrationID)
bts, err := h.client.doPutRequest(path, req)
if err != nil {
return nil, err
}
var r ServiceIntegrationResponse
errR := checkAPIResponse(bts, &r)
return r.ServiceIntegration, errR
}
// Delete the given service integration from Aiven.
func (h *ServiceIntegrationsHandler) Delete(project, integrationID string) error {
path := buildPath("project", project, "integration", integrationID)
bts, err := h.client.doDeleteRequest(path, nil)
if err != nil {
return err
}
return checkAPIResponse(bts, nil)
}
// List all service integration for a given project and service.
func (h *ServiceIntegrationsHandler) List(project, service string) ([]*ServiceIntegration, error) {
path := buildPath("project", project, "service", service, "integration")
bts, err := h.client.doGetRequest(path, nil)
if err != nil {
return nil, err
}
var r ServiceIntegrationListResponse
errR := checkAPIResponse(bts, &r)
return r.ServiceIntegrations, errR
}