github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/config.go (about) 1 package bluemix 2 3 import ( 4 "net/http" 5 "time" 6 7 "github.com/IBM-Cloud/bluemix-go/bmxerror" 8 "github.com/IBM-Cloud/bluemix-go/endpoints" 9 ) 10 11 // ServiceName .. 12 type ServiceName string 13 14 const ( 15 //AccountService ... 16 AccountService ServiceName = ServiceName("account") 17 //AccountServicev1 ... 18 AccountServicev1 ServiceName = ServiceName("accountv1") 19 //CertificateManager ... 20 CertificateManager ServiceName = ServiceName("certificate-manager") 21 //CisService ... 22 CisService ServiceName = ServiceName("cis") 23 //ContainerService ... 24 ContainerService ServiceName = ServiceName("container") 25 //ContainerService ... 26 VpcContainerService ServiceName = ServiceName("containerv2") 27 //RegistryService ... 28 ContainerRegistryService ServiceName = ServiceName("container-registry") 29 //GlobalSearchService ... 30 GlobalSearchService ServiceName = ServiceName("global-search") 31 //GlobalTaggingService ... 32 GlobalTaggingService ServiceName = ServiceName("global-tagging") 33 //IAMService ... 34 IAMService ServiceName = ServiceName("iam") 35 //IAMPAPService 36 IAMPAPService ServiceName = ServiceName("iampap") 37 //IAMUUMService ... 38 IAMUUMService ServiceName = ServiceName("iamuum") 39 //IAMUUMServicev2 ... 40 IAMUUMServicev2 ServiceName = ServiceName("iamuumv2") 41 //IAMPAPServicev2 ... 42 IAMPAPServicev2 ServiceName = ServiceName("iampapv2") 43 //ICDService ... 44 ICDService ServiceName = ServiceName("icd") 45 //MccpService ... 46 MccpService ServiceName = ServiceName("mccp") 47 //resourceManagementService 48 ResourceManagementService ServiceName = ServiceName("resource-management") 49 //resourceManagementService 50 ResourceManagementServicev2 ServiceName = ServiceName("resource-managementv2") 51 //resourceControllerService 52 ResourceControllerService ServiceName = ServiceName("resource-controller") 53 //resourceControllerServicev2 54 ResourceControllerServicev2 ServiceName = ServiceName("resource-controllerv2") 55 //resourceCatalogService 56 ResourceCatalogrService ServiceName = ServiceName("resource-catalog ") 57 //UAAService ... 58 UAAService ServiceName = ServiceName("uaa") 59 //CSEService 60 CseService ServiceName = ServiceName("cse") 61 //SchematicsService ... 62 SchematicsService ServiceName = ServiceName("schematics") 63 //UserManagement ... 64 UserManagement ServiceName = ServiceName("user-management") 65 //HPCService ... 66 HPCService ServiceName = ServiceName("hpcs") 67 //FunctionsService ... 68 FunctionsService ServiceName = ServiceName("functions") 69 ) 70 71 // Config ... 72 type Config struct { 73 IBMID string 74 75 IBMIDPassword string 76 77 BluemixAPIKey string 78 79 IAMAccessToken string 80 IAMRefreshToken string 81 UAAAccessToken string 82 UAARefreshToken string 83 84 //Region is optional. If region is not provided then endpoint must be provided 85 Region string 86 //ResourceGroupID 87 ResourceGroup string 88 //Endpoint is optional. If endpoint is not provided then endpoint must be obtained from region via EndpointLocator 89 Endpoint *string 90 //TokenProviderEndpoint is optional. If endpoint is not provided then endpoint must be obtained from region via EndpointLocator 91 TokenProviderEndpoint *string 92 EndpointLocator endpoints.EndpointLocator 93 MaxRetries *int 94 RetryDelay *time.Duration 95 96 HTTPTimeout time.Duration 97 98 Debug bool 99 100 HTTPClient *http.Client 101 102 SSLDisable bool 103 Visibility string 104 EndpointsFile string 105 UserAgent string 106 } 107 108 // Copy allows the configuration to be overriden or added 109 // Typically the endpoints etc 110 func (c *Config) Copy(mccpgs ...*Config) *Config { 111 out := new(Config) 112 *out = *c 113 if len(mccpgs) == 0 { 114 return out 115 } 116 for _, mergeInput := range mccpgs { 117 if mergeInput.Endpoint != nil { 118 out.Endpoint = mergeInput.Endpoint 119 } 120 } 121 return out 122 } 123 124 // ValidateConfigForService ... 125 func (c *Config) ValidateConfigForService(svc ServiceName) error { 126 if (c.IBMID == "" || c.IBMIDPassword == "") && c.BluemixAPIKey == "" && (c.IAMAccessToken == "" || c.IAMRefreshToken == "") { 127 return bmxerror.New(ErrInsufficientCredentials, "Please check the documentation on how to configure the IBM Cloud credentials") 128 } 129 130 if c.Region == "" && (c.Endpoint == nil || *c.Endpoint == "") { 131 return bmxerror.New(ErrInvalidConfigurationCode, "Please provide region or endpoint") 132 } 133 return nil 134 }