Merge remote-tracking branch 'origin/main' into llb-byow
This commit is contained in:
commit
704d68848c
160 files changed
+15933
-4684
No files matched your search
@@ -589,6 +589,7 @@ func (b *Server) SetupKMSes(ctx context.Context, ui cli.Ui, config *config.Confi
|
||||
configutil.WithPluginOptions(
|
||||
pluginutil.WithPluginsMap(kms_plugin_assets.BuiltinKmsPlugins()),
|
||||
pluginutil.WithPluginsFilesystem(kms_plugin_assets.KmsPluginPrefix, kms_plugin_assets.FileSystem()),
|
||||
pluginutil.WithPluginExecutionDirectory(config.Plugins.ExecutionDir),
|
||||
),
|
||||
configutil.WithLogger(pluginLogger.Named(kms.Type).With("purpose", purpose)),
|
||||
)
|
||||
|
||||
+61
-18
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/cmd/commands/config"
|
||||
"github.com/hashicorp/boundary/internal/cmd/commands/connect"
|
||||
"github.com/hashicorp/boundary/internal/cmd/commands/credentiallibrariescmd"
|
||||
"github.com/hashicorp/boundary/internal/cmd/commands/credentialscmd"
|
||||
"github.com/hashicorp/boundary/internal/cmd/commands/credentialstorescmd"
|
||||
"github.com/hashicorp/boundary/internal/cmd/commands/database"
|
||||
"github.com/hashicorp/boundary/internal/cmd/commands/dev"
|
||||
@@ -411,6 +412,12 @@ func initCommands(ui, serverCmdUi cli.Ui, runOpts *RunOptions) {
|
||||
Func: "create",
|
||||
}, nil
|
||||
},
|
||||
"credential-stores create static": func() (cli.Command, error) {
|
||||
return &credentialstorescmd.StaticCommand{
|
||||
Command: base.NewCommand(ui),
|
||||
Func: "create",
|
||||
}, nil
|
||||
},
|
||||
"credential-stores update": func() (cli.Command, error) {
|
||||
return &credentialstorescmd.Command{
|
||||
Command: base.NewCommand(ui),
|
||||
@@ -423,6 +430,60 @@ func initCommands(ui, serverCmdUi cli.Ui, runOpts *RunOptions) {
|
||||
Func: "update",
|
||||
}, nil
|
||||
},
|
||||
"credential-stores update static": func() (cli.Command, error) {
|
||||
return &credentialstorescmd.StaticCommand{
|
||||
Command: base.NewCommand(ui),
|
||||
Func: "update",
|
||||
}, nil
|
||||
},
|
||||
|
||||
"credentials": func() (cli.Command, error) {
|
||||
return &credentialscmd.Command{
|
||||
Command: base.NewCommand(ui),
|
||||
}, nil
|
||||
},
|
||||
"credentials read": func() (cli.Command, error) {
|
||||
return &credentialscmd.Command{
|
||||
Command: base.NewCommand(ui),
|
||||
Func: "read",
|
||||
}, nil
|
||||
},
|
||||
"credentials delete": func() (cli.Command, error) {
|
||||
return &credentialscmd.Command{
|
||||
Command: base.NewCommand(ui),
|
||||
Func: "delete",
|
||||
}, nil
|
||||
},
|
||||
"credentials list": func() (cli.Command, error) {
|
||||
return &credentialscmd.Command{
|
||||
Command: base.NewCommand(ui),
|
||||
Func: "list",
|
||||
}, nil
|
||||
},
|
||||
"credentials create": func() (cli.Command, error) {
|
||||
return &credentialscmd.Command{
|
||||
Command: base.NewCommand(ui),
|
||||
Func: "create",
|
||||
}, nil
|
||||
},
|
||||
"credentials create username-password": func() (cli.Command, error) {
|
||||
return &credentialscmd.UsernamePasswordCommand{
|
||||
Command: base.NewCommand(ui),
|
||||
Func: "create",
|
||||
}, nil
|
||||
},
|
||||
"credentials update": func() (cli.Command, error) {
|
||||
return &credentialscmd.Command{
|
||||
Command: base.NewCommand(ui),
|
||||
Func: "update",
|
||||
}, nil
|
||||
},
|
||||
"credentials update username-password": func() (cli.Command, error) {
|
||||
return &credentialscmd.UsernamePasswordCommand{
|
||||
Command: base.NewCommand(ui),
|
||||
Func: "update",
|
||||
}, nil
|
||||
},
|
||||
|
||||
"groups": func() (cli.Command, error) {
|
||||
return &groupscmd.Command{
|
||||
@@ -939,24 +1000,6 @@ func initCommands(ui, serverCmdUi cli.Ui, runOpts *RunOptions) {
|
||||
Func: "set-host-sources",
|
||||
}, nil
|
||||
},
|
||||
"targets add-credential-libraries": func() (cli.Command, error) {
|
||||
return &targetscmd.Command{
|
||||
Command: base.NewCommand(ui),
|
||||
Func: "add-credential-libraries",
|
||||
}, nil
|
||||
},
|
||||
"targets remove-credential-libraries": func() (cli.Command, error) {
|
||||
return &targetscmd.Command{
|
||||
Command: base.NewCommand(ui),
|
||||
Func: "remove-credential-libraries",
|
||||
}, nil
|
||||
},
|
||||
"targets set-credential-libraries": func() (cli.Command, error) {
|
||||
return &targetscmd.Command{
|
||||
Command: base.NewCommand(ui),
|
||||
Func: "set-credential-libraries",
|
||||
}, nil
|
||||
},
|
||||
"targets add-credential-sources": func() (cli.Command, error) {
|
||||
return &targetscmd.Command{
|
||||
Command: base.NewCommand(ui),
|
||||
|
||||
@@ -492,6 +492,15 @@ func (c *Command) Run(args []string) (retCode int) {
|
||||
// Credentials are brokered when connecting to the postgres db.
|
||||
// TODO: Figure out how to handle cases where we don't automatically know how to
|
||||
// broker the credentials like unrecognized or multiple credentials.
|
||||
case "ssh":
|
||||
if c.flagExec == "sshpass" {
|
||||
// If we can broker ssh credentials using sshpass, skip displaying creds on client side.
|
||||
// TODO: Figure out how to handle multiple credentials
|
||||
break
|
||||
}
|
||||
|
||||
// We cannot broker credentials print to user
|
||||
fallthrough
|
||||
case "connect":
|
||||
// "connect" indicates there is no subcommand to the connect function.
|
||||
// The only way a user will be able to connect to the session is by
|
||||
@@ -838,7 +847,13 @@ func (c *Command) handleExec(passthroughArgs []string) {
|
||||
args = append(args, c.rdpFlags.buildArgs(c, port, ip, addr)...)
|
||||
|
||||
case "ssh":
|
||||
args = append(args, c.sshFlags.buildArgs(c, port, ip, addr)...)
|
||||
sshArgs, sshEnvs, sshErr := c.sshFlags.buildArgs(c, port, ip, addr)
|
||||
if sshErr != nil {
|
||||
argsErr = sshErr
|
||||
break
|
||||
}
|
||||
args = append(args, sshArgs...)
|
||||
envs = append(envs, sshEnvs...)
|
||||
|
||||
case "kube":
|
||||
kubeArgs, err := c.kubeFlags.buildArgs(c, port, ip, addr)
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package connect
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/hashicorp/boundary/api/targets"
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
type usernamePasswordCredentials struct {
|
||||
Username string `mapstructure:"username"`
|
||||
Password string `mapstructure:"password"`
|
||||
}
|
||||
|
||||
// TODO: this should support multiple types of credentials and return an interface instead
|
||||
// of only usernamepassword. Each subcommand can use the returned credentials as it needs.
|
||||
func parseCredentials(creds []*targets.SessionCredential) ([]usernamePasswordCredentials, error) {
|
||||
if creds == nil {
|
||||
return nil, nil
|
||||
}
|
||||
var out []usernamePasswordCredentials
|
||||
for _, cred := range creds {
|
||||
if cred.CredentialSource == nil {
|
||||
return nil, errors.New("missing credential source")
|
||||
}
|
||||
|
||||
var c usernamePasswordCredentials
|
||||
if cred.CredentialSource.CredentialType == string(credential.UsernamePasswordType) {
|
||||
// Decode attributes from credential struct
|
||||
if err := mapstructure.Decode(cred.Credential, &c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if c.Username != "" && c.Password != "" {
|
||||
out = append(out, c)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Credential type is unspecified, make a best effort attempt to parse both username
|
||||
// and password from Decoded field if it exists
|
||||
if cred.Secret == nil || cred.Secret.Decoded == nil {
|
||||
// No secret data continue to next credential
|
||||
continue
|
||||
}
|
||||
|
||||
switch cred.CredentialSource.Type {
|
||||
case "vault", "static":
|
||||
// Attempt unmarshaling into creds
|
||||
if err := mapstructure.Decode(cred.Secret.Decoded, &c); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if c.Username != "" && c.Password != "" {
|
||||
out = append(out, c)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
package connect
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api/targets"
|
||||
"github.com/hashicorp/boundary/internal/credential"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_parseUsernamePasswordCredentials(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
creds []*targets.SessionCredential
|
||||
wantCreds []usernamePasswordCredentials
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "no-creds",
|
||||
wantCreds: nil,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "no-credential-source",
|
||||
creds: []*targets.SessionCredential{
|
||||
{
|
||||
Credential: map[string]interface{}{
|
||||
"username": "user",
|
||||
"password": "pass",
|
||||
},
|
||||
},
|
||||
},
|
||||
wantCreds: nil,
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "valid-typed",
|
||||
creds: []*targets.SessionCredential{
|
||||
{
|
||||
CredentialSource: &targets.CredentialSource{
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
},
|
||||
Credential: map[string]interface{}{
|
||||
"username": "user",
|
||||
"password": "pass",
|
||||
},
|
||||
},
|
||||
},
|
||||
wantCreds: []usernamePasswordCredentials{
|
||||
{
|
||||
Username: "user",
|
||||
Password: "pass",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "valid-typed-instead-of-decoded",
|
||||
creds: []*targets.SessionCredential{
|
||||
{
|
||||
CredentialSource: &targets.CredentialSource{
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
},
|
||||
Credential: map[string]interface{}{
|
||||
"username": "user",
|
||||
"password": "pass",
|
||||
},
|
||||
Secret: &targets.SessionSecret{
|
||||
Decoded: map[string]interface{}{
|
||||
"username": "secret-user",
|
||||
"password": "secret-pass",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantCreds: []usernamePasswordCredentials{
|
||||
{
|
||||
Username: "user",
|
||||
Password: "pass",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "valid-vault-not-typed",
|
||||
creds: []*targets.SessionCredential{
|
||||
{
|
||||
CredentialSource: &targets.CredentialSource{
|
||||
Type: "vault",
|
||||
},
|
||||
Secret: &targets.SessionSecret{
|
||||
Decoded: map[string]interface{}{
|
||||
"username": "user",
|
||||
"password": "pass",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantCreds: []usernamePasswordCredentials{
|
||||
{
|
||||
Username: "user",
|
||||
Password: "pass",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "valid-static-not-typed",
|
||||
creds: []*targets.SessionCredential{
|
||||
{
|
||||
CredentialSource: &targets.CredentialSource{
|
||||
Type: "static",
|
||||
},
|
||||
Secret: &targets.SessionSecret{
|
||||
Decoded: map[string]interface{}{
|
||||
"username": "user",
|
||||
"password": "pass",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantCreds: []usernamePasswordCredentials{
|
||||
{
|
||||
Username: "user",
|
||||
Password: "pass",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "valid-multiple",
|
||||
creds: []*targets.SessionCredential{
|
||||
{
|
||||
CredentialSource: &targets.CredentialSource{
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
},
|
||||
Credential: map[string]interface{}{
|
||||
"username": "user",
|
||||
"password": "pass",
|
||||
},
|
||||
},
|
||||
{
|
||||
CredentialSource: &targets.CredentialSource{
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
},
|
||||
Credential: map[string]interface{}{
|
||||
"username": "user1",
|
||||
"password": "pass1",
|
||||
},
|
||||
},
|
||||
},
|
||||
wantCreds: []usernamePasswordCredentials{
|
||||
{
|
||||
Username: "user",
|
||||
Password: "pass",
|
||||
},
|
||||
{
|
||||
Username: "user1",
|
||||
Password: "pass1",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "valid-multiple-mixed",
|
||||
creds: []*targets.SessionCredential{
|
||||
{
|
||||
CredentialSource: &targets.CredentialSource{
|
||||
CredentialType: string(credential.UsernamePasswordType),
|
||||
},
|
||||
Credential: map[string]interface{}{
|
||||
"username": "user",
|
||||
"password": "pass",
|
||||
},
|
||||
},
|
||||
{
|
||||
CredentialSource: &targets.CredentialSource{
|
||||
Type: "vault",
|
||||
},
|
||||
Secret: &targets.SessionSecret{
|
||||
Decoded: map[string]interface{}{
|
||||
"username": "user1",
|
||||
"password": "pass1",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
CredentialSource: &targets.CredentialSource{
|
||||
Type: "static",
|
||||
},
|
||||
Secret: &targets.SessionSecret{
|
||||
Decoded: map[string]interface{}{
|
||||
"username": "user2",
|
||||
"password": "pass2",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantCreds: []usernamePasswordCredentials{
|
||||
{
|
||||
Username: "user",
|
||||
Password: "pass",
|
||||
},
|
||||
{
|
||||
Username: "user1",
|
||||
Password: "pass1",
|
||||
},
|
||||
{
|
||||
Username: "user2",
|
||||
Password: "pass2",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
|
||||
creds, err := parseCredentials(tt.creds)
|
||||
if tt.wantErr {
|
||||
require.Error(err)
|
||||
assert.Nil(creds)
|
||||
return
|
||||
}
|
||||
require.NoError(err)
|
||||
assert.ElementsMatch(tt.wantCreds, creds)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ func fmtSecretForTable(indent int, sc *targets.SessionCredential) []string {
|
||||
prefixStr := strings.Repeat(" ", indent)
|
||||
origSecret := []string{fmt.Sprintf("%s %s", prefixStr, sc.Secret.Raw)}
|
||||
switch sc.CredentialSource.Type {
|
||||
case "vault":
|
||||
case "vault", "static":
|
||||
if sc.Credential != nil {
|
||||
maxLength := 0
|
||||
for k := range sc.Credential {
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/cmd/base"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/posener/complete"
|
||||
)
|
||||
|
||||
@@ -52,33 +51,18 @@ func (p *postgresFlags) defaultExec() string {
|
||||
return strings.ToLower(p.flagPostgresStyle)
|
||||
}
|
||||
|
||||
type postgresCredentials struct {
|
||||
Username string `mapstructure:"username"`
|
||||
Password string `mapstructure:"password"`
|
||||
}
|
||||
|
||||
func (p *postgresFlags) buildArgs(c *Command, port, ip, addr string) (args, envs []string, retErr error) {
|
||||
var creds postgresCredentials
|
||||
if c.sessionAuthz != nil && len(c.sessionAuthz.Credentials) > 0 {
|
||||
for _, cred := range c.sessionAuthz.Credentials {
|
||||
if cred.Secret == nil || cred.Secret.Decoded == nil {
|
||||
continue
|
||||
}
|
||||
// TODO: Could allow switching on library ID or name
|
||||
switch cred.CredentialLibrary.Type {
|
||||
case "vault":
|
||||
// Attempt unmarshaling into creds
|
||||
if err := mapstructure.Decode(cred.Secret.Decoded, &creds); err != nil {
|
||||
return nil, nil, fmt.Errorf("Error interpreting Vault secret: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if creds.Username != "" && creds.Password != "" {
|
||||
// In the future we can look for other types if we support other
|
||||
// authentication mechanisms
|
||||
break
|
||||
}
|
||||
var cred usernamePasswordCredentials
|
||||
if c.sessionAuthz != nil {
|
||||
creds, err := parseCredentials(c.sessionAuthz.Credentials)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("Error interpreting secret: %w", err)
|
||||
}
|
||||
if len(creds) > 0 {
|
||||
// Just use first credentials returned
|
||||
cred = creds[0]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
switch p.flagPostgresStyle {
|
||||
@@ -90,13 +74,13 @@ func (p *postgresFlags) buildArgs(c *Command, port, ip, addr string) (args, envs
|
||||
}
|
||||
|
||||
switch {
|
||||
case creds.Username != "":
|
||||
args = append(args, "-U", creds.Username)
|
||||
case cred.Username != "":
|
||||
args = append(args, "-U", cred.Username)
|
||||
case c.flagUsername != "":
|
||||
args = append(args, "-U", c.flagUsername)
|
||||
}
|
||||
|
||||
if creds.Password != "" {
|
||||
if cred.Password != "" {
|
||||
passfile, err := ioutil.TempFile("", "*")
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("Error saving postgres password to tmp file: %w", err)
|
||||
@@ -107,7 +91,7 @@ func (p *postgresFlags) buildArgs(c *Command, port, ip, addr string) (args, envs
|
||||
}
|
||||
return nil
|
||||
})
|
||||
_, err = passfile.WriteString(fmt.Sprintf("*:*:*:*:%s", creds.Password))
|
||||
_, err = passfile.WriteString(fmt.Sprintf("*:*:*:*:%s", cred.Password))
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("Error writing password file to %s: %w", passfile.Name(), err)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package connect
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -19,7 +20,7 @@ func sshOptions(c *Command, set *base.FlagSets) {
|
||||
Name: "style",
|
||||
Target: &c.flagSshStyle,
|
||||
EnvVar: "BOUNDARY_CONNECT_SSH_STYLE",
|
||||
Completion: complete.PredictSet("ssh", "putty"),
|
||||
Completion: complete.PredictSet("ssh", "putty", "sshpass"),
|
||||
Default: "ssh",
|
||||
Usage: `Specifies how the CLI will attempt to invoke an SSH client. This will also set a suitable default for -exec if a value was not specified. Currently-understood values are "ssh" and "putty".`,
|
||||
})
|
||||
@@ -41,18 +42,52 @@ func (s *sshFlags) defaultExec() string {
|
||||
return strings.ToLower(s.flagSshStyle)
|
||||
}
|
||||
|
||||
func (s *sshFlags) buildArgs(c *Command, port, ip, addr string) []string {
|
||||
// Might want -t for ssh or -tt but seems fine without it for now...
|
||||
var args []string
|
||||
switch s.flagSshStyle {
|
||||
func (s *sshFlags) buildArgs(c *Command, port, ip, addr string) (args, envs []string, retErr error) {
|
||||
var cred usernamePasswordCredentials
|
||||
if c.sessionAuthz != nil {
|
||||
creds, err := parseCredentials(c.sessionAuthz.Credentials)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("Error interpreting secret: %w", err)
|
||||
}
|
||||
if len(creds) > 0 {
|
||||
// Just use first credentials returned
|
||||
cred = creds[0]
|
||||
}
|
||||
}
|
||||
|
||||
switch strings.ToLower(s.flagSshStyle) {
|
||||
case "ssh":
|
||||
// Might want -t for ssh or -tt but seems fine without it for now...
|
||||
args = append(args, "-p", port, ip)
|
||||
args = append(args, "-o", fmt.Sprintf("HostKeyAlias=%s", c.sessionAuthzData.HostId))
|
||||
|
||||
// SSH detects a host key change when localhost proxy port changes, disable localhost
|
||||
// host key verification to avoid 'WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED...'
|
||||
args = append(args, "-o", "NoHostAuthenticationForLocalhost=yes")
|
||||
|
||||
case "sshpass":
|
||||
if cred.Password == "" {
|
||||
return nil, nil, errors.New("Password is required when using sshpass")
|
||||
}
|
||||
// sshpass requires that the password is passed as env-var "SSHPASS"
|
||||
// when the using env-vars.
|
||||
envs = append(envs, fmt.Sprintf("SSHPASS=%s", cred.Password))
|
||||
args = append(args, "-e", "ssh")
|
||||
args = append(args, "-p", port, ip)
|
||||
|
||||
// sshpass cannot handle host key checking, disable localhost key verification
|
||||
// to avoid error: 'SSHPASS detected host authentication prompt. Exiting.'
|
||||
args = append(args, "-o", "NoHostAuthenticationForLocalhost=yes")
|
||||
|
||||
case "putty":
|
||||
args = append(args, "-P", port, ip)
|
||||
}
|
||||
if c.flagUsername != "" {
|
||||
|
||||
switch {
|
||||
case cred.Username != "":
|
||||
args = append(args, "-l", cred.Username)
|
||||
case c.flagUsername != "":
|
||||
args = append(args, "-l", c.flagUsername)
|
||||
}
|
||||
return args
|
||||
|
||||
return args, envs, nil
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
// Code generated by "make cli"; DO NOT EDIT.
|
||||
package credentialscmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/credentials"
|
||||
"github.com/hashicorp/boundary/internal/cmd/base"
|
||||
"github.com/hashicorp/boundary/internal/cmd/common"
|
||||
"github.com/hashicorp/go-secure-stdlib/strutil"
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/posener/complete"
|
||||
)
|
||||
|
||||
func initFlags() {
|
||||
flagsOnce.Do(func() {
|
||||
extraFlags := extraActionsFlagsMapFunc()
|
||||
for k, v := range extraFlags {
|
||||
flagsMap[k] = append(flagsMap[k], v...)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
var (
|
||||
_ cli.Command = (*Command)(nil)
|
||||
_ cli.CommandAutocomplete = (*Command)(nil)
|
||||
)
|
||||
|
||||
type Command struct {
|
||||
*base.Command
|
||||
|
||||
Func string
|
||||
|
||||
plural string
|
||||
}
|
||||
|
||||
func (c *Command) AutocompleteArgs() complete.Predictor {
|
||||
initFlags()
|
||||
return complete.PredictAnything
|
||||
}
|
||||
|
||||
func (c *Command) AutocompleteFlags() complete.Flags {
|
||||
initFlags()
|
||||
return c.Flags().Completions()
|
||||
}
|
||||
|
||||
func (c *Command) Synopsis() string {
|
||||
if extra := extraSynopsisFunc(c); extra != "" {
|
||||
return extra
|
||||
}
|
||||
|
||||
synopsisStr := "credential"
|
||||
|
||||
return common.SynopsisFunc(c.Func, synopsisStr)
|
||||
}
|
||||
|
||||
func (c *Command) Help() string {
|
||||
initFlags()
|
||||
|
||||
var helpStr string
|
||||
helpMap := common.HelpMap("credential")
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "read":
|
||||
helpStr = helpMap[c.Func]() + c.Flags().Help()
|
||||
|
||||
case "delete":
|
||||
helpStr = helpMap[c.Func]() + c.Flags().Help()
|
||||
|
||||
case "list":
|
||||
helpStr = helpMap[c.Func]() + c.Flags().Help()
|
||||
|
||||
default:
|
||||
|
||||
helpStr = c.extraHelpFunc(helpMap)
|
||||
|
||||
}
|
||||
|
||||
// Keep linter from complaining if we don't actually generate code using it
|
||||
_ = helpMap
|
||||
return helpStr
|
||||
}
|
||||
|
||||
var flagsMap = map[string][]string{
|
||||
|
||||
"read": {"id"},
|
||||
|
||||
"delete": {"id"},
|
||||
|
||||
"list": {"credential-store-id", "filter"},
|
||||
}
|
||||
|
||||
func (c *Command) Flags() *base.FlagSets {
|
||||
if len(flagsMap[c.Func]) == 0 {
|
||||
return c.FlagSet(base.FlagSetNone)
|
||||
}
|
||||
|
||||
set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat)
|
||||
f := set.NewFlagSet("Command Options")
|
||||
common.PopulateCommonFlags(c.Command, f, "credential", flagsMap, c.Func)
|
||||
|
||||
extraFlagsFunc(c, set, f)
|
||||
|
||||
return set
|
||||
}
|
||||
|
||||
func (c *Command) Run(args []string) int {
|
||||
initFlags()
|
||||
|
||||
switch c.Func {
|
||||
case "":
|
||||
return cli.RunResultHelp
|
||||
|
||||
case "create":
|
||||
return cli.RunResultHelp
|
||||
|
||||
case "update":
|
||||
return cli.RunResultHelp
|
||||
|
||||
}
|
||||
|
||||
c.plural = "credential"
|
||||
switch c.Func {
|
||||
case "list":
|
||||
c.plural = "credentials"
|
||||
}
|
||||
|
||||
f := c.Flags()
|
||||
|
||||
if err := f.Parse(args); err != nil {
|
||||
c.PrintCliError(err)
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
if strutil.StrListContains(flagsMap[c.Func], "id") && c.FlagId == "" {
|
||||
c.PrintCliError(errors.New("ID is required but not passed in via -id"))
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var opts []credentials.Option
|
||||
|
||||
if strutil.StrListContains(flagsMap[c.Func], "credential-store-id") {
|
||||
switch c.Func {
|
||||
|
||||
case "list":
|
||||
if c.FlagCredentialStoreId == "" {
|
||||
c.PrintCliError(errors.New("CredentialStore ID must be passed in via -credential-store-id or BOUNDARY_CREDENTIAL_STORE_ID"))
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
client, err := c.Client()
|
||||
if c.WrapperCleanupFunc != nil {
|
||||
defer func() {
|
||||
if err := c.WrapperCleanupFunc(); err != nil {
|
||||
c.PrintCliError(fmt.Errorf("Error cleaning kms wrapper: %w", err))
|
||||
}
|
||||
}()
|
||||
}
|
||||
if err != nil {
|
||||
c.PrintCliError(fmt.Errorf("Error creating API client: %w", err))
|
||||
return base.CommandCliError
|
||||
}
|
||||
credentialsClient := credentials.NewClient(client)
|
||||
|
||||
if c.FlagFilter != "" {
|
||||
opts = append(opts, credentials.WithFilter(c.FlagFilter))
|
||||
}
|
||||
|
||||
var version uint32
|
||||
|
||||
if ok := extraFlagsHandlingFunc(c, f, &opts); !ok {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
|
||||
var listResult api.GenericListResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "read":
|
||||
result, err = credentialsClient.Read(c.Context, c.FlagId, opts...)
|
||||
|
||||
case "delete":
|
||||
result, err = credentialsClient.Delete(c.Context, c.FlagId, opts...)
|
||||
|
||||
case "list":
|
||||
listResult, err = credentialsClient.List(c.Context, c.FlagCredentialStoreId, opts...)
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraActions(c, result, err, credentialsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
var opts []base.Option
|
||||
|
||||
c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural), opts...)
|
||||
return base.CommandApiError
|
||||
}
|
||||
c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error()))
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
output, err := printCustomActionOutput(c)
|
||||
if err != nil {
|
||||
c.PrintCliError(err)
|
||||
return base.CommandUserError
|
||||
}
|
||||
if output {
|
||||
return base.CommandSuccess
|
||||
}
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "delete":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
c.UI.Output("The delete operation completed successfully.")
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
|
||||
case "list":
|
||||
switch base.Format(c.UI) {
|
||||
case "json":
|
||||
if ok := c.PrintJsonItems(listResult); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
case "table":
|
||||
listedItems := listResult.GetItems().([]*credentials.Credential)
|
||||
c.UI.Output(c.printListTable(listedItems))
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
|
||||
}
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
}
|
||||
|
||||
var (
|
||||
flagsOnce = new(sync.Once)
|
||||
|
||||
extraActionsFlagsMapFunc = func() map[string][]string { return nil }
|
||||
extraSynopsisFunc = func(*Command) string { return "" }
|
||||
extraFlagsFunc = func(*Command, *base.FlagSets, *base.FlagSet) {}
|
||||
extraFlagsHandlingFunc = func(*Command, *base.FlagSets, *[]credentials.Option) bool { return true }
|
||||
executeExtraActions = func(_ *Command, inResult api.GenericResult, inErr error, _ *credentials.Client, _ uint32, _ []credentials.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
}
|
||||
printCustomActionOutput = func(*Command) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -0,0 +1,177 @@
|
||||
package credentialscmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/credentials"
|
||||
"github.com/hashicorp/boundary/internal/cmd/base"
|
||||
)
|
||||
|
||||
func (c *Command) extraHelpFunc(helpMap map[string]func() string) string {
|
||||
var helpStr string
|
||||
switch c.Func {
|
||||
case "":
|
||||
return base.WrapForHelpText([]string{
|
||||
"Usage: boundary credentials [sub command] [options] [args]",
|
||||
"",
|
||||
" This command allows operations on Boundary credential resources. Example:",
|
||||
"",
|
||||
" Read a credential:",
|
||||
"",
|
||||
` $ boundary credentials read -id cred_1234567890`,
|
||||
"",
|
||||
" Please see the credentials subcommand help for detailed usage information.",
|
||||
})
|
||||
case "create":
|
||||
helpStr = base.WrapForHelpText([]string{
|
||||
"Usage: boundary credentials create [type] [sub command] [options] [args]",
|
||||
"",
|
||||
" This command allows create operations on Boundary credential resources. Example:",
|
||||
"",
|
||||
" Create a credential:",
|
||||
"",
|
||||
` $ boundary credentials create username-password -credential-store-id cs_1234567890 -username user -password pass`,
|
||||
"",
|
||||
" Please see the typed subcommand help for detailed usage information.",
|
||||
})
|
||||
case "update":
|
||||
helpStr = base.WrapForHelpText([]string{
|
||||
"Usage: boundary credentials update [type] [sub command] [options] [args]",
|
||||
"",
|
||||
" This command allows update operations on Boundary credential resources. Example:",
|
||||
"",
|
||||
" Update a user password credential:",
|
||||
"",
|
||||
` $ boundary credentials update username-password -id cred_1234567890 -name devops -description "For DevOps usage"`,
|
||||
"",
|
||||
" Please see the typed subcommand help for detailed usage information.",
|
||||
})
|
||||
default:
|
||||
helpStr = helpMap["base"]()
|
||||
}
|
||||
return helpStr + c.Flags().Help()
|
||||
}
|
||||
|
||||
func (c *Command) printListTable(items []*credentials.Credential) string {
|
||||
if len(items) == 0 {
|
||||
return "No credentials found"
|
||||
}
|
||||
|
||||
var output []string
|
||||
output = []string{
|
||||
"",
|
||||
"Credential information:",
|
||||
}
|
||||
for i, m := range items {
|
||||
if i > 0 {
|
||||
output = append(output, "")
|
||||
}
|
||||
if m.Id != "" {
|
||||
output = append(output,
|
||||
fmt.Sprintf(" ID: %s", m.Id),
|
||||
)
|
||||
} else {
|
||||
output = append(output,
|
||||
fmt.Sprintf(" ID: %s", "(not available)"),
|
||||
)
|
||||
}
|
||||
if m.Version > 0 {
|
||||
output = append(output,
|
||||
fmt.Sprintf(" Version: %d", m.Version),
|
||||
)
|
||||
}
|
||||
if m.Type != "" {
|
||||
output = append(output,
|
||||
fmt.Sprintf(" Type: %s", m.Type),
|
||||
)
|
||||
}
|
||||
if m.Name != "" {
|
||||
output = append(output,
|
||||
fmt.Sprintf(" Name: %s", m.Name),
|
||||
)
|
||||
}
|
||||
if m.Description != "" {
|
||||
output = append(output,
|
||||
fmt.Sprintf(" Description: %s", m.Description),
|
||||
)
|
||||
}
|
||||
if len(m.AuthorizedActions) > 0 {
|
||||
output = append(output,
|
||||
" Authorized Actions:",
|
||||
base.WrapSlice(6, m.AuthorizedActions),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return base.WrapForHelpText(output)
|
||||
}
|
||||
|
||||
func printItemTable(result api.GenericResult) string {
|
||||
item := result.GetItem().(*credentials.Credential)
|
||||
nonAttributeMap := map[string]interface{}{}
|
||||
if item.Id != "" {
|
||||
nonAttributeMap["ID"] = item.Id
|
||||
}
|
||||
if item.Version != 0 {
|
||||
nonAttributeMap["Version"] = item.Version
|
||||
}
|
||||
if !item.CreatedTime.IsZero() {
|
||||
nonAttributeMap["Created Time"] = item.CreatedTime.Local().Format(time.RFC1123)
|
||||
}
|
||||
if !item.UpdatedTime.IsZero() {
|
||||
nonAttributeMap["Updated Time"] = item.UpdatedTime.Local().Format(time.RFC1123)
|
||||
}
|
||||
if item.CredentialStoreId != "" {
|
||||
nonAttributeMap["Credential Store ID"] = item.CredentialStoreId
|
||||
}
|
||||
if item.Name != "" {
|
||||
nonAttributeMap["Name"] = item.Name
|
||||
}
|
||||
if item.Description != "" {
|
||||
nonAttributeMap["Description"] = item.Description
|
||||
}
|
||||
if item.Type != "" {
|
||||
nonAttributeMap["Type"] = item.Type
|
||||
}
|
||||
|
||||
maxLength := base.MaxAttributesLength(nonAttributeMap, item.Attributes, keySubstMap)
|
||||
|
||||
ret := []string{
|
||||
"",
|
||||
"Credential information:",
|
||||
base.WrapMap(2, maxLength+2, nonAttributeMap),
|
||||
}
|
||||
|
||||
if item.Scope != nil {
|
||||
ret = append(ret,
|
||||
"",
|
||||
" Scope:",
|
||||
base.ScopeInfoForOutput(item.Scope, maxLength),
|
||||
)
|
||||
}
|
||||
|
||||
if len(item.AuthorizedActions) > 0 {
|
||||
ret = append(ret,
|
||||
"",
|
||||
" Authorized Actions:",
|
||||
base.WrapSlice(4, item.AuthorizedActions),
|
||||
)
|
||||
}
|
||||
|
||||
if len(item.Attributes) > 0 {
|
||||
ret = append(ret,
|
||||
"",
|
||||
" Attributes:",
|
||||
base.WrapMap(4, maxLength, item.Attributes),
|
||||
)
|
||||
}
|
||||
|
||||
return base.WrapForHelpText(ret)
|
||||
}
|
||||
|
||||
var keySubstMap = map[string]string{
|
||||
"username": "Username",
|
||||
"password_hmac": "Password HMAC",
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
// Code generated by "make cli"; DO NOT EDIT.
|
||||
package credentialscmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/credentials"
|
||||
"github.com/hashicorp/boundary/internal/cmd/base"
|
||||
"github.com/hashicorp/boundary/internal/cmd/common"
|
||||
"github.com/hashicorp/go-secure-stdlib/strutil"
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/posener/complete"
|
||||
)
|
||||
|
||||
func initUsernamePasswordFlags() {
|
||||
flagsOnce.Do(func() {
|
||||
extraFlags := extraUsernamePasswordActionsFlagsMapFunc()
|
||||
for k, v := range extraFlags {
|
||||
flagsUsernamePasswordMap[k] = append(flagsUsernamePasswordMap[k], v...)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
var (
|
||||
_ cli.Command = (*UsernamePasswordCommand)(nil)
|
||||
_ cli.CommandAutocomplete = (*UsernamePasswordCommand)(nil)
|
||||
)
|
||||
|
||||
type UsernamePasswordCommand struct {
|
||||
*base.Command
|
||||
|
||||
Func string
|
||||
|
||||
plural string
|
||||
|
||||
extraUsernamePasswordCmdVars
|
||||
}
|
||||
|
||||
func (c *UsernamePasswordCommand) AutocompleteArgs() complete.Predictor {
|
||||
initUsernamePasswordFlags()
|
||||
return complete.PredictAnything
|
||||
}
|
||||
|
||||
func (c *UsernamePasswordCommand) AutocompleteFlags() complete.Flags {
|
||||
initUsernamePasswordFlags()
|
||||
return c.Flags().Completions()
|
||||
}
|
||||
|
||||
func (c *UsernamePasswordCommand) Synopsis() string {
|
||||
if extra := extraUsernamePasswordSynopsisFunc(c); extra != "" {
|
||||
return extra
|
||||
}
|
||||
|
||||
synopsisStr := "credential"
|
||||
|
||||
synopsisStr = fmt.Sprintf("%s %s", "username_password-type", synopsisStr)
|
||||
|
||||
return common.SynopsisFunc(c.Func, synopsisStr)
|
||||
}
|
||||
|
||||
func (c *UsernamePasswordCommand) Help() string {
|
||||
initUsernamePasswordFlags()
|
||||
|
||||
var helpStr string
|
||||
helpMap := common.HelpMap("credential")
|
||||
|
||||
switch c.Func {
|
||||
|
||||
default:
|
||||
|
||||
helpStr = c.extraUsernamePasswordHelpFunc(helpMap)
|
||||
|
||||
}
|
||||
|
||||
// Keep linter from complaining if we don't actually generate code using it
|
||||
_ = helpMap
|
||||
return helpStr
|
||||
}
|
||||
|
||||
var flagsUsernamePasswordMap = map[string][]string{
|
||||
|
||||
"create": {"credential-store-id", "name", "description"},
|
||||
|
||||
"update": {"id", "name", "description", "version"},
|
||||
}
|
||||
|
||||
func (c *UsernamePasswordCommand) Flags() *base.FlagSets {
|
||||
if len(flagsUsernamePasswordMap[c.Func]) == 0 {
|
||||
return c.FlagSet(base.FlagSetNone)
|
||||
}
|
||||
|
||||
set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat)
|
||||
f := set.NewFlagSet("Command Options")
|
||||
common.PopulateCommonFlags(c.Command, f, "username_password-type credential", flagsUsernamePasswordMap, c.Func)
|
||||
|
||||
extraUsernamePasswordFlagsFunc(c, set, f)
|
||||
|
||||
return set
|
||||
}
|
||||
|
||||
func (c *UsernamePasswordCommand) Run(args []string) int {
|
||||
initUsernamePasswordFlags()
|
||||
|
||||
switch c.Func {
|
||||
case "":
|
||||
return cli.RunResultHelp
|
||||
|
||||
}
|
||||
|
||||
c.plural = "username_password-type credential"
|
||||
switch c.Func {
|
||||
case "list":
|
||||
c.plural = "username_password-type credentials"
|
||||
}
|
||||
|
||||
f := c.Flags()
|
||||
|
||||
if err := f.Parse(args); err != nil {
|
||||
c.PrintCliError(err)
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
if strutil.StrListContains(flagsUsernamePasswordMap[c.Func], "id") && c.FlagId == "" {
|
||||
c.PrintCliError(errors.New("ID is required but not passed in via -id"))
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var opts []credentials.Option
|
||||
|
||||
if strutil.StrListContains(flagsUsernamePasswordMap[c.Func], "credential-store-id") {
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
if c.FlagCredentialStoreId == "" {
|
||||
c.PrintCliError(errors.New("CredentialStore ID must be passed in via -credential-store-id or BOUNDARY_CREDENTIAL_STORE_ID"))
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
client, err := c.Client()
|
||||
if c.WrapperCleanupFunc != nil {
|
||||
defer func() {
|
||||
if err := c.WrapperCleanupFunc(); err != nil {
|
||||
c.PrintCliError(fmt.Errorf("Error cleaning kms wrapper: %w", err))
|
||||
}
|
||||
}()
|
||||
}
|
||||
if err != nil {
|
||||
c.PrintCliError(fmt.Errorf("Error creating API client: %w", err))
|
||||
return base.CommandCliError
|
||||
}
|
||||
credentialsClient := credentials.NewClient(client)
|
||||
|
||||
switch c.FlagName {
|
||||
case "":
|
||||
case "null":
|
||||
opts = append(opts, credentials.DefaultName())
|
||||
default:
|
||||
opts = append(opts, credentials.WithName(c.FlagName))
|
||||
}
|
||||
|
||||
switch c.FlagDescription {
|
||||
case "":
|
||||
case "null":
|
||||
opts = append(opts, credentials.DefaultDescription())
|
||||
default:
|
||||
opts = append(opts, credentials.WithDescription(c.FlagDescription))
|
||||
}
|
||||
|
||||
if c.FlagFilter != "" {
|
||||
opts = append(opts, credentials.WithFilter(c.FlagFilter))
|
||||
}
|
||||
|
||||
var version uint32
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "update":
|
||||
switch c.FlagVersion {
|
||||
case 0:
|
||||
opts = append(opts, credentials.WithAutomaticVersioning(true))
|
||||
default:
|
||||
version = uint32(c.FlagVersion)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ok := extraUsernamePasswordFlagsHandlingFunc(c, f, &opts); !ok {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = credentialsClient.Create(c.Context, "username_password", c.FlagCredentialStoreId, opts...)
|
||||
|
||||
case "update":
|
||||
result, err = credentialsClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraUsernamePasswordActions(c, result, err, credentialsClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
var opts []base.Option
|
||||
|
||||
opts = append(opts, base.WithAttributeFieldPrefix("username_password"))
|
||||
|
||||
c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural), opts...)
|
||||
return base.CommandApiError
|
||||
}
|
||||
c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error()))
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
output, err := printCustomUsernamePasswordActionOutput(c)
|
||||
if err != nil {
|
||||
c.PrintCliError(err)
|
||||
return base.CommandUserError
|
||||
}
|
||||
if output {
|
||||
return base.CommandSuccess
|
||||
}
|
||||
|
||||
switch c.Func {
|
||||
|
||||
}
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
}
|
||||
|
||||
var (
|
||||
extraUsernamePasswordActionsFlagsMapFunc = func() map[string][]string { return nil }
|
||||
extraUsernamePasswordSynopsisFunc = func(*UsernamePasswordCommand) string { return "" }
|
||||
extraUsernamePasswordFlagsFunc = func(*UsernamePasswordCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraUsernamePasswordFlagsHandlingFunc = func(*UsernamePasswordCommand, *base.FlagSets, *[]credentials.Option) bool { return true }
|
||||
executeExtraUsernamePasswordActions = func(_ *UsernamePasswordCommand, inResult api.GenericResult, inErr error, _ *credentials.Client, _ uint32, _ []credentials.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
}
|
||||
printCustomUsernamePasswordActionOutput = func(*UsernamePasswordCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -0,0 +1,97 @@
|
||||
package credentialscmd
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/boundary/api/credentials"
|
||||
"github.com/hashicorp/boundary/internal/cmd/base"
|
||||
)
|
||||
|
||||
func init() {
|
||||
extraUsernamePasswordFlagsFunc = extraUsernamePasswordFlagsFuncImpl
|
||||
extraUsernamePasswordActionsFlagsMapFunc = extraUsernamePasswordActionsFlagsMapFuncImpl
|
||||
extraUsernamePasswordFlagsHandlingFunc = extraUsernamePasswordFlagHandlingFuncImpl
|
||||
}
|
||||
|
||||
const (
|
||||
usernameFlagName = "username"
|
||||
passwordFlagName = "password"
|
||||
)
|
||||
|
||||
type extraUsernamePasswordCmdVars struct {
|
||||
flagUsername string
|
||||
flagPassword string
|
||||
}
|
||||
|
||||
func extraUsernamePasswordActionsFlagsMapFuncImpl() map[string][]string {
|
||||
flags := map[string][]string{
|
||||
"create": {
|
||||
usernameFlagName,
|
||||
passwordFlagName,
|
||||
},
|
||||
}
|
||||
flags["update"] = flags["create"]
|
||||
return flags
|
||||
}
|
||||
|
||||
func extraUsernamePasswordFlagsFuncImpl(c *UsernamePasswordCommand, set *base.FlagSets, _ *base.FlagSet) {
|
||||
f := set.NewFlagSet("User Password Credential Options")
|
||||
|
||||
for _, name := range flagsUsernamePasswordMap[c.Func] {
|
||||
switch name {
|
||||
case usernameFlagName:
|
||||
f.StringVar(&base.StringVar{
|
||||
Name: usernameFlagName,
|
||||
Target: &c.flagUsername,
|
||||
Usage: "The username associated with the credential.",
|
||||
})
|
||||
case passwordFlagName:
|
||||
f.StringVar(&base.StringVar{
|
||||
Name: passwordFlagName,
|
||||
Target: &c.flagPassword,
|
||||
Usage: "The password associated with the credential.",
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func extraUsernamePasswordFlagHandlingFuncImpl(c *UsernamePasswordCommand, _ *base.FlagSets, opts *[]credentials.Option) bool {
|
||||
switch c.flagUsername {
|
||||
case "":
|
||||
default:
|
||||
*opts = append(*opts, credentials.WithUsernamePasswordCredentialUsername(c.flagUsername))
|
||||
}
|
||||
switch c.flagPassword {
|
||||
case "":
|
||||
default:
|
||||
*opts = append(*opts, credentials.WithUsernamePasswordCredentialPassword(c.flagPassword))
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *UsernamePasswordCommand) extraUsernamePasswordHelpFunc(_ map[string]func() string) string {
|
||||
var helpStr string
|
||||
switch c.Func {
|
||||
case "create":
|
||||
helpStr = base.WrapForHelpText([]string{
|
||||
"Usage: boundary credentials create username-password -credential-store-id [options] [args]",
|
||||
"",
|
||||
" Create a user password credential. Example:",
|
||||
"",
|
||||
` $ boundary credentials create username-password -credential-store-id csvlt_1234567890 -username user -password pass`,
|
||||
"",
|
||||
"",
|
||||
})
|
||||
|
||||
case "update":
|
||||
helpStr = base.WrapForHelpText([]string{
|
||||
"Usage: boundary credentials update user password [options] [args]",
|
||||
"",
|
||||
" Update a user password credential given its ID. Example:",
|
||||
"",
|
||||
` $ boundary credentials update username-password -id clvlt_1234567890 -name devops -description "For DevOps usage"`,
|
||||
"",
|
||||
"",
|
||||
})
|
||||
}
|
||||
return helpStr + c.Flags().Help()
|
||||
}
|
||||
@@ -33,7 +33,11 @@ func (c *Command) extraHelpFunc(helpMap map[string]func() string) string {
|
||||
"",
|
||||
" Create a vault-type credential store:",
|
||||
"",
|
||||
` $ boundary credential-stores create vault -vault-address "http://localhost:8200" -vault-token "s.s0m3t0k3n"`,
|
||||
` $ boundary credential-stores create vault -scope-id p_1234567890 -vault-address "http://localhost:8200" -vault-token "s.s0m3t0k3n"`,
|
||||
"",
|
||||
" Create a static-type credential store:",
|
||||
"",
|
||||
` $ boundary credential-stores create static -scope-id p_1234567890`,
|
||||
"",
|
||||
" Please see the typed subcommand help for detailed usage information.",
|
||||
})
|
||||
@@ -47,6 +51,10 @@ func (c *Command) extraHelpFunc(helpMap map[string]func() string) string {
|
||||
"",
|
||||
` $ boundary credential-stores update vault -id csvlt_1234567890 -name devops -description "For DevOps usage"`,
|
||||
"",
|
||||
" Update a static-type credential store:",
|
||||
"",
|
||||
` $ boundary credential-stores update static -id cs_1234567890 -name devops -description "For DevOps usage"`,
|
||||
"",
|
||||
" Please see the typed subcommand help for detailed usage information.",
|
||||
})
|
||||
default:
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
// Code generated by "make cli"; DO NOT EDIT.
|
||||
package credentialstorescmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/credentialstores"
|
||||
"github.com/hashicorp/boundary/internal/cmd/base"
|
||||
"github.com/hashicorp/boundary/internal/cmd/common"
|
||||
"github.com/hashicorp/go-secure-stdlib/strutil"
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/posener/complete"
|
||||
)
|
||||
|
||||
func initStaticFlags() {
|
||||
flagsOnce.Do(func() {
|
||||
extraFlags := extraStaticActionsFlagsMapFunc()
|
||||
for k, v := range extraFlags {
|
||||
flagsStaticMap[k] = append(flagsStaticMap[k], v...)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
var (
|
||||
_ cli.Command = (*StaticCommand)(nil)
|
||||
_ cli.CommandAutocomplete = (*StaticCommand)(nil)
|
||||
)
|
||||
|
||||
type StaticCommand struct {
|
||||
*base.Command
|
||||
|
||||
Func string
|
||||
|
||||
plural string
|
||||
}
|
||||
|
||||
func (c *StaticCommand) AutocompleteArgs() complete.Predictor {
|
||||
initStaticFlags()
|
||||
return complete.PredictAnything
|
||||
}
|
||||
|
||||
func (c *StaticCommand) AutocompleteFlags() complete.Flags {
|
||||
initStaticFlags()
|
||||
return c.Flags().Completions()
|
||||
}
|
||||
|
||||
func (c *StaticCommand) Synopsis() string {
|
||||
if extra := extraStaticSynopsisFunc(c); extra != "" {
|
||||
return extra
|
||||
}
|
||||
|
||||
synopsisStr := "credential store"
|
||||
|
||||
synopsisStr = fmt.Sprintf("%s %s", "static-type", synopsisStr)
|
||||
|
||||
return common.SynopsisFunc(c.Func, synopsisStr)
|
||||
}
|
||||
|
||||
func (c *StaticCommand) Help() string {
|
||||
initStaticFlags()
|
||||
|
||||
var helpStr string
|
||||
helpMap := common.HelpMap("credential store")
|
||||
|
||||
switch c.Func {
|
||||
|
||||
default:
|
||||
|
||||
helpStr = c.extraStaticHelpFunc(helpMap)
|
||||
|
||||
}
|
||||
|
||||
// Keep linter from complaining if we don't actually generate code using it
|
||||
_ = helpMap
|
||||
return helpStr
|
||||
}
|
||||
|
||||
var flagsStaticMap = map[string][]string{
|
||||
|
||||
"create": {"scope-id", "name", "description"},
|
||||
|
||||
"update": {"id", "name", "description", "version"},
|
||||
}
|
||||
|
||||
func (c *StaticCommand) Flags() *base.FlagSets {
|
||||
if len(flagsStaticMap[c.Func]) == 0 {
|
||||
return c.FlagSet(base.FlagSetNone)
|
||||
}
|
||||
|
||||
set := c.FlagSet(base.FlagSetHTTP | base.FlagSetClient | base.FlagSetOutputFormat)
|
||||
f := set.NewFlagSet("Command Options")
|
||||
common.PopulateCommonFlags(c.Command, f, "static-type credential store", flagsStaticMap, c.Func)
|
||||
|
||||
extraStaticFlagsFunc(c, set, f)
|
||||
|
||||
return set
|
||||
}
|
||||
|
||||
func (c *StaticCommand) Run(args []string) int {
|
||||
initStaticFlags()
|
||||
|
||||
switch c.Func {
|
||||
case "":
|
||||
return cli.RunResultHelp
|
||||
|
||||
}
|
||||
|
||||
c.plural = "static-type credential store"
|
||||
switch c.Func {
|
||||
case "list":
|
||||
c.plural = "static-type credential stores"
|
||||
}
|
||||
|
||||
f := c.Flags()
|
||||
|
||||
if err := f.Parse(args); err != nil {
|
||||
c.PrintCliError(err)
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
if strutil.StrListContains(flagsStaticMap[c.Func], "id") && c.FlagId == "" {
|
||||
c.PrintCliError(errors.New("ID is required but not passed in via -id"))
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var opts []credentialstores.Option
|
||||
|
||||
if strutil.StrListContains(flagsStaticMap[c.Func], "scope-id") {
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
if c.FlagScopeId == "" {
|
||||
c.PrintCliError(errors.New("Scope ID must be passed in via -scope-id or BOUNDARY_SCOPE_ID"))
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
client, err := c.Client()
|
||||
if c.WrapperCleanupFunc != nil {
|
||||
defer func() {
|
||||
if err := c.WrapperCleanupFunc(); err != nil {
|
||||
c.PrintCliError(fmt.Errorf("Error cleaning kms wrapper: %w", err))
|
||||
}
|
||||
}()
|
||||
}
|
||||
if err != nil {
|
||||
c.PrintCliError(fmt.Errorf("Error creating API client: %w", err))
|
||||
return base.CommandCliError
|
||||
}
|
||||
credentialstoresClient := credentialstores.NewClient(client)
|
||||
|
||||
switch c.FlagName {
|
||||
case "":
|
||||
case "null":
|
||||
opts = append(opts, credentialstores.DefaultName())
|
||||
default:
|
||||
opts = append(opts, credentialstores.WithName(c.FlagName))
|
||||
}
|
||||
|
||||
switch c.FlagDescription {
|
||||
case "":
|
||||
case "null":
|
||||
opts = append(opts, credentialstores.DefaultDescription())
|
||||
default:
|
||||
opts = append(opts, credentialstores.WithDescription(c.FlagDescription))
|
||||
}
|
||||
|
||||
switch c.FlagRecursive {
|
||||
case true:
|
||||
opts = append(opts, credentialstores.WithRecursive(true))
|
||||
}
|
||||
|
||||
if c.FlagFilter != "" {
|
||||
opts = append(opts, credentialstores.WithFilter(c.FlagFilter))
|
||||
}
|
||||
|
||||
var version uint32
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "update":
|
||||
switch c.FlagVersion {
|
||||
case 0:
|
||||
opts = append(opts, credentialstores.WithAutomaticVersioning(true))
|
||||
default:
|
||||
version = uint32(c.FlagVersion)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ok := extraStaticFlagsHandlingFunc(c, f, &opts); !ok {
|
||||
return base.CommandUserError
|
||||
}
|
||||
|
||||
var result api.GenericResult
|
||||
|
||||
switch c.Func {
|
||||
|
||||
case "create":
|
||||
result, err = credentialstoresClient.Create(c.Context, "static", c.FlagScopeId, opts...)
|
||||
|
||||
case "update":
|
||||
result, err = credentialstoresClient.Update(c.Context, c.FlagId, version, opts...)
|
||||
|
||||
}
|
||||
|
||||
result, err = executeExtraStaticActions(c, result, err, credentialstoresClient, version, opts)
|
||||
|
||||
if err != nil {
|
||||
if apiErr := api.AsServerError(err); apiErr != nil {
|
||||
var opts []base.Option
|
||||
|
||||
opts = append(opts, base.WithAttributeFieldPrefix("static"))
|
||||
|
||||
c.PrintApiError(apiErr, fmt.Sprintf("Error from controller when performing %s on %s", c.Func, c.plural), opts...)
|
||||
return base.CommandApiError
|
||||
}
|
||||
c.PrintCliError(fmt.Errorf("Error trying to %s %s: %s", c.Func, c.plural, err.Error()))
|
||||
return base.CommandCliError
|
||||
}
|
||||
|
||||
output, err := printCustomStaticActionOutput(c)
|
||||
if err != nil {
|
||||
c.PrintCliError(err)
|
||||
return base.CommandUserError
|
||||
}
|
||||
if output {
|
||||
return base.CommandSuccess
|
||||
}
|
||||
|
||||
switch c.Func {
|
||||
|
||||
}
|
||||
|
||||
switch base.Format(c.UI) {
|
||||
case "table":
|
||||
c.UI.Output(printItemTable(result))
|
||||
|
||||
case "json":
|
||||
if ok := c.PrintJsonItem(result); !ok {
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
|
||||
return base.CommandSuccess
|
||||
}
|
||||
|
||||
var (
|
||||
extraStaticActionsFlagsMapFunc = func() map[string][]string { return nil }
|
||||
extraStaticSynopsisFunc = func(*StaticCommand) string { return "" }
|
||||
extraStaticFlagsFunc = func(*StaticCommand, *base.FlagSets, *base.FlagSet) {}
|
||||
extraStaticFlagsHandlingFunc = func(*StaticCommand, *base.FlagSets, *[]credentialstores.Option) bool { return true }
|
||||
executeExtraStaticActions = func(_ *StaticCommand, inResult api.GenericResult, inErr error, _ *credentialstores.Client, _ uint32, _ []credentialstores.Option) (api.GenericResult, error) {
|
||||
return inResult, inErr
|
||||
}
|
||||
printCustomStaticActionOutput = func(*StaticCommand) (bool, error) { return false, nil }
|
||||
)
|
||||
@@ -0,0 +1,33 @@
|
||||
package credentialstorescmd
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/boundary/internal/cmd/base"
|
||||
)
|
||||
|
||||
func (c *StaticCommand) extraStaticHelpFunc(helpMap map[string]func() string) string {
|
||||
var helpStr string
|
||||
switch c.Func {
|
||||
case "create":
|
||||
helpStr = base.WrapForHelpText([]string{
|
||||
"Usage: boundary credential-stores create static [options] [args]",
|
||||
"",
|
||||
" Create a static-type credential store. Example:",
|
||||
"",
|
||||
` $ boundary credential-stores create static -scope-id p_1234567890`,
|
||||
"",
|
||||
"",
|
||||
})
|
||||
|
||||
case "update":
|
||||
helpStr = base.WrapForHelpText([]string{
|
||||
"Usage: boundary credential-stores update static [options] [args]",
|
||||
"",
|
||||
" Update a static-type credential store given its ID. Example:",
|
||||
"",
|
||||
` $ boundary credential-stores update static -name devops -description "For DevOps usage"`,
|
||||
"",
|
||||
"",
|
||||
})
|
||||
}
|
||||
return helpStr + c.Flags().Help()
|
||||
}
|
||||
@@ -30,30 +30,26 @@ func init() {
|
||||
}
|
||||
|
||||
type extraCmdVars struct {
|
||||
flagHostSets []string
|
||||
flagHostSources []string
|
||||
flagApplicationCredentialLibraries []string
|
||||
flagApplicationCredentialSources []string
|
||||
flagEgressCredentialSources []string
|
||||
flagHostId string
|
||||
sar *targets.SessionAuthorizationResult
|
||||
flagHostSets []string
|
||||
flagHostSources []string
|
||||
flagApplicationCredentialSources []string
|
||||
flagEgressCredentialSources []string
|
||||
flagHostId string
|
||||
sar *targets.SessionAuthorizationResult
|
||||
}
|
||||
|
||||
func extraActionsFlagsMapFuncImpl() map[string][]string {
|
||||
return map[string][]string{
|
||||
"authorize-session": {"id", "host-id"},
|
||||
"add-host-sets": {"id", "host-set", "version"},
|
||||
"remove-host-sets": {"id", "host-set", "version"},
|
||||
"set-host-sets": {"id", "host-set", "version"},
|
||||
"add-host-sources": {"id", "host-source", "version"},
|
||||
"remove-host-sources": {"id", "host-source", "version"},
|
||||
"set-host-sources": {"id", "host-source", "version"},
|
||||
"add-credential-libraries": {"id", "application-credential-library", "version"},
|
||||
"remove-credential-libraries": {"id", "application-credential-library", "version"},
|
||||
"set-credential-libraries": {"id", "application-credential-library", "version"},
|
||||
"add-credential-sources": {"id", "application-credential-source", "egress-credential-source", "version"},
|
||||
"remove-credential-sources": {"id", "application-credential-source", "egress-credential-source", "version"},
|
||||
"set-credential-sources": {"id", "application-credential-source", "egress-credential-source", "version"},
|
||||
"authorize-session": {"id", "host-id"},
|
||||
"add-host-sets": {"id", "host-set", "version"},
|
||||
"remove-host-sets": {"id", "host-set", "version"},
|
||||
"set-host-sets": {"id", "host-set", "version"},
|
||||
"add-host-sources": {"id", "host-source", "version"},
|
||||
"remove-host-sources": {"id", "host-source", "version"},
|
||||
"set-host-sources": {"id", "host-source", "version"},
|
||||
"add-credential-sources": {"id", "application-credential-source", "egress-credential-source", "version"},
|
||||
"remove-credential-sources": {"id", "application-credential-source", "egress-credential-source", "version"},
|
||||
"set-credential-sources": {"id", "application-credential-source", "egress-credential-source", "version"},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,18 +79,6 @@ func extraSynopsisFuncImpl(c *Command) string {
|
||||
}
|
||||
return wordwrap.WrapString(fmt.Sprintf("%s a target", in), base.TermWidth)
|
||||
|
||||
case "add-credential-libraries", "set-credential-libraries", "remove-credential-libraries":
|
||||
var in string
|
||||
switch {
|
||||
case strings.HasPrefix(c.Func, "add"):
|
||||
in = "Add credential libraries to"
|
||||
case strings.HasPrefix(c.Func, "set"):
|
||||
in = "Set the full contents of the credential libraries on"
|
||||
case strings.HasPrefix(c.Func, "remove"):
|
||||
in = "Remove credential libraries from"
|
||||
}
|
||||
return wordwrap.WrapString(fmt.Sprintf("%s a target. DEPRECATED; use the -sources version instead.", in), base.TermWidth)
|
||||
|
||||
case "add-credential-sources", "set-credential-sources", "remove-credential-sources":
|
||||
var in string
|
||||
switch {
|
||||
@@ -232,48 +216,6 @@ func (c *Command) extraHelpFunc(helpMap map[string]func() string) string {
|
||||
"",
|
||||
"",
|
||||
})
|
||||
case "add-credential-libraries":
|
||||
helpStr = base.WrapForHelpText([]string{
|
||||
"Usage: boundary target add-credential-libraries [options] [args]",
|
||||
"",
|
||||
" DEPRECATED: Use add-credential-sources instead.",
|
||||
"",
|
||||
" This command allows adding credential-library resources to target resources. Example:",
|
||||
"",
|
||||
" Add credential-library resources to a tcp-type target:",
|
||||
"",
|
||||
` $ boundary targets add-credential-libraries -id ttcp_1234567890 -application-credential-library clvlt_1234567890 -application-credential-library clvlt_0987654321`,
|
||||
"",
|
||||
"",
|
||||
})
|
||||
case "remove-credential-libraries":
|
||||
helpStr = base.WrapForHelpText([]string{
|
||||
"Usage: boundary target remove-credential-libraries [options] [args]",
|
||||
"",
|
||||
" DEPRECATED: Use remove-credential-sources instead.",
|
||||
"",
|
||||
" This command allows removing credential-library resources from target resources. Example:",
|
||||
"",
|
||||
" Remove credential-library resources from a tcp-type target:",
|
||||
"",
|
||||
` $ boundary targets remove-credential-libraries -id ttcp_1234567890 -application-credential-library clvlt_1234567890 -application-credential-library clvlt_0987654321`,
|
||||
"",
|
||||
"",
|
||||
})
|
||||
case "set-credential-libraries":
|
||||
helpStr = base.WrapForHelpText([]string{
|
||||
"Usage: boundary target set-credential-libraries [options] [args]",
|
||||
"",
|
||||
" DEPRECATED: Use set-credential-sources instead.",
|
||||
"",
|
||||
" This command allows setting the complete set of credential-library resources on a target resource. Example:",
|
||||
"",
|
||||
" Set credential-library resources on a tcp-type target:",
|
||||
"",
|
||||
` $ boundary targets set-credential-libraries -id ttcp_1234567890 -application-credential-library clvlt_1234567890`,
|
||||
"",
|
||||
"",
|
||||
})
|
||||
case "add-credential-sources":
|
||||
helpStr = base.WrapForHelpText([]string{
|
||||
"Usage: boundary target add-credential-sources [options] [args]",
|
||||
@@ -351,12 +293,6 @@ func extraFlagsFuncImpl(c *Command, _ *base.FlagSets, f *base.FlagSet) {
|
||||
Target: &c.flagHostId,
|
||||
Usage: "The ID of a specific host to connect to out of the hosts from the target's host sets. If not specified, one is chosen at random.",
|
||||
})
|
||||
case "application-credential-library":
|
||||
f.StringSliceVar(&base.StringSliceVar{
|
||||
Name: "application-credential-library",
|
||||
Target: &c.flagApplicationCredentialLibraries,
|
||||
Usage: "The credential-library resource for application purpose to add, set, or remove. May be specified multiple times.",
|
||||
})
|
||||
case "application-credential-source":
|
||||
f.StringSliceVar(&base.StringSliceVar{
|
||||
Name: "application-credential-source",
|
||||
@@ -467,13 +403,6 @@ func extraFlagsHandlingFuncImpl(c *Command, _ *base.FlagSets, opts *[]targets.Op
|
||||
}
|
||||
}
|
||||
|
||||
case "add-credential-libraries", "remove-credential-libraries":
|
||||
if len(c.flagApplicationCredentialLibraries) == 0 {
|
||||
c.UI.Error("No credential-libraries supplied via -application-credential-library")
|
||||
return false
|
||||
}
|
||||
*opts = append(*opts, targets.WithApplicationCredentialLibraryIds(c.flagApplicationCredentialLibraries))
|
||||
|
||||
case "add-credential-sources", "remove-credential-sources":
|
||||
// TODO: As we add other purposes, add them to this check
|
||||
if len(c.flagApplicationCredentialSources)+len(c.flagEgressCredentialSources) == 0 {
|
||||
@@ -488,21 +417,6 @@ func extraFlagsHandlingFuncImpl(c *Command, _ *base.FlagSets, opts *[]targets.Op
|
||||
*opts = append(*opts, targets.WithEgressCredentialSourceIds(c.flagEgressCredentialSources))
|
||||
}
|
||||
|
||||
case "set-credential-libraries":
|
||||
switch len(c.flagApplicationCredentialLibraries) {
|
||||
case 0:
|
||||
c.UI.Error("No credential-libraries supplied via -application-credential-library")
|
||||
return false
|
||||
case 1:
|
||||
if c.flagApplicationCredentialLibraries[0] == "null" {
|
||||
*opts = append(*opts, targets.DefaultApplicationCredentialLibraryIds())
|
||||
break
|
||||
}
|
||||
fallthrough
|
||||
default:
|
||||
*opts = append(*opts, targets.WithApplicationCredentialLibraryIds(c.flagApplicationCredentialLibraries))
|
||||
}
|
||||
|
||||
case "set-credential-sources":
|
||||
// TODO: As we add other purposes, add them to this check
|
||||
if len(c.flagApplicationCredentialSources)+len(c.flagEgressCredentialSources) == 0 {
|
||||
@@ -558,12 +472,6 @@ func executeExtraActionsImpl(c *Command, origResult api.GenericResult, origError
|
||||
return targetClient.RemoveHostSources(c.Context, c.FlagId, version, c.flagHostSources, opts...)
|
||||
case "set-host-sources":
|
||||
return targetClient.SetHostSources(c.Context, c.FlagId, version, c.flagHostSources, opts...)
|
||||
case "add-credential-libraries":
|
||||
return targetClient.AddCredentialLibraries(c.Context, c.FlagId, version, opts...)
|
||||
case "remove-credential-libraries":
|
||||
return targetClient.RemoveCredentialLibraries(c.Context, c.FlagId, version, opts...)
|
||||
case "set-credential-libraries":
|
||||
return targetClient.SetCredentialLibraries(c.Context, c.FlagId, version, opts...)
|
||||
case "add-credential-sources":
|
||||
return targetClient.AddCredentialSources(c.Context, c.FlagId, version, opts...)
|
||||
case "remove-credential-sources":
|
||||
@@ -702,23 +610,6 @@ func printItemTable(result api.GenericResult) string {
|
||||
}
|
||||
|
||||
var credentialSourceMaps map[credential.Purpose][]map[string]interface{}
|
||||
if len(item.ApplicationCredentialLibraries) > 0 {
|
||||
if credentialSourceMaps == nil {
|
||||
credentialSourceMaps = make(map[credential.Purpose][]map[string]interface{})
|
||||
}
|
||||
var applicationCredentialSourceMaps []map[string]interface{}
|
||||
for _, lib := range item.ApplicationCredentialLibraries {
|
||||
m := map[string]interface{}{
|
||||
"ID": lib.Id,
|
||||
"Credential Store ID": lib.CredentialStoreId,
|
||||
}
|
||||
applicationCredentialSourceMaps = append(applicationCredentialSourceMaps, m)
|
||||
}
|
||||
credentialSourceMaps[credential.ApplicationPurpose] = applicationCredentialSourceMaps
|
||||
if l := len("Credential Store ID"); l > maxLength {
|
||||
maxLength = l
|
||||
}
|
||||
}
|
||||
if len(item.ApplicationCredentialSources) > 0 {
|
||||
if credentialSourceMaps == nil {
|
||||
credentialSourceMaps = make(map[credential.Purpose][]map[string]interface{})
|
||||
@@ -888,7 +779,7 @@ func printCustomActionOutputImpl(c *Command) (bool, error) {
|
||||
|
||||
var secretStr []string
|
||||
switch cred.CredentialSource.Type {
|
||||
case "vault":
|
||||
case "vault", "static":
|
||||
switch {
|
||||
case cred.Credential != nil:
|
||||
maxLength := 0
|
||||
|
||||
@@ -249,30 +249,6 @@ func (c *Command) Run(args []string) int {
|
||||
version = uint32(c.FlagVersion)
|
||||
}
|
||||
|
||||
case "add-credential-libraries":
|
||||
switch c.FlagVersion {
|
||||
case 0:
|
||||
opts = append(opts, targets.WithAutomaticVersioning(true))
|
||||
default:
|
||||
version = uint32(c.FlagVersion)
|
||||
}
|
||||
|
||||
case "remove-credential-libraries":
|
||||
switch c.FlagVersion {
|
||||
case 0:
|
||||
opts = append(opts, targets.WithAutomaticVersioning(true))
|
||||
default:
|
||||
version = uint32(c.FlagVersion)
|
||||
}
|
||||
|
||||
case "set-credential-libraries":
|
||||
switch c.FlagVersion {
|
||||
case 0:
|
||||
opts = append(opts, targets.WithAutomaticVersioning(true))
|
||||
default:
|
||||
version = uint32(c.FlagVersion)
|
||||
}
|
||||
|
||||
case "add-credential-sources":
|
||||
switch c.FlagVersion {
|
||||
case 0:
|
||||
|
||||
@@ -197,6 +197,21 @@ var inputStructs = map[string][]*cmdInfo{
|
||||
NeedsSubtypeInCreate: true,
|
||||
PrefixAttributeFieldErrorsWithSubactionPrefix: true,
|
||||
},
|
||||
{
|
||||
ResourceType: resource.CredentialStore.String(),
|
||||
Pkg: "credentialstores",
|
||||
StdActions: []string{"create", "update"},
|
||||
SubActionPrefix: "static",
|
||||
SkipNormalHelp: true,
|
||||
HasExtraHelpFunc: true,
|
||||
HasId: true,
|
||||
HasName: true,
|
||||
HasDescription: true,
|
||||
Container: "Scope",
|
||||
VersionedActions: []string{"update"},
|
||||
NeedsSubtypeInCreate: true,
|
||||
PrefixAttributeFieldErrorsWithSubactionPrefix: true,
|
||||
},
|
||||
},
|
||||
"credentiallibraries": {
|
||||
{
|
||||
@@ -223,6 +238,32 @@ var inputStructs = map[string][]*cmdInfo{
|
||||
PrefixAttributeFieldErrorsWithSubactionPrefix: true,
|
||||
},
|
||||
},
|
||||
"credentials": {
|
||||
{
|
||||
ResourceType: resource.Credential.String(),
|
||||
Pkg: "credentials",
|
||||
StdActions: []string{"read", "delete", "list"},
|
||||
HasExtraHelpFunc: true,
|
||||
Container: "CredentialStore",
|
||||
HasId: true,
|
||||
},
|
||||
{
|
||||
ResourceType: resource.Credential.String(),
|
||||
Pkg: "credentials",
|
||||
StdActions: []string{"create", "update"},
|
||||
SubActionPrefix: "username_password",
|
||||
HasExtraCommandVars: true,
|
||||
SkipNormalHelp: true,
|
||||
HasExtraHelpFunc: true,
|
||||
HasId: true,
|
||||
HasName: true,
|
||||
HasDescription: true,
|
||||
Container: "CredentialStore",
|
||||
VersionedActions: []string{"update"},
|
||||
NeedsSubtypeInCreate: true,
|
||||
PrefixAttributeFieldErrorsWithSubactionPrefix: true,
|
||||
},
|
||||
},
|
||||
"groups": {
|
||||
{
|
||||
ResourceType: resource.Group.String(),
|
||||
@@ -421,7 +462,7 @@ var inputStructs = map[string][]*cmdInfo{
|
||||
HasName: true,
|
||||
HasDescription: true,
|
||||
Container: "Scope",
|
||||
VersionedActions: []string{"add-host-sets", "remove-host-sets", "set-host-sets", "add-host-sources", "remove-host-sources", "set-host-sources", "add-credential-libraries", "remove-credential-libraries", "set-credential-libraries", "add-credential-sources", "remove-credential-sources", "set-credential-sources"},
|
||||
VersionedActions: []string{"add-host-sets", "remove-host-sets", "set-host-sets", "add-host-sources", "remove-host-sources", "set-host-sources", "add-credential-sources", "remove-credential-sources", "set-credential-sources"},
|
||||
},
|
||||
{
|
||||
ResourceType: resource.Target.String(),
|
||||
|
||||
Reference in new issue
Block a user