From 77cdc692572f1dbf436b99057ee74cef82ea1b9a Mon Sep 17 00:00:00 2001 From: ajatprabha Date: Tue, 8 Aug 2023 20:03:17 +0530 Subject: [PATCH] revert unintended password change --- client.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 45b28c7..1a26544 100644 --- a/client.go +++ b/client.go @@ -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). @@ -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)