Skip to content

Commit

Permalink
Improved error message printed in case of missing ADC (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
shyiko committed Aug 10, 2018
1 parent 3ccf0b9 commit 98197f7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion gcp/kms/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 98197f7

Please sign in to comment.