-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* VEC-189 add tls and auth
- Loading branch information
Jesse S
authored
Jul 3, 2024
1 parent
938957b
commit 5700529
Showing
50 changed files
with
1,451 additions
and
408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/docker/config/features.conf | ||
features.conf | ||
/bin/* | ||
embed_*.go | ||
/tmp | ||
tmp | ||
/vendor | ||
/coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package flags | ||
|
||
import ( | ||
"fmt" | ||
"log/slog" | ||
|
||
commonFlags "github.com/aerospike/tools-common-go/flags" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
type ClientFlags struct { | ||
Host *HostPortFlag | ||
Seeds *SeedsSliceFlag | ||
ListenerName StringOptionalFlag | ||
User StringOptionalFlag | ||
Password commonFlags.PasswordFlag | ||
TLSFlags | ||
} | ||
|
||
func NewClientFlags() *ClientFlags { | ||
return &ClientFlags{ | ||
Host: NewDefaultHostPortFlag(), | ||
Seeds: &SeedsSliceFlag{}, | ||
TLSFlags: *NewTLSFlags(), | ||
} | ||
} | ||
|
||
func (cf *ClientFlags) NewClientFlagSet() *pflag.FlagSet { | ||
flagSet := &pflag.FlagSet{} | ||
flagSet.VarP(cf.Host, Host, "h", commonFlags.DefaultWrapHelpString(fmt.Sprintf("The AVS host to connect to. If cluster discovery is needed use --%s", Seeds))) //nolint:lll // For readability | ||
flagSet.Var(cf.Seeds, Seeds, commonFlags.DefaultWrapHelpString(fmt.Sprintf("The AVS seeds to use for cluster discovery. If no cluster discovery is needed (i.e. load-balancer) then use --%s", Host))) //nolint:lll // For readability | ||
flagSet.VarP(&cf.ListenerName, ListenerName, "l", commonFlags.DefaultWrapHelpString("The listener to ask the AVS server for as configured in the AVS server. Likely required for cloud deployments.")) //nolint:lll // For readability | ||
flagSet.VarP(&cf.User, User, "U", commonFlags.DefaultWrapHelpString("The AVS user to authenticate with.")) //nolint:lll // For readability | ||
flagSet.VarP(&cf.Password, Password, "P", commonFlags.DefaultWrapHelpString("The AVS password for the specified user.")) //nolint:lll // For readability | ||
flagSet.AddFlagSet(cf.NewTLSFlagSet(commonFlags.DefaultWrapHelpString)) | ||
|
||
return flagSet | ||
} | ||
|
||
func (cf *ClientFlags) NewSLogAttr() []any { | ||
return []any{slog.String(Host, cf.Host.String()), | ||
slog.String(Seeds, cf.Seeds.String()), | ||
slog.String(ListenerName, cf.ListenerName.String()), | ||
slog.String(User, cf.User.String()), | ||
slog.String(Password, cf.Password.String()), | ||
slog.Bool(TLSCaFile, cf.TLSRootCAFile != nil), | ||
slog.Bool(TLSCaPath, cf.TLSRootCAPath != nil), | ||
slog.Bool(TLSCertFile, cf.TLSCertFile != nil), | ||
slog.Bool(TLSKeyFile, cf.TLSKeyFile != nil), | ||
slog.Bool(TLSKeyFilePass, cf.TLSKeyFilePass != nil), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package flags | ||
|
||
const ( | ||
LogLevel = "log-level" | ||
Seeds = "seeds" | ||
Host = "host" | ||
ListenerName = "listener-name" | ||
User = "user" | ||
Password = "password" | ||
Namespace = "namespace" | ||
Sets = "sets" | ||
IndexName = "index-name" | ||
VectorField = "vector-field" | ||
Dimension = "dimension" | ||
DistanceMetric = "distance-metric" | ||
IndexMeta = "index-meta" | ||
Timeout = "timeout" | ||
Verbose = "verbose" | ||
StorageNamespace = "storage-namespace" | ||
StorageSet = "storage-set" | ||
MaxEdges = "hnsw-max-edges" | ||
ConstructionEf = "hnsw-ef-construction" | ||
Ef = "hnsw-ef" | ||
BatchMaxRecords = "hnsw-batch-max-records" | ||
BatchInterval = "hnsw-batch-interval" | ||
BatchEnabled = "hnsw-batch-enabled" | ||
TLSProtocols = "tls-protocols" | ||
TLSCaFile = "tls-cafile" | ||
TLSCaPath = "tls-capath" | ||
TLSCertFile = "tls-certfile" | ||
TLSKeyFile = "tls-keyfile" | ||
TLSKeyFilePass = "tls-keyfile-password" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package flags | ||
|
||
import ( | ||
"crypto/tls" | ||
|
||
commonClient "github.com/aerospike/tools-common-go/client" | ||
commonFlags "github.com/aerospike/tools-common-go/flags" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
type TLSFlags struct { | ||
TLSProtocols commonFlags.TLSProtocolsFlag | ||
TLSRootCAFile commonFlags.CertFlag | ||
TLSRootCAPath commonFlags.CertPathFlag | ||
TLSCertFile commonFlags.CertFlag | ||
TLSKeyFile commonFlags.CertFlag | ||
TLSKeyFilePass commonFlags.PasswordFlag | ||
} | ||
|
||
func NewTLSFlags() *TLSFlags { | ||
return &TLSFlags{ | ||
TLSProtocols: commonFlags.NewDefaultTLSProtocolsFlag(), | ||
} | ||
} | ||
|
||
// NewTLSFlagSet returns a new pflag.FlagSet with TLS flags defined. Values | ||
// are stored in the TLSFlags struct. | ||
func (tf *TLSFlags) NewTLSFlagSet(fmtUsage commonFlags.UsageFormatter) *pflag.FlagSet { | ||
f := &pflag.FlagSet{} | ||
|
||
f.Var(&tf.TLSRootCAFile, "tls-cafile", fmtUsage("The CA used when connecting to AVS.")) | ||
f.Var(&tf.TLSRootCAPath, "tls-capath", fmtUsage("A path containing CAs for connecting to AVS.")) | ||
f.Var(&tf.TLSCertFile, "tls-certfile", fmtUsage("The certificate file for mutual TLS authentication with AVS.")) | ||
f.Var(&tf.TLSKeyFile, "tls-keyfile", fmtUsage("The key file used for mutual TLS authentication with AVS.")) | ||
f.Var(&tf.TLSKeyFilePass, "tls-keyfile-password", fmtUsage("The password used to decrypt the key-file if encrypted.")) | ||
f.Var(&tf.TLSProtocols, "tls-protocols", fmtUsage( | ||
"Set the TLS protocol selection criteria. This format is the same as"+ | ||
" Apache's SSLProtocol documented at https://httpd.apache.org/docs/current/mod/mod_ssl.html#ssl protocol.", | ||
)) | ||
|
||
return f | ||
} | ||
|
||
func (tf *TLSFlags) NewTLSConfig() (*tls.Config, error) { | ||
rootCA := [][]byte{} | ||
|
||
if len(tf.TLSRootCAFile) != 0 { | ||
rootCA = append(rootCA, tf.TLSRootCAFile) | ||
} | ||
|
||
rootCA = append(rootCA, tf.TLSRootCAPath...) | ||
|
||
return commonClient.NewTLSConfig( | ||
rootCA, | ||
tf.TLSCertFile, | ||
tf.TLSKeyFile, | ||
tf.TLSKeyFilePass, | ||
0, | ||
0, | ||
).NewGoTLSConfig() | ||
} |
Oops, something went wrong.