Skip to content

Commit

Permalink
Applied checkstyle suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
druminski committed Jun 26, 2024
1 parent 3ac18f2 commit 71299b2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
)
Expand All @@ -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")
}
}

Expand Down Expand Up @@ -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<Any?>): Int = props.filterNotNull().count {
if (it is Set<*>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand All @@ -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(
Expand Down

0 comments on commit 71299b2

Please sign in to comment.