Skip to content

Commit

Permalink
fix(iot-dev): fix bug where client options was overridden (#1749)
Browse files Browse the repository at this point in the history
If a user provides a client options instance, but without an SSLContext, we should still keep all the settings they provided while adding the SSLContext generated by the SDK
  • Loading branch information
timtay-microsoft authored Oct 18, 2023
1 parent c6bb05a commit 87a7792
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* Options that allow configuration of the device client instance during initialization.
*/
@Builder
@Builder(toBuilder = true)
public final class ClientOptions
{
private static final int DEFAULT_HTTPS_CONNECT_TIMEOUT_MILLISECONDS = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,15 @@ public static ModuleClient createFromEnvironment(UnixDomainSocketChannel unixDom
sslContext = new IotHubSSLContext().getSSLContext();
}

if (clientOptions == null || clientOptions.getSslContext() == null)
if (clientOptions != null && clientOptions.getSslContext() == null)
{
// only override the SSLContext if the user didn't set it
// Clone the existing client options, but with the new SSLContext
clientOptions = clientOptions.toBuilder().sslContext(sslContext)
.build();
}
else if (clientOptions == null)
{
// only override the client options completely if the user didn't provide any
clientOptions = ClientOptions.builder().sslContext(sslContext).build();
}
else
Expand Down

0 comments on commit 87a7792

Please sign in to comment.