From c31b1e4544f36292a3fa3deb356f9eaaa982f4de Mon Sep 17 00:00:00 2001 From: shimataro Date: Mon, 8 Mar 2021 20:27:45 +0900 Subject: [PATCH] use `known_hosts: no` instead of `no_known_hosts: true` --- .../workflows/verify-on-container-centos.yml | 2 +- .../workflows/verify-on-container-ubuntu.yml | 2 +- .github/workflows/verify-on-macos.yml | 2 +- .github/workflows/verify-on-ubuntu.yml | 2 +- .github/workflows/verify-on-windows.yml | 2 +- action.yml | 6 +--- lib/index.js | 26 ++------------- src/main.ts | 32 ++----------------- 8 files changed, 10 insertions(+), 64 deletions(-) diff --git a/.github/workflows/verify-on-container-centos.yml b/.github/workflows/verify-on-container-centos.yml index 547a997..b576325 100644 --- a/.github/workflows/verify-on-container-centos.yml +++ b/.github/workflows/verify-on-container-centos.yml @@ -317,6 +317,6 @@ jobs: uses: ./. with: key: ${{ secrets.SSH_KEY_PEM }} - no_known_hosts: true + known_hosts: no - name: print created files run: ls -l /root/.ssh diff --git a/.github/workflows/verify-on-container-ubuntu.yml b/.github/workflows/verify-on-container-ubuntu.yml index af30c3a..fe9051e 100644 --- a/.github/workflows/verify-on-container-ubuntu.yml +++ b/.github/workflows/verify-on-container-ubuntu.yml @@ -337,6 +337,6 @@ jobs: uses: ./. with: key: ${{ secrets.SSH_KEY_PEM }} - no_known_hosts: true + known_hosts: no - name: print created files run: ls -l /root/.ssh diff --git a/.github/workflows/verify-on-macos.yml b/.github/workflows/verify-on-macos.yml index 5e8aabf..c1bb2f8 100644 --- a/.github/workflows/verify-on-macos.yml +++ b/.github/workflows/verify-on-macos.yml @@ -255,6 +255,6 @@ jobs: uses: ./. with: key: ${{ secrets.SSH_KEY_PEM }} - no_known_hosts: true + known_hosts: no - name: print created files run: ls -l ~/.ssh diff --git a/.github/workflows/verify-on-ubuntu.yml b/.github/workflows/verify-on-ubuntu.yml index 28aab71..4999d0e 100644 --- a/.github/workflows/verify-on-ubuntu.yml +++ b/.github/workflows/verify-on-ubuntu.yml @@ -275,6 +275,6 @@ jobs: uses: ./. with: key: ${{ secrets.SSH_KEY_PEM }} - no_known_hosts: true + known_hosts: no - name: print created files run: ls -l ~/.ssh diff --git a/.github/workflows/verify-on-windows.yml b/.github/workflows/verify-on-windows.yml index 328c932..532b123 100644 --- a/.github/workflows/verify-on-windows.yml +++ b/.github/workflows/verify-on-windows.yml @@ -255,6 +255,6 @@ jobs: uses: ./. with: key: ${{ secrets.SSH_KEY_PEM }} - no_known_hosts: true + known_hosts: no - name: print created files run: ls -l ~/.ssh diff --git a/action.yml b/action.yml index 6608df2..d7f469e 100644 --- a/action.yml +++ b/action.yml @@ -14,7 +14,7 @@ inputs: required: false default: "id_rsa" known_hosts: - description: "public keys of SSH servers" + description: "public keys of SSH servers, or set to 'no' in order to omit it" required: true default: "" config: @@ -25,10 +25,6 @@ inputs: description: "replace / ignore / fail" required: false default: "fail" - no_known_hosts: - description: "enables not providing known_hosts file" - required: false - default: "0" runs: using: "node12" main: "lib/index.js" diff --git a/lib/index.js b/lib/index.js index 3b1f766..0c373cc 100644 --- a/lib/index.js +++ b/lib/index.js @@ -428,13 +428,12 @@ const core = __importStar(__nccwpck_require__(186)); function main() { try { // parameters - const noKnownHosts = string2boolean(core.getInput("no_known_hosts")); const key = core.getInput("key", { required: true, }); const name = core.getInput("name"); const knownHosts = core.getInput("known_hosts", { - required: !noKnownHosts, // optional if no_known_hosts is true + required: true, }); const config = core.getInput("config"); const ifKeyExists = core.getInput("if_key_exists"); @@ -457,7 +456,7 @@ function main() { }, }); } - if (knownHosts !== "") { + if (knownHosts !== "no") { files.push({ name: "known_hosts", contents: insertLf(knownHosts, true, true), @@ -488,27 +487,6 @@ function main() { core.setFailed(err.message); } } -/** - * convert string to boolean - * @param value string value - * @returns boolean value - */ -function string2boolean(value) { - // true if "true" / "yes" / "on" - switch (value.trim().toLowerCase()) { - case "true": - case "yes": - case "on": - return true; - } - // true if number and non-zero - const numberValue = Number(value); - if (!isNaN(numberValue) && numberValue !== 0) { - return true; - } - // false otherwise - return false; -} /** * get home directory * @returns home directory diff --git a/src/main.ts b/src/main.ts index c040087..b778e0c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,13 +18,12 @@ function main(): void try { // parameters - const noKnownHosts = string2boolean(core.getInput("no_known_hosts")); const key = core.getInput("key", { required: true, }); const name = core.getInput("name"); const knownHosts = core.getInput("known_hosts", { - required: !noKnownHosts, // optional if no_known_hosts is true + required: true, }); const config = core.getInput("config"); const ifKeyExists = core.getInput("if_key_exists"); @@ -50,7 +49,7 @@ function main(): void }, }); } - if(knownHosts !== "") + if(knownHosts !== "no") { files.push({ name: "known_hosts", @@ -88,33 +87,6 @@ function main(): void } } -/** - * convert string to boolean - * @param value string value - * @returns boolean value - */ -function string2boolean(value: string): boolean -{ - // true if "true" / "yes" / "on" - switch(value.trim().toLowerCase()) - { - case "true": - case "yes": - case "on": - return true; - } - - // true if number and non-zero - const numberValue = Number(value); - if(!isNaN(numberValue) && numberValue !== 0) - { - return true; - } - - // false otherwise - return false; -} - /** * get home directory * @returns home directory