From 98197f72c0c2ace90ac6d1f2a525e2f5a1ea8615 Mon Sep 17 00:00:00 2001 From: Stanley Shyiko Date: Fri, 10 Aug 2018 12:51:17 -0700 Subject: [PATCH] Improved error message printed in case of missing ADC (#14) --- gcp/kms/client.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gcp/kms/client.go b/gcp/kms/client.go index f6bcac1..7db2956 100644 --- a/gcp/kms/client.go +++ b/gcp/kms/client.go @@ -5,6 +5,8 @@ import ( "golang.org/x/net/context" "golang.org/x/oauth2/google" "google.golang.org/api/cloudkms/v1" + "fmt" + "strings" ) type CloudKMSClient struct { @@ -15,7 +17,10 @@ func New() (*CloudKMSClient, error) { ctx := context.Background() client, err := google.DefaultClient(ctx, cloudkms.CloudPlatformScope) if err != nil { - return nil, err + if strings.Contains(err.Error(), "could not find default credentials") { + return nil, fmt.Errorf("Application Default Credentials (ADC) not found.\n" + + "Either `gcloud auth application-default login` or set GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json (env variable)") + } } svc, err := cloudkms.New(client) if err != nil {