Skip to content

Commit

Permalink
chore!: remove deprecated methods (#906)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Mar 21, 2020
1 parent d337131 commit f453fb7
Show file tree
Hide file tree
Showing 13 changed files with 2 additions and 369 deletions.
14 changes: 0 additions & 14 deletions src/auth/computeclient.ts
Expand Up @@ -55,20 +55,6 @@ export class Compute extends OAuth2Client {
this.scopes = arrify(options.scopes);
}

/**
* Indicates whether the credential requires scopes to be created by calling
* createdScoped before use.
* @deprecated
* @return Boolean indicating if scope is required.
*/
createScopedRequired() {
// On compute engine, scopes are specified at the compute instance's
// creation time, and cannot be changed. For this reason, always return
// false.
messages.warn(messages.COMPUTE_CREATE_SCOPED_DEPRECATED);
return false;
}

/**
* Refreshes the access token.
* @param refreshToken Unused parameter
Expand Down
17 changes: 0 additions & 17 deletions src/auth/googleauth.ts
Expand Up @@ -137,23 +137,6 @@ export class GoogleAuth {
this.clientOptions = opts.clientOptions;
}

/**
* THIS METHOD HAS BEEN DEPRECATED.
* It will be removed in 3.0. Please use getProjectId instead.
*/
getDefaultProjectId(): Promise<string>;
getDefaultProjectId(callback: ProjectIdCallback): void;
getDefaultProjectId(
callback?: ProjectIdCallback
): Promise<string | null> | void {
messages.warn(messages.DEFAULT_PROJECT_ID_DEPRECATED);
if (callback) {
this.getProjectIdAsync().then(r => callback(null, r), callback);
} else {
return this.getProjectIdAsync();
}
}

/**
* Obtains the default project ID for the application.
* @param callback Optional callback
Expand Down
27 changes: 0 additions & 27 deletions src/auth/iam.ts
Expand Up @@ -32,33 +32,6 @@ export class IAMAuth {
this.token = token;
}

/**
* Indicates whether the credential requires scopes to be created by calling
* createdScoped before use.
* @deprecated
* @return always false
*/
createScopedRequired() {
// IAM authorization does not use scopes.
messages.warn(messages.IAM_CREATE_SCOPED_DEPRECATED);
return false;
}

/**
* Pass the selector and token to the metadataFn callback.
* @deprecated
* @param unused_uri is required of the credentials interface
* @param metadataFn a callback invoked with object containing request
* metadata.
*/
getRequestMetadata(
unusedUri: string | null,
metadataFn: (err: Error | null, metadata?: RequestMetadata) => void
) {
messages.warn(messages.IAM_GET_REQUEST_METADATA_DEPRECATED);
metadataFn(null, this.getRequestHeaders());
}

/**
* Acquire the HTTP headers required to make an authenticated request.
*/
Expand Down
29 changes: 0 additions & 29 deletions src/auth/jwtaccess.ts
Expand Up @@ -57,35 +57,6 @@ export class JWTAccess {
this.keyId = keyId;
}

/**
* Indicates whether the credential requires scopes to be created by calling
* createdScoped before use.
* @deprecated
* @return always false
*/
createScopedRequired(): boolean {
// JWT Header authentication does not use scopes.
messages.warn(messages.JWT_ACCESS_CREATE_SCOPED_DEPRECATED);
return false;
}

/**
* Get a non-expired access token, after refreshing if necessary.
*
* @param authURI The URI being authorized.
* @param additionalClaims An object with a set of additional claims to
* include in the payload.
* @deprecated Please use `getRequestHeaders` instead.
* @returns An object that includes the authorization header.
*/
getRequestMetadata(
url: string,
additionalClaims?: Claims
): RequestMetadataResponse {
messages.warn(messages.JWT_ACCESS_GET_REQUEST_METADATA_DEPRECATED);
return {headers: this.getRequestHeaders(url, additionalClaims)};
}

/**
* Get a non-expired access token, after refreshing if necessary.
*
Expand Down
11 changes: 0 additions & 11 deletions src/auth/jwtclient.ts
Expand Up @@ -174,17 +174,6 @@ export class JWT extends OAuth2Client implements IdTokenProvider {
return gtoken.idToken;
}

/**
* Indicates whether the credential requires scopes to be created by calling
* createScoped before use.
* @deprecated
* @return false if createScoped does not need to be called.
*/
createScopedRequired() {
messages.warn(messages.JWT_CREATE_SCOPED_DEPRECATED);
return !this.hasScopes();
}

/**
* Determine if there are currently scopes available.
*/
Expand Down
27 changes: 0 additions & 27 deletions src/auth/oauth2client.ts
Expand Up @@ -759,33 +759,6 @@ export class OAuth2Client extends AuthClient {
}
}

