Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tlsfirst option to pass through to NATS connections #208

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Flags:
--tlscacert string Client certificate CA on NATS connections.
--tlscert string Client certificate file for NATS connections.
--tlskey string Client private key for NATS connections.
--tlsfirst bool Whether to use TLS First connections.
--user string NATS user name or token
-v, --version version for nats-surveyor
```
Expand Down
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ func init() {
rootCmd.Flags().String("tlscacert", "", "Client certificate CA on NATS connections.")
_ = viper.BindPFlag("tlscacert", rootCmd.Flags().Lookup("tlscacert"))

// tlsfirst
rootCmd.Flags().Bool("tlsfirst", false, "Whether to use TLS First connections.")
_ = viper.BindPFlag("tlsfirst", rootCmd.Flags().Lookup("tlsfirst"))

// http-tlscert
rootCmd.Flags().String("http-tlscert", "", "Server certificate file (Enables HTTPS).")
_ = viper.BindPFlag("http-tlscert", rootCmd.Flags().Lookup("http-tlscert"))
Expand Down Expand Up @@ -255,6 +259,7 @@ func getSurveyorOpts() *surveyor.Options {
opts.CertFile = viper.GetString("tlscert")
opts.KeyFile = viper.GetString("tlskey")
opts.CaFile = viper.GetString("tlscacert")
opts.TLSFirst = viper.GetBool("tlsfirst")
opts.HTTPCertFile = viper.GetString("http-tlscert")
opts.HTTPKeyFile = viper.GetString("http-tlskey")
opts.HTTPCaFile = viper.GetString("http-tlscacert")
Expand Down
4 changes: 4 additions & 0 deletions surveyor/surveyor.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type Options struct {
CertFile string
KeyFile string
CaFile string
TLSFirst bool
HTTPCertFile string
HTTPKeyFile string
HTTPCaFile string
Expand Down Expand Up @@ -184,6 +185,9 @@ func newSurveyorConnPool(opts *Options, reconnectCtr *prometheus.CounterVec) *na
}),
nats.MaxReconnects(10240),
)
if opts.TLSFirst {
natsOpts = append(natsOpts, nats.TLSHandshakeFirst())
}
return newNatsConnPool(opts.Logger, natsDefaults, natsOpts)
}

Expand Down