Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

chore: switch to axios#182

Merged
JustinBeckwith merged 9 commits intogoogleapis:nextfrom
JustinBeckwith:tests
Nov 24, 2017
Merged

chore: switch to axios#182
JustinBeckwith merged 9 commits intogoogleapis:nextfrom
JustinBeckwith:tests

Conversation

@JustinBeckwith
Copy link
Contributor

@JustinBeckwith JustinBeckwith commented Nov 18, 2017

Switching out request for axios, and making the API support callback and async styles.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 18, 2017
@JustinBeckwith
Copy link
Contributor Author

@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.

@JustinBeckwith JustinBeckwith added this to the 1.0 milestone Nov 19, 2017
package.json Outdated

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@JustinBeckwith JustinBeckwith changed the base branch from master to next November 21, 2017 02:09

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@JustinBeckwith
Copy link
Contributor Author

@ofrobots I think I covered all the feedback so far. Ready for the next wave :)

Copy link
Contributor

@ofrobots ofrobots left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial comments. Still want going through the rest of the file, but ran out of time.

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.

});
protected async refreshToken(refreshToken?: string|
null): Promise<GetTokenResponse> {
try {

This comment was marked as spam.

This comment was marked as spam.

expiry_date?: number;
access_token?: string;
token_type?: string;
expires_in?: number;

This comment was marked as spam.

This comment was marked as spam.

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.

return;
}
// environment variable
projectId = this.getProductionProjectId();

This comment was marked as spam.

This comment was marked as spam.

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.

This comment was marked as spam.

This comment was marked as spam.

Copy link
Contributor

@ofrobots ofrobots left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still more to come

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.

let client: UserRefreshClient|JWT;
if (!json) {
try {
if (!json) {

This comment was marked as spam.

This comment was marked as spam.

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.

*/
fromAPIKey(
apiKey: string, callback?: (err?: Error|null, client?: JWT) => void) {
apiKey: string,

This comment was marked as spam.

This comment was marked as spam.

(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.

} 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.

});
});
}
} as Credentials;

This comment was marked as spam.

This comment was marked as spam.

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.

done(err);
}

private async fromStreamAsync(inputStream: stream.Readable) {

This comment was marked as spam.

This comment was marked as spam.

*/
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.

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.

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.

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.

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.

src/options.ts Outdated
@@ -0,0 +1,33 @@
import {AxiosRequestConfig} from 'axios';

This comment was marked as spam.

This comment was marked as spam.

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.

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.

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.

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.


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.

@JustinBeckwith JustinBeckwith merged commit 98b2b1a into googleapis:next Nov 24, 2017
ofrobots pushed a commit to ofrobots/google-auth-library-nodejs that referenced this pull request Dec 1, 2017
ofrobots pushed a commit that referenced this pull request Jan 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants