Skip to content

Commit

Permalink
add option for credentials file for NATS; more info: https://docs.nat…
Browse files Browse the repository at this point in the history
  • Loading branch information
paigeadelethompson committed Sep 10, 2024
1 parent 7a4ef24 commit a2d2ee1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions setup/config/config_jetstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ type JetStream struct {
NoLog bool `yaml:"-"`
// Disables TLS validation. This should NOT be used in production
DisableTLSValidation bool `yaml:"disable_tls_validation"`
// A credentials file to be used for authentication, example:
// https://docs.nats.io/using-nats/developer/connecting/creds
Credentials Path `yaml:"credentials_path"`
}

func (c *JetStream) Prefixed(name string) string {
Expand All @@ -38,6 +41,7 @@ func (c *JetStream) Defaults(opts DefaultOpts) {
c.StoragePath = Path("./")
c.NoLog = true
c.DisableTLSValidation = true
c.Credentials = Path("")
}
}

Expand Down
3 changes: 3 additions & 0 deletions setup/jetstream/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func setupNATS(process *process.ProcessContext, cfg *config.JetStream, nc *natsc
InsecureSkipVerify: true,
}))
}
if string(cfg.Credentials) != "" {
opts = append(opts, natsclient.UserCredentials(string(cfg.Credentials)))
}
nc, err = natsclient.Connect(strings.Join(cfg.Addresses, ","), opts...)
if err != nil {
logrus.WithError(err).Panic("Unable to connect to NATS")
Expand Down

0 comments on commit a2d2ee1

Please sign in to comment.