Skip to content

Commit

Permalink
Fixed ktlint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
milux committed Jun 10, 2024
1 parent eac6b3a commit 61660de
Show file tree
Hide file tree
Showing 62 changed files with 382 additions and 374 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ class ArtifactRequestCreationProcessor : Processor {
LOG.debug("[IN] ${this::class.java.simpleName}")
}
ArtifactRequestMessageBuilder().run {
exchange.getProperty(ARTIFACT_URI_PROPERTY)?.let {
if (it is URI) {
it
} else {
URI.create(it.toString())
exchange
.getProperty(ARTIFACT_URI_PROPERTY)
?.let {
if (it is URI) {
it
} else {
URI.create(it.toString())
}
}?.let {
_requestedArtifact_(it)
}
}?.let {
_requestedArtifact_(it)
}
let {
if (LOG.isDebugEnabled) {
LOG.debug("Serialisation header: {}", SERIALIZER.serialize(it.build()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ class ContractRequestCreationProcessor : Processor {
._action_(listOf(Action.USE))
.build()
)
)
.build()
).build()
SERIALIZER.serialize(contractRequest).let {
if (LOG.isDebugEnabled) LOG.debug("Serialization body: {}", it)
exchange.message.body = it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ object UsageControlMaps {

fun getExchangePeerIdentity(exchange: Exchange): String? = exchangePeerIdentityMap[exchange]

fun getExchangeContract(exchange: Exchange): ContractAgreement? {
return exchangePeerIdentityMap[exchange]?.let { identity ->
fun getExchangeContract(exchange: Exchange): ContractAgreement? =
exchangePeerIdentityMap[exchange]?.let { identity ->
peerContracts[identity]?.let { uri ->
contractMap[uri] ?: throw RuntimeException("Contract $uri is not available!")
}
}
}

fun addContractAgreement(contractAgreement: ContractAgreement) {
contractMap[contractAgreement.id] = contractAgreement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,61 +29,62 @@ import java.io.InputStream
import java.io.InputStreamReader
import java.nio.charset.StandardCharsets

class MultiPartStringParser internal constructor(private val multipartInput: InputStream) :
UploadContext {
private var boundary: String? = null
var header: String? = null
var payload: InputStream? = null
var payloadContentType: String? = null
class MultiPartStringParser internal constructor(
private val multipartInput: InputStream
) : UploadContext {
private var boundary: String? = null
var header: String? = null
var payload: InputStream? = null
var payloadContentType: String? = null

override fun getCharacterEncoding(): String = StandardCharsets.UTF_8.name()
override fun getCharacterEncoding(): String = StandardCharsets.UTF_8.name()

@Deprecated(
"Deprecated in favor of contentLength(), see parent class org.apache.commons.fileupload.UploadContext",
ReplaceWith("contentLength()")
)
override fun getContentLength() = -1
@Deprecated(
"Deprecated in favor of contentLength(), see parent class org.apache.commons.fileupload.UploadContext",
ReplaceWith("contentLength()")
)
override fun getContentLength() = -1

override fun getContentType() = "multipart/form-data, boundary=$boundary"
override fun getContentType() = "multipart/form-data, boundary=$boundary"

override fun getInputStream() = multipartInput
override fun getInputStream() = multipartInput

override fun contentLength() = -1L
override fun contentLength() = -1L

companion object {
private val LOG = LoggerFactory.getLogger(MultiPartStringParser::class.java)
}
companion object {
private val LOG = LoggerFactory.getLogger(MultiPartStringParser::class.java)
}

init {
multipartInput.mark(10240)
BufferedReader(InputStreamReader(multipartInput, StandardCharsets.UTF_8)).use { reader ->
val boundaryLine =
reader.readLine()
?: throw IOException(
"Message body appears to be empty, expected multipart boundary."
)
boundary = boundaryLine.substring(2).trim { it <= ' ' }
multipartInput.reset()
for (i in FileUpload(DiskFileItemFactory()).parseRequest(this)) {
val fieldName = i.fieldName
if (LOG.isTraceEnabled) {
LOG.trace("Found multipart field with name \"{}\"", fieldName)
init {
multipartInput.mark(10240)
BufferedReader(InputStreamReader(multipartInput, StandardCharsets.UTF_8)).use { reader ->
val boundaryLine =
reader.readLine()
?: throw IOException(
"Message body appears to be empty, expected multipart boundary."
)
boundary = boundaryLine.substring(2).trim { it <= ' ' }
multipartInput.reset()
for (i in FileUpload(DiskFileItemFactory()).parseRequest(this)) {
val fieldName = i.fieldName
if (LOG.isTraceEnabled) {
LOG.trace("Found multipart field with name \"{}\"", fieldName)
}
if (MultiPartConstants.MULTIPART_HEADER == fieldName) {
header = i.string
if (LOG.isDebugEnabled) {
LOG.debug("Found header:\n{}", header)
}
if (MultiPartConstants.MULTIPART_HEADER == fieldName) {
header = i.string
if (LOG.isDebugEnabled) {
LOG.debug("Found header:\n{}", header)
}
} else if (MultiPartConstants.MULTIPART_PAYLOAD == fieldName) {
payload = i.inputStream
payloadContentType = i.contentType
if (LOG.isDebugEnabled) {
LOG.debug("Found body with Content-Type \"{}\"", payloadContentType)
}
} else {
throw IOException("Unknown multipart field name detected: $fieldName")
} else if (MultiPartConstants.MULTIPART_PAYLOAD == fieldName) {
payload = i.inputStream
payloadContentType = i.contentType
if (LOG.isDebugEnabled) {
LOG.debug("Found body with Content-Type \"{}\"", payloadContentType)
}
} else {
throw IOException("Unknown multipart field name detected: $fieldName")
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ class AisecDapsDriverFactoryBean : FactoryBean<AisecDapsDriver> {
var transportCertificatesParameters: SSLContextParameters by BeanSetter {
val ks =
loadKeyStore(
it.keyManagers.keyStore.resource.let(Paths::get)
it.keyManagers.keyStore.resource
.let(Paths::get)
?: throw RuntimeException("Error loading transport certificates: No KeyStore file provided!"),
it.keyManagers.keyStore.password?.toCharArray()
it.keyManagers.keyStore.password
?.toCharArray()
?: throw RuntimeException("Error loading transport certificates: No KeyStore password provided!")
)
builder.loadTransportCertsFromKeystore(ks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import org.springframework.beans.factory.FactoryBean
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

class BeanSetter<T, FC>(val setConsumer: (T) -> Unit) : ReadWriteProperty<FactoryBean<FC>, T> {
class BeanSetter<T, FC>(
val setConsumer: (T) -> Unit
) : ReadWriteProperty<FactoryBean<FC>, T> {
override operator fun getValue(
thisRef: FactoryBean<FC>,
property: KProperty<*>
): T {
throw UnsupportedOperationException("FactoryBean set-only Builder method")
}
): T = throw UnsupportedOperationException("FactoryBean set-only Builder method")

override operator fun setValue(
thisRef: FactoryBean<FC>,
Expand Down
45 changes: 23 additions & 22 deletions ids-acme/src/main/kotlin/de/fhg/aisec/ids/acme/AcmeClientService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ import java.util.Date
// Every day at 3:00 (3 am)
// property = [Scheduler.PROPERTY_SCHEDULER_EXPRESSION + "=0 0 3 * * ?"]
)
class AcmeClientService : AcmeClient, Runnable, SslContextFactoryReloadableRegistry {
class AcmeClientService :
AcmeClient,
Runnable,
SslContextFactoryReloadableRegistry {
@Autowired
private lateinit var settings: Settings

Expand All @@ -82,9 +85,7 @@ class AcmeClientService : AcmeClient, Runnable, SslContextFactoryReloadableRegis
}
}

override fun getChallengeAuthorization(challenge: String): String? {
return challengeMap[challenge]
}
override fun getChallengeAuthorization(challenge: String): String? = challengeMap[challenge]

private fun ensureKeys(targetDirectory: Path) {
listOf("acme.key", "domain.key").forEach { keyFile ->
Expand All @@ -109,7 +110,8 @@ class AcmeClientService : AcmeClient, Runnable, SslContextFactoryReloadableRegis

private fun getACMEKeyPair(targetDirectory: Path): KeyPair {
try {
Files.newBufferedReader(targetDirectory.resolve("acme.key"), StandardCharsets.UTF_8)
Files
.newBufferedReader(targetDirectory.resolve("acme.key"), StandardCharsets.UTF_8)
.use { fileReader ->
return KeyPairUtils.readKeyPair(fileReader)
}
Expand Down Expand Up @@ -190,8 +192,7 @@ class AcmeClientService : AcmeClient, Runnable, SslContextFactoryReloadableRegis
.parallelStream()
.map<Http01Challenge> { authorization ->
authorization.findChallenge(Http01Challenge.TYPE)
}
.forEach { challenge ->
}.forEach { challenge ->
challengeMap[challenge.token] = challenge.authorization
try {
// solve the challenge
Expand Down Expand Up @@ -222,21 +223,21 @@ class AcmeClientService : AcmeClient, Runnable, SslContextFactoryReloadableRegis
val timestamp =
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HH:mm:ss.SSS"))
try {
Files.newBufferedReader(
targetDirectory.resolve("domain.key"),
StandardCharsets.UTF_8
)
.use { keyReader ->
Files.newBufferedWriter(
targetDirectory.resolve("csr_ $timestamp.csr"),
StandardCharsets.UTF_8
)
.use { csrWriter ->
Files.newBufferedWriter(
targetDirectory.resolve("cert-chain_$timestamp.crt"),
StandardCharsets.UTF_8
)
.use { chainWriter ->
Files
.newBufferedReader(
targetDirectory.resolve("domain.key"),
StandardCharsets.UTF_8
).use { keyReader ->
Files
.newBufferedWriter(
targetDirectory.resolve("csr_ $timestamp.csr"),
StandardCharsets.UTF_8
).use { csrWriter ->
Files
.newBufferedWriter(
targetDirectory.resolve("cert-chain_$timestamp.crt"),
StandardCharsets.UTF_8
).use { chainWriter ->
val domainKeyPair = KeyPairUtils.readKeyPair(keyReader)

val csrb = CSRBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ import java.util.regex.Pattern
* @see [Boulder](https://github.com/letsencrypt/boulder)
*/
class BoulderAcmeProvider : AbstractAcmeProvider() {
override fun accepts(serverUri: URI): Boolean {
return "acme" == serverUri.scheme && "boulder" == serverUri.host
}
override fun accepts(serverUri: URI): Boolean = "acme" == serverUri.scheme && "boulder" == serverUri.host

override fun resolve(serverUri: URI): URL {
try {
Expand Down
4 changes: 3 additions & 1 deletion ids-api/src/main/kotlin/de/fhg/aisec/ids/api/LazyProducer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
*/
package de.fhg.aisec.ids.api

class LazyProducer<T>(generator: () -> T) : () -> T {
class LazyProducer<T>(
generator: () -> T
) : () -> T {
private val value: T by lazy(generator)

override operator fun invoke() = value
Expand Down
5 changes: 4 additions & 1 deletion ids-api/src/main/kotlin/de/fhg/aisec/ids/api/Result.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@
package de.fhg.aisec.ids.api

/** Generic result of an API call. */
open class Result(var isSuccessful: Boolean = true, var message: String = "ok")
open class Result(
var isSuccessful: Boolean = true,
var message: String = "ok"
)
5 changes: 2 additions & 3 deletions ids-api/src/main/kotlin/de/fhg/aisec/ids/api/RunCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ package de.fhg.aisec.ids.api
import java.io.IOException
import java.util.concurrent.TimeUnit

fun String.runCommand(): String? {
return try {
fun String.runCommand(): String? =
try {
val parts = this.split("\\s".toRegex())
val proc =
ProcessBuilder(*parts.toTypedArray())
Expand All @@ -36,4 +36,3 @@ fun String.runCommand(): String? {
e.printStackTrace()
null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class ApplicationContainer {
var labels: Map<String, Any> = emptyMap()
var volumes: List<Any> = emptyList()

override fun toString(): String {
return (
override fun toString(): String =
(
"ApplicationContainer [id=" +
id +
", image=" +
Expand All @@ -97,5 +97,4 @@ class ApplicationContainer {
description +
"]"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,5 @@ class IDSCPClientEndpoint {
var attestationResult: RatResult? = null
var endpointKey: String? = null

override fun toString(): String {
return "IDSCPEndpoint [endpoint_identifier=$endpointIdentifier]"
}
override fun toString(): String = "IDSCPEndpoint [endpoint_identifier=$endpointIdentifier]"
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ class IDSCPIncomingConnection {
var metaData: String? = null
private var dynamicAttributeToken: String? = null

override fun toString(): String {
return (
override fun toString(): String =
(
"IDSCPConnection [endpoint_identifier=" +
endpointIdentifier +
", attestationResult=" +
attestationResult +
"]"
)
}

fun setDynamicAttributeToken(dynamicAttributeToken: String?) {
this.dynamicAttributeToken = dynamicAttributeToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,5 @@ class IDSCPOutgoingConnection {
var attestationResult: RatResult? = null
var metaData: String? = null

override fun toString(): String {
return "IDSCPOutgoingConnection [endpoint_identifier=$endpointIdentifier]"
}
override fun toString(): String = "IDSCPOutgoingConnection [endpoint_identifier=$endpointIdentifier]"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ package de.fhg.aisec.ids.api.conm
*
* @author Julian Schuette (julian.schuette@aisec.fraunhofer.de)
*/
class RatResult(val status: Status, reason: String?) {
class RatResult(
val status: Status,
reason: String?
) {
enum class Status {
FAILED,
SUCCESS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ abstract class CounterExample {
var steps: List<String>? = null
protected set

override fun toString(): String {
return """
Explanation: $explanation
${java.lang.String.join("\n|-- ", steps)}
""".trimIndent()
}
override fun toString(): String =
"""
Explanation: $explanation
${java.lang.String.join("\n|-- ", steps)}
""".trimIndent()
}
Loading

0 comments on commit 61660de

Please sign in to comment.