Skip to content

Commit

Permalink
chore: address linting issues (#990)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Jul 7, 2020
1 parent b82db03 commit 88a46b0
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 103 deletions.
4 changes: 1 addition & 3 deletions src/auth/computeclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ import arrify = require('arrify');
import {GaxiosError} from 'gaxios';
import * as gcpMetadata from 'gcp-metadata';

import * as messages from '../messages';

import {CredentialRequest, Credentials} from './credentials';
import {IdTokenProvider} from './idtokenclient';
import {GetTokenResponse, OAuth2Client, RefreshOptions} from './oauth2client';

export interface ComputeOptions extends RefreshOptions {
Expand Down Expand Up @@ -60,6 +57,7 @@ export class Compute extends OAuth2Client {
* @param refreshToken Unused parameter
*/
protected async refreshTokenNoCache(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
refreshToken?: string | null
): Promise<GetTokenResponse> {
const tokenPath = `service-accounts/${this.serviceAccountEmail}/token`;
Expand Down
30 changes: 13 additions & 17 deletions src/auth/googleauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ import * as path from 'path';
import * as stream from 'stream';

import {createCrypto} from '../crypto/crypto';
import * as messages from '../messages';
import {DefaultTransporter, Transporter} from '../transporters';

import {Compute, ComputeOptions} from './computeclient';
import {CredentialBody, JWTInput} from './credentials';
import {IdTokenClient, IdTokenProvider} from './idtokenclient';
import {IdTokenClient} from './idtokenclient';
import {GCPEnv, getEnv} from './envDetect';
import {JWT, JWTOptions} from './jwtclient';
import {
Expand Down Expand Up @@ -551,22 +550,19 @@ export class GoogleAuth {
*/
private async getDefaultServiceProjectId(): Promise<string | null> {
return new Promise<string | null>(resolve => {
exec(
'gcloud config config-helper --format json',
(err, stdout, stderr) => {
if (!err && stdout) {
try {
const projectId = JSON.parse(stdout).configuration.properties.core
.project;
resolve(projectId);
return;
} catch (e) {
// ignore errors
}
exec('gcloud config config-helper --format json', (err, stdout) => {
if (!err && stdout) {
try {
const projectId = JSON.parse(stdout).configuration.properties.core
.project;
resolve(projectId);
return;
} catch (e) {
// ignore errors
}
resolve(null);
}
);
resolve(null);
});
});
}

Expand Down Expand Up @@ -760,7 +756,7 @@ export class GoogleAuth {
* HTTP request using the given options.
* @param opts Axios request options for the HTTP request.
*/
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async request<T = any>(opts: GaxiosOptions): Promise<GaxiosResponse<T>> {
const client = await this.getClient();
return client.request<T>(opts);
Expand Down
2 changes: 0 additions & 2 deletions src/auth/iam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import * as messages from '../messages';

export interface RequestMetadata {
'x-goog-iam-authority-selector': string;
'x-goog-iam-authorization-token': string;
Expand Down
3 changes: 1 addition & 2 deletions src/auth/idtokenclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {BodyResponseCallback} from '../transporters';

import {Credentials} from './credentials';
import {Headers, OAuth2Client, RequestMetadataResponse} from './oauth2client';

Expand Down Expand Up @@ -49,6 +47,7 @@ export class IdTokenClient extends OAuth2Client {
}

protected async getRequestMetadataAsync(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
url?: string | null
): Promise<RequestMetadataResponse> {
if (
Expand Down
5 changes: 2 additions & 3 deletions src/auth/jwtaccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import * as jws from 'jws';
import * as LRU from 'lru-cache';
import * as stream from 'stream';

import * as messages from '../messages';
import {JWTInput} from './credentials';
import {Headers, RequestMetadataResponse} from './oauth2client';
import {Headers} from './oauth2client';

const DEFAULT_HEADER: jws.Header = {
alg: 'RS256',
Expand Down Expand Up @@ -150,7 +149,7 @@ export class JWTAccess {
callback?: (err?: Error) => void
): void | Promise<void> {
if (callback) {
this.fromStreamAsync(inputStream).then(r => callback(), callback);
this.fromStreamAsync(inputStream).then(() => callback(), callback);
} else {
return this.fromStreamAsync(inputStream);
}
Expand Down
4 changes: 2 additions & 2 deletions src/auth/jwtclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import {GoogleToken} from 'gtoken';
import * as stream from 'stream';

import * as messages from '../messages';
import {CredentialBody, Credentials, JWTInput} from './credentials';
import {IdTokenProvider} from './idtokenclient';
import {JWTAccess} from './jwtaccess';
Expand Down Expand Up @@ -224,6 +223,7 @@ export class JWT extends OAuth2Client implements IdTokenProvider {
* @private
*/
protected async refreshTokenNoCache(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
refreshToken?: string | null
): Promise<GetTokenResponse> {
const gtoken = this.createGToken();
Expand Down Expand Up @@ -300,7 +300,7 @@ export class JWT extends OAuth2Client implements IdTokenProvider {
callback?: (err?: Error | null) => void
): void | Promise<void> {
if (callback) {
this.fromStreamAsync(inputStream).then(r => callback(), callback);
this.fromStreamAsync(inputStream).then(() => callback(), callback);
} else {
return this.fromStreamAsync(inputStream);
}
Expand Down
6 changes: 2 additions & 4 deletions src/auth/oauth2client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ import * as stream from 'stream';
import * as formatEcdsa from 'ecdsa-sig-formatter';

import {createCrypto, JwkCertificate, hasBrowserCrypto} from '../crypto/crypto';
import * as messages from '../messages';
import {BodyResponseCallback} from '../transporters';

import {AuthClient} from './authclient';
import {CredentialRequest, Credentials, JWTInput} from './credentials';
import {CredentialRequest, Credentials} from './credentials';
import {LoginTicket, TokenPayload} from './loginticket';
/**
* The results from the `generateCodeVerifierAsync` method. To learn more,
Expand Down Expand Up @@ -774,6 +773,7 @@ export class OAuth2Client extends AuthClient {
}

protected async getRequestMetadataAsync(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
url?: string | null
): Promise<RequestMetadataResponse> {
const thisCreds = this.credentials;
Expand Down Expand Up @@ -1138,8 +1138,6 @@ export class OAuth2Client extends AuthClient {
}

async getIapPublicKeysAsync(): Promise<IapPublicKeysResponse> {
const nowTime = new Date().getTime();

let res: GaxiosResponse;
const url: string = OAuth2Client.GOOGLE_OAUTH2_IAP_PUBLIC_KEY_URL_;

Expand Down
10 changes: 3 additions & 7 deletions src/auth/refreshclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@

import * as stream from 'stream';
import {JWTInput} from './credentials';
import {
Headers,
GetTokenResponse,
OAuth2Client,
RefreshOptions,
} from './oauth2client';
import {GetTokenResponse, OAuth2Client, RefreshOptions} from './oauth2client';

export interface UserRefreshClientOptions extends RefreshOptions {
clientId?: string;
Expand Down Expand Up @@ -76,6 +71,7 @@ export class UserRefreshClient extends OAuth2Client {
* @param callback Optional callback.
*/
protected async refreshTokenNoCache(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
refreshToken?: string | null
): Promise<GetTokenResponse> {
return super.refreshTokenNoCache(this._refreshToken);
Expand Down Expand Up @@ -135,7 +131,7 @@ export class UserRefreshClient extends OAuth2Client {
callback?: (err?: Error) => void
): void | Promise<void> {
if (callback) {
this.fromStreamAsync(inputStream).then(r => callback(), callback);
this.fromStreamAsync(inputStream).then(() => callback(), callback);
} else {
return this.fromStreamAsync(inputStream);
}
Expand Down
2 changes: 1 addition & 1 deletion src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function warn(warning: Warning) {
// @types/node doesn't recognize the emitWarning syntax which
// accepts a config object, so `as any` it is
// https://nodejs.org/docs/latest-v8.x/api/process.html#process_process_emitwarning_warning_options
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
process.emitWarning(warning.message, warning as any);
} else {
console.warn(warning.message);
Expand Down
2 changes: 1 addition & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// previous version of the API, it referred to a `Request` options object.
// Now it refers to an Axiox Request Config object. This is here to help
// ensure users don't pass invalid options when they upgrade from 0.x to 1.x.
// tslint:disable-next-line no-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function validate(options: any) {
const vpairs = [
{invalid: 'uri', expected: 'url'},
Expand Down
18 changes: 16 additions & 2 deletions system-test/fixtures/kitchen/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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();
async function getToken() {
const token = await jwt.getToken('token');
const projectId = await auth.getProjectId();
const creds = await auth.getApplicationDefault();
await auth.getProjectId();
await auth.getApplicationDefault();
return token;
}
getToken();

0 comments on commit 88a46b0

Please sign in to comment.