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

     1  package satellitev1
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/IBM-Cloud/bluemix-go/api/container/containerv2"
     8  	"github.com/IBM-Cloud/bluemix-go/client"
     9  )
    10  
    11  type SatelliteLocationInfo struct {
    12  	ID                string      `json:"id"`
    13  	Name              string      `json:"name"`
    14  	Region            string      `json:"region"`
    15  	ResourceGroup     string      `json:"resourceGroup"`
    16  	ResourceGroupName string      `json:"resourceGroupName"`
    17  	PodSubnet         string      `json:"podSubnet"`
    18  	ServiceSubnet     string      `json:"serviceSubnet"`
    19  	CreatedDate       string      `json:"createdDate"`
    20  	MasterKubeVersion string      `json:"masterKubeVersion"`
    21  	TargetVersion     string      `json:"targetVersion"`
    22  	WorkerCount       int         `json:"workerCount"`
    23  	Location          string      `json:"location"`
    24  	Datacenter        string      `json:"datacenter"`
    25  	MultiAzCapable    bool        `json:"multiAzCapable"`
    26  	Provider          string      `json:"provider"`
    27  	State             string      `json:"state"`
    28  	Status            string      `json:"status"`
    29  	VersionEOS        string      `json:"versionEOS"`
    30  	IsPaid            bool        `json:"isPaid"`
    31  	Entitlement       string      `json:"entitlement"`
    32  	Type              string      `json:"type"`
    33  	Addons            interface{} `json:"addons"`
    34  	EtcdPort          string      `json:"etcdPort"`
    35  	MasterURL         string      `json:"masterURL"`
    36  	Ingress           struct {
    37  		Hostname   string `json:"hostname"`
    38  		SecretName string `json:"secretName"`
    39  		Status     string `json:"status"`
    40  		Message    string `json:"message"`
    41  	} `json:"ingress"`
    42  	CaCertRotationStatus struct {
    43  		Status              string `json:"status"`
    44  		ActionTriggerDate   string `json:"actionTriggerDate"`
    45  		ActionCompletedDate string `json:"actionCompletedDate"`
    46  	} `json:"caCertRotationStatus"`
    47  	ImageSecurityEnabled bool     `json:"imageSecurityEnabled"`
    48  	DisableAutoUpdate    bool     `json:"disableAutoUpdate"`
    49  	Crn                  string   `json:"crn"`
    50  	WorkerZones          []string `json:"workerZones"`
    51  	Lifecycle            struct {
    52  		MasterStatus             string `json:"masterStatus"`
    53  		MasterStatusModifiedDate string `json:"masterStatusModifiedDate"`
    54  		MasterHealth             string `json:"masterHealth"`
    55  		MasterState              string `json:"masterState"`
    56  		ModifiedDate             string `json:"modifiedDate"`
    57  	} `json:"lifecycle"`
    58  	ServiceEndpoints struct {
    59  		PrivateServiceEndpointEnabled bool   `json:"privateServiceEndpointEnabled"`
    60  		PrivateServiceEndpointURL     string `json:"privateServiceEndpointURL"`
    61  		PublicServiceEndpointEnabled  bool   `json:"publicServiceEndpointEnabled"`
    62  		PublicServiceEndpointURL      string `json:"publicServiceEndpointURL"`
    63  	} `json:"serviceEndpoints"`
    64  	Features struct {
    65  		KeyProtectEnabled bool `json:"keyProtectEnabled"`
    66  		PullSecretApplied bool `json:"pullSecretApplied"`
    67  	} `json:"features"`
    68  	Vpcs      interface{} `json:"vpcs"`
    69  	CosConfig struct {
    70  		Region          string `json:"region"`
    71  		Bucket          string `json:"bucket"`
    72  		Endpoint        string `json:"endpoint"`
    73  		ServiceInstance struct {
    74  			Crn string `json:"crn"`
    75  		} `json:"serviceInstance"`
    76  	} `json:"cos_config"`
    77  	Description string `json:"description"`
    78  	Deployments struct {
    79  		Enabled bool   `json:"enabled"`
    80  		Message string `json:"message"`
    81  	} `json:"deployments"`
    82  	Hosts struct {
    83  		Total     int `json:"total"`
    84  		Available int `json:"available"`
    85  	} `json:"hosts"`
    86  	Iaas struct {
    87  		Provider string `json:"provider"`
    88  		Region   string `json:"region"`
    89  	} `json:"iaas"`
    90  	OpenVpnServerPort int `json:"open_vpn_server_port"`
    91  }
    92  
    93  type SatelliteEndpoints struct {
    94  	Endpoint []SatelliteEndpointInfo `json:"endpoints"`
    95  }
    96  
    97  type SatelliteEndpointInfo struct {
    98  	Cert             *EndpointCerts `json:"certs,omitempty"`
    99  	ClientHost       string         `json:"client_host"`
   100  	ClientMutualAuth bool           `json:"client_mutual_auth"`
   101  	ClientPort       int            `json:"client_port"`
   102  	ClientProtocol   string         `json:"client_protocol"`
   103  	ConnType         string         `json:"conn_type"`
   104  	ConnectorPort    int            `json:"connector_port"`
   105  	CreatedAt        time.Time      `json:"created_at"`
   106  	CreatedBy        string         `json:"created_by"`
   107  	Crn              string         `json:"crn"`
   108  	DisplayName      string         `json:"display_name"`
   109  	HTTPTunnelOnTCP  interface{}    `json:"http_tunnel_on_tcp"`
   110  	LastChange       time.Time      `json:"last_change"`
   111  	LocationID       string         `json:"location_id"`
   112  	Performance      struct {
   113  		Connection        int           `json:"connection"`
   114  		RxBandwidth       int           `json:"rx_bandwidth"`
   115  		TxBandwidth       int           `json:"tx_bandwidth"`
   116  		Bandwidth         int           `json:"bandwidth"`
   117  		ToCloudDataRate   int           `json:"to_cloud_data_rate"`
   118  		FromCloudDataRate int           `json:"from_cloud_data_rate"`
   119  		TotalDataRate     int           `json:"total_data_rate"`
   120  		Connectors        []interface{} `json:"connectors"`
   121  	} `json:"performance"`
   122  	Region           string        `json:"region"`
   123  	RejectUnauth     bool          `json:"reject_unauth"`
   124  	ServerHost       string        `json:"server_host"`
   125  	ServerMutualAuth bool          `json:"server_mutual_auth"`
   126  	ServerPort       int           `json:"server_port"`
   127  	ServerProtocol   string        `json:"server_protocol"`
   128  	ServiceName      string        `json:"service_name"`
   129  	Sni              interface{}   `json:"sni"`
   130  	Sources          []interface{} `json:"sources"`
   131  	Status           string        `json:"status"`
   132  	Timeout          int           `json:"timeout"`
   133  	CertificateInfo  string        `json:"certificate_info"`
   134  	EndpointID       string        `json:"endpoint_id"`
   135  }
   136  
   137  type CreateEndpointResponse struct {
   138  	LocationID       string         `json:"location_id"`
   139  	Crn              string         `json:"crn"`
   140  	ConnType         string         `json:"conn_type"`
   141  	DisplayName      string         `json:"display_name"`
   142  	ServiceName      string         `json:"service_name"`
   143  	ClientHost       interface{}    `json:"client_host"`
   144  	ClientPort       interface{}    `json:"client_port"`
   145  	ServerHost       string         `json:"server_host"`
   146  	ServerPort       int            `json:"server_port"`
   147  	ConnectorPort    int            `json:"connector_port"`
   148  	ClientProtocol   string         `json:"client_protocol"`
   149  	ClientMutualAuth bool           `json:"client_mutual_auth"`
   150  	ServerProtocol   string         `json:"server_protocol"`
   151  	ServerMutualAuth bool           `json:"server_mutual_auth"`
   152  	RejectUnauth     bool           `json:"reject_unauth"`
   153  	Sources          []interface{}  `json:"sources"`
   154  	Timeout          int            `json:"timeout"`
   155  	HTTPTunnelOnTCP  interface{}    `json:"http_tunnel_on_tcp"`
   156  	Cert             *EndpointCerts `json:"certs,omitempty"`
   157  	Status           string         `json:"status"`
   158  	CreatedBy        string         `json:"created_by"`
   159  	CreatedAt        time.Time      `json:"created_at"`
   160  	LastChange       time.Time      `json:"last_change"`
   161  	Performance      struct {
   162  		Connection  int           `json:"connection"`
   163  		RxBandwidth int           `json:"rx_bandwidth"`
   164  		TxBandwidth int           `json:"tx_bandwidth"`
   165  		Bandwidth   int           `json:"bandwidth"`
   166  		Connectors  []interface{} `json:"connectors"`
   167  	} `json:"performance"`
   168  	Region     string `json:"region"`
   169  	EndpointID string `json:"endpoint_id"`
   170  }
   171  
   172  type CreateEndpointRequest struct {
   173  	EndpointID       string         `json:"-"`
   174  	ConnType         string         `json:"conn_type,omitempty"`
   175  	DisplayName      string         `json:"display_name,omitempty"`
   176  	ServerHost       string         `json:"server_host,omitempty"`
   177  	ServerPort       int            `json:"server_port,omitempty"`
   178  	Sni              string         `json:"sni,omitempty"`
   179  	ClientProtocol   string         `json:"client_protocol,omitempty"`
   180  	ClientMutualAuth bool           `json:"client_mutual_auth,omitempty"`
   181  	ServerProtocol   string         `json:"server_protocol,omitempty"`
   182  	ServerMutualAuth bool           `json:"server_mutual_auth,omitempty"`
   183  	RejectUnauth     bool           `json:"reject_unauth,omitempty"`
   184  	Timeout          int            `json:"timeout,omitempty"`
   185  	CreatedBy        string         `json:"created_by,omitempty"`
   186  	Cert             *EndpointCerts `json:"certs,omitempty"`
   187  }
   188  
   189  type AddSourcesRequest struct {
   190  	Sources []EndpointSource `json:"sources"`
   191  }
   192  
   193  type EndpointSource struct {
   194  	SourceID string `json:"source_id"`
   195  	Enabled  bool   `json:"enabled"`
   196  }
   197  
   198  type EndpointCerts struct {
   199  	Client struct {
   200  		Cert struct {
   201  			Filename     string `json:"filename,omitempty"`
   202  			FileContents string `json:"file_contents,omitempty"`
   203  		} `json:"cert,omitempty"`
   204  	} `json:"client,omitempty"`
   205  	Server struct {
   206  		Cert struct {
   207  			Filename     string `json:"filename,omitempty"`
   208  			FileContents string `json:"file_contents,omitempty"`
   209  		} `json:"cert,omitempty"`
   210  	} `json:"server,omitempty"`
   211  	Connector struct {
   212  		Cert struct {
   213  			Filename     string `json:"filename,omitempty"`
   214  			FileContents string `json:"file_contents,omitempty"`
   215  		} `json:"cert,omitempty"`
   216  		Key struct {
   217  			Filename     string `json:"filename,omitempty"`
   218  			FileContents string `json:"file_contents,omitempty"`
   219  		} `json:"key,omitempty"`
   220  	} `json:"connector,omitempty"`
   221  }
   222  
   223  type Endpoint interface {
   224  	GetEndpointInfo(locationID, endpointID string, target containerv2.ClusterTargetHeader) (SatelliteEndpointInfo, error)
   225  	CreateSatelliteEndpoint(params CreateEndpointRequest, target containerv2.ClusterTargetHeader) (CreateEndpointResponse, error)
   226  	GetEndpoints(locationID string, target containerv2.ClusterTargetHeader) (*SatelliteEndpoints, error)
   227  	DeleteEndpoint(locationID, endpointID string, target containerv2.ClusterTargetHeader) error
   228  	AddSourcesToEndpoint(locationID, endpointID string, params AddSourcesRequest, target containerv2.ClusterTargetHeader) error
   229  }
   230  
   231  type endpoint struct {
   232  	client     *client.Client
   233  	pathPrefix string
   234  }
   235  
   236  func newEndpointAPI(c *client.Client) Endpoint {
   237  	return &endpoint{
   238  		client: c,
   239  	}
   240  }
   241  
   242  func (s *endpoint) GetEndpointInfo(locationID, endpointID string, target containerv2.ClusterTargetHeader) (SatelliteEndpointInfo, error) {
   243  	SatEndpointInfo := SatelliteEndpointInfo{}
   244  	rawURL := fmt.Sprintf("v1/locations/%s/endpoints/%s", locationID, endpointID)
   245  	_, err := s.client.Get(rawURL, &SatEndpointInfo, target.ToMap())
   246  	return SatEndpointInfo, err
   247  }
   248  
   249  func (s *endpoint) GetEndpoints(locationID string, target containerv2.ClusterTargetHeader) (*SatelliteEndpoints, error) {
   250  	SatEndpointInfo := new(SatelliteEndpoints)
   251  	rawURL := fmt.Sprintf("v1/locations/%s/endpoints", locationID)
   252  	_, err := s.client.Get(rawURL, &SatEndpointInfo, target.ToMap())
   253  	if err != nil {
   254  		return nil, err
   255  	}
   256  	return SatEndpointInfo, err
   257  }
   258  
   259  func (s *endpoint) CreateSatelliteEndpoint(params CreateEndpointRequest, target containerv2.ClusterTargetHeader) (CreateEndpointResponse, error) {
   260  	var endpoint CreateEndpointResponse
   261  	rawURL := fmt.Sprintf("/v1/locations/%s/endpoints", params.EndpointID)
   262  	_, err := s.client.Post(rawURL, params, &endpoint, target.ToMap())
   263  	return endpoint, err
   264  }
   265  
   266  func (s *endpoint) DeleteEndpoint(locationID, endpointID string, target containerv2.ClusterTargetHeader) error {
   267  	rawURL := fmt.Sprintf("v1/locations/%s/endpoints/%s", locationID, endpointID)
   268  	_, err := s.client.Delete(rawURL, target.ToMap())
   269  	return err
   270  }
   271  
   272  func (s *endpoint) AddSourcesToEndpoint(locationID,
   273  	endpointID string, params AddSourcesRequest,
   274  	target containerv2.ClusterTargetHeader) error {
   275  
   276  	var endpoint CreateEndpointResponse
   277  	rawURL := fmt.Sprintf("/v1/locations/%s/endpoints/%s/sources", locationID, endpointID)
   278  	_, err := s.client.Patch(rawURL, params, &endpoint, target.ToMap())
   279  	return err
   280  }