diff --git a/dist/index.js b/dist/index.js index 2c23f23..a972acd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -342,6 +342,7 @@ const { homePath, sshAgentCmdDefault, sshAddCmdDefault, gitCmdDefault } = __webp try { const privateKey = core.getInput('ssh-private-key'); + const useBase64 = core.getInput('use-base64'); const logPublicKey = core.getBooleanInput('log-public-key', {default: true}); const sshAgentCmdInput = core.getInput('ssh-agent-cmd'); @@ -379,7 +380,12 @@ try { console.log("Adding private key(s) to agent"); - privateKey.split(/(?=-----BEGIN)/).forEach(function(key) { + let decodedPrivateKey = privateKey; + // base64 decode privateKey + if (useBase64 === 'true') { + decodedPrivateKey = Buffer.from(privateKey, 'base64').toString('utf8'); + } + decodedPrivateKey.split(/(?=-----BEGIN)/).forEach(function(key) { child_process.execFileSync(sshAddCmd, ['-'], { input: key.trim() + "\n" }); }); diff --git a/index.js b/index.js index 0c2e08b..3efbb05 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ const { homePath, sshAgentCmdDefault, sshAddCmdDefault, gitCmdDefault } = requir try { const privateKey = core.getInput('ssh-private-key'); + const useBase64 = core.getInput('use-base64'); const logPublicKey = core.getBooleanInput('log-public-key', {default: true}); const sshAgentCmdInput = core.getInput('ssh-agent-cmd'); @@ -43,7 +44,12 @@ try { console.log("Adding private key(s) to agent"); - privateKey.split(/(?=-----BEGIN)/).forEach(function(key) { + let decodedPrivateKey = privateKey; + // base64 decode privateKey + if (useBase64 === 'true') { + decodedPrivateKey = Buffer.from(privateKey, 'base64').toString('utf8'); + } + decodedPrivateKey.split(/(?=-----BEGIN)/).forEach(function(key) { child_process.execFileSync(sshAddCmd, ['-'], { input: key.trim() + "\n" }); });