Skip to content

Commit

Permalink
revert unintended password change
Browse files Browse the repository at this point in the history
  • Loading branch information
ajatprabha committed Aug 8, 2023
1 parent 27e4ff6 commit 77cdc69
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ func toClientOptions(c *Client, o *clientOptions) *mqtt.ClientOptions {
opts.SetClientID(o.clientID)
}

setCredentials(o, opts)

opts.AddBroker(formatAddressWithProtocol(o)).
SetUsername(o.username).
SetPassword(o.password).
SetTLSConfig(o.tlsConfig).
SetAutoReconnect(o.autoReconnect).
SetCleanSession(o.cleanSession).
Expand All @@ -195,6 +195,23 @@ func toClientOptions(c *Client, o *clientOptions) *mqtt.ClientOptions {
return opts
}

func setCredentials(o *clientOptions, opts *mqtt.ClientOptions) {
if o.credentialFetcher != nil {
ctx, cancel := context.WithTimeout(context.Background(), o.credentialFetchTimeout)
defer cancel()

if c, err := o.credentialFetcher.Credentials(ctx); err == nil {
opts.SetUsername(c.Username)
opts.SetPassword(c.Password)

return
}
}

opts.SetUsername(o.username)
opts.SetPassword(o.password)
}

func formatAddressWithProtocol(opts *clientOptions) string {
if opts.tlsConfig != nil {
return fmt.Sprintf("tls://%s", opts.brokerAddress)
Expand Down

0 comments on commit 77cdc69

Please sign in to comment.