Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
fix(deps): update dependency google-auth-library to v3 (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
renovate[bot] authored and JustinBeckwith committed Jan 18, 2019
1 parent 470c548 commit 077ffa6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"dependencies": {
"configstore": "^4.0.0",
"google-auth-library": "^2.0.0",
"google-auth-library": "^3.0.0",
"pumpify": "^1.5.1",
"request": "^2.87.0",
"stream-events": "^1.0.4"
Expand All @@ -57,7 +57,7 @@
"@types/request": "^2.47.0",
"@types/through2": "^2.0.33",
"assert-rejects": "^1.0.0",
"axios": "^0.18.0",
"gaxios": "^1.2.2",
"codecov": "^3.0.4",
"gts": "^0.9.0",
"intelli-espower-loader": "^1.0.1",
Expand Down
19 changes: 10 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/

import {AxiosError, AxiosRequestConfig, AxiosResponse} from 'axios';
import * as ConfigStore from 'configstore';
import {createHash} from 'crypto';
import {GaxiosError, GaxiosOptions, GaxiosPromise} from 'gaxios';
import {GoogleAuth, GoogleAuthOptions} from 'google-auth-library';
import * as Pumpify from 'pumpify';
import * as r from 'request';
Expand Down Expand Up @@ -232,7 +232,7 @@ export class Upload extends Pumpify {
protected async createURIAsync(): Promise<string> {
const metadata = this.metadata;

const reqOpts: AxiosRequestConfig = {
const reqOpts: GaxiosOptions = {
method: 'POST',
url: [BASE_URI, this.bucket, 'o'].join('/'),
params: {name: this.file, uploadType: 'resumable'},
Expand All @@ -241,7 +241,8 @@ export class Upload extends Pumpify {
};

if (metadata.contentLength) {
reqOpts.headers!['X-Upload-Content-Length'] = metadata.contentLength;
reqOpts.headers!['X-Upload-Content-Length'] =
metadata.contentLength.toString();
}

if (metadata.contentType) {
Expand Down Expand Up @@ -361,7 +362,7 @@ export class Upload extends Pumpify {
}

private async getAndSetOffset() {
const opts = {
const opts: GaxiosOptions = {
method: 'PUT',
url: this.uri!,
headers: {'Content-Length': 0, 'Content-Range': 'bytes */*'}
Expand Down Expand Up @@ -401,13 +402,13 @@ export class Upload extends Pumpify {
}
}

private async makeRequest(reqOpts: AxiosRequestConfig):
Promise<AxiosResponse> {
private async makeRequest(reqOpts: GaxiosOptions): GaxiosPromise {
if (this.encryption) {
reqOpts.headers = reqOpts.headers || {};
reqOpts.headers['x-goog-encryption-algorithm'] = 'AES256';
reqOpts.headers['x-goog-encryption-key'] = this.encryption.key;
reqOpts.headers['x-goog-encryption-key-sha256'] = this.encryption.hash;
reqOpts.headers['x-goog-encryption-key'] = this.encryption.key.toString();
reqOpts.headers['x-goog-encryption-key-sha256'] =
this.encryption.hash.toString();
}

if (this.userProject) {
Expand All @@ -418,7 +419,7 @@ export class Upload extends Pumpify {

const res = await this.authClient.request(reqOpts);
if (res.data && res.data.error) {
const err = new Error(res.data.error) as AxiosError;
const err = new Error(res.data.error) as GaxiosError;
err.response = res;
throw err;
}
Expand Down
34 changes: 17 additions & 17 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import * as assert from 'assert';
import {AxiosError, AxiosRequestConfig, AxiosResponse} from 'axios';
import * as crypto from 'crypto';
import {EventEmitter} from 'events';
import * as isStream from 'is-stream';
Expand All @@ -20,6 +19,7 @@ import * as through from 'through2';
const assertRejects = require('assert-rejects');

import {CreateUriCallback} from '../src';
import {GaxiosOptions, GaxiosError, GaxiosResponse} from 'gaxios';

type RequestResponse = r.Response;

Expand Down Expand Up @@ -229,7 +229,7 @@ describe('gcs-resumable-upload', () => {

describe('#createURI', () => {
it('should make the correct request', (done) => {
up.makeRequest = async (reqOpts: AxiosRequestConfig) => {
up.makeRequest = async (reqOpts: GaxiosOptions) => {
assert.strictEqual(reqOpts.method, 'POST');
assert.strictEqual(
reqOpts.url,
Expand All @@ -251,7 +251,7 @@ describe('gcs-resumable-upload', () => {
const kmsKeyName = 'kms-key-name';
const up = upload({bucket: BUCKET, file: FILE, kmsKeyName});

up.makeRequest = async (reqOpts: AxiosRequestConfig) => {
up.makeRequest = async (reqOpts: GaxiosOptions) => {
assert.strictEqual(reqOpts.params.kmsKeyName, kmsKeyName);
done();
return {headers: {location: '/foo'}};
Expand All @@ -261,7 +261,7 @@ describe('gcs-resumable-upload', () => {
});

it('should respect 0 as a generation', (done) => {
up.makeRequest = async (reqOpts: AxiosRequestConfig) => {
up.makeRequest = async (reqOpts: GaxiosOptions) => {
assert.strictEqual(reqOpts.params.ifGenerationMatch, 0);
done();
return {headers: {location: '/foo'}};
Expand Down Expand Up @@ -292,7 +292,7 @@ describe('gcs-resumable-upload', () => {
const RESP = {headers: {location: URI}} as RequestResponse;

beforeEach(() => {
up.makeRequest = async (reqOpts: AxiosRequestConfig) => {
up.makeRequest = async (reqOpts: GaxiosOptions) => {
return RESP;
};
});
Expand Down Expand Up @@ -372,7 +372,7 @@ describe('gcs-resumable-upload', () => {
up.uri = URI;
up.offset = OFFSET;

up.getRequestStream = async (reqOpts: AxiosRequestConfig) => {
up.getRequestStream = async (reqOpts: GaxiosOptions) => {
assert.strictEqual(reqOpts.method, 'PUT');
assert.strictEqual(reqOpts.url, up.uri);
assert.deepEqual(
Expand Down Expand Up @@ -619,7 +619,7 @@ describe('gcs-resumable-upload', () => {
it('should make the correct request', (done) => {
const URI = 'uri';
up.uri = URI;
up.makeRequest = async (reqOpts: AxiosRequestConfig) => {
up.makeRequest = async (reqOpts: GaxiosOptions) => {
assert.strictEqual(reqOpts.method, 'PUT');
assert.strictEqual(reqOpts.url, URI);
assert.deepEqual(
Expand All @@ -632,8 +632,8 @@ describe('gcs-resumable-upload', () => {
});

describe('restart on 404', () => {
const RESP = {status: 404} as AxiosResponse;
const ERROR = new Error(':(') as AxiosError;
const RESP = {status: 404} as GaxiosResponse;
const ERROR = new Error(':(') as GaxiosError;
ERROR.response = RESP;

beforeEach(() => {
Expand All @@ -659,8 +659,8 @@ describe('gcs-resumable-upload', () => {
});

describe('restart on 410', () => {
const ERROR = new Error(':(') as AxiosError;
const RESP = {status: 410} as AxiosResponse;
const ERROR = new Error(':(') as GaxiosError;
const RESP = {status: 410} as GaxiosResponse;
ERROR.response = RESP;

beforeEach(() => {
Expand Down Expand Up @@ -700,7 +700,7 @@ describe('gcs-resumable-upload', () => {
[mockAuthorizeRequest(), nock(REQ_OPTS.url).get('/').reply(200, {})];
const res = await up.makeRequest(REQ_OPTS);
scopes.forEach(x => x.done());
const headers = res.request.headers;
const headers = res.config.headers;
assert.equal(headers['x-goog-encryption-algorithm'], 'AES256');
assert.equal(headers['x-goog-encryption-key'], up.encryption.key);
assert.equal(headers['x-goog-encryption-key-sha256'], up.encryption.hash);
Expand All @@ -710,8 +710,8 @@ describe('gcs-resumable-upload', () => {
const scopes = [
mockAuthorizeRequest(), nock(REQ_OPTS.url).get(queryPath).reply(200, {})
];
const res = await up.makeRequest(REQ_OPTS);
assert.strictEqual(res.request.path, queryPath);
const res: GaxiosResponse = await up.makeRequest(REQ_OPTS);
assert.strictEqual(res.config.url, REQ_OPTS.url + queryPath);
scopes.forEach(x => x.done());
});

Expand All @@ -730,7 +730,7 @@ describe('gcs-resumable-upload', () => {
];
const res = await up.makeRequest(REQ_OPTS);
scopes.forEach(x => x.done());
assert.strictEqual(res.request.path, queryPath);
assert.strictEqual(res.config.url, REQ_OPTS.url + queryPath);
assert.deepStrictEqual(res.headers, {});
});

Expand All @@ -747,7 +747,7 @@ describe('gcs-resumable-upload', () => {
const response = {error: ':('};
mockAuthorizeRequest();
const scope = nock(REQ_OPTS.url).get(queryPath).reply(500, response);
await assertRejects(up.makeRequest(REQ_OPTS), (err: AxiosError) => {
await assertRejects(up.makeRequest(REQ_OPTS), (err: GaxiosError) => {
assert.equal(err.response!.status, 500);
assert.deepStrictEqual(response, err.response!.data);
return true;
Expand All @@ -760,7 +760,7 @@ describe('gcs-resumable-upload', () => {
mockAuthorizeRequest();
const scope =
nock(REQ_OPTS.url).get(queryPath).reply(500, response.data);
await assertRejects(up.makeRequest(REQ_OPTS), (err: AxiosError) => {
await assertRejects(up.makeRequest(REQ_OPTS), (err: GaxiosError) => {
scope.done();
assert.strictEqual(err.message, response.data.error);
assert.deepStrictEqual(err.response!.status, 500);
Expand Down

0 comments on commit 077ffa6

Please sign in to comment.