Skip to content

Commit

Permalink
Merge pull request #20 from APoniatowski/Dev
Browse files Browse the repository at this point in the history
Dev -> v1.4.0
  • Loading branch information
APoniatowski authored Feb 22, 2020
2 parents 6d3897d + e050047 commit 93e9fee
Show file tree
Hide file tree
Showing 10 changed files with 376 additions and 45 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
/bin
/.vscode
/pkg
/.circleci
config/config.yml
config/config-testing.yml
config/config-testing-linux.yml
config/pool.yml
config/pool-testing.yml
config/pool-testing-linux.yml
/.github
/src
/GoSSH
Expand Down
6 changes: 5 additions & 1 deletion config/config.yml → config/pool.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@ ServerGroup1: #group name, spacing does not matter
Username: user11 ##
Password: password11 ### FQDN, is needed. Username defaults to root,
Key_Path: /path/to/key ## password or key needed, ports default to 22
Port: 22 #
Port: 22 # and OS will include all package managers per OS
OS: debian
Server12:
FQDN: hostname12.whatever.com
Username: user12
Password: password12
Key_Path: /path/to/key
Port: 223
OS: centos # or rhel
ServerGroup2:
Server21:
FQDN: hostname21.whatever.com
Username: user21
Password: password21
Key_Path: /path/to/key
Port: 2233
OS: fedora
Server22:
FQDN: hostname22.whatever.com
Username: user22
Password: password22
Key_Path: /path/to/key
Port:
OS: opensuse
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ module github.com/APoniatowski/GoSSH
go 1.13

require (
github.com/mattn/go-tty v0.0.3 // indirect
github.com/superhawk610/bar v0.0.0-20190614064228-4fbf44d086fd
github.com/superhawk610/terminal v0.0.0-20200123193603-cbc69427a94a // indirect
github.com/urfave/cli v1.22.2
golang.org/x/crypto v0.0.0-20191202143827-86a70503ff7e
gopkg.in/yaml.v2 v2.2.2
)
28 changes: 28 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,37 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-tty v0.0.3 h1:5OfyWorkyO7xP52Mq7tB36ajHDG5OHrmBGIS/DtakQI=
github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/superhawk610/bar v0.0.0-20190614064228-4fbf44d086fd h1:RtN5diZmNgmPlhSmV1jmjAkg2id74n/D/1495RGt6vY=
github.com/superhawk610/bar v0.0.0-20190614064228-4fbf44d086fd/go.mod h1:xc6t0MG+8Mbj9wnHBEdvX2TRtNIaqhM5fW3R+dF9vH8=
github.com/superhawk610/terminal v0.0.0-20200123193603-cbc69427a94a h1:VUj2GCy6JR4N7a0ymeNg7byzp4cidSRzJl5lOHiyAFo=
github.com/superhawk610/terminal v0.0.0-20200123193603-cbc69427a94a/go.mod h1:NQ3EEKWSeofexUwENLX3lv4WR2qeGiLlbf/NveZ7ZAQ=
github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo=
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191202143827-86a70503ff7e h1:egKlR8l7Nu9vHGWbcUV8lqR4987UfUbBd7GbhqGzNYU=
golang.org/x/crypto v0.0.0-20191202143827-86a70503ff7e/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6 h1:Sy5bstxEqwwbYs6n0/pBuxKENqOeZUgD45Gp3Q3pqLg=
golang.org/x/crypto v0.0.0-20200221170553-0f24fbd83dfb h1:Bg7BRk6M/6/zfhJrglNmi/oiI2jwKuETZ3vrdYr1qFk=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e h1:N7DeIrjYszNmSW409R3frPPwglRwMkXSBzwVbkOjLLA=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
20 changes: 16 additions & 4 deletions loggerlib/loggerlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,21 @@ func ErrorLogger(servername string, option string, output []byte) {
}

