From 6232a1437e73e80928aaa4ce5071339179a5aa7c Mon Sep 17 00:00:00 2001 From: Hubert <70658889+HubertJan@users.noreply.github.com> Date: Tue, 12 Mar 2024 22:37:01 +0100 Subject: [PATCH] refactor!: Move Base AuthClient Types to authclient.ts --- src/auth/authclient.ts | 10 +++++++++- src/auth/awsclient.ts | 3 +-- src/auth/awsrequestsigner.ts | 2 +- src/auth/baseexternalclient.ts | 3 +-- src/auth/downscopedclient.ts | 3 +-- src/auth/externalAccountAuthorizedUserClient.ts | 3 +-- src/auth/googleauth.ts | 4 ++-- src/auth/idtokenclient.ts | 2 +- src/auth/jwtaccess.ts | 2 +- src/auth/oauth2client.ts | 11 +---------- src/auth/passthrough.ts | 3 +-- src/auth/stscredentials.ts | 2 +- test/externalclienthelper.ts | 2 +- test/test.downscopedclient.ts | 2 +- test/test.oauth2common.ts | 2 +- 15 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/auth/authclient.ts b/src/auth/authclient.ts index 29e1602a..bf24dc30 100644 --- a/src/auth/authclient.ts +++ b/src/auth/authclient.ts @@ -17,7 +17,6 @@ import {Gaxios, GaxiosOptions, GaxiosPromise, GaxiosResponse} from 'gaxios'; import {DefaultTransporter, Transporter} from '../transporters'; import {Credentials} from './credentials'; -import {GetAccessTokenResponse, Headers} from './oauth2client'; import {OriginalAndCamel, originalOrCamelOptions} from '../util'; /** @@ -260,3 +259,12 @@ export abstract class AuthClient return headers; } } + +export interface Headers { + [index: string]: string; +} + +export interface GetAccessTokenResponse { + token?: string | null; + res?: GaxiosResponse | null; +} \ No newline at end of file diff --git a/src/auth/awsclient.ts b/src/auth/awsclient.ts index dc2e0eee..0426607c 100644 --- a/src/auth/awsclient.ts +++ b/src/auth/awsclient.ts @@ -19,8 +19,7 @@ import { BaseExternalAccountClient, BaseExternalAccountClientOptions, } from './baseexternalclient'; -import {Headers} from './oauth2client'; -import {AuthClientOptions} from './authclient'; +import {Headers, AuthClientOptions} from './authclient'; /** * AWS credentials JSON interface. This is used for AWS workloads. diff --git a/src/auth/awsrequestsigner.ts b/src/auth/awsrequestsigner.ts index 4bb5a151..cb0126c3 100644 --- a/src/auth/awsrequestsigner.ts +++ b/src/auth/awsrequestsigner.ts @@ -14,7 +14,7 @@ import {GaxiosOptions} from 'gaxios'; -import {Headers} from './oauth2client'; +import {Headers} from './authclient'; import {Crypto, createCrypto, fromArrayBufferToHex} from '../crypto/crypto'; type HttpMethod = diff --git a/src/auth/baseexternalclient.ts b/src/auth/baseexternalclient.ts index 45ff17ff..5e4f90d9 100644 --- a/src/auth/baseexternalclient.ts +++ b/src/auth/baseexternalclient.ts @@ -21,9 +21,8 @@ import { import * as stream from 'stream'; import {Credentials} from './credentials'; -import {AuthClient, AuthClientOptions} from './authclient'; +import {AuthClient, AuthClientOptions, GetAccessTokenResponse, Headers} from './authclient'; import {BodyResponseCallback} from '../transporters'; -import {GetAccessTokenResponse, Headers} from './oauth2client'; import * as sts from './stscredentials'; import {ClientAuthentication} from './oauth2common'; import {SnakeToCamelObject, originalOrCamelOptions} from '../util'; diff --git a/src/auth/downscopedclient.ts b/src/auth/downscopedclient.ts index 2e2716f1..5058c11a 100644 --- a/src/auth/downscopedclient.ts +++ b/src/auth/downscopedclient.ts @@ -22,9 +22,8 @@ import * as stream from 'stream'; import {BodyResponseCallback} from '../transporters'; import {Credentials} from './credentials'; -import {AuthClient, AuthClientOptions} from './authclient'; +import {AuthClient, AuthClientOptions, GetAccessTokenResponse, Headers} from './authclient'; -import {GetAccessTokenResponse, Headers} from './oauth2client'; import * as sts from './stscredentials'; /** diff --git a/src/auth/externalAccountAuthorizedUserClient.ts b/src/auth/externalAccountAuthorizedUserClient.ts index c9534440..bed389f7 100644 --- a/src/auth/externalAccountAuthorizedUserClient.ts +++ b/src/auth/externalAccountAuthorizedUserClient.ts @@ -12,8 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import {AuthClient, AuthClientOptions} from './authclient'; -import {Headers} from './oauth2client'; +import {AuthClient, AuthClientOptions, Headers} from './authclient'; import { ClientAuthentication, getErrorFromOAuthErrorResponse, diff --git a/src/auth/googleauth.ts b/src/auth/googleauth.ts index 472ae789..393673ed 100644 --- a/src/auth/googleauth.ts +++ b/src/auth/googleauth.ts @@ -28,7 +28,7 @@ import {CredentialBody, ImpersonatedJWTInput, JWTInput} from './credentials'; import {IdTokenClient} from './idtokenclient'; import {GCPEnv, getEnv} from './envDetect'; import {JWT, JWTOptions} from './jwtclient'; -import {Headers, OAuth2ClientOptions} from './oauth2client'; +import {OAuth2ClientOptions} from './oauth2client'; import { UserRefreshClient, UserRefreshClientOptions, @@ -47,7 +47,7 @@ import { EXTERNAL_ACCOUNT_TYPE, BaseExternalAccountClient, } from './baseexternalclient'; -import {AuthClient, AuthClientOptions, DEFAULT_UNIVERSE} from './authclient'; +import {AuthClient, AuthClientOptions, DEFAULT_UNIVERSE, Headers} from './authclient'; import { EXTERNAL_ACCOUNT_AUTHORIZED_USER_TYPE, ExternalAccountAuthorizedUserClient, diff --git a/src/auth/idtokenclient.ts b/src/auth/idtokenclient.ts index 5bd62b52..24d1f859 100644 --- a/src/auth/idtokenclient.ts +++ b/src/auth/idtokenclient.ts @@ -13,8 +13,8 @@ // limitations under the License. import {Credentials} from './credentials'; +import {Headers} from './authclient'; import { - Headers, OAuth2Client, OAuth2ClientOptions, RequestMetadataResponse, diff --git a/src/auth/jwtaccess.ts b/src/auth/jwtaccess.ts index b7c61147..0cabbcbb 100644 --- a/src/auth/jwtaccess.ts +++ b/src/auth/jwtaccess.ts @@ -16,7 +16,7 @@ import * as jws from 'jws'; import * as stream from 'stream'; import {JWTInput} from './credentials'; -import {Headers} from './oauth2client'; +import {Headers} from './authclient'; import {LRUCache} from '../util'; const DEFAULT_HEADER: jws.Header = { diff --git a/src/auth/oauth2client.ts b/src/auth/oauth2client.ts index c9f87d56..a139d7b6 100644 --- a/src/auth/oauth2client.ts +++ b/src/auth/oauth2client.ts @@ -25,7 +25,7 @@ import * as formatEcdsa from 'ecdsa-sig-formatter'; import {createCrypto, JwkCertificate, hasBrowserCrypto} from '../crypto/crypto'; import {BodyResponseCallback} from '../transporters'; -import {AuthClient, AuthClientOptions} from './authclient'; +import {AuthClient, AuthClientOptions, GetAccessTokenResponse, Headers} from './authclient'; import {CredentialRequest, Credentials} from './credentials'; import {LoginTicket, TokenPayload} from './loginticket'; /** @@ -54,10 +54,6 @@ export interface PublicKeys { [index: string]: string; } -export interface Headers { - [index: string]: string; -} - export enum CodeChallengeMethod { Plain = 'plain', S256 = 'S256', @@ -336,11 +332,6 @@ export interface GetAccessTokenCallback { ): void; } -export interface GetAccessTokenResponse { - token?: string | null; - res?: GaxiosResponse | null; -} - export interface RefreshAccessTokenCallback { ( err: GaxiosError | null, diff --git a/src/auth/passthrough.ts b/src/auth/passthrough.ts index bde50cba..6d6b7c17 100644 --- a/src/auth/passthrough.ts +++ b/src/auth/passthrough.ts @@ -13,8 +13,7 @@ // limitations under the License. import {GaxiosOptions} from 'gaxios'; -import {AuthClient} from './authclient'; -import {GetAccessTokenResponse, Headers} from './oauth2client'; +import {AuthClient, GetAccessTokenResponse, Headers} from './authclient'; /** * An AuthClient without any Authentication information. Useful for: diff --git a/src/auth/stscredentials.ts b/src/auth/stscredentials.ts index a075eae1..26dc860f 100644 --- a/src/auth/stscredentials.ts +++ b/src/auth/stscredentials.ts @@ -16,7 +16,7 @@ import {GaxiosError, GaxiosOptions, GaxiosResponse} from 'gaxios'; import * as querystring from 'querystring'; import {DefaultTransporter, Transporter} from '../transporters'; -import {Headers} from './oauth2client'; +import {Headers} from './authclient'; import { ClientAuthentication, OAuthClientAuthHandler, diff --git a/test/externalclienthelper.ts b/test/externalclienthelper.ts index 9cc62adf..4e13bafa 100644 --- a/test/externalclienthelper.ts +++ b/test/externalclienthelper.ts @@ -15,7 +15,7 @@ import * as assert from 'assert'; import * as nock from 'nock'; import * as qs from 'querystring'; -import {GetAccessTokenResponse} from '../src/auth/oauth2client'; +import {GetAccessTokenResponse} from '../src/auth/authclient'; import {OAuthErrorResponse} from '../src/auth/oauth2common'; import {StsSuccessfulResponse} from '../src/auth/stscredentials'; import { diff --git a/test/test.downscopedclient.ts b/test/test.downscopedclient.ts index d280a9ee..bab83773 100644 --- a/test/test.downscopedclient.ts +++ b/test/test.downscopedclient.ts @@ -31,7 +31,7 @@ import { OAuthErrorResponse, getErrorFromOAuthErrorResponse, } from '../src/auth/oauth2common'; -import {GetAccessTokenResponse, Headers} from '../src/auth/oauth2client'; +import {GetAccessTokenResponse, Headers} from '../src/auth/authclient'; nock.disableNetConnect(); diff --git a/test/test.oauth2common.ts b/test/test.oauth2common.ts index 9b0a485f..3581530c 100644 --- a/test/test.oauth2common.ts +++ b/test/test.oauth2common.ts @@ -17,7 +17,7 @@ import {describe, it} from 'mocha'; import * as assert from 'assert'; import * as querystring from 'querystring'; -import {Headers} from '../src/auth/oauth2client'; +import {Headers} from '../src/auth/authclient'; import { ClientAuthentication, OAuthClientAuthHandler,