Skip to content

Commit

Permalink
chore: export class types and remove properties from GoogleAuth (#202)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The IAMAuth, Compute, JWT, JWTAccess, OAuth2, and UserRefreshClient types are no longer available as public properties on the GoogleAuth object.  They are now exported directly from the top level module.
  • Loading branch information
JustinBeckwith authored Dec 1, 2017
1 parent e2a3370 commit 2bf0c28
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 188 deletions.
32 changes: 0 additions & 32 deletions src/auth/googleauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,38 +84,6 @@ export class GoogleAuth {

cachedCredential: OAuth2Client|null = null;

/**
* Convenience field mapping in the IAM credential type.
*/
IAMAuth = IAMAuth;

/**
* Convenience field mapping in the Compute credential type.
*/
Compute = Compute;

/**
* Convenience field mapping in the JWT credential type.
*/
JWT = JWT;

/**
* Convenience field mapping in the JWT Access credential type.
*/
JWTAccess = JWTAccess;

/**
* Convenience field mapping in the OAuth2 credential type.
*/
// lint is checking for camelCase properties, but OAuth is proper here
// tslint:disable-next-line variable-name
OAuth2 = OAuth2Client;

/**
* Convenience field mapping to the UserRefreshClient credential type.
*/
UserRefreshClient = UserRefreshClient;

/**
* Export DefaultTransporter as a static property of the class.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export {Compute} from './auth/computeclient';
export {GoogleAuth} from './auth/googleauth';
export {IAMAuth} from './auth/iam';
export {JWTAccess} from './auth/jwtaccess';
export {JWT} from './auth/jwtclient';
export {OAuth2Client} from './auth/oauth2client';
export {UserRefreshClient} from './auth/refreshclient';
export {DefaultTransporter} from './transporters';
4 changes: 2 additions & 2 deletions test/fixtures/kitchen/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {GoogleAuth} from 'google-auth-library';
import {GoogleAuth, JWT} from 'google-auth-library';
// uncomment the line below during development
// import {GoogleAuth} from '../../../../build/src/index';
const jwt = new JWT();
const auth = new GoogleAuth();
const jwt = new auth.JWT();
async function getToken() {
const token = await jwt.getToken('token');
const projectId = await auth.getDefaultProjectId();
Expand Down
11 changes: 4 additions & 7 deletions test/test.compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ import * as assert from 'assert';
import {AxiosRequestConfig} from 'axios';
import * as nock from 'nock';

import {Compute} from '../src/auth/computeclient';
import {Credentials} from '../src/auth/credentials';
import {GoogleAuth} from '../src/auth/googleauth';
import {Compute} from '../src/index';

nock.disableNetConnect();

describe('Initial credentials', () => {
it('should create a dummy refresh token string', () => {
// It is important that the compute client is created with a refresh token
// value filled in, or else the rest of the logic will not work.
const auth = new GoogleAuth();
const compute = new auth.Compute();
const compute = new Compute();
assert.equal('compute-placeholder', compute.credentials.refresh_token);
});
});
Expand All @@ -42,8 +41,7 @@ describe('Compute auth client', () => {
// set up compute client.
let compute: Compute;
beforeEach(() => {
const auth = new GoogleAuth();
compute = new auth.Compute();
compute = new Compute();
});

it('should get an access token for the first request', done => {
Expand Down Expand Up @@ -86,8 +84,7 @@ describe('Compute auth client', () => {

describe('.createScopedRequired', () => {
it('should return false', () => {
const auth = new GoogleAuth();
const c = new auth.Compute();
const c = new Compute();
assert.equal(false, c.createScopedRequired());
});
});
Expand Down
21 changes: 6 additions & 15 deletions test/test.googleauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import * as nock from 'nock';
import * as path from 'path';
import * as stream from 'stream';

import {GoogleAuth} from '../src/auth/googleauth';
import {JWT} from '../src/auth/jwtclient';
import {UserRefreshClient} from '../src/auth/refreshclient';
import {BodyResponseCallback, DefaultTransporter} from '../src/transporters';
import {DefaultTransporter, GoogleAuth, JWT, UserRefreshClient} from '../src/index';
import {BodyResponseCallback} from '../src/transporters';

nock.disableNetConnect();

Expand Down Expand Up @@ -327,8 +325,7 @@ describe('GoogleAuth', () => {

describe('Refresh token', () => {
it('should error on empty json', () => {
const auth = new GoogleAuth();
const jwt = new auth.JWT();
const jwt = new JWT();
assert.throws(() => {
jwt.fromJSON({});
});
Expand All @@ -337,9 +334,7 @@ describe('GoogleAuth', () => {
it('should error on missing client_id', () => {
const json = createRefreshJSON();
delete json.client_id;

const auth = new GoogleAuth();
const jwt = new auth.JWT();
const jwt = new JWT();
assert.throws(() => {
jwt.fromJSON(json);
});
Expand All @@ -348,9 +343,7 @@ describe('GoogleAuth', () => {
it('should error on missing client_secret', () => {
const json = createRefreshJSON();
delete json.client_secret;

const auth = new GoogleAuth();
const jwt = new auth.JWT();
const jwt = new JWT();
assert.throws(() => {
jwt.fromJSON(json);
});
Expand All @@ -359,9 +352,7 @@ describe('GoogleAuth', () => {
it('should error on missing refresh_token', () => {
const json = createRefreshJSON();
delete json.refresh_token;

const auth = new GoogleAuth();
const jwt = new auth.JWT();
const jwt = new JWT();
assert.throws(() => {
jwt.fromJSON(json);
});
Expand Down
8 changes: 4 additions & 4 deletions test/test.iam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
*/

import * as assert from 'assert';
import {GoogleAuth} from '../src/auth/googleauth';
import {IAMAuth, RequestMetadata} from '../src/auth/iam';

import {RequestMetadata} from '../src/auth/iam';
import {GoogleAuth, IAMAuth} from '../src/index';

describe('.getRequestMetadata', () => {
const testSelector = 'a-test-selector';
const testToken = 'a-test-token';
let client: IAMAuth;
beforeEach(() => {
const auth = new GoogleAuth();
client = new auth.IAMAuth(testSelector, testToken);
client = new IAMAuth(testSelector, testToken);
});

it('passes the token and selector to the callback ', (done) => {
Expand Down
Loading

0 comments on commit 2bf0c28

Please sign in to comment.