github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/api/container/containerv1/api_service.go (about)

     1  package containerv1
     2  
     3  import (
     4  	gohttp "net/http"
     5  
     6  	bluemix "github.com/IBM-Cloud/bluemix-go"
     7  	"github.com/IBM-Cloud/bluemix-go/authentication"
     8  	"github.com/IBM-Cloud/bluemix-go/client"
     9  	"github.com/IBM-Cloud/bluemix-go/http"
    10  	"github.com/IBM-Cloud/bluemix-go/rest"
    11  	"github.com/IBM-Cloud/bluemix-go/session"
    12  )
    13  
    14  //ErrCodeAPICreation ...
    15  const ErrCodeAPICreation = "APICreationError"
    16  
    17  //ContainerServiceAPI is the Aramda K8s client ...
    18  type ContainerServiceAPI interface {
    19  	Albs() Albs
    20  	Clusters() Clusters
    21  	Workers() Workers
    22  	WorkerPools() WorkerPool
    23  	WebHooks() Webhooks
    24  	Subnets() Subnets
    25  	KubeVersions() KubeVersions
    26  	Vlans() Vlans
    27  	Kms() Kms
    28  	AddOns() AddOns
    29  	Apikeys() Apikeys
    30  }
    31  
    32  //ContainerService holds the client
    33  type csService struct {
    34  	*client.Client
    35  }
    36  
    37  //New ...
    38  func New(sess *session.Session) (ContainerServiceAPI, error) {
    39  	config := sess.Config.Copy()
    40  	err := config.ValidateConfigForService(bluemix.ContainerService)
    41  	if err != nil {
    42  		return nil, err
    43  	}
    44  	if config.HTTPClient == nil {
    45  		config.HTTPClient = http.NewHTTPClient(config)
    46  	}
    47  	tokenRefreher, err := authentication.NewIAMAuthRepository(config, &rest.Client{
    48  		DefaultHeader: gohttp.Header{
    49  			"X-Original-User-Agent": []string{config.UserAgent},
    50  			"User-Agent":            []string{http.UserAgent()},
    51  		},
    52  		HTTPClient: config.HTTPClient,
    53  	})
    54  	if err != nil {
    55  		return nil, err
    56  	}
    57  	if config.IAMAccessToken == "" {
    58  		err := authentication.PopulateTokens(tokenRefreher, config)
    59  		if err != nil {
    60  			return nil, err
    61  		}
    62  	}
    63  	if config.Endpoint == nil {
    64  		ep, err := config.EndpointLocator.ContainerEndpoint()
    65  		if err != nil {
    66  			return nil, err
    67  		}
    68  		config.Endpoint = &ep
    69  	}
    70  
    71  	return &csService{
    72  		Client: client.New(config, bluemix.ContainerService, tokenRefreher),
    73  	}, nil
    74  }
    75  
    76  //Albs implement albs API
    77  func (c *csService) Albs() Albs {
    78  	return newAlbAPI(c.Client)
    79  }
    80  
    81  //Clusters implements Clusters API
    82  func (c *csService) Clusters() Clusters {
    83  	return newClusterAPI(c.Client)
    84  }
    85  
    86  //Workers implements Cluster Workers API
    87  func (c *csService) Workers() Workers {
    88  	return newWorkerAPI(c.Client)
    89  }
    90  
    91  //WorkerPools implements Cluster WorkerPools API
    92  func (c *csService) WorkerPools() WorkerPool {
    93  	return newWorkerPoolAPI(c.Client)
    94  }
    95  
    96  //Subnets implements Cluster Subnets API
    97  func (c *csService) Subnets() Subnets {
    98  	return newSubnetAPI(c.Client)
    99  }
   100  
   101  //Webhooks implements Cluster WebHooks API
   102  func (c *csService) WebHooks() Webhooks {
   103  	return newWebhookAPI(c.Client)
   104  }
   105  
   106  //KubeVersions implements Cluster WebHooks API
   107  func (c *csService) KubeVersions() KubeVersions {
   108  	return newKubeVersionAPI(c.Client)
   109  }
   110  
   111  //Vlans implements DC Cluster Vlan API
   112  func (c *csService) Vlans() Vlans {
   113  	return newVlanAPI(c.Client)
   114  }
   115  
   116  //Kms implements Cluster Kms API
   117  func (c *csService) Kms() Kms {
   118  	return newKmsAPI(c.Client)
   119  }
   120  
   121  //AddOns implements Cluster Add Ons
   122  func (c *csService) AddOns() AddOns {
   123  	return newAddOnsAPI(c.Client)
   124  }
   125  
   126  //AddOns implements Cluster Add Ons
   127  func (c *csService) Apikeys() Apikeys {
   128  	return newApiKeyAPI(c.Client)
   129  }