@probot/get-private-key
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -1,82 +0,94 @@ | ||
'use strict'; | ||
"use strict"; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
// pkg/dist-src/index.js | ||
var dist_src_exports = {}; | ||
__export(dist_src_exports, { | ||
getPrivateKey: () => getPrivateKey | ||
}); | ||
module.exports = __toCommonJS(dist_src_exports); | ||
var import_path = require("path"); | ||
var import_fs = require("fs"); | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
// pkg/dist-src/version.js | ||
var VERSION = "1.1.2"; | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var isBase64 = _interopDefault(require('is-base64')); | ||
const VERSION = "0.0.0-development"; | ||
const begin = "-----BEGIN RSA PRIVATE KEY-----"; | ||
const end = "-----END RSA PRIVATE KEY-----"; | ||
// pkg/dist-src/index.js | ||
var begin = "-----BEGIN RSA PRIVATE KEY-----"; | ||
var end = "-----END RSA PRIVATE KEY-----"; | ||
function getPrivateKey(options = {}) { | ||
const env = options.env || process.env; | ||
const cwd = options.cwd || process.cwd(); | ||
if (options.filepath) { | ||
return fs.readFileSync(path.resolve(cwd, options.filepath), "utf-8"); | ||
return (0, import_fs.readFileSync)((0, import_path.resolve)(cwd, options.filepath), "utf-8"); | ||
} | ||
if (env.PRIVATE_KEY) { | ||
let privateKey = env.PRIVATE_KEY; | ||
if (isBase64(privateKey)) { | ||
// Decode base64-encoded certificate | ||
privateKey = Buffer.from(privateKey, "base64").toString(); | ||
} | ||
if (privateKey.includes(begin) && privateKey.includes(end)) { | ||
// newlines are escaped | ||
if (privateKey.indexOf("\\n") !== -1) { | ||
privateKey = privateKey.replace(/\\n/g, "\n"); | ||
} // newlines are missing | ||
} | ||
if (privateKey.indexOf("\n") === -1) { | ||
privateKey = addNewlines(privateKey); | ||
} | ||
return privateKey; | ||
} | ||
throw new Error(`[@probot/get-private-key] The contents of "env.PRIVATE_KEY" could not be validated. Please check to ensure you have copied the contents of the .pem file correctly.`); | ||
throw new Error( | ||
`[@probot/get-private-key] The contents of "env.PRIVATE_KEY" could not be validated. Please check to ensure you have copied the contents of the .pem file correctly.` | ||
); | ||
} | ||
if (env.PRIVATE_KEY_PATH) { | ||
const filepath = path.resolve(cwd, env.PRIVATE_KEY_PATH); | ||
if (fs.existsSync(filepath)) { | ||
return fs.readFileSync(filepath, "utf-8"); | ||
const filepath = (0, import_path.resolve)(cwd, env.PRIVATE_KEY_PATH); | ||
if ((0, import_fs.existsSync)(filepath)) { | ||
return (0, import_fs.readFileSync)(filepath, "utf-8"); | ||
} else { | ||
throw new Error(`[@probot/get-private-key] Private key does not exists at path: "${env.PRIVATE_KEY_PATH}". Please check to ensure that "env.PRIVATE_KEY_PATH" is correct.`); | ||
throw new Error( | ||
`[@probot/get-private-key] Private key does not exists at path: "${env.PRIVATE_KEY_PATH}". Please check to ensure that "env.PRIVATE_KEY_PATH" is correct.` | ||
); | ||
} | ||
} | ||
const pemFiles = fs.readdirSync(cwd).filter(path => path.endsWith(".pem")); | ||
const pemFiles = (0, import_fs.readdirSync)(cwd).filter((path) => path.endsWith(".pem")); | ||
if (pemFiles.length > 1) { | ||
const paths = pemFiles.join(", "); | ||
throw new Error(`[@probot/get-private-key] More than one file found: "${paths}". Set { filepath } option or set one of the environment variables: PRIVATE_KEY, PRIVATE_KEY_PATH`); | ||
throw new Error( | ||
`[@probot/get-private-key] More than one file found: "${paths}". Set { filepath } option or set one of the environment variables: PRIVATE_KEY, PRIVATE_KEY_PATH` | ||
); | ||
} else if (pemFiles[0]) { | ||
return getPrivateKey({ | ||
filepath: pemFiles[0], | ||
cwd | ||
}); | ||
return getPrivateKey({ filepath: pemFiles[0], cwd }); | ||
} | ||
return null; | ||
} | ||
function isBase64(str) { | ||
return Buffer.from(str, "base64").toString("base64") === str; | ||
} | ||
function addNewlines(privateKey) { | ||
const middleLength = privateKey.length - begin.length - end.length - 2; | ||
const middle = privateKey.substr(begin.length + 1, middleLength); | ||
return `${begin}\n${middle.trim().replace(/\s+/g, "\n")}\n${end}`; | ||
return `${begin} | ||
${middle.trim().replace(/\s+/g, "\n")} | ||
${end}`; | ||
} | ||
getPrivateKey.VERSION = VERSION; | ||
exports.getPrivateKey = getPrivateKey; | ||
//# sourceMappingURL=index.js.map | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
getPrivateKey | ||
}); |
import { resolve } from "path"; | ||
import { existsSync, readdirSync, readFileSync } from "fs"; | ||
import isBase64 from "is-base64"; | ||
import { VERSION } from "./version"; | ||
const begin = "-----BEGIN RSA PRIVATE KEY-----"; | ||
const end = "-----END RSA PRIVATE KEY-----"; | ||
export function getPrivateKey(options = {}) { | ||
const env = options.env || process.env; | ||
const cwd = options.cwd || process.cwd(); | ||
if (options.filepath) { | ||
return readFileSync(resolve(cwd, options.filepath), "utf-8"); | ||
function getPrivateKey(options = {}) { | ||
const env = options.env || process.env; | ||
const cwd = options.cwd || process.cwd(); | ||
if (options.filepath) { | ||
return readFileSync(resolve(cwd, options.filepath), "utf-8"); | ||
} | ||
if (env.PRIVATE_KEY) { | ||
let privateKey = env.PRIVATE_KEY; | ||
if (isBase64(privateKey)) { | ||
privateKey = Buffer.from(privateKey, "base64").toString(); | ||
} | ||
if (env.PRIVATE_KEY) { | ||
let privateKey = env.PRIVATE_KEY; | ||
if (isBase64(privateKey)) { | ||
// Decode base64-encoded certificate | ||
privateKey = Buffer.from(privateKey, "base64").toString(); | ||
} | ||
if (privateKey.includes(begin) && privateKey.includes(end)) { | ||
// newlines are escaped | ||
if (privateKey.indexOf("\\n") !== -1) { | ||
privateKey = privateKey.replace(/\\n/g, "\n"); | ||
} | ||
// newlines are missing | ||
if (privateKey.indexOf("\n") === -1) { | ||
privateKey = addNewlines(privateKey); | ||
} | ||
return privateKey; | ||
} | ||
throw new Error(`[@probot/get-private-key] The contents of "env.PRIVATE_KEY" could not be validated. Please check to ensure you have copied the contents of the .pem file correctly.`); | ||
if (privateKey.includes(begin) && privateKey.includes(end)) { | ||
if (privateKey.indexOf("\\n") !== -1) { | ||
privateKey = privateKey.replace(/\\n/g, "\n"); | ||
} | ||
if (privateKey.indexOf("\n") === -1) { | ||
privateKey = addNewlines(privateKey); | ||
} | ||
return privateKey; | ||
} | ||
if (env.PRIVATE_KEY_PATH) { | ||
const filepath = resolve(cwd, env.PRIVATE_KEY_PATH); | ||
if (existsSync(filepath)) { | ||
return readFileSync(filepath, "utf-8"); | ||
} | ||
else { | ||
throw new Error(`[@probot/get-private-key] Private key does not exists at path: "${env.PRIVATE_KEY_PATH}". Please check to ensure that "env.PRIVATE_KEY_PATH" is correct.`); | ||
} | ||
throw new Error( | ||
`[@probot/get-private-key] The contents of "env.PRIVATE_KEY" could not be validated. Please check to ensure you have copied the contents of the .pem file correctly.` | ||
); | ||
} | ||
if (env.PRIVATE_KEY_PATH) { | ||
const filepath = resolve(cwd, env.PRIVATE_KEY_PATH); | ||
if (existsSync(filepath)) { | ||
return readFileSync(filepath, "utf-8"); | ||
} else { | ||
throw new Error( | ||
`[@probot/get-private-key] Private key does not exists at path: "${env.PRIVATE_KEY_PATH}". Please check to ensure that "env.PRIVATE_KEY_PATH" is correct.` | ||
); | ||
} | ||
const pemFiles = readdirSync(cwd).filter((path) => path.endsWith(".pem")); | ||
if (pemFiles.length > 1) { | ||
const paths = pemFiles.join(", "); | ||
throw new Error(`[@probot/get-private-key] More than one file found: "${paths}". Set { filepath } option or set one of the environment variables: PRIVATE_KEY, PRIVATE_KEY_PATH`); | ||
} | ||
else if (pemFiles[0]) { | ||
return getPrivateKey({ filepath: pemFiles[0], cwd }); | ||
} | ||
return null; | ||
} | ||
const pemFiles = readdirSync(cwd).filter((path) => path.endsWith(".pem")); | ||
if (pemFiles.length > 1) { | ||
const paths = pemFiles.join(", "); | ||
throw new Error( | ||
`[@probot/get-private-key] More than one file found: "${paths}". Set { filepath } option or set one of the environment variables: PRIVATE_KEY, PRIVATE_KEY_PATH` | ||
); | ||
} else if (pemFiles[0]) { | ||
return getPrivateKey({ filepath: pemFiles[0], cwd }); | ||
} | ||
return null; | ||
} | ||
function isBase64(str) { | ||
return Buffer.from(str, "base64").toString("base64") === str; | ||
} | ||
function addNewlines(privateKey) { | ||
const middleLength = privateKey.length - begin.length - end.length - 2; | ||
const middle = privateKey.substr(begin.length + 1, middleLength); | ||
return `${begin}\n${middle.trim().replace(/\s+/g, "\n")}\n${end}`; | ||
const middleLength = privateKey.length - begin.length - end.length - 2; | ||
const middle = privateKey.substr(begin.length + 1, middleLength); | ||
return `${begin} | ||
${middle.trim().replace(/\s+/g, "\n")} | ||
${end}`; | ||
} | ||
getPrivateKey.VERSION = VERSION; | ||
export { | ||
getPrivateKey | ||
}; |
@@ -1,1 +0,4 @@ | ||
export const VERSION = "0.0.0-development"; | ||
const VERSION = "1.1.2"; | ||
export { | ||
VERSION | ||
}; |
@@ -1,2 +0,2 @@ | ||
declare type Options = { | ||
type Options = { | ||
filepath?: string; | ||
@@ -3,0 +3,0 @@ env?: { |
@@ -1,1 +0,1 @@ | ||
export declare const VERSION = "0.0.0-development"; | ||
export declare const VERSION = "1.1.2"; |
{ | ||
"name": "@probot/get-private-key", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"version": "1.1.2", | ||
"description": "Get private key from a path, environment variables, or a `*.pem` file in the current working directory", | ||
"version": "1.1.1", | ||
"license": "ISC", | ||
"files": [ | ||
"dist-*/", | ||
"bin/" | ||
], | ||
"pika": true, | ||
"sideEffects": false, | ||
"main": "dist-node/index.js", | ||
"repository": "github:probot/get-private-key", | ||
"keywords": [ | ||
@@ -16,27 +14,24 @@ "github-app", | ||
], | ||
"repository": "github:probot/get-private-key", | ||
"dependencies": { | ||
"@types/is-base64": "^1.1.0", | ||
"is-base64": "^1.1.0" | ||
}, | ||
"author": "Gregor Martynus (https://twitter.com/gr2m)", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@pika/pack": "^0.5.0", | ||
"@pika/plugin-build-node": "^0.9.0", | ||
"@pika/plugin-build-web": "^0.9.0", | ||
"@pika/plugin-ts-standard-pkg": "^0.9.0", | ||
"@tsconfig/node12": "^1.0.7", | ||
"@types/jest": "^26.0.0", | ||
"jest": "^26.0.1", | ||
"@octokit/tsconfig": "^2.0.0", | ||
"@types/jest": "^29.0.0", | ||
"esbuild": "^0.19.4", | ||
"glob": "^10.3.10", | ||
"jest": "^29.0.0", | ||
"prettier": "^2.1.2", | ||
"semantic-release": "^17.0.0", | ||
"semantic-release": "^22.0.5", | ||
"semantic-release-plugin-update-version-in-files": "^1.0.0", | ||
"ts-jest": "^26.0.0", | ||
"typescript": "^4.0.5" | ||
"ts-jest": "^29.0.0", | ||
"typescript": "^5.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"files": [ | ||
"dist-*/**", | ||
"bin/**" | ||
], | ||
"module": "dist-web/index.js", | ||
"types": "dist-types/index.d.ts", | ||
"source": "dist-src/index.js", | ||
"types": "dist-types/index.d.ts", | ||
"main": "dist-node/index.js" | ||
"sideEffects": false | ||
} |
@@ -30,3 +30,3 @@ # @probot/get-private-key | ||
Install with <code>npm install octokit-auth-probot</code> | ||
Install with <code>npm install @probot/get-private-key</code> | ||
@@ -33,0 +33,0 @@ ```js |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
21239
0
10
11
241
0
6
1
- Removed@types/is-base64@^1.1.0
- Removedis-base64@^1.1.0
- Removed@types/is-base64@1.1.3(transitive)
- Removedis-base64@1.1.0(transitive)