add option use-base64 for encoded key

This commit is contained in:
Li Sheng 2023-09-15 15:27:39 +02:00
parent d4b9b8ff72
commit 4f7ffe435c
2 changed files with 14 additions and 2 deletions

8
dist/index.js vendored
View file

@ -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" });
});

View file

@ -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" });
});