-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.go
74 lines (59 loc) · 1.81 KB
/
cli.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
package vault_plugin_auth_tencentcloud
import (
"errors"
"fmt"
"strings"
"github.com/hashicorp/vault-plugin-auth-tencentcloud/tools"
"github.com/hashicorp/vault/api"
)
// vault cli handler
type CLIHandler struct{}
// auth
func (h *CLIHandler) Auth(c *api.Client, m map[string]string) (*api.Secret, error) {
mount, ok := m["mount"]
if !ok {
mount = "tencentcloud"
}
role := m["role"]
sid := m["secret_id"]
skey := m["secret_key"]
token := m["token"]
region := m["region"]
loginData := tools.GenerateLoginDataV2(role, sid, skey, token, region)
path := fmt.Sprintf("auth/%s/login", mount)
secret, err := c.Logical().Write(path, loginData)
if err != nil {
return nil, err
}
if secret == nil {
return nil, errors.New("empty response from credential provider")
}
return secret, nil
}
// help
func (h *CLIHandler) Help() string {
help := `
Usage: vault login -method=tencentcloud [CONFIG K=V...]
The TencentCloud auth method allows users to authenticate with TencentCloud CAM
credentials.
The TencentCloud CAM credentials may be specified explicitly via the command line:
$ vault login -method=tencentcloud secret_id=... secret_key=... token=... region=...
Configuration:
secret_id=<string>
Explicit TencentCloud secret id
secret_key=<string>
Explicit TencentCloud secret key
token=<string>
Explicit TencentCloud token
region=<string>
Explicit TencentCloud region
mount=<string>
Path where the TencentCloud credential method is mounted. This is usually provided
via the -path flag in the "vault login" command, but it can be specified
here as well. If specified here, it takes precedence over the value for
-path. The default value is "tencentcloud".
role=<string>
Name of the role to request a token against
`
return strings.TrimSpace(help)
}