{"size": 1935, "ext": "js", "max_stars_repo_path": "utilities/aws/src/ssh/Host-Entry.js", "max_stars_repo_name": "cloud-hybrid/delta", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "utilities/aws/src/ssh/Host-Entry.js", "max_issues_repo_name": "cloud-hybrid/delta", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "utilities/aws/src/ssh/Host-Entry.js", "max_forks_repo_name": "cloud-hybrid/delta", "max_forks_repo_forks_event_min_datetime": "2022-01-03T05:33:15.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-03T05:33:15.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 24.1875, "max_line_length": 138, "alphanum_fraction": 0.5715762274}
/***
 * @name        Host SSH-Entry
 * @package     @cloud-technology
 * @summary     ESM SSH Extension
 *
 * @author      Jacob B. Sanders
 * @license     BSD 3-Clause License
 * @copyright   Cloud-Technology LLC. & Affiliates
 */


import * as OS from "os";
import * as Path from "path";

/***
 * User Information (OS)
 *
 * @type {{uid: number, gid: number, shell: string, username: string, homedir: string}}
 *
 */

const User = {... OS.userInfo()};

const Default = {
    SSH: Path.join(User.homedir, ".ssh", "id_rsa"),
    Username: User.username,
    Bastion: "localhost",
    Alias: "Local-Host",
    IP: "127.0.0.1"
};

/***
 * Create a SSH Configuration Entry
 *
 * @param alias {String} Target SSH Cofiguration Common-Name
 * @param hostname {String} Target SSH Hostname
 * @param user {String} Target SSH Username
 * @param key {String} System Path Location of SSH-Private Key
 * @param bastion {String} Target Bastion Host
 *
 * @return {string}
 *
 * @constructor
 *
 * @example
 *
 * console.log(Entry());
 *
 * >>> Host Local-Host
 * >>>     Hostname 127.0.0.1
 * >>>     User Jacob-Sanders
 * >>>     IdentityFile /Users/Jacob-Sanders/.ssh/id_rsa
 * >>>     ProxyCommand ssh localhost nc %h %p
 *
 */

const Entry = ({alias = Default.Alias, hostname = Default.IP, user = Default.Username, key = Default.SSH, bastion = Default.Bastion}) => {
    return [
        ["Host", alias].join(" "),
        ["   ", "Hostname", hostname].join(" "),
        ["   ", "User", user].join(" "),
        ["   ", "IdentityFile", key].join(" "),
        ["   ", "ProxyCommand", "ssh", bastion, "-i", key, "-W", "%h:%p"].join(" ")
    ].join("\n");
};

const Overwrite = () => {
    return [
        ["Host", "*"].join(" "),
        ["   StrictHostKeyChecking", "no"].join(" "),
        ["   UserKnownHostsFile=/dev/null"]
    ].join("\n");
}

export { Entry, Overwrite, User, Default };

export default Entry;

/// console.log(Entry());
