-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
69 lines (58 loc) · 1.29 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
"log"
"os"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Name = "pepper"
app.Version = "0.1.0"
app.Usage = "pepper <target> <function> [ARGUMENTS ...]"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "hostname, H",
Usage: "Salt API hostname. Should include http[s]//.",
EnvVar: "SALT_HOST",
},
cli.StringFlag{
Name: "username, u",
Usage: "Salt API username.",
EnvVar: "SALT_USER",
},
cli.StringFlag{
Name: "password, p",
Usage: "Salt API password.",
EnvVar: "SALT_PASSWORD",
},
cli.StringFlag{
Name: "auth, a",
Value: "ldap",
Usage: "Salt authentication method.",
EnvVar: "SALT_AUTH",
},
}
app.Action = func(c *cli.Context) error {
if len(c.Args()) < 2 {
fmt.Println("pepper <target> <function> [ARGUMENTS ...]")
return nil
}
hostname := c.String("hostname")
username := c.String("username")
password := c.String("password")
auth := c.String("auth")
salt := NewSalt(hostname)
err := salt.Login(username, password, auth)
if err != nil {
log.Fatal(err)
}
target := c.Args().Get(0)
function := c.Args().Get(1)
arguments := c.Args().Get(2)
response, _ := salt.Run(target, function, arguments)
fmt.Println(response)
return nil
}
app.Run(os.Args)
}