/**
* Obtain the set of headers required to authenticate a request.
*
* @deprecated Use getRequestHeaders instead.
* @param url the Uri being authorized
* @param callback the func described above
*/
getRequestMetadata(url?: string | null): Promise<RequestMetadataResponse>;
getRequestMetadata(
url: string | null,
callback: RequestMetadataCallback
): void;
getRequestMetadata(
url: string | null,
callback?: RequestMetadataCallback
): Promise<RequestMetadataResponse> | void {
messages.warn(messages.OAUTH_GET_REQUEST_METADATA_DEPRECATED);
if (callback) {
this.getRequestMetadataAsync(url).then(
r => callback(null, r.headers, r.res),
callback
);
} else {
return this.getRequestMetadataAsync();
}
}

/**
* The main authentication interface. It takes an optional url which when
* present is the endpoint being accessed, and returns a Promise which
Expand Down
76 changes: 0 additions & 76 deletions src/messages.ts
Expand Up @@ -40,79 +40,3 @@ export interface Warning {
message: string;
warned?: boolean;
}

export const DEFAULT_PROJECT_ID_DEPRECATED = {
code: 'google-auth-library:DEP002',
type: WarningTypes.DEPRECATION,
message: [
'The `getDefaultProjectId` method has been deprecated, and will be removed',
'in the 3.0 release of google-auth-library. Please use the `getProjectId`',
'method instead.',
].join(' '),
};

export const COMPUTE_CREATE_SCOPED_DEPRECATED = {
code: 'google-auth-library:DEP003',
type: WarningTypes.DEPRECATION,
message: [
'The `createScopedRequired` method on the `Compute` class has been deprecated,',
'and will be removed in the 3.0 release of google-auth-library.',
].join(' '),
};

export const JWT_CREATE_SCOPED_DEPRECATED = {
code: 'google-auth-library:DEP004',
type: WarningTypes.DEPRECATION,
message: [
'The `createScopedRequired` method on the `JWT` class has been deprecated,',
'and will be removed in the 3.0 release of google-auth-library.',
].join(' '),
};

export const IAM_CREATE_SCOPED_DEPRECATED = {
code: 'google-auth-library:DEP005',
type: WarningTypes.DEPRECATION,
message: [
'The `createScopedRequired` method on the `IAM` class has been deprecated,',
'and will be removed in the 3.0 release of google-auth-library.',
].join(' '),
};

export const JWT_ACCESS_CREATE_SCOPED_DEPRECATED = {
code: 'google-auth-library:DEP006',
type: WarningTypes.DEPRECATION,
message: [
'The `createScopedRequired` method on the `JWTAccess` class has been deprecated,',
'and will be removed in the 3.0 release of google-auth-library.',
].join(' '),
};

export const OAUTH_GET_REQUEST_METADATA_DEPRECATED = {
code: 'google-auth-library:DEP004',
type: WarningTypes.DEPRECATION,
message: [
'The `getRequestMetadata` method on the `OAuth2` class has been deprecated,',
'and will be removed in the 3.0 release of google-auth-library. Please use',
'the `getRequestHeaders` method instead.',
].join(' '),
};

export const IAM_GET_REQUEST_METADATA_DEPRECATED = {
code: 'google-auth-library:DEP005',
type: WarningTypes.DEPRECATION,
message: [
'The `getRequestMetadata` method on the `IAM` class has been deprecated,',
'and will be removed in the 3.0 release of google-auth-library. Please use',
'the `getRequestHeaders` method instead.',
].join(' '),
};

export const JWT_ACCESS_GET_REQUEST_METADATA_DEPRECATED = {
code: 'google-auth-library:DEP006',
type: WarningTypes.DEPRECATION,
message: [
'The `getRequestMetadata` method on the `JWTAccess` class has been deprecated,',
'and will be removed in the 3.0 release of google-auth-library. Please use',
'the `getRequestHeaders` method instead.',
].join(' '),
};
13 changes: 0 additions & 13 deletions test/test.compute.ts
Expand Up @@ -150,19 +150,6 @@ describe('compute', () => {
scope.done();
});

it('should emit warning for createScopedRequired', () => {
let called = false;
sandbox.stub(process, 'emitWarning').callsFake(() => (called = true));
// tslint:disable-next-line deprecation
compute.createScopedRequired();
assert.strictEqual(called, true);
});

it('should return false for createScopedRequired', () => {
// tslint:disable-next-line deprecation
assert.strictEqual(false, compute.createScopedRequired());
});

it('should return a helpful message on request response.statusCode 403', async () => {
const scope = mockToken(403);
const expected = new RegExp(
Expand Down
30 changes: 0 additions & 30 deletions test/test.googleauth.ts
Expand Up @@ -1407,36 +1407,6 @@ describe('googleauth', () => {
assert.strictEqual(value, signedBlob);
});

it('should warn the user if using the getDefaultProjectId method', done => {
mockEnvVar('GCLOUD_PROJECT', STUB_PROJECT);
sandbox
.stub(process, 'emitWarning')
.callsFake((message, warningOrType) => {
assert.strictEqual(
message,
messages.DEFAULT_PROJECT_ID_DEPRECATED.message
);
const warningType =
typeof warningOrType === 'string'
? warningOrType
: // @types/node doesn't recognize the emitWarning syntax which
// tslint:disable-next-line no-any
(warningOrType as any).type;
assert.strictEqual(warningType, messages.WarningTypes.DEPRECATION);
done();
});
auth.getDefaultProjectId();
});

it('should only emit warnings once', async () => {
// The warning was used above, so invoking it here should have no effect.
mockEnvVar('GCLOUD_PROJECT', STUB_PROJECT);
let count = 0;
sandbox.stub(process, 'emitWarning').callsFake(() => count++);
await auth.getDefaultProjectId();
assert.strictEqual(count, 0);
});

it('should pass options to the JWT constructor via constructor', async () => {
const subject = 'science!';
const auth = new GoogleAuth({
Expand Down
17 changes: 0 additions & 17 deletions test/test.iam.ts
Expand Up @@ -16,7 +16,6 @@ import * as assert from 'assert';
import {describe, it, beforeEach, afterEach} from 'mocha';
import * as sinon from 'sinon';
import {IAMAuth} from '../src';
import * as messages from '../src/messages';

describe('iam', () => {
const testSelector = 'a-test-selector';
Expand All @@ -38,20 +37,4 @@ describe('iam', () => {
assert.strictEqual(creds!['x-goog-iam-authority-selector'], testSelector);
assert.strictEqual(creds!['x-goog-iam-authorization-token'], testToken);
});

it('should warn about deprecation of getRequestMetadata', done => {
const stub = sandbox.stub(messages, 'warn');
// tslint:disable-next-line deprecation
client.getRequestMetadata(null, () => {
assert.strictEqual(stub.calledOnce, true);
done();
});
});

it('should emit warning for createScopedRequired', () => {
const stub = sandbox.stub(process, 'emitWarning');
// tslint:disable-next-line deprecation
client.createScopedRequired();
assert(stub.called);
});
});

0 comments on commit f453fb7

Please sign in to comment.