// GeneralError General error logging
func GeneralError(e error) {
if e != nil {
// log.Fatal(e)
log.Println(e)
func GeneralError(servername string, option string, output error) {
currentDate := time.Now()
dateFormatted := currentDate.Format("2006-01-02")
path, _ := filepath.Abs("./logs/errors/")
err := os.MkdirAll(path, os.ModePerm)
if err == nil || os.IsExist(err) {
errFile, err := os.OpenFile(path+"/"+dateFormatted+".log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Println(err)
}
defer errFile.Close()
logger := log.New(errFile, option, log.LstdFlags)
errOut := output.Error()
logger.Print(servername + ": " + errOut)
} else {
log.Println(err)
}
}
156 changes: 146 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"log"
"os"
"strings"

"github.com/APoniatowski/GoSSH/clioptions"
"github.com/APoniatowski/GoSSH/sshlib"
Expand All @@ -13,18 +14,27 @@ import (
// Main function to carry out operations
func main() {
var cmd []string

var switches *sshlib.Switches = &sshlib.OSSwitcher
// had issues with pointers and booleans, so I found a article which gave this as a solution:
toggleswitchtrue := true
toggleswitchfalse := false
switches.Updater = &toggleswitchfalse
switches.UpdaterFull = &toggleswitchfalse
switches.Install = &toggleswitchfalse
switches.Uninstall = &toggleswitchfalse
// create one variable and reference it, so essentially this would take less expensive, as it is pointing to 2 memory locations
// instead of 4.
app := cli.NewApp()
app.Name = "GoSSH"
app.Version = "1.0.1"
app.Version = "1.4.0"
app.Usage = "Open Source Go Infrastucture Automation Tool"
app.UsageText = "GoSSH [global options] command [subcommand] [script or arguments...]"
app.EnableBashCompletion = true
app.Commands = []cli.Command{
{
Name: "sequential",
Aliases: []string{"s"},
Usage: "Run the command sequentially on all servers in your config file",
Usage: "Run the command sequentially on all servers in your pool",
Action: func(c *cli.Context) error {
yamlparser.Rollcall()
cmd = os.Args[2:]
Expand All @@ -35,13 +45,55 @@ func main() {
Subcommands: []cli.Command{
{
Name: "run",
Usage: "Run a bash script on the defined servers",
Usage: "Run a bash script on the servers in your pool",
Action: func(c *cli.Context) error {
yamlparser.Rollcall()
cmd := os.Args[3]
cmdargs := os.Args[4:]
command := clioptions.BashScriptParse(cmd, cmdargs)
sshlib.RunAllServers(&yamlparser.Config, &command)
sshlib.RunSequentially(&yamlparser.Config, &command)
return nil
},
},
{
Name: "update",
Usage: "update all remote servers in pool",
Action: func(c *cli.Context) error {
yamlparser.Rollcall()
command := ""
osSwitch := strings.Join(os.Args[3:], " ")
if osSwitch == "os" || osSwitch == "OS" {
switches.UpdaterFull = &toggleswitchtrue
} else {
switches.Updater = &toggleswitchtrue
}
sshlib.RunSequentially(&yamlparser.Config, &command)
return nil
},
},
{
Name: "install",
Usage: "Install packages on all remote servers in pool",
Action: func(c *cli.Context) error {
yamlparser.Rollcall()
command := ""
cmdargs := os.Args[3:]
command = strings.Join(cmdargs, " ")
switches.Install = &toggleswitchtrue
sshlib.RunSequentially(&yamlparser.Config, &command)
return nil
},
},
{
Name: "uninstall",
Usage: "Uninstall packages on all remote servers in pool",
Action: func(c *cli.Context) error {
yamlparser.Rollcall()
command := ""
cmdargs := os.Args[3:]
command = strings.Join(cmdargs, " ")
switches.Uninstall = &toggleswitchtrue
sshlib.RunSequentially(&yamlparser.Config, &command)
return nil
},
},
Expand All @@ -60,7 +112,7 @@ func main() {
{
Name: "groups",
Aliases: []string{"g"},
Usage: "Run the command on all servers per group concurrently in your config file",
Usage: "Run the command on all servers per group concurrently in your pool",
Action: func(c *cli.Context) error {
yamlparser.Rollcall()
cmd = os.Args[2:]
Expand All @@ -71,13 +123,55 @@ func main() {
Subcommands: []cli.Command{
{
Name: "run",
Usage: "Run a bash script on the defined servers",
Usage: "Run a bash script on the servers in your pool",
Action: func(c *cli.Context) error {
yamlparser.Rollcall()
cmd := os.Args[3]
cmdargs := os.Args[4:]
command := clioptions.BashScriptParse(cmd, cmdargs)
sshlib.RunAllServers(&yamlparser.Config, &command)
sshlib.RunGroups(&yamlparser.Config, &command)
return nil
},
},
{
Name: "update",
Usage: "update all remote servers in pool",
Action: func(c *cli.Context) error {
yamlparser.Rollcall()
command := ""
osSwitch := strings.Join(os.Args[3:], " ")
if osSwitch == "os" || osSwitch == "OS" {
switches.UpdaterFull = &toggleswitchtrue
} else {
switches.Updater = &toggleswitchtrue
}
sshlib.RunGroups(&yamlparser.Config, &command)
return nil
},
},
{
Name: "install",
Usage: "Install packages on all remote servers in pool",
Action: func(c *cli.Context) error {
yamlparser.Rollcall()
command := ""
cmdargs := os.Args[3:]
command = strings.Join(cmdargs, " ")
switches.Install = &toggleswitchtrue
sshlib.RunGroups(&yamlparser.Config, &command)
return nil
},
},
{
Name: "uninstall",
Usage: "Uninstall packages on all remote servers in pool",
Action: func(c *cli.Context) error {
yamlparser.Rollcall()
command := ""
cmdargs := os.Args[3:]
command = strings.Join(cmdargs, " ")
switches.Uninstall = &toggleswitchtrue
sshlib.RunGroups(&yamlparser.Config, &command)
return nil
},
},
Expand All @@ -96,7 +190,7 @@ func main() {
{
Name: "all",
Aliases: []string{"a"},
Usage: "Run the command on all servers concurrently in your config file",
Usage: "Run the command on all servers concurrently in your pool",
Action: func(c *cli.Context) error {
yamlparser.Rollcall()
cmd = os.Args[2:]
Expand All @@ -107,7 +201,7 @@ func main() {
Subcommands: []cli.Command{
{
Name: "run",
Usage: "Run a bash script on the defined servers",
Usage: "Run a bash script on the servers in your pool",
Action: func(c *cli.Context) error {
yamlparser.Rollcall()
cmd := os.Args[3]
Expand All @@ -117,6 +211,48 @@ func main() {
return nil
},
},
{
Name: "update",
Usage: "Update all remote servers in pool",
Action: func(c *cli.Context) error {
yamlparser.Rollcall()
command := ""
osSwitch := strings.Join(os.Args[3:], " ")
if osSwitch == "os" || osSwitch == "OS" {
switches.UpdaterFull = &toggleswitchtrue
} else {
switches.Updater = &toggleswitchtrue
}
sshlib.RunAllServers(&yamlparser.Config, &command)
return nil
},
},
{
Name: "install",
Usage: "Install packages on all remote servers in pool",
Action: func(c *cli.Context) error {
yamlparser.Rollcall()
command := ""
cmdargs := os.Args[3:]
command = strings.Join(cmdargs, " ")
switches.Install = &toggleswitchtrue
sshlib.RunAllServers(&yamlparser.Config, &command)
return nil
},
},
{
Name: "uninstall",
Usage: "Uninstall packages on all remote servers in pool",
Action: func(c *cli.Context) error {
yamlparser.Rollcall()
command := ""
cmdargs := os.Args[3:]
command = strings.Join(cmdargs, " ")
switches.Uninstall = &toggleswitchtrue
sshlib.RunAllServers(&yamlparser.Config, &command)
return nil
},
},
//-----------------placeholder--------------------
// {
// Name: "remove",
Expand Down
Loading

0 comments on commit 93e9fee

Please sign in to comment.