chore: switch to axios#182
chore: switch to axios#182JustinBeckwith merged 9 commits intogoogleapis:nextfrom JustinBeckwith:tests
Conversation
|
@ofrobots all the tests are passing, this is ready for a pass. Apologies for the size of the review, couldn't really find a way to split it up. |
package.json
Outdated
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/auth/authclient.ts
Outdated
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/transporters.ts
Outdated
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/auth/authclient.ts
Outdated
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/transporters.ts
Outdated
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@ofrobots I think I covered all the feedback so far. Ready for the next wave :) |
ofrobots
left a comment
There was a problem hiding this comment.
Some initial comments. Still want going through the rest of the file, but ran out of time.
src/auth/computeclient.ts
Outdated
| try { | ||
| const url = this.opts.tokenUrl || Compute._GOOGLE_OAUTH2_TOKEN_URL; | ||
| // request for new token | ||
| const res = await this.transporter.request({url}); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| }); | ||
| protected async refreshToken(refreshToken?: string| | ||
| null): Promise<GetTokenResponse> { | ||
| try { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| expiry_date?: number; | ||
| access_token?: string; | ||
| token_type?: string; | ||
| expires_in?: number; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| getDefaultProjectId(callback: ProjectIdCallback) { | ||
| getDefaultProjectId(): Promise<string>; | ||
| getDefaultProjectId(callback: ProjectIdCallback): void; | ||
| getDefaultProjectId(callback?: ProjectIdCallback): Promise<string|null>|void { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/auth/googleauth.ts
Outdated
| return; | ||
| } | ||
| // environment variable | ||
| projectId = this.getProductionProjectId(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| callback: | ||
| (error: Error|null, stdout: string, stderr: string|null) => void) { | ||
| exec('gcloud -q config list core/project --format=json', callback); | ||
| _getSDKDefaultProjectId(): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| if (gce) { | ||
| // For GCE, just return a default ComputeClient. It will take care of | ||
| // the rest. | ||
| return {projectId: null, credential: new Compute()}; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| let client: UserRefreshClient|JWT; | ||
| if (!json) { | ||
| try { | ||
| if (!json) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| json: JWTInput, | ||
| callback?: (err: Error|null, client?: UserRefreshClient|JWT) => void) { | ||
| fromJSON(json: JWTInput): JWT|UserRefreshClient; | ||
| fromJSON(json: JWTInput, callback: CredentialCallback): void; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| */ | ||
| fromAPIKey( | ||
| apiKey: string, callback?: (err?: Error|null, client?: JWT) => void) { | ||
| apiKey: string, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| (err: Error|null, headers?: http.IncomingHttpHeaders|null) => void) { | ||
| const iat = Math.floor(new Date().getTime() / 1000); | ||
| const exp = iat + 3600; // 3600 seconds = 1 hour | ||
| getRequestMetadata(authURI: string): RequestMetadataResponse; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/auth/jwtclient.ts
Outdated
| } else { | ||
| return newGToken.getToken((err2?: Error|null, token?: string|null) => { | ||
| return done(err2, { | ||
| async refreshToken(refreshToken?: string|null) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/auth/jwtclient.ts
Outdated
| }); | ||
| }); | ||
| } | ||
| } as Credentials; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| done(new Error( | ||
| 'The incoming JSON object does not contain a private_key field')); | ||
| return; | ||
| fromJSON(json: JWTInput, callback?: (err?: Error) => void): void { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/auth/jwtclient.ts
Outdated
| done(err); | ||
| } | ||
|
|
||
| private async fromStreamAsync(inputStream: stream.Readable) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| */ | ||
| fromAPIKey(apiKey: string, callback?: (err: Error) => void) { | ||
| const done = callback || noop; | ||
| fromAPIKey(apiKey: string, callback?: (err?: Error) => void): void { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| const res = await this.transporter.request<CredentialRequest>( | ||
| {method: 'POST', url, data}); | ||
| const tokens = res.data as Credentials; | ||
| if (res.data && res.data.expires_in) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/auth/oauth2client.ts
Outdated
| return {token: r.credentials.access_token, res: r.res}; | ||
| } else { | ||
| return callback(null, this.credentials.access_token, null); | ||
| return {token: this.credentials.access_token, res: undefined}; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/auth/oauth2client.ts
Outdated
| const headers = { | ||
| Authorization: credentials.token_type + ' ' + tokens.access_token | ||
| }; | ||
| return {headers, res: r ? r.res : null}; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| if (callback) { | ||
| callback(new Error( | ||
| 'Must pass in a JSON object containing the user refresh token')); | ||
| try { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/options.ts
Outdated
| @@ -0,0 +1,33 @@ | |||
| import {AxiosRequestConfig} from 'axios'; | |||
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| jwt.fromAPIKey(KEY, (err) => { | ||
| assert.strictEqual(jwt.apiKey, KEY); | ||
| assert.strictEqual(err, null); | ||
| assert.equal(err, null); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
test/test.oauth2.ts
Outdated
| const oauth2client = | ||
| new auth.OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI); | ||
| oauth2client.request(({} as request.OptionsWithUri), (err, result) => { | ||
| oauth2client.request(({} as AxiosRequestConfig), (err, result) => { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
test/test.oauth2.ts
Outdated
| oauth2client.revokeCredentials((err, result) => { | ||
| assert.equal(err, null); | ||
| assert.equal(result.success, true); | ||
| assert(result); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
test/test.oauth2.ts
Outdated
| assert(tokens.expiry_date >= now + (10 * 1000)); | ||
| assert(tokens.expiry_date <= now + (15 * 1000)); | ||
| assert(tokens); | ||
| if (tokens && tokens.expiry_date) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
test/test.transporters.ts
Outdated
|
|
||
| it('should set default client user agent if none is set', () => { | ||
| const opts = transporter.configure(({} as request.OptionsWithUrl)); | ||
| const opts = transporter.configure(({} as AxiosRequestConfig)); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Switching out request for axios, and making the API support callback and async styles.