From 4fe684463817900b4e8b6380f5631a3e6eb6cecd Mon Sep 17 00:00:00 2001 From: SamKirkland Date: Sun, 30 Aug 2020 00:05:41 -0500 Subject: [PATCH] more optional props --- README.md | 1 + dist/index.js | 41 +++++++++++++++++++++++++++++----------- src/main.ts | 52 ++++++++++++++++++++++++++++++++++++--------------- 3 files changed, 68 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 4150e56..5d9c36b 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ I strongly recommend you store your `password` as a secret. | `include` | No | | `` | :warning: not implemented yet - An array of glob patterns, these files will always be included in the publish/delete process - even if no change occurred | | `exclude` | No | | `.git*` `.git*/**` `node_modules/**` `node_modules/**/*` | An array of glob patterns, these files will not be included in the publish/delete process | | `log-level` | No | `info` | `info` | `warn`: only important/warning info, `info`: default, log important/warning info & progress info, `debug`: log everything for debugging | +| `security` | No | `strict` | `loose` | `strict`: Reject any connection which is not authorized with the list of supplied CAs. `loose`: Allow connection even when the domain is not certificate | # Common Examples diff --git a/dist/index.js b/dist/index.js index 33a7819..4ae2078 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6803,14 +6803,15 @@ async function runDeployment() { password: core.getInput("password", { required: true }), protocol: optionalProtocol("protocol", core.getInput("protocol")), port: optionalInt("port", core.getInput("port")), - "local-dir": core.getInput("local-dir"), - "server-dir": core.getInput("server-dir"), - "state-name": core.getInput("state-name"), + "local-dir": optionalString(core.getInput("local-dir")), + "server-dir": optionalString(core.getInput("server-dir")), + "state-name": optionalString(core.getInput("state-name")), "dry-run": optionalBoolean("dry-run", core.getInput("dry-run")), "dangerous-clean-slate": optionalBoolean("dangerous-clean-slate", core.getInput("dangerous-clean-slate")), "include": optionalStringArray("include", core.getInput("include")), "exclude": optionalStringArray("exclude", core.getInput("exclude")), - "log-level": optionalLogLevel("log-level", core.getInput("log-level")) + "log-level": optionalLogLevel("log-level", core.getInput("log-level")), + "security": optionalSecurity("security", core.getInput("security")) }; try { await ftp_deploy_1.deploy(args); @@ -6820,8 +6821,14 @@ async function runDeployment() { } } runDeployment(); +function optionalString(rawValue) { + if (rawValue.length === 0) { + return undefined; + } + return rawValue; +} function optionalBoolean(argumentName, rawValue) { - if (rawValue === undefined) { + if (rawValue.length === 0) { return undefined; } const cleanValue = rawValue.toLowerCase(); @@ -6834,7 +6841,7 @@ function optionalBoolean(argumentName, rawValue) { core.setFailed(`${argumentName}: invalid parameter - please use a boolean, you provided "${rawValue}". Try true or false instead.`); } function optionalProtocol(argumentName, rawValue) { - if (rawValue === undefined) { + if (rawValue.length === 0) { return undefined; } const cleanValue = rawValue.toLowerCase(); @@ -6850,7 +6857,7 @@ function optionalProtocol(argumentName, rawValue) { core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "ftp", "ftps", or "ftps-legacy" instead.`); } function optionalLogLevel(argumentName, rawValue) { - if (rawValue === undefined) { + if (rawValue.length === 0) { return undefined; } const cleanValue = rawValue.toLowerCase(); @@ -6865,19 +6872,31 @@ function optionalLogLevel(argumentName, rawValue) { } core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "warn", "info", or "debug" instead.`); } -function optionalInt(argumentName, rawValue) { - if (rawValue === undefined) { +function optionalSecurity(argumentName, rawValue) { + if (rawValue.length === 0) { return undefined; } const cleanValue = rawValue.toLowerCase(); - const valueAsNumber = parseFloat(cleanValue); + if (cleanValue === "loose") { + return "loose"; + } + if (cleanValue === "strict") { + return "strict"; + } + core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "loose" or "strict" instead.`); +} +function optionalInt(argumentName, rawValue) { + if (rawValue.length === 0) { + return undefined; + } + const valueAsNumber = parseFloat(rawValue); if (Number.isInteger(valueAsNumber)) { return valueAsNumber; } core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try a whole number (no decimals) instead like 1234`); } function optionalStringArray(argumentName, rawValue) { - if (rawValue === undefined) { + if (rawValue.length === 0) { return undefined; } // split value by space and comma diff --git a/src/main.ts b/src/main.ts index d75c034..83bb746 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,14 +9,15 @@ async function runDeployment() { password: core.getInput("password", { required: true }), protocol: optionalProtocol("protocol", core.getInput("protocol")), port: optionalInt("port", core.getInput("port")), - "local-dir": core.getInput("local-dir"), - "server-dir": core.getInput("server-dir"), - "state-name": core.getInput("state-name"), + "local-dir": optionalString(core.getInput("local-dir")), + "server-dir": optionalString(core.getInput("server-dir")), + "state-name": optionalString(core.getInput("state-name")), "dry-run": optionalBoolean("dry-run", core.getInput("dry-run")), "dangerous-clean-slate": optionalBoolean("dangerous-clean-slate", core.getInput("dangerous-clean-slate")), "include": optionalStringArray("include", core.getInput("include")), "exclude": optionalStringArray("exclude", core.getInput("exclude")), - "log-level": optionalLogLevel("log-level", core.getInput("log-level")) + "log-level": optionalLogLevel("log-level", core.getInput("log-level")), + "security": optionalSecurity("security", core.getInput("security")) }; @@ -36,10 +37,16 @@ runDeployment(); +function optionalString(rawValue: string): string | undefined { + if (rawValue.length === 0) { + return undefined; + } + return rawValue; +} -function optionalBoolean(argumentName: string, rawValue: string | undefined): boolean | undefined { - if (rawValue === undefined) { +function optionalBoolean(argumentName: string, rawValue: string): boolean | undefined { + if (rawValue.length === 0) { return undefined; } @@ -54,8 +61,8 @@ function optionalBoolean(argumentName: string, rawValue: string | undefined): bo core.setFailed(`${argumentName}: invalid parameter - please use a boolean, you provided "${rawValue}". Try true or false instead.`); } -function optionalProtocol(argumentName: string, rawValue: string | undefined): "ftp" | "ftps" | "ftps-legacy" | undefined { - if (rawValue === undefined) { +function optionalProtocol(argumentName: string, rawValue: string): "ftp" | "ftps" | "ftps-legacy" | undefined { + if (rawValue.length === 0) { return undefined; } @@ -73,8 +80,8 @@ function optionalProtocol(argumentName: string, rawValue: string | undefined): " core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "ftp", "ftps", or "ftps-legacy" instead.`); } -function optionalLogLevel(argumentName: string, rawValue: string | undefined): "warn" | "info" | "debug" | undefined { - if (rawValue === undefined) { +function optionalLogLevel(argumentName: string, rawValue: string): "warn" | "info" | "debug" | undefined { + if (rawValue.length === 0) { return undefined; } @@ -92,13 +99,28 @@ function optionalLogLevel(argumentName: string, rawValue: string | undefined): " core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "warn", "info", or "debug" instead.`); } -function optionalInt(argumentName: string, rawValue: string | undefined): number | undefined { - if (rawValue === undefined) { +function optionalSecurity(argumentName: string, rawValue: string): "loose" | "strict" | undefined { + if (rawValue.length === 0) { return undefined; } const cleanValue = rawValue.toLowerCase(); - const valueAsNumber = parseFloat(cleanValue); + if (cleanValue === "loose") { + return "loose"; + } + if (cleanValue === "strict") { + return "strict"; + } + + core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "loose" or "strict" instead.`); +} + +function optionalInt(argumentName: string, rawValue: string): number | undefined { + if (rawValue.length === 0) { + return undefined; + } + + const valueAsNumber = parseFloat(rawValue); if (Number.isInteger(valueAsNumber)) { return valueAsNumber; @@ -107,8 +129,8 @@ function optionalInt(argumentName: string, rawValue: string | undefined): number core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try a whole number (no decimals) instead like 1234`); } -function optionalStringArray(argumentName: string, rawValue: string | undefined): string[] | undefined { - if (rawValue === undefined) { +function optionalStringArray(argumentName: string, rawValue: string): string[] | undefined { + if (rawValue.length === 0) { return undefined; }