@@ -37,3 +37,47 @@ func LoadGCPCredentials() string {
3737 }
3838 return credentialsData
3939}
40+
41+ // Better way than copying?
42+ // https://github.com/hashicorp/terraform-provider-google/blob/8a362008bd4d36b6a882eb53455f87305e6dff52/google/service_scope.go#L5-L48
43+ func canonicalizeServiceScope (scope string ) string {
44+ // This is a convenience map of short names used by the gcloud tool
45+ // to the GCE auth endpoints they alias to.
46+ scopeMap := map [string ]string {
47+ "bigquery" : "https://www.googleapis.com/auth/bigquery" ,
48+ "cloud-platform" : "https://www.googleapis.com/auth/cloud-platform" ,
49+ "cloud-source-repos" : "https://www.googleapis.com/auth/source.full_control" ,
50+ "cloud-source-repos-ro" : "https://www.googleapis.com/auth/source.read_only" ,
51+ "compute-ro" : "https://www.googleapis.com/auth/compute.readonly" ,
52+ "compute-rw" : "https://www.googleapis.com/auth/compute" ,
53+ "datastore" : "https://www.googleapis.com/auth/datastore" ,
54+ "logging-write" : "https://www.googleapis.com/auth/logging.write" ,
55+ "monitoring" : "https://www.googleapis.com/auth/monitoring" ,
56+ "monitoring-read" : "https://www.googleapis.com/auth/monitoring.read" ,
57+ "monitoring-write" : "https://www.googleapis.com/auth/monitoring.write" ,
58+ "pubsub" : "https://www.googleapis.com/auth/pubsub" ,
59+ "service-control" : "https://www.googleapis.com/auth/servicecontrol" ,
60+ "service-management" : "https://www.googleapis.com/auth/service.management.readonly" ,
61+ "sql" : "https://www.googleapis.com/auth/sqlservice" ,
62+ "sql-admin" : "https://www.googleapis.com/auth/sqlservice.admin" ,
63+ "storage-full" : "https://www.googleapis.com/auth/devstorage.full_control" ,
64+ "storage-ro" : "https://www.googleapis.com/auth/devstorage.read_only" ,
65+ "storage-rw" : "https://www.googleapis.com/auth/devstorage.read_write" ,
66+ "taskqueue" : "https://www.googleapis.com/auth/taskqueue" ,
67+ "trace" : "https://www.googleapis.com/auth/trace.append" ,
68+ "useraccounts-ro" : "https://www.googleapis.com/auth/cloud.useraccounts.readonly" ,
69+ "useraccounts-rw" : "https://www.googleapis.com/auth/cloud.useraccounts" ,
70+ "userinfo-email" : "https://www.googleapis.com/auth/userinfo.email" ,
71+ }
72+ if matchedURL , ok := scopeMap [scope ]; ok {
73+ return matchedURL
74+ }
75+ return scope
76+ }
77+ func CanonicalizeServiceScopes (scopes []string ) []string {
78+ cs := make ([]string , len (scopes ))
79+ for i , scope := range scopes {
80+ cs [i ] = canonicalizeServiceScope (scope )
81+ }
82+ return cs
83+ }
0 commit comments