Skip to content

Commit a77d17b

Browse files
committed
validate -reunforweb and-forceencryption
1 parent 52ad77b commit a77d17b

2 files changed

Lines changed: 49 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
1616
- Support for content (and table rows) repeated by referred array variables
1717
- In both repeated content and variable structure paths it is possible to use literal path (e.g. Data.Clients.Value)
1818
or reference to a variable
19+
- Validate that IPS does not use unsupported parameters on first access
1920

2021
### Changed
2122

migration-library/src/main/kotlin/com/quadient/migration/service/ipsclient/IpsClient.kt

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.quadient.migration.service.ipsclient
22

3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
34
import com.fasterxml.jackson.dataformat.xml.XmlMapper
45
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
56
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
67
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement
78
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText
9+
import com.fasterxml.jackson.module.kotlin.readValue
810
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
911
import kotlinx.serialization.Serializable
1012
import org.slf4j.LoggerFactory
@@ -249,6 +251,41 @@ class IpsClient(private val host: String, private val port: Int, private val tim
249251
this._version = version()
250252
}
251253

254+
init {
255+
val result = serverProperties()
256+
if (result != null) {
257+
if (result.runForWeb) {
258+
throw RuntimeException("IPS server has -runforweb enabled, this is currently not supported.")
259+
}
260+
if (result.encryptionRequired) {
261+
throw RuntimeException("IPS server has -forceencryption enabled, this is currently not supported.")
262+
}
263+
}
264+
265+
}
266+
267+
private fun serverProperties(): ServerProperties? {
268+
val command = "diag"
269+
270+
this.writeLine(command).getOrElse {
271+
logger.error("Failed to write diag command to ips", it)
272+
return null
273+
}
274+
275+
val response = this.readLine().split(";")
276+
if (response.getOrNull(0) != "ok" || response.getOrNull(1)?.toLongOrNull() == null) {
277+
logger.error("Failed to get diagnostics from ips. Expected byte size, got $response")
278+
return null
279+
}
280+
val bytesToRead = response[1].toInt()
281+
val bytes = ByteArray(bytesToRead)
282+
this.reader.readNBytes(bytes, 0, bytesToRead)
283+
284+
val stat: ServerProperties = xmlMapper.readValue(bytes)
285+
286+
return stat
287+
}
288+
252289
private fun version(): Version? {
253290
val command = "version"
254291

@@ -381,14 +418,22 @@ class Output {
381418
}
382419
}
383420

421+
@JsonIgnoreProperties(ignoreUnknown = true)
422+
@Serializable
423+
data class ServerProperties(
424+
@param:JacksonXmlProperty(localName = "RunForWeb") val runForWeb: Boolean,
425+
@param:JacksonXmlProperty(localName = "Encrypted") val encrypted: Boolean,
426+
@param:JacksonXmlProperty(localName = "EncryptionRequired") val encryptionRequired: Boolean,
427+
)
428+
384429
@Serializable
385430
data class Coms(
386-
@JacksonXmlProperty(localName = "ImportLayoutXml") val values: ImportLayoutXml
431+
@param:JacksonXmlProperty(localName = "ImportLayoutXml") val values: ImportLayoutXml
387432
) {
388433
@Serializable
389434
data class ImportLayoutXml(
390-
@JacksonXmlProperty(localName = "ModuleName") val moduleName: String,
435+
@param:JacksonXmlProperty(localName = "ModuleName") val moduleName: String,
391436

392-
@JacksonXmlProperty(localName = "FileName") val fileName: String
437+
@param:JacksonXmlProperty(localName = "FileName") val fileName: String
393438
)
394439
}

0 commit comments

Comments
 (0)