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

     1  package aiven
     2  
     3  type (
     4  	// AWSPrivatelinkHandler is the client that interacts with the AWS Privatelink API on Aiven.
     5  	AWSPrivatelinkHandler struct {
     6  		client *Client
     7  	}
     8  
     9  	// AWSPrivatelinkRequest holds the parameters to create a new
    10  	// or update an existing AWS Privatelink.
    11  	AWSPrivatelinkRequest struct {
    12  		Principals []string `json:"principals"`
    13  	}
    14  
    15  	// AWSPrivatelinkResponse represents the response from Aiven after
    16  	// interacting with the AWS Privatelink.
    17  	AWSPrivatelinkResponse struct {
    18  		APIResponse
    19  		AWSServiceID   string   `json:"aws_service_id"`
    20  		AWSServiceName string   `json:"aws_service_name"`
    21  		State          string   `json:"state"`
    22  		Principals     []string `json:"principals"`
    23  	}
    24  )
    25  
    26  // Create creates an AWS Privatelink
    27  func (h *AWSPrivatelinkHandler) Create(project, serviceName string, principals []string) (*AWSPrivatelinkResponse, error) {
    28  	path := buildPath("project", project, "service", serviceName, "privatelink", "aws")
    29  	bts, err := h.client.doPostRequest(path, AWSPrivatelinkRequest{
    30  		Principals: principals,
    31  	})
    32  	if err != nil {
    33  		return nil, err
    34  	}
    35  
    36  	var rsp AWSPrivatelinkResponse
    37  	if err := checkAPIResponse(bts, &rsp); err != nil {
    38  		return nil, err
    39  	}
    40  
    41  	return &rsp, nil
    42  }
    43  
    44  // Update updates an AWS Privatelink
    45  func (h *AWSPrivatelinkHandler) Update(project, serviceName string, principals []string) (*AWSPrivatelinkResponse, error) {
    46  	path := buildPath("project", project, "service", serviceName, "privatelink", "aws")
    47  	bts, err := h.client.doPutRequest(path, AWSPrivatelinkRequest{
    48  		Principals: principals,
    49  	})
    50  	if err != nil {
    51  		return nil, err
    52  	}
    53  
    54  	var rsp AWSPrivatelinkResponse
    55  	if err := checkAPIResponse(bts, &rsp); err != nil {
    56  		return nil, err
    57  	}
    58  
    59  	return &rsp, nil
    60  }
    61  
    62  // Get retrieves an AWS Privatelink
    63  func (h *AWSPrivatelinkHandler) Get(project, serviceName string) (*AWSPrivatelinkResponse, error) {
    64  	path := buildPath("project", project, "service", serviceName, "privatelink", "aws")
    65  	bts, err := h.client.doGetRequest(path, nil)
    66  	if err != nil {
    67  		return nil, err
    68  	}
    69  
    70  	var rsp AWSPrivatelinkResponse
    71  	if err := checkAPIResponse(bts, &rsp); err != nil {
    72  		return nil, err
    73  	}
    74  
    75  	return &rsp, nil
    76  }
    77  
    78  // Delete deletes an AWS Privatelink
    79  func (h *AWSPrivatelinkHandler) Delete(project, serviceName string) error {
    80  	path := buildPath("project", project, "service", serviceName, "privatelink", "aws")
    81  	rsp, err := h.client.doDeleteRequest(path, nil)
    82  	if err != nil {
    83  		return err
    84  	}
    85  
    86  	return checkAPIResponse(rsp, nil)
    87  }