github.com/aiven/aiven-go-client@v1.36.0/service_integration.go (about)

     1  package aiven
     2  
     3  type (
     4  	// NewServiceIntegration defines partial set of service integration fields used
     5  	// when passing integration as part of service creation call
     6  	NewServiceIntegration struct {
     7  		DestinationEndpointID *string                `json:"dest_endpoint_id"`
     8  		DestinationService    *string                `json:"dest_service"`
     9  		IntegrationType       string                 `json:"integration_type"`
    10  		SourceService         *string                `json:"source_service"`
    11  		SourceEndpointID      *string                `json:"source_endpoint_id"`
    12  		UserConfig            map[string]interface{} `json:"user_config,omitempty"`
    13  	}
    14  
    15  	// ServiceIntegration represents a service integration endpoint,
    16  	// like parameters for integration to Datadog
    17  	ServiceIntegration struct {
    18  		Active                  bool                   `json:"active"`
    19  		Description             string                 `json:"description"`
    20  		DestinationProject      *string                `json:"dest_project"`
    21  		DestinationService      *string                `json:"dest_service"`
    22  		DestinationEndpointID   *string                `json:"dest_endpoint_id"`
    23  		DestinationEndpointName *string                `json:"dest_endpoint"`
    24  		DestinationServiceType  *string                `json:"dest_service_type"`
    25  		Enabled                 bool                   `json:"enabled"`
    26  		IntegrationType         string                 `json:"integration_type"`
    27  		IntegrationStatus       map[string]interface{} `json:"integration_status"`
    28  		ServiceIntegrationID    string                 `json:"service_integration_id"`
    29  		SourceProject           *string                `json:"source_project"`
    30  		SourceService           *string                `json:"source_service"`
    31  		SourceEndpointID        *string                `json:"source_endpoint_id"`
    32  		SourceEndpointName      *string                `json:"source_endpoint"`
    33  		SourceServiceType       *string                `json:"source_service_type"`
    34  		UserConfig              map[string]interface{} `json:"user_config"`
    35  	}
    36  
    37  	// ServiceIntegrationsHandler is the client that interacts
    38  	// with the Service Integration Endpoints API endpoints on Aiven.
    39  	ServiceIntegrationsHandler struct {
    40  		client *Client
    41  	}
    42  
    43  	// CreateServiceIntegrationRequest are the parameters to create a Service Integration.
    44  	CreateServiceIntegrationRequest struct {
    45  		DestinationService    *string                `json:"dest_service,omitempty"`
    46  		DestinationEndpointID *string                `json:"dest_endpoint_id,omitempty"`
    47  		DestinationProject    *string                `json:"dest_project,omitempty"`
    48  		IntegrationType       string                 `json:"integration_type"`
    49  		SourceService         *string                `json:"source_service,omitempty"`
    50  		SourceProject         *string                `json:"source_project,omitempty"`
    51  		SourceEndpointID      *string                `json:"source_endpoint_id,omitempty"`
    52  		UserConfig            map[string]interface{} `json:"user_config,omitempty"`
    53  	}
    54  
    55  	// UpdateServiceIntegrationRequest are the parameters to update a Service Integration.
    56  	UpdateServiceIntegrationRequest struct {
    57  		UserConfig map[string]interface{} `json:"user_config"`
    58  	}
    59  
    60  	// ServiceIntegrationResponse represents the response from Aiven
    61  	// after interacting with the Service Integration API.
    62  	ServiceIntegrationResponse struct {
    63  		APIResponse
    64  		ServiceIntegration *ServiceIntegration `json:"service_integration"`
    65  	}
    66  
    67  	// ServiceIntegrationListResponse represents the response from Aiven
    68  	// for listing service integrations.
    69  	ServiceIntegrationListResponse struct {
    70  		APIResponse
    71  		ServiceIntegrations []*ServiceIntegration `json:"service_integrations"`
    72  	}
    73  )
    74  
    75  // Create the given Service Integration on Aiven.
    76  func (h *ServiceIntegrationsHandler) Create(
    77  	project string,
    78  	req CreateServiceIntegrationRequest,
    79  ) (*ServiceIntegration, error) {
    80  	path := buildPath("project", project, "integration")
    81  	bts, err := h.client.doPostRequest(path, req)
    82  	if err != nil {
    83  		return nil, err
    84  	}
    85  
    86  	var r ServiceIntegrationResponse
    87  	errR := checkAPIResponse(bts, &r)
    88  
    89  	return r.ServiceIntegration, errR
    90  }
    91  
    92  // Get a specific service integration endpoint from Aiven.
    93  func (h *ServiceIntegrationsHandler) Get(project, integrationID string) (*ServiceIntegration, error) {
    94  	path := buildPath("project", project, "integration", integrationID)
    95  	bts, err := h.client.doGetRequest(path, nil)
    96  	if err != nil {
    97  		return nil, err
    98  	}
    99  
   100  	var r ServiceIntegrationResponse
   101  	errR := checkAPIResponse(bts, &r)
   102  
   103  	return r.ServiceIntegration, errR
   104  }
   105  
   106  // Update the given service integration with the given parameters.
   107  func (h *ServiceIntegrationsHandler) Update(
   108  	project string,
   109  	integrationID string,
   110  	req UpdateServiceIntegrationRequest,
   111  ) (*ServiceIntegration, error) {
   112  	path := buildPath("project", project, "integration", integrationID)
   113  	bts, err := h.client.doPutRequest(path, req)
   114  	if err != nil {
   115  		return nil, err
   116  	}
   117  
   118  	var r ServiceIntegrationResponse
   119  	errR := checkAPIResponse(bts, &r)
   120  
   121  	return r.ServiceIntegration, errR
   122  }
   123  
   124  // Delete the given service integration from Aiven.
   125  func (h *ServiceIntegrationsHandler) Delete(project, integrationID string) error {
   126  	path := buildPath("project", project, "integration", integrationID)
   127  	bts, err := h.client.doDeleteRequest(path, nil)
   128  	if err != nil {
   129  		return err
   130  	}
   131  
   132  	return checkAPIResponse(bts, nil)
   133  }
   134  
   135  // List all service integration for a given project and service.
   136  func (h *ServiceIntegrationsHandler) List(project, service string) ([]*ServiceIntegration, error) {
   137  	path := buildPath("project", project, "service", service, "integration")
   138  	bts, err := h.client.doGetRequest(path, nil)
   139  	if err != nil {
   140  		return nil, err
   141  	}
   142  
   143  	var r ServiceIntegrationListResponse
   144  	errR := checkAPIResponse(bts, &r)
   145  
   146  	return r.ServiceIntegrations, errR
   147  }