Cassandra Connect Support (#5952)
* Init cassandra * Init cassandra * Initial Cassandra Command Support For cqlsh * Add Make Gen * adding cassandra test * Cleanup cassandra docker setup * Adding container wait * Container restart * Minor Fix * Cleanup docker and test * Adding final tests * Removing comment * Fixing cleanup (uncomment) * Removing bad yaml * Cleanup * Cleanup * Adressing PR review comments * Adding test support * fix spacing * Adding changelog * docs * docs * adding cassandra page * nav * Versbose commenting * cleanup naming of file * updating helper func to return errors * doc change * Removed an incorrect comment and now passing the config by reference. * Comment cleanup * Fix option warning in cassandra connect command (#5951) * Add healthcheck to caller function as it's resposible for container health * Resolve Comments * Update Log Typo --------- Co-authored-by: Bharath Gajjala <120367134+bgajjala8@users.noreply.github.com>
This commit is contained in:
1 parent
029aa361bd
commit
4d3cb76c28
10 files changed
+504
-1
No files matched your search
@@ -417,6 +417,12 @@ func initCommands(ui, serverCmdUi cli.Ui, runOpts *RunOptions) {
|
||||
Func: "mysql",
|
||||
}
|
||||
}),
|
||||
"connect cassandra": wrapper.Wrap(func() wrapper.WrappableCommand {
|
||||
return &connect.Command{
|
||||
Command: base.NewCommand(ui, opts...),
|
||||
Func: "cassandra",
|
||||
}
|
||||
}),
|
||||
"connect rdp": wrapper.Wrap(func() wrapper.WrappableCommand {
|
||||
return &connect.Command{
|
||||
Command: base.NewCommand(ui, opts...),
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package connect
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/boundary/api/proxy"
|
||||
"github.com/hashicorp/boundary/internal/cmd/base"
|
||||
"github.com/posener/complete"
|
||||
)
|
||||
|
||||
const (
|
||||
cassandraSynopsis = "Authorize a session against a target and invoke a Cassandra client to connect"
|
||||
)
|
||||
|
||||
func cassandraOptions(c *Command, set *base.FlagSets) {
|
||||
f := set.NewFlagSet("Cassandra Options")
|
||||
|
||||
f.StringVar(&base.StringVar{
|
||||
Name: "style",
|
||||
Target: &c.flagCassandraStyle,
|
||||
EnvVar: "BOUNDARY_CONNECT_CASSANDRA_STYLE",
|
||||
Completion: complete.PredictSet("cqlsh"),
|
||||
Default: "cqlsh",
|
||||
Usage: `Specifies how the CLI will attempt to invoke a Cassandra client. This will also set a suitable default for -exec if a value was not specified. Currently-understood values are "cqlsh".`,
|
||||
})
|
||||
|
||||
f.StringVar(&base.StringVar{
|
||||
Name: "username",
|
||||
Target: &c.flagUsername,
|
||||
EnvVar: "BOUNDARY_CONNECT_USERNAME",
|
||||
Completion: complete.PredictNothing,
|
||||
Usage: `Specifies the username to pass through to the client. May be overridden by credentials sourced from a credential store.`,
|
||||
})
|
||||
|
||||
f.StringVar(&base.StringVar{
|
||||
Name: "keyspace",
|
||||
Target: &c.flagDbname,
|
||||
EnvVar: "BOUNDARY_CONNECT_KEYSPACE",
|
||||
Completion: complete.PredictNothing,
|
||||
Usage: `Specifies the keyspace name to pass through to the client.`,
|
||||
})
|
||||
}
|
||||
|
||||
type cassandraFlags struct {
|
||||
flagCassandraStyle string
|
||||
}
|
||||
|
||||
func (m *cassandraFlags) defaultExec() string {
|
||||
return strings.ToLower(m.flagCassandraStyle)
|
||||
}
|
||||
|
||||
func (m *cassandraFlags) buildArgs(c *Command, port, ip, _ string, creds proxy.Credentials) (args, envs []string, retCreds proxy.Credentials, retErr error) {
|
||||
var username, password string
|
||||
|
||||
retCreds = creds
|
||||
if len(retCreds.UsernamePassword) > 0 {
|
||||
// Mark credential as consumed, such that it is not printed to the user
|
||||
retCreds.UsernamePassword[0].Consumed = true
|
||||
|
||||
// Grab the first available username/password credential brokered
|
||||
username = retCreds.UsernamePassword[0].Username
|
||||
password = retCreds.UsernamePassword[0].Password
|
||||
}
|
||||
|
||||
switch m.flagCassandraStyle {
|
||||
case "cqlsh":
|
||||
switch {
|
||||
case username != "":
|
||||
args = append(args, "-u", username)
|
||||
case c.flagUsername != "":
|
||||
args = append(args, "-u", c.flagUsername)
|
||||
}
|
||||
|
||||
if c.flagDbname != "" {
|
||||
args = append(args, "-k", c.flagDbname)
|
||||
} else {
|
||||
c.UI.Warn("Credentials are being brokered but no -keyspace parameter provided. cqlsh may misinterpret another parameter as the keyspace name.")
|
||||
}
|
||||
|
||||
if password != "" {
|
||||
passfile, err := os.CreateTemp("", "*")
|
||||
if err != nil {
|
||||
return nil, nil, proxy.Credentials{}, fmt.Errorf("Error saving cassandra password to tmp file: %w", err)
|
||||
}
|
||||
|
||||
c.cleanupFuncs = append(c.cleanupFuncs, func() error {
|
||||
if err := os.Remove(passfile.Name()); err != nil {
|
||||
return fmt.Errorf("Error removing temporary password file; consider removing %s manually: %w", passfile.Name(), err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
_, err = passfile.WriteString("[PlainTextAuthProvider]\npassword = " + password)
|
||||
if err != nil {
|
||||
passfile.Close()
|
||||
return nil, nil, proxy.Credentials{}, fmt.Errorf("Error writing password file to %s: %w", passfile.Name(), err)
|
||||
}
|
||||
|
||||
if err := passfile.Close(); err != nil {
|
||||
return nil, nil, proxy.Credentials{}, fmt.Errorf("Error closing password file after writing to %s: %w", passfile.Name(), err)
|
||||
}
|
||||
|
||||
args = append(args, "--credentials", passfile.Name())
|
||||
}
|
||||
|
||||
args = append(args, ip)
|
||||
if port != "" {
|
||||
args = append(args, port)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -80,6 +80,9 @@ type Command struct {
|
||||
// MySQL
|
||||
mysqlFlags
|
||||
|
||||
// Cassandra
|
||||
cassandraFlags
|
||||
|
||||
// RDP
|
||||
rdpFlags
|
||||
|
||||
@@ -108,6 +111,8 @@ func (c *Command) Synopsis() string {
|
||||
return postgresSynopsis
|
||||
case "mysql":
|
||||
return mysqlSynopsis
|
||||
case "cassandra":
|
||||
return cassandraSynopsis
|
||||
case "rdp":
|
||||
return rdpSynopsis
|
||||
case "ssh":
|
||||
@@ -230,6 +235,9 @@ func (c *Command) Flags() *base.FlagSets {
|
||||
case "mysql":
|
||||
mysqlOptions(c, set)
|
||||
|
||||
case "cassandra":
|
||||
cassandraOptions(c, set)
|
||||
|
||||
case "rdp":
|
||||
rdpOptions(c, set)
|
||||
|
||||
@@ -319,6 +327,8 @@ func (c *Command) Run(args []string) (retCode int) {
|
||||
c.flagExec = c.postgresFlags.defaultExec()
|
||||
case "mysql":
|
||||
c.flagExec = c.mysqlFlags.defaultExec()
|
||||
case "cassandra":
|
||||
c.flagExec = c.cassandraFlags.defaultExec()
|
||||
case "rdp":
|
||||
c.flagExec = c.rdpFlags.defaultExec()
|
||||
case "kube":
|
||||
@@ -673,6 +683,16 @@ func (c *Command) handleExec(clientProxy *apiproxy.ClientProxy, passthroughArgs
|
||||
envs = append(envs, mysqlEnvs...)
|
||||
creds = mysqlCreds
|
||||
|
||||
case "cassandra":
|
||||
cassandraArgs, cassandraEnvs, cassandraCreds, cassandraErr := c.cassandraFlags.buildArgs(c, port, host, addr, creds)
|
||||
if cassandraErr != nil {
|
||||
argsErr = cassandraErr
|
||||
break
|
||||
}
|
||||
args = append(args, cassandraArgs...)
|
||||
envs = append(envs, cassandraEnvs...)
|
||||
creds = cassandraCreds
|
||||
|
||||
case "rdp":
|
||||
args = append(args, c.rdpFlags.buildArgs(c, port, host, addr)...)
|
||||
|
||||
|
||||
Reference in new issue
Block a user