Skip to content

Commit

Permalink
initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
garygrossgarten committed Aug 30, 2019
1 parent a0811b7 commit 22bdbf9
Show file tree
Hide file tree
Showing 14 changed files with 358 additions and 43 deletions.
34 changes: 28 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
name: Hello World Billy Action
name: Run SSH command
author: garygrossgarten
description: Hello World Project to show billy integration in GitHub Javascript Actions
description: Github Action to run commands on a remote server using SSH
inputs:
name:
description: "Name of greeted person"
command:
description: "Command to execute on the remote server."
required: true
host:
description: "Hostname or IP address of the server."
required: false
default: "localhost"
username:
description: "Username for authentication."
required: false
port:
description: "Port number of the server."
required: false
default: "22"
privateKey:
description: "File Location or string that contains a private key for either key-based or hostbased user authentication (OpenSSH format)"
required: false
password:
description: "Password for password-based user authentication."
required: false
passphrase:
description: "For an encrypted private key, this is the passphrase used to decrypt it."
required: false
tryKeyboard:
description: "Try keyboard-interactive user authentication if primary user authentication method fails."
required: false
default: "World"
runs:
using: "node12"
main: "dist/index.js"
color: purple
icon: heart
icon: code
8 changes: 5 additions & 3 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env node
import { CorePlugin } from "@fivethree/billy-plugin-core";
import { GithubActionsPlugin } from "@garygrossgarten/billy-plugin-github-actions";
export interface Hello extends CorePlugin, GithubActionsPlugin {
export interface SSH extends CorePlugin, GithubActionsPlugin {
}
export declare class Hello {
hello(name: any): Promise<void>;
export declare class SSH {
ssh(command: string, host: string, username: string, port: number, privateKey: string, password: string, passphrase: string, tryKeyboard: boolean): Promise<void>;
private connect;
private executeCommand;
}
79 changes: 70 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,88 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const billy_core_1 = require("@fivethree/billy-core");
const billy_plugin_core_1 = require("@fivethree/billy-plugin-core");
const billy_plugin_github_actions_1 = require("@garygrossgarten/billy-plugin-github-actions");
let Hello = class Hello {
hello(name) {
const node_ssh_1 = __importDefault(require("node-ssh"));
const keyboard_1 = require("./keyboard");
let SSH = class SSH {
ssh(command, host = "localhost", username, port = 22, privateKey, password, passphrase, tryKeyboard) {
return __awaiter(this, void 0, void 0, function* () {
const ssh = yield this.connect(host, username, port, privateKey, password, passphrase, tryKeyboard);
yield this.executeCommand(ssh, command);
ssh.dispose();
});
}
connect(host = "localhost", username, port = 22, privateKey, password, passphrase, tryKeyboard) {
return __awaiter(this, void 0, void 0, function* () {
const ssh = new node_ssh_1.default();
const m1 = yield this.colorize("orange", `Establishing a SSH connection to ${host}.`);
console.log(m1);
try {
yield ssh.connect({
host: host,
port: port,
username: username,
password: password,
passphrase: passphrase,
privateKey: privateKey,
tryKeyboard: tryKeyboard,
onKeyboardInteractive: tryKeyboard ? keyboard_1.keyboardFunction(password) : null
});
console.log(`🤝 Connected to ${host}.`);
}
catch (err) {
console.error(`⚠️ The GitHub Action couldn't connect to ${host}.`, err);
process.abort();
}
return ssh;
});
}
executeCommand(ssh, command) {
return __awaiter(this, void 0, void 0, function* () {
console.log(`Hello ${name}!`);
const m2 = yield this.colorize("orange", `Executing command:`);
console.log(`${m2} ${command}`);
try {
yield ssh.exec(command, [], {
stream: "both",
onStdout(chunk) {
console.log(chunk.toString("utf8"));
},
onStderr(chunk) {
console.log(chunk.toString("utf8"));
}
});
console.log("✅ SSH Action finished.");
}
catch (err) {
console.error(`⚠️ An error happened executing command ${command}.`, err);
process.abort();
}
});
}
};
__decorate([
billy_core_1.usesPlugins(billy_plugin_core_1.CorePlugin, billy_plugin_github_actions_1.GithubActionsPlugin),
billy_core_1.Hook(billy_core_1.onStart),
billy_plugin_github_actions_1.GitHubAction(),
__param(0, billy_plugin_github_actions_1.input("name")),
__param(0, billy_plugin_github_actions_1.input("command")),
__param(1, billy_plugin_github_actions_1.input("host")),
__param(2, billy_plugin_github_actions_1.input("username")),
__param(3, billy_plugin_github_actions_1.input("port")),
__param(4, billy_plugin_github_actions_1.input("privateKey")),
__param(5, billy_plugin_github_actions_1.input("password")),
__param(6, billy_plugin_github_actions_1.input("passphrase")),
__param(7, billy_plugin_github_actions_1.input("tryKeyboard")),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:paramtypes", [String, Object, String, Object, String, String, String, Boolean]),
__metadata("design:returntype", Promise)
], Hello.prototype, "hello", null);
Hello = __decorate([
], SSH.prototype, "ssh", null);
SSH = __decorate([
billy_core_1.App()
], Hello);
exports.Hello = Hello;
], SSH);
exports.SSH = SSH;
1 change: 1 addition & 0 deletions dist/keyboard.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const keyboardFunction: (password: any) => (name: any, instructions: any, instructionsLang: any, prompts: any, finish: any) => void;
8 changes: 8 additions & 0 deletions dist/keyboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.keyboardFunction = password => (name, instructions, instructionsLang, prompts, finish) => {
if (prompts.length > 0 &&
prompts[0].prompt.toLowerCase().includes("password")) {
finish([password]);
}
};
1 change: 1 addition & 0 deletions dist/pk.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const privateKey = "-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABAhLqUiyV\nARBpBBW328043UAAAAEAAAAAEAAAEXAAAAB3NzaC1yc2EAAAADAQABAAABAQC10IgQWVud\nAlygnpA7erbIQK+e/HzXo1mt3JW7KdXHJAlb3Hb+oeRFHSAnkhzUhfJoL+5CFEkHdxplKL\nj1/WlVTUo2Na8OGmPV2zCdH+Xg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w6UtMJ3axfHa2NhcgAKu/H/YtIev0HRNe91nrbdHSqIBjwHG9\n8MuESak1fR743MSzJi6nIXdIBWrRhcjykuIfdDZEfURXttwX+qr96ERcg9joKyDsRCarYM\nhGdMpMX49HNORi383B7v67Q4WRluzBRezlPTtSIch5G0VKZBaJ+hYTqvCrViofIeUYd8R4\nrfFCpC2yyqYMGKcxXwYO8b40vQgFuaQvPT6H7scwFHOfYaPAexUtCzWydSbD6dZhpYHAVi\npAs8+v9WxL03KD+4gm134shT7/8ZISEu3ZD+5LH1O7VZnZz3kHQ2cmN5R4MeEdXW/RLOE0\n+YKF7qWUoTynCFFJbModhtK2pLzjEjG+B1Gjymyv52zmmCeYjr6Lw1EkKyyUR/MULhcelf\nRN4tdafeyTS+cT/N3oqCG/GU+2s5j2vCW+XliNdnS3/a5qtmLAEWzRtWcEC4D2pbFagunU\nSDDJvfo2fr61ocDXsg5hhkJYBA6BFsxdiVVSE/NHEHqpsta0vC\n-----END OPENSSH PRIVATE KEY-----\n";
31 changes: 31 additions & 0 deletions dist/pk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.privateKey = `-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABAhLqUiyV
ARBpBBW328043UAAAAEAAAAAEAAAEXAAAAB3NzaC1yc2EAAAADAQABAAABAQC10IgQWVud
AlygnpA7erbIQK+e/HzXo1mt3JW7KdXHJAlb3Hb+oeRFHSAnkhzUhfJoL+5CFEkHdxplKL
j1/WlVTUo2Na8OGmPV2zCdH+XgcLOP7IIrVlVjS67IBFocpnjVjl+9qolkec7cl3k3+tRs
zy/IDs1/5FXx2afcSE8KNaAtX3StjLc2Hzl1r+vZb5+PtUnTvHuU+96uSCse3w/lN73Mgo
arYRyAWVv3U5X0VvDF+ADWQbL4pA9CGR1cKGCyqUX7irO+Da0r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R4
rfFCpC2yyqYMGKcxXwYO8b40vQgFuaQvPT6H7scwFHOfYaPAexUtCzWydSbD6dZhpYHAVi
pAs8+v9WxL03KD+4gm134shT7/8ZISEu3ZD+5LH1O7VZnZz3kHQ2cmN5R4MeEdXW/RLOE0
+YKF7qWUoTynCFFJbModhtK2pLzjEjG+B1Gjymyv52zmmCeYjr6Lw1EkKyyUR/MULhcelf
RN4tdafeyTS+cT/N3oqCG/GU+2s5j2vCW+XliNdnS3/a5qtmLAEWzRtWcEC4D2pbFagunU
SDDJvfo2fr61ocDXsg5hhkJYBA6BFsxdiVVSE/NHEHqpsta0vC
-----END OPENSSH PRIVATE KEY-----
`;
1 change: 1 addition & 0 deletions dist/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const keyboardFunction: (password: any) => (name: any, instructions: any, instructionsLang: any, prompts: any, finish: any) => void;
8 changes: 8 additions & 0 deletions dist/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.keyboardFunction = password => (name, instructions, instructionsLang, prompts, finish) => {
if (prompts.length > 0 &&
prompts[0].prompt.toLowerCase().includes("password")) {
finish([password]);
}
};
91 changes: 89 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 22bdbf9

Please sign in to comment.