github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/api/satellite/satellitev1/source.go (about)

     1  package satellitev1
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/IBM-Cloud/bluemix-go/api/container/containerv2"
     7  	"github.com/IBM-Cloud/bluemix-go/client"
     8  )
     9  
    10  type CreateSatelliteEndpointSourceRequest struct {
    11  	LocationID string   `json:"-"`
    12  	Type       string   `json:"type"` // service
    13  	SourceName string   `json:"source_name"`
    14  	Addresses  []string `json:"addresses"`
    15  }
    16  
    17  type CreateSatelliteEndpointSourceResponse struct {
    18  	LocationID string   `json:"location_id"`
    19  	SourceName string   `json:"source_name"`
    20  	Type       string   `json:"type"`
    21  	Addresses  []string `json:"addresses"`
    22  	CreatedAT  string   `json:"created_at"`
    23  	LastChange string   `json:"last_change"`
    24  	SourceID   string   `json:"source_id"`
    25  }
    26  
    27  type UpdateSatelliteEndpointSourceRequest struct {
    28  	SourceName string   `json:"source_name"`
    29  	Addresses  []string `json:"addresses"`
    30  }
    31  
    32  type UpdateSatelliteEndpointSourceResponse CreateSatelliteEndpointSourceResponse
    33  
    34  type source struct {
    35  	client     *client.Client
    36  	pathPrefix string
    37  }
    38  
    39  type SatelliteSources struct {
    40  	Sources []SatelliteSourceInfo `json:"sources"`
    41  }
    42  
    43  type SatelliteSourceInfo struct {
    44  	Addresses  []string `json:"addresses"`
    45  	CreatedAt  string   `json:"created_at"`
    46  	LastChange string   `json:"last_change"`
    47  	LocationID string   `json:"location_id"`
    48  	SourceName string   `json:"source_name"`
    49  	Type       string   `json:"type"`
    50  	SourceID   string   `json:"source_id"`
    51  }
    52  type Source interface {
    53  	//GetEndpointInfo(locationID, endpointID string, target containerv2.ClusterTargetHeader) (SatelliteEndpointInfo, error)
    54  	CreateSatelliteEndpointSource(params CreateSatelliteEndpointSourceRequest,
    55  		target containerv2.ClusterTargetHeader) (CreateSatelliteEndpointSourceResponse, error)
    56  	ListSatelliteEndpointSources(locationID string,
    57  		target containerv2.ClusterTargetHeader) (*SatelliteSources, error)
    58  	UpdateSatelliteEndpointSources(locationID string, sourceID string,
    59  		params UpdateSatelliteEndpointSourceRequest,
    60  		target containerv2.ClusterTargetHeader) (UpdateSatelliteEndpointSourceResponse, error)
    61  }
    62  
    63  func newSourceAPI(c *client.Client) Source {
    64  	return &source{
    65  		client: c,
    66  	}
    67  }
    68  
    69  func (s *source) CreateSatelliteEndpointSource(params CreateSatelliteEndpointSourceRequest,
    70  	target containerv2.ClusterTargetHeader) (CreateSatelliteEndpointSourceResponse, error) {
    71  
    72  	var source CreateSatelliteEndpointSourceResponse
    73  	rawURL := fmt.Sprintf("/v1/locations/%s/sources", params.LocationID)
    74  	_, err := s.client.Post(rawURL, params, &source, target.ToMap())
    75  	return source, err
    76  }
    77  
    78  func (s *source) ListSatelliteEndpointSources(locationID string,
    79  	target containerv2.ClusterTargetHeader) (*SatelliteSources, error) {
    80  
    81  	SatSourceInfo := new(SatelliteSources)
    82  	rawURL := fmt.Sprintf("v1/locations/%s/sources", locationID)
    83  	_, err := s.client.Get(rawURL, &SatSourceInfo, target.ToMap())
    84  	if err != nil {
    85  		return nil, err
    86  	}
    87  	return SatSourceInfo, nil
    88  }
    89  
    90  func (s *source) UpdateSatelliteEndpointSources(locationID string, sourceID string,
    91  	params UpdateSatelliteEndpointSourceRequest,
    92  	target containerv2.ClusterTargetHeader) (UpdateSatelliteEndpointSourceResponse, error) {
    93  	var source UpdateSatelliteEndpointSourceResponse
    94  
    95  	rawURL := fmt.Sprintf("/v1/locations/%s/sources/%s", locationID, sourceID)
    96  	_, err := s.client.Patch(rawURL, params, &source, target.ToMap())
    97  	return source, err
    98  }