Skip to content

Commit

Permalink
Merge pull request #136 from kobergj/NatsAuthentication
Browse files Browse the repository at this point in the history
Allow username/password authentication in events/natsjs
  • Loading branch information
kobergj authored Dec 15, 2023
2 parents bbace9e + ac82881 commit f7f8d32
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions v4/events/natsjs/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func connectToNatsJetStream(options Options) (nats.JetStreamContext, error) {
nopts.Name = options.Name
}

if options.Username != "" && options.Password != "" {
nopts.User = options.Username
nopts.Password = options.Password
}

conn, err := nopts.Connect()
if err != nil {
tls := nopts.TLSConfig != nil
Expand Down
10 changes: 10 additions & 0 deletions v4/events/natsjs/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type Options struct {
SyncPublish bool
Name string
DisableDurableStreams bool
Username string
Password string
}

// Option is a function which configures options.
Expand Down Expand Up @@ -84,3 +86,11 @@ func DisableDurableStreams() Option {
o.DisableDurableStreams = true
}
}

// Authenticate authenticates the connection with the given username and password.
func Authenticate(username, password string) Option {
return func(o *Options) {
o.Username = username
o.Password = password
}
}

0 comments on commit f7f8d32

Please sign in to comment.