Skip to content

Commit

Permalink
v1.0.0 release, minor fixing. Will do some clean-up in sshlib to pass…
Browse files Browse the repository at this point in the history
… a struct as parameters, instead of variables
  • Loading branch information
APoniatowski committed Jan 20, 2020
1 parent 1fa84b8 commit 2389e35
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 62 deletions.
4 changes: 2 additions & 2 deletions clioptions/clioptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ func GeneralCommandParse(cmd []string) string {
return command
}

//BashScriptParse not yet worked on
//BashScriptParse bash script parser, to pass write the script on the server, run it and remove it.
// It also accepts args for the script. Dependency scripts will not work, as they are considered a separate script
func BashScriptParse(cmd string, cmdargs []string) string {
scriptargs := strings.Join(cmdargs, " ")
script, _ := os.Open(cmd)
Expand All @@ -23,7 +24,6 @@ func BashScriptParse(cmd string, cmdargs []string) string {
scanner.Split(bufio.ScanLines)
var lines []string
for scanner.Scan() {
// need to do some conditional logic to find $ and add a \ before it, to make echo work
lines = append(lines, scanner.Text())
lines = append(lines, "\n")
}
Expand Down
119 changes: 61 additions & 58 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"log"
"os"

Expand All @@ -17,9 +16,10 @@ func main() {

app := cli.NewApp()
app.Name = "GoSSH"
app.Version = "0.9.0"
app.Version = "1.0.0"
app.Usage = "Open Source Go Infrastucture Automation Tool"
app.UsageText = "gossh [global options] command [subcommand] [script or arguments...]"
app.UsageText = "GoSSH [global options] command [subcommand] [script or arguments...]"
app.EnableBashCompletion = true
app.Commands = []cli.Command{
{
Name: "sequential",
Expand All @@ -32,6 +32,30 @@ func main() {
sshlib.RunSequentially(&yamlparser.Config, &command)
return nil
},
Subcommands: []cli.Command{
{
Name: "run",
Usage: "Run a bash script on the defined servers",
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)
return nil
},
},
//-----------------placeholder--------------------
// {
// Name: "remove",
// Usage: "remove an existing template",
// Action: func(c *cli.Context) error {
// fmt.Println("removed task template: ", c.Args().First())
// return nil
// },
// },
//-----------------placeholder--------------------
},
},
{
Name: "groups",
Expand All @@ -44,6 +68,30 @@ func main() {
sshlib.RunGroups(&yamlparser.Config, &command)
return nil
},
Subcommands: []cli.Command{
{
Name: "run",
Usage: "Run a bash script on the defined servers",
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)
return nil
},
},
//-----------------placeholder--------------------
// {
// Name: "remove",
// Usage: "remove an existing template",
// Action: func(c *cli.Context) error {
// fmt.Println("removed task template: ", c.Args().First())
// return nil
// },
// },
//-----------------placeholder--------------------
},
},
{
Name: "all",
Expand All @@ -61,7 +109,6 @@ func main() {
Name: "run",
Usage: "Run a bash script on the defined servers",
Action: func(c *cli.Context) error {
fmt.Println("new task template: ", c.Args().First())
yamlparser.Rollcall()
cmd := os.Args[3]
cmdargs := os.Args[4:]
Expand All @@ -70,14 +117,16 @@ func main() {
return nil
},
},
{
Name: "remove",
Usage: "remove an existing template",
Action: func(c *cli.Context) error {
fmt.Println("removed task template: ", c.Args().First())
return nil
},
},
//-----------------placeholder--------------------
// {
// Name: "remove",
// Usage: "remove an existing template",
// Action: func(c *cli.Context) error {
// fmt.Println("removed task template: ", c.Args().First())
// return nil
// },
// },
//-----------------placeholder--------------------
},
},
}
Expand All @@ -95,49 +144,3 @@ func main() {
log.Fatal(err)
}
}


// switch serveroptions := os.Args[1]; serveroptions {
// case "seq":
// command := cli.GeneralCommandParse(cmd)
// sshlib.RunSequentially(&yamlparser.Config, &command)
// case "groups":
// command := cli.GeneralCommandParse(cmd)
// sshlib.RunGroups(&yamlparser.Config, &command)
// case "all":
// command := cli.GeneralCommandParse(cmd)
// sshlib.RunAllServers(&yamlparser.Config, &command)
// default:
// fmt.Println("Usage: gossh [option] [command]")
// fmt.Println("Options:")
// fmt.Println(" seq - Run the command sequentially on all servers in your config file")
// fmt.Println(" groups - Run the command on all servers per group concurrently in your config file")
// fmt.Println(" all - Run the command on all servers concurrently in your config file")
// fmt.Println("need to add another option [option1 or] [option 2]")
// }

// switch scriptingoptions := os.Args[2]; scriptingoptions {
// case "run":
// command := cli.BashScriptParse(cmd)
// sshlib.RunAllServers(&yamlparser.Config, &command)
// default:
// fmt.Println("Usage: gossh [option] [command]")
// fmt.Println("Options:")
// fmt.Println(" seq - Run the command sequentially on all servers in your config file")
// fmt.Println(" groups - Run the command on all servers per group concurrently in your config file")
// fmt.Println(" all - Run the command on all servers concurrently in your config file")
// fmt.Println("need to add another option [option1 or] [option 2]")
// }

// if len(os.Args) > 2 {
// cmd = os.Args[2:] // will change this to 3 later, when I see a need to expand on more arguments, eg. running only 1 group, or x amount of servers
// } else {
// fmt.Println("No command was specified, please specify a command.")
// fmt.Println("Usage: gossh [option] [command]")
// fmt.Println("Options:")
// fmt.Println(" seq - Run the command sequentially on all servers in your config file")
// fmt.Println(" groups - Run the command on all servers per group concurrently in your config file")
// fmt.Println(" all - Run the command on all servers concurrently in your config file")
// fmt.Println("need to add another option [option1 or] [option 2]")
// os.Exit(-1)
// }
4 changes: 2 additions & 2 deletions sshlib/sshlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func connectAndRun(command *string, servername string, fqdn string, username str
ssh.KeyAlgoECDSA521,
ssh.KeyAlgoED25519,
},
Timeout: 5 * time.Second,
Timeout: 15 * time.Second,
}
connection, err := ssh.Dial("tcp", fqdn+":"+port, sshConfig)
loggerlib.GeneralError(err)
Expand Down Expand Up @@ -139,7 +139,7 @@ func connectAndRunSeq(command *string, servername string, fqdn string, username
ssh.KeyAlgoECDSA521,
ssh.KeyAlgoED25519,
},
Timeout: 5 * time.Second,
Timeout: 15 * time.Second,
}
connection, err := ssh.Dial("tcp", fqdn+":"+port, sshConfig)
loggerlib.GeneralError(err)
Expand Down

0 comments on commit 2389e35

Please sign in to comment.