Skip to content

Commit

Permalink
fix(deps): remove dependency on mime (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Jan 26, 2021
1 parent 69e06d7 commit 0a1e6b3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,15 @@
"dependencies": {
"gaxios": "^4.0.0",
"google-p12-pem": "^3.0.3",
"jws": "^4.0.0",
"mime": "^2.2.0"
"jws": "^4.0.0"
},
"devDependencies": {
"@compodoc/compodoc": "^1.1.7",
"@types/jws": "^3.1.0",
"@types/mime": "^2.0.0",
"@types/mocha": "^8.0.0",
"@types/nock": "^10.0.0",
"@types/node": "^10.0.3",
"c8": "^7.0.0",
"codecov": "^3.0.2",
"gts": "^3.0.0",
"js-green-licenses": "^2.0.0",
"linkinator": "^2.0.0",
"mocha": "^8.0.0",
"nock": "^13.0.0",
Expand Down
1 change: 0 additions & 1 deletion repo-debug.log

This file was deleted.

18 changes: 9 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import * as fs from 'fs';
import {request} from 'gaxios';
import * as jws from 'jws';
import * as mime from 'mime';
import * as path from 'path';
import {promisify} from 'util';

const readFile = fs.readFile
Expand Down Expand Up @@ -168,10 +168,9 @@ export class GoogleToken {
* @returns an object with privateKey and clientEmail properties
*/
async getCredentials(keyFile: string): Promise<Credentials> {
const mimeType = mime.getType(keyFile);
switch (mimeType) {
case 'application/json': {
// *.json file
const ext = path.extname(keyFile);
switch (ext) {
case '.json': {
const key = await readFile(keyFile, 'utf8');
const body = JSON.parse(key);
const privateKey = body.private_key;
Expand All @@ -184,13 +183,14 @@ export class GoogleToken {
}
return {privateKey, clientEmail};
}
case 'application/x-x509-ca-cert': {
// *.pem file
case '.der':
case '.crt':
case '.pem': {
const privateKey = await readFile(keyFile, 'utf8');
return {privateKey};
}
case 'application/x-pkcs12': {
// *.p12 file
case '.p12':
case '.pfx': {
// NOTE: The loading of `google-p12-pem` is deferred for performance
// reasons. The `node-forge` npm module in `google-p12-pem` adds a fair
// bit time to overall module loading, and is likely not frequently
Expand Down

0 comments on commit 0a1e6b3

Please sign in to comment.