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

     1  package mccpv2
     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  //MccpServiceAPI is the mccpv2 client ...
    18  type MccpServiceAPI interface {
    19  	Organizations() Organizations
    20  	Spaces() Spaces
    21  	ServiceInstances() ServiceInstances
    22  	ServiceKeys() ServiceKeys
    23  	ServicePlans() ServicePlans
    24  	ServiceOfferings() ServiceOfferings
    25  	SpaceQuotas() SpaceQuotas
    26  	OrgQuotas() OrgQuotas
    27  	Apps() Apps
    28  	Routes() Routes
    29  	SharedDomains() SharedDomains
    30  	PrivateDomains() PrivateDomains
    31  	ServiceBindings() ServiceBindings
    32  	Regions() RegionRepository
    33  }
    34  
    35  //MccpService holds the client
    36  type mccpService struct {
    37  	*client.Client
    38  }
    39  
    40  //New ...
    41  func New(sess *session.Session) (MccpServiceAPI, error) {
    42  	config := sess.Config.Copy()
    43  	err := config.ValidateConfigForService(bluemix.MccpService)
    44  	if err != nil {
    45  		return nil, err
    46  	}
    47  	if config.HTTPClient == nil {
    48  		config.HTTPClient = http.NewHTTPClient(config)
    49  	}
    50  	tokenRefreher, err := authentication.NewUAARepository(config, &rest.Client{
    51  		DefaultHeader: gohttp.Header{
    52  			"X-Original-User-Agent": []string{config.UserAgent},
    53  			"User-Agent":            []string{http.UserAgent()},
    54  		},
    55  		HTTPClient: config.HTTPClient,
    56  	})
    57  	if err != nil {
    58  		return nil, err
    59  	}
    60  	if config.UAAAccessToken == "" || config.UAARefreshToken == "" {
    61  		err := authentication.PopulateTokens(tokenRefreher, config)
    62  		if err != nil {
    63  			return nil, err
    64  		}
    65  	}
    66  	if config.Endpoint == nil {
    67  		ep, err := config.EndpointLocator.MCCPAPIEndpoint()
    68  		if err != nil {
    69  			return nil, err
    70  		}
    71  		config.Endpoint = &ep
    72  	}
    73  
    74  	return &mccpService{
    75  		Client: client.New(config, bluemix.MccpService, tokenRefreher),
    76  	}, nil
    77  }
    78  
    79  //Organizations implements Organizations APIs
    80  func (c *mccpService) Organizations() Organizations {
    81  	return newOrganizationAPI(c.Client)
    82  }
    83  
    84  //Spaces implements Spaces APIs
    85  func (c *mccpService) Spaces() Spaces {
    86  	return newSpacesAPI(c.Client)
    87  }
    88  
    89  //ServicePlans implements ServicePlans APIs
    90  func (c *mccpService) ServicePlans() ServicePlans {
    91  	return newServicePlanAPI(c.Client)
    92  }
    93  
    94  //ServiceOfferings implements ServiceOfferings APIs
    95  func (c *mccpService) ServiceOfferings() ServiceOfferings {
    96  	return newServiceOfferingAPI(c.Client)
    97  }
    98  
    99  //ServiceInstances implements ServiceInstances APIs
   100  func (c *mccpService) ServiceInstances() ServiceInstances {
   101  	return newServiceInstanceAPI(c.Client)
   102  }
   103  
   104  //ServiceKeys implements ServiceKey APIs
   105  func (c *mccpService) ServiceKeys() ServiceKeys {
   106  	return newServiceKeyAPI(c.Client)
   107  }
   108  
   109  //SpaceQuotas implements SpaceQuota APIs
   110  func (c *mccpService) SpaceQuotas() SpaceQuotas {
   111  	return newSpaceQuotasAPI(c.Client)
   112  }
   113  
   114  //OrgQuotas implements OrgQuota APIs
   115  func (c *mccpService) OrgQuotas() OrgQuotas {
   116  	return newOrgQuotasAPI(c.Client)
   117  }
   118  
   119  //ServiceBindings implements ServiceBindings APIs
   120  func (c *mccpService) ServiceBindings() ServiceBindings {
   121  	return newServiceBindingAPI(c.Client)
   122  }
   123  
   124  //Apps implements Apps APIs
   125  
   126  func (c *mccpService) Apps() Apps {
   127  	return newAppAPI(c.Client)
   128  }
   129  
   130  //Routes implements Route APIs
   131  
   132  func (c *mccpService) Routes() Routes {
   133  	return newRouteAPI(c.Client)
   134  }
   135  
   136  //SharedDomains implements SharedDomian APIs
   137  
   138  func (c *mccpService) SharedDomains() SharedDomains {
   139  	return newSharedDomainAPI(c.Client)
   140  }
   141  
   142  //PrivateDomains implements PrivateDomains APIs
   143  
   144  func (c *mccpService) PrivateDomains() PrivateDomains {
   145  	return newPrivateDomainAPI(c.Client)
   146  }
   147  
   148  //Regions implements Regions APIs
   149  
   150  func (c *mccpService) Regions() RegionRepository {
   151  	return newRegionRepositoryAPI(c.Client)
   152  }