@@ -53,12 +53,13 @@ export const EXPIRATION_TIME_OFFSET = 5 * 60 * 1000;
53
53
* 3. external_Account => non-GCP service (eg. AWS, Azure, K8s)
54
54
*/
55
55
export const EXTERNAL_ACCOUNT_TYPE = 'external_account' ;
56
- /** Cloud resource manager URL used to retrieve project information. */
56
+ /**
57
+ * Cloud resource manager URL used to retrieve project information.
58
+ *
59
+ * @deprecated use {@link BaseExternalAccountClient.cloudResourceManagerURL} instead
60
+ **/
57
61
export const CLOUD_RESOURCE_MANAGER =
58
62
'https://cloudresourcemanager.googleapis.com/v1/projects/' ;
59
- /** The workforce audience pattern. */
60
- const WORKFORCE_AUDIENCE_PATTERN =
61
- '//iam\\.googleapis\\.com/locations/[^/]+/workforcePools/[^/]+/providers/.+' ;
62
63
63
64
// eslint-disable-next-line @typescript-eslint/no-var-requires
64
65
const pkg = require ( '../../../package.json' ) ;
@@ -88,6 +89,12 @@ export interface BaseExternalAccountClientOptions
88
89
client_id ?: string ;
89
90
client_secret ?: string ;
90
91
workforce_pool_user_project ?: string ;
92
+ scopes ?: string [ ] ;
93
+ /**
94
+ * @example
95
+ * https://cloudresourcemanager.googleapis.com/v1/projects/
96
+ **/
97
+ cloud_resource_manager_url ?: string | URL ;
91
98
}
92
99
93
100
/**
@@ -150,6 +157,13 @@ export abstract class BaseExternalAccountClient extends AuthClient {
150
157
public projectNumber : string | null ;
151
158
private readonly configLifetimeRequested : boolean ;
152
159
protected credentialSourceType ?: string ;
160
+ /**
161
+ * @example
162
+ * ```ts
163
+ * new URL('https://cloudresourcemanager.googleapis.com/v1/projects/');
164
+ * ```
165
+ */
166
+ protected cloudResourceManagerURL : URL | string ;
153
167
/**
154
168
* Instantiate a BaseExternalAccountClient instance using the provided JSON
155
169
* object loaded from an external account credentials file.
@@ -195,6 +209,11 @@ export abstract class BaseExternalAccountClient extends AuthClient {
195
209
serviceAccountImpersonation
196
210
) . get ( 'token_lifetime_seconds' ) ;
197
211
212
+ this . cloudResourceManagerURL = new URL (
213
+ opts . get ( 'cloud_resource_manager_url' ) ||
214
+ `https://cloudresourcemanager.${ this . universeDomain } /v1/projects/`
215
+ ) ;
216
+
198
217
if ( clientId ) {
199
218
this . clientAuth = {
200
219
confidentialClientType : 'basic' ,
@@ -204,22 +223,11 @@ export abstract class BaseExternalAccountClient extends AuthClient {
204
223
}
205
224
206
225
this . stsCredential = new sts . StsCredentials ( tokenUrl , this . clientAuth ) ;
207
- // Default OAuth scope. This could be overridden via public property.
208
- this . scopes = [ DEFAULT_OAUTH_SCOPE ] ;
226
+ this . scopes = opts . get ( 'scopes' ) || [ DEFAULT_OAUTH_SCOPE ] ;
209
227
this . cachedAccessToken = null ;
210
228
this . audience = opts . get ( 'audience' ) ;
211
229
this . subjectTokenType = subjectTokenType ;
212
230
this . workforcePoolUserProject = workforcePoolUserProject ;
213
- const workforceAudiencePattern = new RegExp ( WORKFORCE_AUDIENCE_PATTERN ) ;
214
- if (
215
- this . workforcePoolUserProject &&
216
- ! this . audience . match ( workforceAudiencePattern )
217
- ) {
218
- throw new Error (
219
- 'workforcePoolUserProject should not be set for non-workforce pool ' +
220
- 'credentials.'
221
- ) ;
222
- }
223
231
this . serviceAccountImpersonationUrl = serviceAccountImpersonationUrl ;
224
232
this . serviceAccountImpersonationLifetime =
225
233
serviceAccountImpersonationLifetime ;
@@ -360,7 +368,7 @@ export abstract class BaseExternalAccountClient extends AuthClient {
360
368
const headers = await this . getRequestHeaders ( ) ;
361
369
const response = await this . transporter . request < ProjectInfo > ( {
362
370
headers,
363
- url : `${ CLOUD_RESOURCE_MANAGER } ${ projectNumber } ` ,
371
+ url : `${ this . cloudResourceManagerURL . toString ( ) } ${ projectNumber } ` ,
364
372
responseType : 'json' ,
365
373
} ) ;
366
374
this . projectId = response . data . projectId ;
@@ -576,11 +584,9 @@ export abstract class BaseExternalAccountClient extends AuthClient {
576
584
// be normalized.
577
585
if ( typeof this . scopes === 'string' ) {
578
586
return [ this . scopes ] ;
579
- } else if ( typeof this . scopes === 'undefined' ) {
580
- return [ DEFAULT_OAUTH_SCOPE ] ;
581
- } else {
582
- return this . scopes ;
583
587
}
588
+
589
+ return this . scopes || [ DEFAULT_OAUTH_SCOPE ] ;
584
590
}
585
591
586
592
private getMetricsHeaderValue ( ) : string {
0 commit comments