@probot/get-private-key
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -13,2 +13,4 @@ 'use strict'; | ||
const begin = "-----BEGIN RSA PRIVATE KEY-----"; | ||
const end = "-----END RSA PRIVATE KEY-----"; | ||
function getPrivateKey(options = {}) { | ||
@@ -30,8 +32,14 @@ const env = options.env || process.env; | ||
const begin = "-----BEGIN RSA PRIVATE KEY-----"; | ||
const end = "-----END RSA PRIVATE KEY-----"; | ||
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.includes(begin) && privateKey.includes(end)) { | ||
// Full key with new lines | ||
return privateKey.replace(/\\n/g, "\n"); | ||
if (privateKey.indexOf("\n") === -1) { | ||
privateKey = addNewlines(privateKey); | ||
} | ||
return privateKey; | ||
} | ||
@@ -66,2 +74,9 @@ | ||
} | ||
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}`; | ||
} | ||
getPrivateKey.VERSION = VERSION; | ||
@@ -68,0 +83,0 @@ |
@@ -5,2 +5,4 @@ import { resolve } from "path"; | ||
import { VERSION } from "./version"; | ||
const begin = "-----BEGIN RSA PRIVATE KEY-----"; | ||
const end = "-----END RSA PRIVATE KEY-----"; | ||
export function getPrivateKey(options = {}) { | ||
@@ -18,7 +20,12 @@ const env = options.env || process.env; | ||
} | ||
const begin = "-----BEGIN RSA PRIVATE KEY-----"; | ||
const end = "-----END RSA PRIVATE KEY-----"; | ||
if (privateKey.includes(begin) && privateKey.includes(end)) { | ||
// Full key with new lines | ||
return privateKey.replace(/\\n/g, "\n"); | ||
// 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; | ||
} | ||
@@ -46,2 +53,7 @@ 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.`); | ||
} | ||
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}`; | ||
} | ||
getPrivateKey.VERSION = VERSION; |
{ | ||
"name": "@probot/get-private-key", | ||
"description": "Get private key from a path, environment variables, or a `*.pem` file in the current working directory", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"license": "ISC", | ||
@@ -16,3 +16,3 @@ "files": [ | ||
], | ||
"repository": "https://github.com/probot/get-private-key", | ||
"repository": "github:probot/get-private-key", | ||
"dependencies": { | ||
@@ -19,0 +19,0 @@ "@types/is-base64": "^1.1.0", |
Sorry, the diff of this file is not supported yet
15347
133