diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/config/LocalReplyConfigFactory.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/config/LocalReplyConfigFactory.kt index 0dafc418a..6c4c240c6 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/config/LocalReplyConfigFactory.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/config/LocalReplyConfigFactory.kt @@ -184,25 +184,20 @@ class LocalReplyConfigFactory( validateHeaderMatcher(matcherAndMapper.headerMatcher) } - if (definitions != 1) { - throw IllegalArgumentException( - "One and only one of: headerMatcher, responseFlagMatcher, statusCodeMatcher has to be defined.") + require(definitions != 1) { + "One and only one of: headerMatcher, responseFlagMatcher, statusCodeMatcher has to be defined." } } private fun validateHeaderMatcher(headerMatcher: HeaderMatcherProperties) { - if (headerMatcher.exactMatch.isNotEmpty() && headerMatcher.regexMatch.isNotEmpty()) { - throw IllegalArgumentException( - "Only one of: exactMatch, regexMatch can be defined." - ) + require(headerMatcher.exactMatch.isNotEmpty() && headerMatcher.regexMatch.isNotEmpty()) { + "Only one of: exactMatch, regexMatch can be defined." } } private fun validateResponseFormatProperties(responseFormat: ResponseFormat) { - if (responseFormat.jsonFormat.isNotEmpty() && responseFormat.textFormat.isNotEmpty()) { - throw IllegalArgumentException( - "Only one of: jsonFormat, textFormat can be defined." - ) + require(responseFormat.jsonFormat.isNotEmpty() && responseFormat.textFormat.isNotEmpty()) { + "Only one of: jsonFormat, textFormat can be defined." } } } diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/RBACFilterFactory.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/RBACFilterFactory.kt index 572d7ad0c..8e8f77c73 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/RBACFilterFactory.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/RBACFilterFactory.kt @@ -54,8 +54,11 @@ class RBACFilterFactory( init { incomingPermissionsProperties.selectorMatching.forEach { - if (it.key !in incomingServicesIpRangeAuthentication && it.key !in incomingServicesSourceAuthentication) { - throw IllegalArgumentException("${it.key} is not defined in ip range or ip from discovery section.") + require( + it.key !in incomingServicesIpRangeAuthentication && + it.key !in incomingServicesSourceAuthentication + ) { + "${it.key} is not defined in ip range or ip from discovery section." } } } @@ -368,15 +371,18 @@ class RBACFilterFactory( principal ) ) + OAuth.Policy.STRICT -> mergePrincipals( listOf( strictPolicyPrincipal, principal ) ) + OAuth.Policy.ALLOW_MISSING_OR_FAILED -> { principal } + null -> { principal } diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/SanUriMatcherFactory.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/SanUriMatcherFactory.kt index 8de9f6acf..d0028c305 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/SanUriMatcherFactory.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/SanUriMatcherFactory.kt @@ -35,8 +35,8 @@ class SanUriMatcherFactory( private fun getSanUriFormatSplit(): Pair { val format = tlsProperties.sanUriFormat val parts = format.split(serviceNameTemplate) - if (parts.size != 2) { - throw IllegalArgumentException("SAN URI $format does not properly contain $serviceNameTemplate") + require(parts.size != 2) { + "SAN URI $format does not properly contain $serviceNameTemplate" } return parts[0] to parts[1] } diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/ServiceTagMetadataGenerator.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/ServiceTagMetadataGenerator.kt index 2d641a693..565430d82 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/ServiceTagMetadataGenerator.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/routes/ServiceTagMetadataGenerator.kt @@ -23,9 +23,8 @@ class ServiceTagMetadataGenerator(properties: ServiceTagsProperties = ServiceTag init { properties.allowedTagsCombinations.forEach { - if (it.tags.size < 2 || it.tags.size > 3) { - throw IllegalArgumentException( - "A tags combination must contain 2 or 3 tags. Combination with ${it.tags.size} tags found") + require(it.tags.size < 2 || it.tags.size > 3) { + "A tags combination must contain 2 or 3 tags. Combination with ${it.tags.size} tags found" } } val combinationsByService = properties.allowedTagsCombinations diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/utils/ReactorUtils.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/utils/ReactorUtils.kt index d219efc29..00fccdc2d 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/utils/ReactorUtils.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/utils/ReactorUtils.kt @@ -130,8 +130,8 @@ private fun measureScannableBuffer( * To access actual buffer size, we need to extract it from inners(). We don't know how many sources will * be available, so it must be stated explicitly as innerSources parameter. */ - (0 until innerSources).forEach { - meterRegistry.gauge("${bufferMetric(name)}_$it", scannable, innerBufferExtractor(it)) + for (i in 0 until innerSources) { + meterRegistry.gauge("${bufferMetric(name)}_$i", scannable, innerBufferExtractor(i)) } } diff --git a/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/config/envoy/EgressOperations.kt b/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/config/envoy/EgressOperations.kt index 6b6d89905..26b7eaff0 100644 --- a/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/config/envoy/EgressOperations.kt +++ b/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/config/envoy/EgressOperations.kt @@ -22,6 +22,7 @@ class EgressOperations(val envoy: EnvoyContainer) { body: RequestBody? = null ) = callWithHostHeader(service, headers, pathAndQuery, method, body) + @Suppress("detekt.ForEachOnRange") fun callServiceRepeatedly( service: String, stats: CallStats, diff --git a/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/config/envoycontrol/EnvoyControlTestApp.kt b/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/config/envoycontrol/EnvoyControlTestApp.kt index 168cd1b0f..2e72c3703 100644 --- a/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/config/envoycontrol/EnvoyControlTestApp.kt +++ b/envoy-control-tests/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/config/envoycontrol/EnvoyControlTestApp.kt @@ -220,8 +220,9 @@ class EnvoyControlRunnerTestApp( .execute().addToCloseableResponses() } - override fun meterRegistry() = app.context().getBean(MeterRegistry::class.java) - ?: throw IllegalStateException("MeterRegistry bean not found in the context") + override fun meterRegistry() = checkNotNull(app.context().getBean(MeterRegistry::class.java)) { + "MeterRegistry bean not found in the context" + } companion object { val logger by logger()