Skip to content

Commit

Permalink
improvement: remove config customization from configureFromZip method
Browse files Browse the repository at this point in the history
It's possible to customize the config object after it was created by the
configureFromZip method. This change helps us to keep the default
settings in one place (the initialization of the `Config` object).

Ref #113
  • Loading branch information
andreasgrill committed Sep 17, 2024
1 parent 4eff6ac commit 4c85ccd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,13 @@ data class Config(
* @param archiveOptions The options to configure the name of the files inside your ZIP
* archive (optional, default: ArchiveOptions()).
* @param port The port number for the API (default: "1883").
* @param mqttConnectOptions The MQTT connect options (optional, default:
* MqttConnectOptions()).
* @param requestIdGenerator The generator for request IDs (optional, default:
* DefaultRequestIdGenerator()).
* @param logoutOnClose Whether to log out on close (optional).
* @return A [Config] instance configured from the provided ZIP file that you can use to
* connect to the XesarMqttInstance.
*/
fun configureFromZip(
configurationZipFile: Path,
archiveOptions: ArchiveOptions = ArchiveOptions(),
port: String? = null,
mqttConnectOptions: MqttConnectOptions = MqttConnectOptions(),
requestIdGenerator: IRequestIdGenerator = DefaultRequestIdGenerator(),
logoutOnClose: Boolean = true,
): Config {

val zipFile = extractZipFile(configurationZipFile)
Expand All @@ -135,15 +127,7 @@ data class Config(
readX509CertificateFromZip(
archiveOptions.clientCertificateName, zipFile),
clientKey = readKeyPairWithZip(archiveOptions.clientKeyName, zipFile)),
uuidGenerator = requestIdGenerator,
mqttConnectOptions =
MqttConnectOptions(
isCleanSession = mqttConnectOptions.isCleanSession,
connectionTimeout = mqttConnectOptions.connectionTimeout,
isAutomaticReconnect = mqttConnectOptions.isAutomaticReconnect,
maxInflight = mqttConnectOptions.maxInflight,
keepAliveInterval = mqttConnectOptions.keepAliveInterval),
logoutOnClose = logoutOnClose)
)
}

private fun readTokenProperties(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ class ConfigTest :
val certificateZipFile = copyResourceToTempFile("/certificates/certificates.zip")

val configZip =
Config.configureFromZip(
certificateZipFile.toPath(),
mqttConnectOptions = Config.MqttConnectOptions(isCleanSession = true))
Config.configureFromZip(certificateZipFile.toPath())
.copy(mqttConnectOptions = Config.MqttConnectOptions(isCleanSession = true))

configZip.apiProperties.userId.shouldBeEqual(
UUID.fromString("35919920-c5aa-4371-900a-2ad6aa8206e0"))
Expand Down

0 comments on commit 4c85ccd

Please sign in to comment.