Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: remove additionalOptions from AuthClients #1689

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/auth/awsclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
BaseExternalAccountClientOptions,
} from './baseexternalclient';
import {Headers} from './oauth2client';
import {AuthClientOptions} from './authclient';

/**
* AWS credentials JSON interface. This is used for AWS workloads.
Expand Down Expand Up @@ -82,16 +81,9 @@ export class AwsClient extends BaseExternalAccountClient {
* An error is thrown if the credential is not a valid AWS credential.
* @param options The external account options object typically loaded
* from the external account JSON credential file.
* @param additionalOptions **DEPRECATED, all options are available in the
* `options` parameter.** Optional additional behavior customization options.
* These currently customize expiration threshold time and whether to retry
* on 401/403 API request errors.
*/
constructor(
options: AwsClientOptions,
additionalOptions?: AuthClientOptions
) {
super(options, additionalOptions);
constructor(options: AwsClientOptions) {
super(options);
this.environmentId = options.credential_source.environment_id;
// This is only required if the AWS region is not available in the
// AWS_REGION or AWS_DEFAULT_REGION environment variables.
Expand Down
9 changes: 2 additions & 7 deletions src/auth/baseexternalclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,13 @@ export abstract class BaseExternalAccountClient extends AuthClient {
* @param options The external account options object typically loaded
* from the external account JSON credential file. The camelCased options
* are aliases for the snake_cased options.
* @param additionalOptions **DEPRECATED, all options are available in the
* `options` parameter.** Optional additional behavior customization options.
* These currently customize expiration threshold time and whether to retry
* on 401/403 API request errors.
*/
constructor(
options:
| BaseExternalAccountClientOptions
| SnakeToCamelObject<BaseExternalAccountClientOptions>,
additionalOptions?: AuthClientOptions
| SnakeToCamelObject<BaseExternalAccountClientOptions>
) {
super({...options, ...additionalOptions});
super(options);

const opts = originalOrCamelOptions(
options as BaseExternalAccountClientOptions
Expand Down
12 changes: 3 additions & 9 deletions src/auth/downscopedclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import * as stream from 'stream';

import {BodyResponseCallback} from '../transporters';
import {Credentials} from './credentials';
import {AuthClient, AuthClientOptions} from './authclient';
import {AuthClient} from './authclient';

import {GetAccessTokenResponse, Headers} from './oauth2client';
import * as sts from './stscredentials';
Expand Down Expand Up @@ -123,18 +123,12 @@ export class DownscopedClient extends AuthClient {
* on the resource that the rule applies to, the upper bound of the
* permissions that are available on that resource and an optional
* condition to further restrict permissions.
* @param additionalOptions **DEPRECATED, set this in the provided `authClient`.**
* Optional additional behavior customization options.
* @param quotaProjectId **DEPRECATED, set this in the provided `authClient`.**
* Optional quota project id for setting up in the x-goog-user-project header.
*/
constructor(
private readonly authClient: AuthClient,
private readonly credentialAccessBoundary: CredentialAccessBoundary,
additionalOptions?: AuthClientOptions,
quotaProjectId?: string
private readonly credentialAccessBoundary: CredentialAccessBoundary
) {
super({...additionalOptions, quotaProjectId});
super();
// Check 1-10 Access Boundary Rules are defined within Credential Access
// Boundary.
if (
Expand Down
19 changes: 6 additions & 13 deletions src/auth/externalAccountAuthorizedUserClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {AuthClient, AuthClientOptions} from './authclient';
import {AuthClient} from './authclient';
import {Headers} from './oauth2client';
import {
ClientAuthentication,
Expand Down Expand Up @@ -161,16 +161,9 @@ export class ExternalAccountAuthorizedUserClient extends AuthClient {
* An error is throws if the credential is not valid.
* @param options The external account authorized user option object typically
* from the external accoutn authorized user JSON credential file.
* @param additionalOptions **DEPRECATED, all options are available in the
* `options` parameter.** Optional additional behavior customization options.
* These currently customize expiration threshold time and whether to retry
* on 401/403 API request errors.
*/
constructor(
options: ExternalAccountAuthorizedUserClientOptions,
additionalOptions?: AuthClientOptions
) {
super({...options, ...additionalOptions});
constructor(options: ExternalAccountAuthorizedUserClientOptions) {
super(options);
this.refreshToken = options.refresh_token;
const clientAuth = {
confidentialClientType: 'basic',
Expand All @@ -190,13 +183,13 @@ export class ExternalAccountAuthorizedUserClient extends AuthClient {
// As threshold could be zero,
// eagerRefreshThresholdMillis || EXPIRATION_TIME_OFFSET will override the
// zero value.
if (typeof additionalOptions?.eagerRefreshThresholdMillis !== 'number') {
if (typeof options?.eagerRefreshThresholdMillis !== 'number') {
this.eagerRefreshThresholdMillis = EXPIRATION_TIME_OFFSET;
} else {
this.eagerRefreshThresholdMillis = additionalOptions!
this.eagerRefreshThresholdMillis = options!
.eagerRefreshThresholdMillis as number;
}
this.forceRefreshOnFailure = !!additionalOptions?.forceRefreshOnFailure;
this.forceRefreshOnFailure = !!options?.forceRefreshOnFailure;

if (options.universe_domain) {
this.universeDomain = options.universe_domain;
Expand Down
20 changes: 4 additions & 16 deletions src/auth/externalclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
PluggableAuthClient,
PluggableAuthClientOptions,
} from './pluggable-auth-client';
import {AuthClientOptions} from './authclient';

export type ExternalAccountClientOptions =
| IdentityPoolClientOptions
Expand Down Expand Up @@ -60,32 +59,21 @@ export class ExternalAccountClient {
* underlying credential source.
* @param options The external account options object typically loaded
* from the external account JSON credential file.
* @param additionalOptions **DEPRECATED, all options are available in the
* `options` parameter.** Optional additional behavior customization options.
* These currently customize expiration threshold time and whether to retry
* on 401/403 API request errors.
* @return A BaseExternalAccountClient instance or null if the options
* provided do not correspond to an external account credential.
*/
static fromJSON(
options: ExternalAccountClientOptions,
additionalOptions?: AuthClientOptions
options: ExternalAccountClientOptions
): BaseExternalAccountClient | null {
if (options && options.type === EXTERNAL_ACCOUNT_TYPE) {
if ((options as AwsClientOptions).credential_source?.environment_id) {
return new AwsClient(options as AwsClientOptions, additionalOptions);
return new AwsClient(options as AwsClientOptions);
} else if (
(options as PluggableAuthClientOptions).credential_source?.executable
) {
return new PluggableAuthClient(
options as PluggableAuthClientOptions,
additionalOptions
);
return new PluggableAuthClient(options as PluggableAuthClientOptions);
} else {
return new IdentityPoolClient(
options as IdentityPoolClientOptions,
additionalOptions
);
return new IdentityPoolClient(options as IdentityPoolClientOptions);
}
} else {
return null;
Expand Down
16 changes: 8 additions & 8 deletions src/auth/googleauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,16 +622,16 @@ export class GoogleAuth<T extends AuthClient = JSONClient> {
} else if (json.type === IMPERSONATED_ACCOUNT_TYPE) {
client = this.fromImpersonatedJSON(json as ImpersonatedJWTInput);
} else if (json.type === EXTERNAL_ACCOUNT_TYPE) {
client = ExternalAccountClient.fromJSON(
json as ExternalAccountClientOptions,
options
)!;
client = ExternalAccountClient.fromJSON({
...json,
...options,
} as ExternalAccountClientOptions)!;
client.scopes = this.getAnyScopes();
} else if (json.type === EXTERNAL_ACCOUNT_AUTHORIZED_USER_TYPE) {
client = new ExternalAccountAuthorizedUserClient(
json as ExternalAccountAuthorizedUserClientOptions,
options
);
client = new ExternalAccountAuthorizedUserClient({
...json,
...options,
} as ExternalAccountAuthorizedUserClientOptions);
} else {
(options as JWTOptions).scopes = this.scopes;
client = new JWT(options);
Expand Down
10 changes: 2 additions & 8 deletions src/auth/identitypoolclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
BaseExternalAccountClient,
BaseExternalAccountClientOptions,
} from './baseexternalclient';
import {AuthClientOptions} from './authclient';
import {SnakeToCamelObject, originalOrCamelOptions} from '../util';

// fs.readfile is undefined in browser karma tests causing
Expand Down Expand Up @@ -76,18 +75,13 @@ export class IdentityPoolClient extends BaseExternalAccountClient {
* @param options The external account options object typically loaded
* from the external account JSON credential file. The camelCased options
* are aliases for the snake_cased options.
* @param additionalOptions **DEPRECATED, all options are available in the
* `options` parameter.** Optional additional behavior customization options.
* These currently customize expiration threshold time and whether to retry
* on 401/403 API request errors.
*/
constructor(
options:
| IdentityPoolClientOptions
| SnakeToCamelObject<IdentityPoolClientOptions>,
additionalOptions?: AuthClientOptions
| SnakeToCamelObject<IdentityPoolClientOptions>
) {
super(options, additionalOptions);
super(options);

const opts = originalOrCamelOptions(options as IdentityPoolClientOptions);
const credentialSource = opts.get('credential_source');
Expand Down
12 changes: 2 additions & 10 deletions src/auth/pluggable-auth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
InvalidExpirationTimeFieldError,
} from './executable-response';
import {PluggableAuthHandler} from './pluggable-auth-handler';
import {AuthClientOptions} from './authclient';

/**
* Defines the credential source portion of the configuration for PluggableAuthClient.
Expand Down Expand Up @@ -189,16 +188,9 @@ export class PluggableAuthClient extends BaseExternalAccountClient {
* An error is thrown if the credential is not a valid pluggable auth credential.
* @param options The external account options object typically loaded from
* the external account JSON credential file.
* @param additionalOptions **DEPRECATED, all options are available in the
* `options` parameter.** Optional additional behavior customization options.
* These currently customize expiration threshold time and whether to retry
* on 401/403 API request errors.
*/
constructor(
options: PluggableAuthClientOptions,
additionalOptions?: AuthClientOptions
) {
super(options, additionalOptions);
constructor(options: PluggableAuthClientOptions) {
super(options);
if (!options.credential_source.executable) {
throw new Error('No valid Pluggable Auth "credential_source" provided.');
}
Expand Down
Loading
Loading