-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.go
186 lines (181 loc) · 4.15 KB
/
app.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package main
import (
"errors"
"fmt"
"io/ioutil"
"github.com/stephane-martin/vssh/commands"
"github.com/stephane-martin/vssh/widgets"
"github.com/gabriel-vasile/mimetype"
"github.com/urfave/cli"
)
// App returns the vssh application object.
func App() *cli.App {
app := cli.NewApp()
app.Name = "vssh"
app.Usage = "SSH/SCP using certificates signed by Vault"
app.Version = version
app.Commands = []cli.Command{
commands.SSHCommand(),
commands.SCPCommand(),
commands.SFTPCommand(),
commands.TopCommand(),
commands.BrowseCommand(),
commands.TunnelCommand(),
commands.ResolveCommand(),
commands.SocksCommand(),
commands.HTTPProxyCommand(),
{
Name: "version",
Usage: "print vssh version",
Action: func(c *cli.Context) error {
fmt.Println(version)
return nil
},
},
{
Name: "mimetype",
Usage: "detect mimetype of file argument",
Action: func(c *cli.Context) error {
if len(c.Args()) == 0 {
return nil
}
mime, ext, err := mimetype.DetectFile(c.Args()[0])
if err != nil {
fmt.Println(err)
return nil
}
fmt.Println(mime, ext)
return nil
},
},
{
Name: "less",
Usage: "show local file content",
Action: func(c *cli.Context) (e error) {
defer func() {
if e != nil {
e = cli.NewExitError(e.Error(), 1)
}
}()
args := c.Args()
if len(args) != 1 {
return errors.New("less takes one argument")
}
fname := args[0]
content, err := ioutil.ReadFile(fname)
if err != nil {
return err
}
return widgets.ShowFile(args[0], content, c.GlobalBool("pager"))
},
},
}
app.Flags = GlobalFlags()
return app
}
// GlobalFlags returns the global flags for vssh.
func GlobalFlags() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: "vault-address,vault-addr",
Value: "http://127.0.0.1:8200",
EnvVar: "VAULT_ADDR",
Usage: "the address of the Vault server",
},
cli.StringFlag{
Name: "vault-token,token",
Value: "",
EnvVar: "VAULT_TOKEN",
Usage: "Vault authentication token",
},
cli.StringFlag{
Name: "vault-auth-method,vault-method,method",
Usage: "type of authentication",
Value: "token",
EnvVar: "VAULT_AUTH_METHOD",
},
cli.StringFlag{
Name: "vault-auth-path,vault-path,path",
Usage: "remote path in Vault where the chosen auth method is mounted",
Value: "",
EnvVar: "VAULT_AUTH_PATH",
},
cli.StringFlag{
Name: "vault-username",
Usage: "Vault username or RoleID",
Value: "",
EnvVar: "VAULT_USERNAME",
},
cli.StringFlag{
Name: "vault-password",
Usage: "Vault password or SecretID",
Value: "",
EnvVar: "VAULT_PASSWORD",
},
cli.StringFlag{
Name: "vault-ssh-mount,mount",
Usage: "Vault SSH signer mount point",
EnvVar: "VAULT_SSH_MOUNT",
Value: "ssh-client-signer",
},
cli.StringFlag{
Name: "vault-ssh-role,role",
Usage: "Vault signing role",
EnvVar: "VAULT_SSH_ROLE",
},
cli.StringFlag{
Name: "http-proxy,httpproxy",
Usage: "specify a URL to connect through a HTTP proxy",
Value: "",
EnvVar: "SSH_HTTP_PROXY",
},
cli.StringFlag{
Name: "login,l",
Usage: "SSH remote user",
EnvVar: "SSH_USER",
},
cli.IntFlag{
Name: "ssh-port,sshport,P",
Usage: "SSH remote port",
EnvVar: "SSH_PORT",
Value: 22,
},
cli.StringFlag{
Name: "privkey,private,identity,i",
Usage: "filesystem path to SSH private key",
EnvVar: "IDENTITY",
Value: "",
},
cli.StringFlag{
Name: "vprivkey,vprivate,videntity",
Usage: "Vault secret path to SSH private key",
EnvVar: "VIDENTITY",
Value: "",
},
cli.BoolFlag{
Name: "insecure",
Usage: "do not check the remote SSH host key",
EnvVar: "SSH_INSECURE",
},
cli.BoolFlag{
Name: "password",
Usage: "enable SSH password authentication",
EnvVar: "VSSH_SSH_PASSWORD",
},
cli.BoolFlag{
Name: "agent",
Usage: "enable SSH agent authentication",
EnvVar: "VSSH_SSH_AGENT",
},
cli.StringFlag{
Name: "loglevel",
Usage: "logging level",
Value: "info",
},
cli.BoolFlag{
Name: "pager",
Usage: "use external pager",
EnvVar: "VSSH_EXTERNAL_PAGER",
},
}
}