Skip to content

Commit

Permalink
feat(events/natjs): Allow username/password authentication
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <[email protected]>
  • Loading branch information
kobergj committed Dec 15, 2023
1 parent bbace9e commit ac82881
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 ac82881

Please sign in to comment.