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

     1  package registryv1
     2  
     3  import (
     4  	gohttp "net/http"
     5  
     6  	ibmcloud "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  const (
    18  	accountIDHeader     = "Account"
    19  	resourceGroupHeader = "X-Auth-Resource-Group"
    20  )
    21  
    22  //RegistryServiceAPI is the IBM Cloud Registry client ...
    23  type RegistryServiceAPI interface {
    24  	Builds() Builds
    25  	Namespaces() Namespaces
    26  	Tokens() Tokens
    27  	Images() Images
    28  	/*Auth() Auth
    29  	Messages() Messages
    30  	Plans() Plans
    31  	Quotas() Quotas
    32  	*/
    33  }
    34  
    35  //RegistryService holds the client
    36  type rsService struct {
    37  	*client.Client
    38  }
    39  
    40  func addToRequestHeader(h interface{}, r *rest.Request) {
    41  	switch v := h.(type) {
    42  	case map[string]string:
    43  		for key, value := range v {
    44  			r.Set(key, value)
    45  		}
    46  	}
    47  }
    48  
    49  //New ...
    50  func New(sess *session.Session) (RegistryServiceAPI, error) {
    51  	config := sess.Config.Copy()
    52  	err := config.ValidateConfigForService(ibmcloud.ContainerRegistryService)
    53  	if err != nil {
    54  		return nil, err
    55  	}
    56  	if config.HTTPClient == nil {
    57  		config.HTTPClient = http.NewHTTPClient(config)
    58  	}
    59  	tokenRefreher, err := authentication.NewIAMAuthRepository(config, &rest.Client{
    60  		DefaultHeader: gohttp.Header{
    61  			"X-Original-User-Agent": []string{config.UserAgent},
    62  			"User-Agent":            []string{http.UserAgent()},
    63  		},
    64  		HTTPClient: config.HTTPClient,
    65  	})
    66  	if err != nil {
    67  		return nil, err
    68  	}
    69  	if config.IAMAccessToken == "" {
    70  		err := authentication.PopulateTokens(tokenRefreher, config)
    71  		if err != nil {
    72  			return nil, err
    73  		}
    74  	}
    75  	if config.Endpoint == nil {
    76  		ep, err := config.EndpointLocator.ContainerRegistryEndpoint()
    77  		if err != nil {
    78  			return nil, err
    79  		}
    80  		config.Endpoint = &ep
    81  	}
    82  
    83  	return &rsService{
    84  		Client: client.New(config, ibmcloud.ContainerRegistryService, tokenRefreher),
    85  	}, nil
    86  }
    87  
    88  //Builds implements builds API
    89  func (c *rsService) Builds() Builds {
    90  	return newBuildAPI(c.Client)
    91  }
    92  
    93  //Namespaces implements Namespaces API
    94  func (c *rsService) Namespaces() Namespaces {
    95  	return newNamespaceAPI(c.Client)
    96  }
    97  
    98  //Tokens implements Tokens API
    99  func (c *rsService) Tokens() Tokens {
   100  	return newTokenAPI(c.Client)
   101  }
   102  
   103  //Images implements Images API
   104  func (c *rsService) Images() Images {
   105  	return newImageAPI(c.Client)
   106  }
   107  
   108  /*
   109  //Auth implement auth API
   110  func (c *csService) Auth() Auth {
   111  	return newAuthAPI(c.Client)
   112  }
   113  
   114  
   115  //Messages implements Messages API
   116  func (c *csService) Messages() Messages {
   117  	return newMessageAPI(c.Client)
   118  }
   119  
   120  
   121  
   122  //Plans implements Plans API
   123  func (c *csService) Plans() Plans {
   124  	return newPlanAPI(c.Client)
   125  }
   126  
   127  //Quotas implements Quotas API
   128  func (c *csService) Quotas() Quotas {
   129  	return newQuotaAPI(c.Client)
   130  }
   131  
   132  
   133  */