Skip to content

Commit

Permalink
Add tlsfirst option to pass through to NATS connections (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnweldon authored Jul 2, 2024
1 parent 8d8f7d0 commit bb66bf1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
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

0 comments on commit bb66bf1

Please sign in to comment.