From 9da88d1fc07104d34d8dae5b7c9bacf4cce61a64 Mon Sep 17 00:00:00 2001 From: Ashish K Thakur Date: Sat, 13 May 2017 01:42:00 +0530 Subject: [PATCH] Fixes #92 --- builtin/providers/ibmcloud/config.go | 64 +++++++++++-------- .../bluemix-go/authentication/auth.go | 6 +- .../bluemix-go/endpoints/endpoints.go | 16 +++-- vendor/vendor.json | 56 ++++++++-------- .../providers/ibmcloud/index.html.markdown | 5 +- 5 files changed, 84 insertions(+), 63 deletions(-) diff --git a/builtin/providers/ibmcloud/config.go b/builtin/providers/ibmcloud/config.go index 8a908bd07ac4..9bf3bcc0527e 100644 --- a/builtin/providers/ibmcloud/config.go +++ b/builtin/providers/ibmcloud/config.go @@ -2,6 +2,7 @@ package ibmcloud import ( "errors" + "fmt" "log" "os" "time" @@ -13,6 +14,8 @@ import ( "github.com/IBM-Bluemix/bluemix-go/api/account/accountv2" "github.com/IBM-Bluemix/bluemix-go/api/cf/cfv2" "github.com/IBM-Bluemix/bluemix-go/api/k8scluster/k8sclusterv1" + "github.com/IBM-Bluemix/bluemix-go/bmxerror" + "github.com/IBM-Bluemix/bluemix-go/endpoints" bxsession "github.com/IBM-Bluemix/bluemix-go/session" ) @@ -172,11 +175,12 @@ func (c *Config) ClientSession() (interface{}, error) { return nil, err } + session := clientSession{ + session: sess, + } + if sess.BluemixSession == nil { log.Println("Skipping Bluemix Clients configuration") - session := clientSession{ - session: sess, - } return session, nil } @@ -199,33 +203,41 @@ func (c *Config) ClientSession() (interface{}, error) { } accountAPI := accClient.Accounts() - clusterClient, err := k8sclusterv1.New(sess.BluemixSession) - if err != nil { - return nil, err - } - clustersAPI := clusterClient.Clusters() - clusterWorkerAPI := clusterClient.Workers() - clusterSubnetsAPI := clusterClient.Subnets() - clusterWebhookAPI := clusterClient.WebHooks() - - session := clientSession{ - session: sess, - - csClient: clustersAPI, - csSubnet: clusterSubnetsAPI, - csWorker: clusterWorkerAPI, - csWebHook: clusterWebhookAPI, + skipClusterConfig := c.SkipServiceConfig.Contains("cluster") - cfOrgClient: orgAPI, - cfServiceInstanceClient: serviceInstanceAPI, - cfServiceKeysClient: serviceKeysAPI, - cfServicePlanClient: servicePlanAPI, - cfServiceOfferingsClient: serviceOfferringAPI, - cfSpaceClient: spaceAPI, + if !skipClusterConfig { + clusterClient, err := k8sclusterv1.New(sess.BluemixSession) + if err != nil { + if apiErr, ok := err.(bmxerror.Error); ok { + if apiErr.Code() == endpoints.ErrCodeServiceEndpoint { + return nil, fmt.Errorf(`Cluster service doesn't exist in the region %q.\nTo remediate the problem please skip the cluster service configuration by specifying "cluster" in skip_service_configuration in the provider block`, c.Region) - bluemixAccountClient: accountAPI, + } + } + return nil, err + } + clustersAPI := clusterClient.Clusters() + clusterWorkerAPI := clusterClient.Workers() + clusterSubnetsAPI := clusterClient.Subnets() + clusterWebhookAPI := clusterClient.WebHooks() + + session.csClient = clustersAPI + session.csSubnet = clusterSubnetsAPI + session.csWorker = clusterWorkerAPI + session.csWebHook = clusterWebhookAPI + + } else { + log.Println("Skipping cluster configuration") } + session.cfOrgClient = orgAPI + session.cfServiceInstanceClient = serviceInstanceAPI + session.cfServiceKeysClient = serviceKeysAPI + session.cfServicePlanClient = servicePlanAPI + session.cfServiceOfferingsClient = serviceOfferringAPI + session.cfSpaceClient = spaceAPI + session.bluemixAccountClient = accountAPI + return session, nil } diff --git a/vendor/github.com/IBM-Bluemix/bluemix-go/authentication/auth.go b/vendor/github.com/IBM-Bluemix/bluemix-go/authentication/auth.go index 185f462e66e8..5e5d2326db55 100644 --- a/vendor/github.com/IBM-Bluemix/bluemix-go/authentication/auth.go +++ b/vendor/github.com/IBM-Bluemix/bluemix-go/authentication/auth.go @@ -1,6 +1,8 @@ package authentication import ( + "errors" + bluemix "github.com/IBM-Bluemix/bluemix-go" "github.com/IBM-Bluemix/bluemix-go/client" ) @@ -12,7 +14,7 @@ const ( //PopulateTokens populate the relevant tokens in the bluemix Config using the token provider func PopulateTokens(tokenProvider client.TokenProvider, c *bluemix.Config) error { - if c.IBMIDPassword != "" { + if c.IBMID != "" && c.IBMIDPassword != "" { err := tokenProvider.AuthenticatePassword(c.IBMID, c.IBMIDPassword) return err } @@ -20,5 +22,5 @@ func PopulateTokens(tokenProvider client.TokenProvider, c *bluemix.Config) error err := tokenProvider.AuthenticateAPIKey(c.BluemixAPIKey) return err } - return nil + return errors.New("Insufficient credentials, need IBMID/IBMIDPassword or Bluemix API Key") } diff --git a/vendor/github.com/IBM-Bluemix/bluemix-go/endpoints/endpoints.go b/vendor/github.com/IBM-Bluemix/bluemix-go/endpoints/endpoints.go index c93cf86d9318..84fc9bfec35b 100644 --- a/vendor/github.com/IBM-Bluemix/bluemix-go/endpoints/endpoints.go +++ b/vendor/github.com/IBM-Bluemix/bluemix-go/endpoints/endpoints.go @@ -3,6 +3,7 @@ package endpoints import ( "fmt" + "github.com/IBM-Bluemix/bluemix-go/bmxerror" "github.com/IBM-Bluemix/bluemix-go/helpers" ) @@ -15,6 +16,11 @@ type EndpointLocator interface { UAAEndpoint() (string, error) } +const ( + //ErrCodeServiceEndpoint ... + ErrCodeServiceEndpoint = "ServiceEndpointDoesnotExist" +) + var regionToEndpoint = map[string]map[string]string{ "cf": { "us-south": "https://api.ng.bluemix.net", @@ -62,7 +68,7 @@ func (e *endpointLocator) CFAPIEndpoint() (string, error) { return helpers.EnvFallBack([]string{"IBMCLOUD_CF_API_ENDPOINT"}, ep), nil } - return "", fmt.Errorf("Cloud Foundry endpoint doesn't exist for region: %q", e.region) + return "", bmxerror.New(ErrCodeServiceEndpoint, fmt.Sprintf("Cloud Foundry endpoint doesn't exist for region: %q", e.region)) } func (e *endpointLocator) UAAEndpoint() (string, error) { @@ -71,7 +77,7 @@ func (e *endpointLocator) UAAEndpoint() (string, error) { return helpers.EnvFallBack([]string{"IBMCLOUD_UAA_ENDPOINT"}, ep), nil } - return "", fmt.Errorf("UAA endpoint doesn't exist for region: %q", e.region) + return "", bmxerror.New(ErrCodeServiceEndpoint, fmt.Sprintf("UAA endpoint doesn't exist for region: %q", e.region)) } func (e *endpointLocator) AccountManagementEndpoint() (string, error) { @@ -80,7 +86,7 @@ func (e *endpointLocator) AccountManagementEndpoint() (string, error) { return helpers.EnvFallBack([]string{"IBMCLOUD_ACCOUNT_MANAGEMENT_API_ENDPOINT"}, ep), nil } - return "", fmt.Errorf("Account Management endpoint doesn't exist for region: %q", e.region) + return "", bmxerror.New(ErrCodeServiceEndpoint, fmt.Sprintf("Account Management endpoint doesn't exist for region: %q", e.region)) } func (e *endpointLocator) IAMEndpoint() (string, error) { @@ -89,7 +95,7 @@ func (e *endpointLocator) IAMEndpoint() (string, error) { return helpers.EnvFallBack([]string{"IBMCLOUD_IAM_API_ENDPOINT"}, ep), nil } - return "", fmt.Errorf("IAM endpoint doesn't exist for region: %q", e.region) + return "", bmxerror.New(ErrCodeServiceEndpoint, fmt.Sprintf("IAM endpoint doesn't exist for region: %q", e.region)) } func (e *endpointLocator) ClusterEndpoint() (string, error) { @@ -97,5 +103,5 @@ func (e *endpointLocator) ClusterEndpoint() (string, error) { //As the current list of regionToEndpoint above is not exhaustive we allow to read endpoints from the env return helpers.EnvFallBack([]string{"IBMCLOUD_CS_API_ENDPOINT"}, ep), nil } - return "", fmt.Errorf("Container Service endpoint doesn't exist for region: %q", e.region) + return "", bmxerror.New(ErrCodeServiceEndpoint, fmt.Sprintf("Container Service endpoint doesn't exist for region: %q", e.region)) } diff --git a/vendor/vendor.json b/vendor/vendor.json index 220d9a053a27..b15dfcb92908 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -389,80 +389,80 @@ { "checksumSHA1": "uXoiqDVU3TZxsSfbeVKP60Gmtzo=", "path": "github.com/IBM-Bluemix/bluemix-go", - "revision": "362904bd1c6d939837d106772ffe378e4c36285a", - "revisionTime": "2017-05-10T12:44:42Z" + "revision": "424f9c5b3a7a5d8b209fe337493e1d0717bf3b46", + "revisionTime": "2017-05-12T19:21:55Z" }, { "checksumSHA1": "i79PeKQLMC6r4u4H7KDTNzMMbSo=", "path": "github.com/IBM-Bluemix/bluemix-go/api/account/accountv2", - "revision": "362904bd1c6d939837d106772ffe378e4c36285a", - "revisionTime": "2017-05-10T12:44:42Z" + "revision": "424f9c5b3a7a5d8b209fe337493e1d0717bf3b46", + "revisionTime": "2017-05-12T19:21:55Z" }, { "checksumSHA1": "qAdyQ7iezAj/cMtoOm1NLYiTMF8=", "path": "github.com/IBM-Bluemix/bluemix-go/api/cf/cfv2", - "revision": "362904bd1c6d939837d106772ffe378e4c36285a", - "revisionTime": "2017-05-10T12:44:42Z" + "revision": "424f9c5b3a7a5d8b209fe337493e1d0717bf3b46", + "revisionTime": "2017-05-12T19:21:55Z" }, { "checksumSHA1": "p42EedBTf9mwostBJjXX5QjJoHA=", "path": "github.com/IBM-Bluemix/bluemix-go/api/k8scluster/k8sclusterv1", - "revision": "362904bd1c6d939837d106772ffe378e4c36285a", - "revisionTime": "2017-05-10T12:44:42Z" + "revision": "424f9c5b3a7a5d8b209fe337493e1d0717bf3b46", + "revisionTime": "2017-05-12T19:21:55Z" }, { - "checksumSHA1": "nGL+HGbR0VSA5GWURG0FHmnZKU4=", + "checksumSHA1": "2dS1wigwpyW5ixKmyOPrUeLWW1c=", "path": "github.com/IBM-Bluemix/bluemix-go/authentication", - "revision": "362904bd1c6d939837d106772ffe378e4c36285a", - "revisionTime": "2017-05-10T12:44:42Z" + "revision": "424f9c5b3a7a5d8b209fe337493e1d0717bf3b46", + "revisionTime": "2017-05-12T19:21:55Z" }, { "checksumSHA1": "YBML7SGPWwMvtuJFqSyTjtxvPYs=", "path": "github.com/IBM-Bluemix/bluemix-go/bmxerror", - "revision": "362904bd1c6d939837d106772ffe378e4c36285a", - "revisionTime": "2017-05-10T12:44:42Z" + "revision": "424f9c5b3a7a5d8b209fe337493e1d0717bf3b46", + "revisionTime": "2017-05-12T19:21:55Z" }, { "checksumSHA1": "CnOI3bB+qKzMlr8p0XuxPalIKko=", "path": "github.com/IBM-Bluemix/bluemix-go/client", - "revision": "362904bd1c6d939837d106772ffe378e4c36285a", - "revisionTime": "2017-05-10T12:44:42Z" + "revision": "424f9c5b3a7a5d8b209fe337493e1d0717bf3b46", + "revisionTime": "2017-05-12T19:21:55Z" }, { - "checksumSHA1": "3MRpIixjbF/sPGwa0z6VOGU1JsA=", + "checksumSHA1": "BqwaZM5Nf6lTTlcpkfucuT2ZYhk=", "path": "github.com/IBM-Bluemix/bluemix-go/endpoints", - "revision": "362904bd1c6d939837d106772ffe378e4c36285a", - "revisionTime": "2017-05-10T12:44:42Z" + "revision": "424f9c5b3a7a5d8b209fe337493e1d0717bf3b46", + "revisionTime": "2017-05-12T19:21:55Z" }, { "checksumSHA1": "WSGgwampernftuHCz6XiOfFpcoM=", "path": "github.com/IBM-Bluemix/bluemix-go/helpers", - "revision": "362904bd1c6d939837d106772ffe378e4c36285a", - "revisionTime": "2017-05-10T12:44:42Z" + "revision": "424f9c5b3a7a5d8b209fe337493e1d0717bf3b46", + "revisionTime": "2017-05-12T19:21:55Z" }, { "checksumSHA1": "GwQQNVaNODYWHyAUFw/PAvr+ePY=", "path": "github.com/IBM-Bluemix/bluemix-go/http", - "revision": "362904bd1c6d939837d106772ffe378e4c36285a", - "revisionTime": "2017-05-10T12:44:42Z" + "revision": "424f9c5b3a7a5d8b209fe337493e1d0717bf3b46", + "revisionTime": "2017-05-12T19:21:55Z" }, { "checksumSHA1": "+YWMAtV5wQvcHDWzPmsZ1hRA1ic=", "path": "github.com/IBM-Bluemix/bluemix-go/rest", - "revision": "362904bd1c6d939837d106772ffe378e4c36285a", - "revisionTime": "2017-05-10T12:44:42Z" + "revision": "424f9c5b3a7a5d8b209fe337493e1d0717bf3b46", + "revisionTime": "2017-05-12T19:21:55Z" }, { "checksumSHA1": "n5SnBu2teZIcsVylQbtHrqBExZY=", "path": "github.com/IBM-Bluemix/bluemix-go/session", - "revision": "362904bd1c6d939837d106772ffe378e4c36285a", - "revisionTime": "2017-05-10T12:44:42Z" + "revision": "424f9c5b3a7a5d8b209fe337493e1d0717bf3b46", + "revisionTime": "2017-05-12T19:21:55Z" }, { "checksumSHA1": "WKFwS8jLgaJThltcgWFKjwyMlCI=", "path": "github.com/IBM-Bluemix/bluemix-go/trace", - "revision": "362904bd1c6d939837d106772ffe378e4c36285a", - "revisionTime": "2017-05-10T12:44:42Z" + "revision": "424f9c5b3a7a5d8b209fe337493e1d0717bf3b46", + "revisionTime": "2017-05-12T19:21:55Z" }, { "checksumSHA1": "B+GonfgNwOAJMEe0WUHQGATRtMA=", diff --git a/website/source/docs/providers/ibmcloud/index.html.markdown b/website/source/docs/providers/ibmcloud/index.html.markdown index 34abce20d8a3..bb1010f57f4a 100644 --- a/website/source/docs/providers/ibmcloud/index.html.markdown +++ b/website/source/docs/providers/ibmcloud/index.html.markdown @@ -107,9 +107,11 @@ See `skip_service_configuration` in the Argument Reference below. The below configuration will direct the provider to not configure the softlayer client and hence not complain if softlayer_username and softlayer_api_key are missing in the provider. +``` provider "ibmcloud" { skip_service_configuration = ["softlayer"] } +``` ## Argument Reference @@ -128,5 +130,4 @@ The following arguments are supported in the `provider` block: * `region` - (Optional) The Bluemix region. It can also be sourced from the `BM_REGION` or `BLUEMIX_REGION` environment variable. The former variable has higher precedence. Default value: `us-south`. -* `skip_service_configuration` - (Optional, Set) The options allows one to skip configuring the provider for IBM Cloud services which the user may not create. Supported values are - `bluemix` and `softlayer`. This is useful when a user has credentials for only a particular service for example SoftLayer. In that case provider will not complain about the absence of `bluemix_api_key`. - +* `skip_service_configuration` - (Optional, Set) The options allows one to skip configuring the provider for IBM Cloud services which the user may not create. Supported values are - `bluemix`, `softlayer` and `cluster`. This is useful when a user has credentials for only a particular service for example SoftLayer. In that case provider will not complain about the absence of `bluemix_api_key`.