Skip to content

Commit

Permalink
change policy id to json form in RBACFilterFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
kozjan committed Dec 13, 2024
1 parent 866410f commit 5ddee5a
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 193 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package pl.allegro.tech.servicemesh.envoycontrol.groups

import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.google.protobuf.Duration
import com.google.protobuf.Struct
import com.google.protobuf.Value
Expand Down Expand Up @@ -810,6 +812,12 @@ data class IncomingEndpoint(
val oauth: OAuth? = null
) : EndpointBase

val mapper = jacksonObjectMapper()

fun IncomingEndpoint.toJson(): String {
val jsonString = mapper.writeValueAsString(this)
return jsonString
}
data class IncomingRateLimitEndpoint(
val path: String,
val pathMatchingType: PathMatchingType = PathMatchingType.PATH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import pl.allegro.tech.servicemesh.envoycontrol.groups.Incoming
import pl.allegro.tech.servicemesh.envoycontrol.groups.IncomingEndpoint
import pl.allegro.tech.servicemesh.envoycontrol.groups.OAuth
import pl.allegro.tech.servicemesh.envoycontrol.groups.Role
import pl.allegro.tech.servicemesh.envoycontrol.groups.toJson
import pl.allegro.tech.servicemesh.envoycontrol.logger
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.Client
import pl.allegro.tech.servicemesh.envoycontrol.snapshot.GlobalSnapshot
Expand Down Expand Up @@ -180,13 +181,13 @@ class RBACFilterFactory(
it.endpoint.unlistedClientsPolicy == Incoming.UnlistedPolicy.BLOCKANDLOG ||
it.endpoint.oauth?.policy != null
}
.map { (endpoint, policy) -> "$endpoint" to policy }.toMap()
.map { (endpoint, policy) -> endpoint.toJson() to policy }.toMap()

val loggedEndpointsPolicies = incomingEndpointsPolicies.asSequence()
.filter {
it.endpoint.unlistedClientsPolicy == Incoming.UnlistedPolicy.LOG && it.endpoint.oauth?.policy == null
}
.map { (endpoint, policy) -> "$endpoint" to policy }.toMap()
.map { (endpoint, policy) -> endpoint.toJson() to policy }.toMap()

val allowUnlistedPolicies = unlistedAndLoggedEndpointsPolicies(
incomingPermissions,
Expand Down
Loading

0 comments on commit 5ddee5a

Please sign in to comment.