Skip to content

Commit

Permalink
fix: move to axios
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Zuev committed Dec 24, 2021
1 parent 3d3a6f2 commit 438f7c6
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 122 deletions.
10 changes: 0 additions & 10 deletions config/jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ import * as path from 'path';
* https://jestjs.io/docs/configuration
*/

const modulesToTransform = [
'node-fetch',
'fetch-blob',
'data-uri-to-buffer',
'formdata-polyfill',
];

export default {
moduleFileExtensions: [
'js',
Expand All @@ -22,7 +15,4 @@ export default {
transform: {
'^.+\\.[tj]s$': 'ts-jest',
},
transformIgnorePatterns: [
`node_modules/(?!(${modulesToTransform.join('|')})/.*)`,
],
};
143 changes: 41 additions & 102 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
"homepage": "https://github.com/yandex-cloud/nodejs-sdk#readme",
"dependencies": {
"@grpc/grpc-js": "https://gitpkg.now.sh/DavyJohnes/grpc-node/packages/grpc-js?fix-class-options-issue-with-dist",
"axios": "^0.24.0",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"log4js": "^6.3.0",
"luxon": "^2.2.0",
"nice-grpc": "^1.0.4",
"nice-grpc-client-middleware-deadline": "^1.0.4",
"node-fetch": "^3.1.0",
"protobufjs": "^6.8.8",
"utility-types": "^3.10.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/token-service/iam-token-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { credentials, Metadata } from '@grpc/grpc-js';
import { credentials } from '@grpc/grpc-js';
import * as jwt from 'jsonwebtoken';
import { DateTime } from 'luxon';
import { createChannel } from 'nice-grpc';
Expand Down
11 changes: 5 additions & 6 deletions src/token-service/metadata-token-service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fetch, { RequestInit } from 'node-fetch';
import axios, { AxiosRequestConfig } from 'axios';

import { TokenService } from '../types';

type Options = RequestInit;
type Options = AxiosRequestConfig;

const DEFAULT_URL = 'http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token';
const DEFAULT_OPTIONS: Options = {
Expand Down Expand Up @@ -36,14 +36,13 @@ export class MetadataTokenService implements TokenService {
}

private async fetchToken(): Promise<string> {
const res = await fetch(this.url, this.opts);
const res = await axios.get<{ access_token: string }>(this.url, this.opts);

if (!res.ok) {
if (res.status !== 200) {
throw new Error(`failed to fetch token from metadata service: ${res.status} ${res.statusText}`);
}
const data = (await res.json()) as { access_token: string };

return data.access_token;
return res.data.access_token;
}

private async initialize() {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.eslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"include": [
"./src",
"./config",
"./scripts"
"./scripts",
"./examples"
]
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true
"resolveJsonModule": true,
"lib": ["es6"]
},
"include": [
"./src"
Expand Down

0 comments on commit 438f7c6

Please sign in to comment.