1
0
Fork 0
mirror of https://github.com/shimataro/ssh-key-action.git synced 2025-06-19 22:52:10 +10:00

Feature/centos (#176)

* check on CentOS container

* update README

* update links

* update CHANGELOG

* refactor insertLf()
This commit is contained in:
shimataro 2021-02-24 21:24:03 +09:00 committed by GitHub
parent cdcc4725b3
commit 68b956be12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 137 additions and 57 deletions

View file

@ -430,9 +430,9 @@ function main() {
const files = [
{
name: core.getInput("name"),
contents: insertLf(core.getInput("key", { required: true }), {
append: true,
}),
contents: insertLf(core.getInput("key", {
required: true,
}), false, true),
options: {
mode: 0o400,
flag: "ax",
@ -440,10 +440,9 @@ function main() {
},
{
name: "known_hosts",
contents: insertLf(core.getInput("known_hosts", { required: true }), {
prepend: true,
append: true,
}),
contents: insertLf(core.getInput("known_hosts", {
required: true,
}), true, true),
options: {
mode: 0o644,
flag: "a",
@ -451,10 +450,7 @@ function main() {
},
{
name: "config",
contents: insertLf(core.getInput("config"), {
prepend: true,
append: true,
}),
contents: insertLf(core.getInput("config"), true, true),
options: {
mode: 0o644,
flag: "a",
@ -510,20 +506,20 @@ function getHomeEnv() {
/**
* prepend/append LF to value if not empty
* @param value the value to insert LF
* @param options options
* @param prepend true to prepend
* @param append true to append
* @returns new value
*/
function insertLf(value, options) {
const normalizedOptions = Object.assign({ prepend: false, append: false }, options);
function insertLf(value, prepend, append) {
let affectedValue = value;
if (value.length === 0) {
// do nothing if empty
return "";
}
if (normalizedOptions.prepend && !affectedValue.startsWith("\n")) {
if (prepend && !affectedValue.startsWith("\n")) {
affectedValue = `\n${affectedValue}`;
}
if (normalizedOptions.append && !affectedValue.endsWith("\n")) {
if (append && !affectedValue.endsWith("\n")) {
affectedValue = `${affectedValue}\n`;
}
return affectedValue;