github.com/aiven/aiven-go-client@v1.36.0/service_integration_endpoint.go (about) 1 package aiven 2 3 import ( 4 "fmt" 5 ) 6 7 type ( 8 // ServiceIntegrationEndpoint represents a service integration endpoint, 9 // like parameters for integration to Datadog 10 ServiceIntegrationEndpoint struct { 11 EndpointID string `json:"endpoint_id"` 12 EndpointName string `json:"endpoint_name"` 13 EndpointType string `json:"endpoint_type"` 14 UserConfig map[string]interface{} `json:"user_config"` 15 EndpointConfig map[string]interface{} `json:"endpoint_config"` 16 } 17 18 // ServiceIntegrationEndpointsHandler is the client that interacts 19 // with the Service Integration Endpoints API endpoints on Aiven. 20 ServiceIntegrationEndpointsHandler struct { 21 client *Client 22 } 23 24 // CreateServiceIntegrationEndpointRequest are the parameters to create 25 // a Service Integration Endpoint. 26 CreateServiceIntegrationEndpointRequest struct { 27 EndpointName string `json:"endpoint_name"` 28 EndpointType string `json:"endpoint_type"` 29 UserConfig map[string]interface{} `json:"user_config,omitempty"` 30 } 31 32 // UpdateServiceIntegrationEndpointRequest are the parameters to update 33 // a Service Integration Endpoint. 34 UpdateServiceIntegrationEndpointRequest struct { 35 UserConfig map[string]interface{} `json:"user_config,omitempty"` 36 } 37 38 // ServiceIntegrationEndpointResponse represents the response from Aiven 39 // after interacting with the Service Integration Endpoints API. 40 ServiceIntegrationEndpointResponse struct { 41 APIResponse 42 ServiceIntegrationEndpoint *ServiceIntegrationEndpoint `json:"service_integration_endpoint"` 43 } 44 45 // ServiceIntegrationEndpointListResponse represents the response from Aiven 46 // for listing service integration endpoints. 47 ServiceIntegrationEndpointListResponse struct { 48 APIResponse 49 ServiceIntegrationEndpoints []*ServiceIntegrationEndpoint `json:"service_integration_endpoints"` 50 } 51 ) 52 53 // Create the given Service Integration Endpoint on Aiven. 54 func (h *ServiceIntegrationEndpointsHandler) Create( 55 project string, 56 req CreateServiceIntegrationEndpointRequest, 57 ) (*ServiceIntegrationEndpoint, error) { 58 path := buildPath("project", project, "integration_endpoint") 59 bts, err := h.client.doPostRequest(path, req) 60 if err != nil { 61 return nil, err 62 } 63 64 var r ServiceIntegrationEndpointResponse 65 errR := checkAPIResponse(bts, &r) 66 67 return r.ServiceIntegrationEndpoint, errR 68 } 69 70 // Get a specific service integration endpoint from Aiven. 71 func (h *ServiceIntegrationEndpointsHandler) Get(project, endpointID string) (*ServiceIntegrationEndpoint, error) { 72 // There's no API for getting integration endpoint by ID. List all endpoints 73 // and pick the correct one instead. (There shouldn't ever be many endpoints.) 74 endpoints, err := h.List(project) 75 if err != nil { 76 return nil, err 77 } 78 79 for _, endpoint := range endpoints { 80 if endpoint.EndpointID == endpointID { 81 return endpoint, nil 82 } 83 } 84 85 err = Error{Message: fmt.Sprintf("Integration endpoint with ID %v not found", endpointID), Status: 404} 86 return nil, err 87 } 88 89 // Update the given service integration endpoint with the given parameters. 90 func (h *ServiceIntegrationEndpointsHandler) Update( 91 project string, 92 endpointID string, 93 req UpdateServiceIntegrationEndpointRequest, 94 ) (*ServiceIntegrationEndpoint, error) { 95 path := buildPath("project", project, "integration_endpoint", endpointID) 96 bts, err := h.client.doPutRequest(path, req) 97 if err != nil { 98 return nil, err 99 } 100 101 var r ServiceIntegrationEndpointResponse 102 errR := checkAPIResponse(bts, &r) 103 104 return r.ServiceIntegrationEndpoint, errR 105 } 106 107 // Delete the given service integration endpoint from Aiven. 108 func (h *ServiceIntegrationEndpointsHandler) Delete(project, endpointID string) error { 109 path := buildPath("project", project, "integration_endpoint", endpointID) 110 bts, err := h.client.doDeleteRequest(path, nil) 111 if err != nil { 112 return err 113 } 114 115 return checkAPIResponse(bts, nil) 116 } 117 118 // List all service integration endpoints for a given project. 119 func (h *ServiceIntegrationEndpointsHandler) List(project string) ([]*ServiceIntegrationEndpoint, error) { 120 path := buildPath("project", project, "integration_endpoint") 121 bts, err := h.client.doGetRequest(path, nil) 122 if err != nil { 123 return nil, err 124 } 125 126 var r ServiceIntegrationEndpointListResponse 127 errR := checkAPIResponse(bts, &r) 128 129 return r.ServiceIntegrationEndpoints, errR 130 }