From ad4e7856eff67986923dce5c774dbabfba628bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Chantre?= Date: Sat, 1 May 2021 11:32:31 +0200 Subject: [PATCH] Add ssh-config input (#11) Closes #10 --- README.md | 5 ++++- action.yaml | 4 ++++ index.js | 13 +++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2c452b6..6c0eb97 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,15 @@ with: private-key: ${{ secrets.PRIVATE_KEY }} known-hosts: ${{ secrets.KNOWN_HOSTS }} + ssh-config: ${{ secrets.SSH_CONFIG }} dep: deploy prod -v ``` ## Inputs - `private-key` - Required. A private key to accessing servers. -- `known-hosts` - Optional. Host fingerprints. If omitted `StrictHostKeyChecking=no` will be used. +- `known-hosts` - Optional. Host fingerprints. If omitted `StrictHostKeyChecking=no` will be used unless `ssh-config` is provided. +- `ssh-config` - Optional. SSH configuration. - `dep` - Required. Arguments to pass to Deployer command. ## Deployer version @@ -41,5 +43,6 @@ deploy: with: private-key: ${{ secrets.PRIVATE_KEY }} known-hosts: ${{ secrets.KNOWN_HOSTS }} + ssh-config: ${{ secrets.SSH_CONFIG }} dep: deploy prod -v ``` diff --git a/action.yaml b/action.yaml index d2ed6e1..5427806 100644 --- a/action.yaml +++ b/action.yaml @@ -8,6 +8,10 @@ inputs: description: 'Known hosts' required: false default: '' + ssh-config: + description: 'SSH configuration' + required: false + default: '' dep: description: 'Deployer command' required: false diff --git a/index.js b/index.js index 6c503a6..2629224 100644 --- a/index.js +++ b/index.js @@ -26,12 +26,17 @@ function ssh() { let privateKey = core.getInput('private-key').replace('/\r/g', '').trim() + '\n' execa.sync('ssh-add', ['-'], {input: privateKey}) - let knownHosts = core.getInput('known-hosts') - if (knownHosts === '') { - fs.appendFileSync(`${ssh}/config`, `StrictHostKeyChecking no`) - } else { + const knownHosts = core.getInput('known-hosts') + if (knownHosts !== '') { fs.appendFileSync(`${ssh}/known_hosts`, knownHosts) fs.chmodSync(`${ssh}/known_hosts`, '644') + } else { + fs.appendFileSync(`${ssh}/config`, `StrictHostKeyChecking no`) + } + + const sshConfig = core.getInput('ssh-config') + if (sshConfig !== '') { + fs.writeFile(`${ssh}/config`, sshConfig) } }