diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/NodeMetadata.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/NodeMetadata.kt index 7f39887c2..be745b8f2 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/NodeMetadata.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/groups/NodeMetadata.kt @@ -372,7 +372,8 @@ fun Value.toIncomingEndpoint(properties: SnapshotProperties): IncomingEndpoint { val paths = this.field("paths")?.list().orEmpty().map { it.stringValue }.toSet() if (isMoreThanOnePropertyDefined(paths, path, pathPrefix, pathRegex)) { - throw NodeMetadataValidationException("Precisely one of 'paths', 'path', 'pathPrefix' or 'pathRegex' field is allowed") + throw NodeMetadataValidationException( + "Precisely one of 'paths', 'path', 'pathPrefix' or 'pathRegex' field is allowed") } val methods = this.field("methods")?.list().orEmpty().map { it.stringValue }.toSet() @@ -381,8 +382,10 @@ fun Value.toIncomingEndpoint(properties: SnapshotProperties): IncomingEndpoint { val oauth = properties.let { this.field("oauth")?.toOAuth(it) } return when { - paths.isNotEmpty() -> IncomingEndpoint(paths, "", PathMatchingType.PATH, methods, clients, unlistedClientsPolicy, oauth) - path != null -> IncomingEndpoint(paths, path, PathMatchingType.PATH, methods, clients, unlistedClientsPolicy, oauth) + paths.isNotEmpty() -> IncomingEndpoint( + paths, "", PathMatchingType.PATH, methods, clients, unlistedClientsPolicy, oauth) + path != null -> IncomingEndpoint( + paths, path, PathMatchingType.PATH, methods, clients, unlistedClientsPolicy, oauth) pathPrefix != null -> IncomingEndpoint( paths, pathPrefix, PathMatchingType.PATH_PREFIX, methods, clients, unlistedClientsPolicy, oauth ) @@ -391,7 +394,8 @@ fun Value.toIncomingEndpoint(properties: SnapshotProperties): IncomingEndpoint { paths, pathRegex, PathMatchingType.PATH_REGEX, methods, clients, unlistedClientsPolicy, oauth ) - else -> throw NodeMetadataValidationException("One of 'paths', 'path', 'pathPrefix' or 'pathRegex' field is required") + else -> throw NodeMetadataValidationException( + "One of 'paths', 'path', 'pathPrefix' or 'pathRegex' field is required") } } @@ -422,7 +426,8 @@ fun Value.toIncomingRateLimitEndpoint(): IncomingRateLimitEndpoint { } } -fun isMoreThanOnePropertyDefined(vararg properties: Any?): Boolean = countNonNullAndNotEmptyProperties(properties.toList()) > 1 +fun isMoreThanOnePropertyDefined(vararg properties: Any?): Boolean = + countNonNullAndNotEmptyProperties(properties.toList()) > 1 private fun countNonNullAndNotEmptyProperties(props: List): Int = props.filterNotNull().count { if (it is Set<*>) { diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/JwtFilterFactory.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/JwtFilterFactory.kt index e6b8ea8f8..76b6797c9 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/JwtFilterFactory.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/JwtFilterFactory.kt @@ -106,7 +106,8 @@ class JwtFilterFactory( requirementRuleWithURITemplateMatching(it, endpoint.methods, providers) }.toSet() } else { - setOf(requirementRuleWithPathMatching(endpoint.path, endpoint.pathMatchingType, endpoint.methods, providers)) + setOf(requirementRuleWithPathMatching( + endpoint.path, endpoint.pathMatchingType, endpoint.methods, providers)) } } diff --git a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/RBACFilterPermissions.kt b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/RBACFilterPermissions.kt index 26990a52e..64e54c0bd 100644 --- a/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/RBACFilterPermissions.kt +++ b/envoy-control-core/src/main/kotlin/pl/allegro/tech/servicemesh/envoycontrol/snapshot/resource/listeners/filters/RBACFilterPermissions.kt @@ -14,10 +14,11 @@ import pl.allegro.tech.servicemesh.envoycontrol.groups.PathMatchingType class RBACFilterPermissions { fun createCombinedPermissions(incomingEndpoint: IncomingEndpoint): Permission.Builder { val permissions = listOfNotNull( - if (incomingEndpoint.paths.isNotEmpty()) + if (incomingEndpoint.paths.isNotEmpty()) { createPathTemplatesPermissionForEndpoint(incomingEndpoint) - else - createPathPermissionForEndpoint(incomingEndpoint), + } else { + createPathPermissionForEndpoint(incomingEndpoint) + }, createMethodPermissions(incomingEndpoint), ) .map { it.build() } @@ -33,7 +34,7 @@ class RBACFilterPermissions { incomingEndpoint.paths.map(this::createPathTemplate))) } - private fun createPathTemplate(path: String): Permission{ + private fun createPathTemplate(path: String): Permission { return permission().setUriTemplate(TypedExtensionConfig.newBuilder() .setName("envoy.path.match.uri_template.uri_template_matcher") .setTypedConfig(Any.pack(