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

Allow username/password authentication in events/natsjs #136

Merged
merged 1 commit into from
Dec 15, 2023
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
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
}
}