github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/api/globaltagging/globaltaggingv3/api_service.go (about) 1 package globaltaggingv3 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 //ICDServiceAPI is the Cloud Internet Services API ... 18 type GlobalTaggingServiceAPI interface { 19 Tags() Tags 20 } 21 22 //ICDService holds the client 23 type globalTaggingService struct { 24 *client.Client 25 } 26 27 //New ... 28 func New(sess *session.Session) (GlobalTaggingServiceAPI, error) { 29 config := sess.Config.Copy() 30 err := config.ValidateConfigForService(bluemix.GlobalTaggingService) 31 if err != nil { 32 return nil, err 33 } 34 if config.HTTPClient == nil { 35 config.HTTPClient = http.NewHTTPClient(config) 36 } 37 tokenRefreher, err := authentication.NewIAMAuthRepository(config, &rest.Client{ 38 DefaultHeader: gohttp.Header{ 39 "X-Original-User-Agent": []string{config.UserAgent}, 40 "User-Agent": []string{http.UserAgent()}, 41 }, 42 HTTPClient: config.HTTPClient, 43 }) 44 if err != nil { 45 return nil, err 46 } 47 if config.IAMAccessToken == "" { 48 err := authentication.PopulateTokens(tokenRefreher, config) 49 if err != nil { 50 return nil, err 51 } 52 } 53 if config.Endpoint == nil { 54 ep, err := config.EndpointLocator.GlobalTaggingEndpoint() 55 if err != nil { 56 return nil, err 57 } 58 config.Endpoint = &ep 59 } 60 61 return &globalTaggingService{ 62 Client: client.New(config, bluemix.GlobalTaggingService, tokenRefreher), 63 }, nil 64 } 65 66 //Tagging implements the global tagging API 67 func (c *globalTaggingService) Tags() Tags { 68 return newTaggingAPI(c.Client) 69 }