Skip to content

Commit

Permalink
Lots of updates and ktlint syntax fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
milux committed Nov 24, 2023
1 parent f14fc05 commit a2a4943
Show file tree
Hide file tree
Showing 112 changed files with 1,729 additions and 1,387 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
java-version: '21'
- name: Setup protoc
uses: arduino/[email protected]
with:
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax = docker/dockerfile:experimental

ARG BUILDER_IMAGE=amd64/eclipse-temurin:17-jdk-focal
ARG BASE_IMAGE=gcr.io/distroless/java17-debian11
ARG BUILDER_IMAGE=amd64/eclipse-temurin:21-jdk
ARG BASE_IMAGE=gcr.io/distroless/java21-debian12

FROM $BUILDER_IMAGE AS builder
LABEL AUTHOR="Michael Lux ([email protected])"
Expand Down
9 changes: 7 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ allprojects {
group = "de.fhg.aisec.ids"
version = "7.2.0"

val versionRegex = ".*(rc-?[0-9]*|beta|-b.+)$".toRegex(RegexOption.IGNORE_CASE)
val versionRegex = ".*((rc|beta)-?[0-9]*|-b[0-9.]+)$".toRegex(RegexOption.IGNORE_CASE)

tasks.withType<DependencyUpdatesTask> {
rejectVersionIf {
Expand Down Expand Up @@ -81,6 +81,9 @@ subprojects {
),
"org.eclipse.jetty" to mapOf(
"*" to versions.jetty.get()
),
"org.bouncycastle" to mapOf(
"*" to versions.bouncyCastle.get()
)
)
// We need to explicitly specify the kotlin version for all kotlin dependencies,
Expand Down Expand Up @@ -146,7 +149,9 @@ configure(subprojects.filter { it.name != "examples" }) {
spotless {
kotlin {
target("src/*/kotlin/**/*.kt")
ktlint(libs.versions.ktlint.get())
ktlint(libs.versions.ktlint.get()).editorConfigOverride(mapOf(
"ktlint_code_style" to "ktlint_official"
))
licenseHeader(
"""/*-
* ========================LICENSE_START=================================
Expand Down
2 changes: 1 addition & 1 deletion buildx/docker-buildx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fi
eval set -- "$PARSED"

DOCKER_BUILD_TAGS="develop"
BASE_IMAGE_ARG="gcr.io/distroless/java17-debian11"
BASE_IMAGE_ARG="gcr.io/distroless/java21-debian12"
TARGETS="core"
OUTPUT_TYPE="docker"
BAKE_ARGS=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import java.net.URI

@Component("artifactRequestCreationProcessor")
class ArtifactRequestCreationProcessor : Processor {

override fun process(exchange: Exchange) {
if (LOG.isDebugEnabled) {
LOG.debug("[IN] ${this::class.java.simpleName}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,23 @@ import org.springframework.stereotype.Component

@Component("artifactRequestProcessor")
class ArtifactRequestProcessor : Processor {

override fun process(exchange: Exchange) {
if (LOG.isDebugEnabled) {
LOG.debug("[IN] ${this::class.java.simpleName}")
}

val artifactRequestMessage = exchange.message.getHeader(
IDS_HEADER,
ArtifactRequestMessage::class.java
)
val artifactRequestMessage =
exchange.message.getHeader(
IDS_HEADER,
ArtifactRequestMessage::class.java
)
val requestedArtifact = artifactRequestMessage.requestedArtifact

// TODO: If transferContract doesn't match expected contract from database, send rejection!
val usedContract = ProviderDB.artifactUrisMapped2ContractAgreements[
Pair(requestedArtifact, UsageControlMaps.getExchangePeerIdentity(exchange))
]
val usedContract =
ProviderDB.artifactUrisMapped2ContractAgreements[
Pair(requestedArtifact, UsageControlMaps.getExchangePeerIdentity(exchange))
]
if (LOG.isDebugEnabled) {
LOG.debug("Contract for requested Artifact found {}", usedContract)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,22 @@ import org.springframework.stereotype.Component

@Component("contractAgreementReceiverProcessor")
class ContractAgreementReceiverProcessor : Processor {

override fun process(exchange: Exchange) {
if (LOG.isDebugEnabled) {
LOG.debug("[IN] ${this::class.java.simpleName}")
}

val contractAgreementMessage = exchange.message.getHeader(
IDS_HEADER,
ContractAgreementMessage::class.java
)
val contractAgreementMessage =
exchange.message.getHeader(
IDS_HEADER,
ContractAgreementMessage::class.java
)

val contractAgreement = SERIALIZER.deserialize(
exchange.message.getBody(String::class.java),
ContractAgreement::class.java
)
val contractAgreement =
SERIALIZER.deserialize(
exchange.message.getBody(String::class.java),
ContractAgreement::class.java
)

UsageControlMaps.addContractAgreement(contractAgreement)
if (LOG.isDebugEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,27 @@ import org.slf4j.Logger
import java.net.URI

object ContractHelper {

fun collectContractProperties(requestedArtifact: URI, exchange: Exchange): Map<String, Any> {
val contractProperties = mutableMapOf<String, Any>(
ContractConstants.ARTIFACT_URI_PROPERTY to requestedArtifact
)
fun collectContractProperties(
requestedArtifact: URI,
exchange: Exchange
): Map<String, Any> {
val contractProperties =
mutableMapOf<String, Any>(
ContractConstants.ARTIFACT_URI_PROPERTY to requestedArtifact
)
// Docker image whitelisting
contractProperties[ContractConstants.UC_DOCKER_IMAGE_URIS] = (
exchange.getProperty(ContractConstants.UC_DOCKER_IMAGE_URIS)
// Legacy property name without "uc-" prefix
?: exchange.getProperty("containerUri")
?: ""
contractProperties[ContractConstants.UC_DOCKER_IMAGE_URIS] =
(
exchange.getProperty(ContractConstants.UC_DOCKER_IMAGE_URIS)
// Legacy property name without "uc-" prefix
?: exchange.getProperty("containerUri")
?: ""
).toString()
.split(Regex("\\s+"))
.map(String::trim)
.filter(String::isNotEmpty)
.map(URI::create)
.toList()
.split(Regex("\\s+"))
.map(String::trim)
.filter(String::isNotEmpty)
.map(URI::create)
.toList()
// Add not after (BEFORE) usage constraint
exchange.getProperty(ContractConstants.UC_NOT_AFTER_DATETIME)?.let {
contractProperties[ContractConstants.UC_NOT_AFTER_DATETIME] = it
Expand All @@ -58,11 +62,16 @@ object ContractHelper {
return contractProperties
}

fun handleContractOffer(exchange: Exchange, correlationId: URI, logger: Logger) {
val contractOfferReceived = ContractUtils.SERIALIZER.deserialize(
exchange.message.getBody(String::class.java),
ContractOffer::class.java
)
fun handleContractOffer(
exchange: Exchange,
correlationId: URI,
logger: Logger
) {
val contractOfferReceived =
ContractUtils.SERIALIZER.deserialize(
exchange.message.getBody(String::class.java),
ContractOffer::class.java
)

// if contract is denied send ContractRejectionMsg else send ContractAgreementMsg
val contractOfferIsAccepted = true
Expand All @@ -79,18 +88,19 @@ object ContractHelper {
}
}

val contractAgreement = ContractAgreementBuilder()
._consumer_(contractOfferReceived.consumer)
._provider_(contractOfferReceived.provider)
._contractAnnex_(contractOfferReceived.contractAnnex)
._contractDate_(contractOfferReceived.contractDate)
._contractDocument_(contractOfferReceived.contractDocument)
._contractEnd_(contractOfferReceived.contractEnd)
._contractStart_(contractOfferReceived.contractStart)
._obligation_(contractOfferReceived.obligation)
._prohibition_(contractOfferReceived.prohibition)
._permission_(contractOfferReceived.permission)
.build()
val contractAgreement =
ContractAgreementBuilder()
._consumer_(contractOfferReceived.consumer)
._provider_(contractOfferReceived.provider)
._contractAnnex_(contractOfferReceived.contractAnnex)
._contractDate_(contractOfferReceived.contractDate)
._contractDocument_(contractOfferReceived.contractDocument)
._contractEnd_(contractOfferReceived.contractEnd)
._contractStart_(contractOfferReceived.contractStart)
._obligation_(contractOfferReceived.obligation)
._prohibition_(contractOfferReceived.prohibition)
._permission_(contractOfferReceived.permission)
.build()

UsageControlMaps.addContractAgreement(contractAgreement)
if (logger.isDebugEnabled) {
Expand All @@ -107,7 +117,11 @@ object ContractHelper {
}
}

private fun createContractRejectionMessage(exchange: Exchange, correlationId: URI, logger: Logger) {
private fun createContractRejectionMessage(
exchange: Exchange,
correlationId: URI,
logger: Logger
) {
if (logger.isDebugEnabled) {
logger.debug("Constructing ContractRejectionMessage")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ import java.net.URI
* This Processor handles a ContractRequestMessage and creates a ContractResponseMessage.
*/
@Component("contractOfferCreationProcessor")
class ContractOfferCreationProcessor(@Autowired private val contractManager: ContractManager) : Processor {

class ContractOfferCreationProcessor(
@Autowired private val contractManager: ContractManager
) : Processor {
override fun process(exchange: Exchange) {
if (LOG.isDebugEnabled) {
LOG.debug("[IN] ${this::class.java.simpleName}")
Expand All @@ -49,13 +50,14 @@ class ContractOfferCreationProcessor(@Autowired private val contractManager: Con
exchange.message.setHeader(IDS_HEADER, it)
}

val artifactUri = exchange.getProperty(ContractConstants.ARTIFACT_URI_PROPERTY)?.let {
if (it is URI) {
it
} else {
URI.create(it.toString())
}
} ?: throw RuntimeException("No property \"artifactUri\" found in Exchange, cannot build contract!")
val artifactUri =
exchange.getProperty(ContractConstants.ARTIFACT_URI_PROPERTY)?.let {
if (it is URI) {
it
} else {
URI.create(it.toString())
}
} ?: throw RuntimeException("No property \"artifactUri\" found in Exchange, cannot build contract!")

val contractProperties = ContractHelper.collectContractProperties(artifactUri, exchange)
val contractOffer = contractManager.makeContract(contractProperties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ import org.springframework.stereotype.Component
* This Processor handles a ContractRequestMessage and creates a ContractResponseMessage.
*/
@Component("contractOfferLoaderProcessor")
class ContractOfferLoaderProcessor(@Autowired private val contractManager: ContractManager) : Processor {

class ContractOfferLoaderProcessor(
@Autowired private val contractManager: ContractManager
) : Processor {
override fun process(exchange: Exchange) {
if (LOG.isDebugEnabled) {
LOG.debug("[IN] ${this::class.java.simpleName}")
Expand All @@ -49,9 +50,10 @@ class ContractOfferLoaderProcessor(@Autowired private val contractManager: Contr
}

val storeKey = exchange.getProperty(CONTRACT_STORE_KEY)?.toString()
val contractOffer = storeKey?.let {
contractManager.loadContract(it)
} ?: throw RuntimeException("Error loading ContractOffer with store key \"$storeKey\"")
val contractOffer =
storeKey?.let {
contractManager.loadContract(it)
} ?: throw RuntimeException("Error loading ContractOffer with store key \"$storeKey\"")

SERIALIZER.serialize(contractOffer).let {
if (LOG.isDebugEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ import org.springframework.stereotype.Component
*/
@Component("contractOfferProcessor")
class ContractOfferProcessor : Processor {

override fun process(exchange: Exchange) {
if (LOG.isDebugEnabled) {
LOG.debug("[IN] ${this::class.java.simpleName}")
}

val contractOfferMessage = exchange.message.getHeader(
IDS_HEADER,
ContractOfferMessage::class.java
)
val contractOfferMessage =
exchange.message.getHeader(
IDS_HEADER,
ContractOfferMessage::class.java
)

ContractHelper.handleContractOffer(exchange, contractOfferMessage.id, LOG)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@ import java.net.URI
* This Processor handles a ContractRequestMessage and creates a ContractResponseMessage.
*/
@Component("contractOfferStoreProcessor")
class ContractOfferStoreProcessor(@Autowired private val contractManager: ContractManager) : Processor {

class ContractOfferStoreProcessor(
@Autowired private val contractManager: ContractManager
) : Processor {
override fun process(exchange: Exchange) {
if (LOG.isDebugEnabled) {
LOG.debug("[IN] ${this::class.java.simpleName}")
}

val artifactUri = exchange.getProperty(ContractConstants.ARTIFACT_URI_PROPERTY)?.let {
if (it is URI) {
it
} else {
URI.create(it.toString())
}
} ?: throw RuntimeException("No property \"artifactUri\" found in Exchange, cannot build contract!")
val artifactUri =
exchange.getProperty(ContractConstants.ARTIFACT_URI_PROPERTY)?.let {
if (it is URI) {
it
} else {
URI.create(it.toString())
}
} ?: throw RuntimeException("No property \"artifactUri\" found in Exchange, cannot build contract!")

exchange.getProperty(CONTRACT_STORE_KEY)?.toString()?.let {
val contractProperties = ContractHelper.collectContractProperties(artifactUri, exchange)
Expand Down
Loading

0 comments on commit a2a4943

Please sign in to comment.