Skip to content

Commit

Permalink
base policy on pulsar dependencies
Browse files Browse the repository at this point in the history
also the test testPoliciesOperations is verifying the tolerated policies actions
  • Loading branch information
KannarFr committed Mar 11, 2024
1 parent 764aab5 commit a31c3f6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public final class BiscuitFormatter {
* </code>
*/
public static final String policiesOperations =
Arrays.stream(BiscuitPolicyOperation.values())
.map(policyOperation -> policyOperation.toString().toLowerCase())
BiscuitPolicyOperation.WHITELISTED_POLICIES_ACTIONS.stream()
.map(String::toLowerCase)
.sorted()
.collect(Collectors.joining("\",\"", "[\"", "\"]"));

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,55 @@
package com.clevercloud.biscuitpulsar.operation;

public enum BiscuitPolicyOperation {
ALL_READ,
//ALL_WRITE,
ANTI_AFFINITY_READ,
//ANTI_AFFINITY_WRITE,
AUTO_SUBSCRIPTION_CREATION_READ,
AUTO_SUBSCRIPTION_CREATION_WRITE,
AUTO_TOPIC_CREATION_READ,
AUTO_TOPIC_CREATION_WRITE,
BACKLOG_READ,
BACKLOG_WRITE,
COMPACTION_READ,
COMPACTION_WRITE,
DEDUPLICATION_READ,
DEDUPLICATION_SNAPSHOT_READ,
DEDUPLICATION_SNAPSHOT_WRITE,
DEDUPLICATION_WRITE,
DELAYED_DELIVERY_READ,
DELAYED_DELIVERY_WRITE,
ENCRYPTION_READ,
ENCRYPTION_WRITE,
INACTIVE_TOPIC_READ,
INACTIVE_TOPIC_WRITE,
MAX_CONSUMERS_READ,
//MAX_CONSUMERS_WRITE,
MAX_PRODUCERS_READ,
//MAX_PRODUCERS_WRITE,
MAX_SUBSCRIPTIONS_READ,
//MAX_SUBSCRIPTIONS_WRITE,
MAX_TOPICS_READ,
//MAX_TOPICS_WRITE,
MAX_UNACKED_READ,
MAX_UNACKED_WRITE,
OFFLOAD_READ,
//OFFLOAD_WRITE,
PARTITION_READ,
PARTITION_WRITE,
PERSISTENCE_READ,
PERSISTENCE_WRITE,
RATE_READ,
RATE_WRITE,
REPLICATION_RATE_READ,
//REPLICATION_RATE_WRITE,
REPLICATION_READ,
//REPLICATION_WRITE,
RESOURCEGROUP_READ,
RESOURCEGROUP_WRITE,
RETENTION_READ,
RETENTION_WRITE,
SCHEMA_COMPATIBILITY_STRATEGY_READ,
SCHEMA_COMPATIBILITY_STRATEGY_WRITE,
SUBSCRIPTION_AUTH_MODE_READ,
SUBSCRIPTION_AUTH_MODE_WRITE,
SUBSCRIPTION_EXPIRATION_TIME_READ,
SUBSCRIPTION_EXPIRATION_TIME_WRITE,
TTL_READ,
TTL_WRITE,
}
import org.apache.pulsar.common.policies.data.PolicyName;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

public final class BiscuitPolicyOperation {

private static final Set<PolicyName> POLICIES = new HashSet<>(Arrays.stream(PolicyName.values()).toList());

private static final Set<PolicyName> POLICIES_WHITELISTED_WRITES = new HashSet<>(Arrays.asList(
// PolicyName.ALL,
// PolicyName.ANTI_AFFINITY,
PolicyName.AUTO_SUBSCRIPTION_CREATION,
PolicyName.AUTO_TOPIC_CREATION,
PolicyName.BACKLOG,
PolicyName.COMPACTION,
PolicyName.DELAYED_DELIVERY,
PolicyName.INACTIVE_TOPIC,
PolicyName.DEDUPLICATION,
// PolicyName.MAX_CONSUMERS,
// PolicyName.MAX_PRODUCERS,
PolicyName.DEDUPLICATION_SNAPSHOT,
PolicyName.MAX_UNACKED,
// PolicyName.MAX_SUBSCRIPTIONS,
// PolicyName.OFFLOAD,
PolicyName.PARTITION,
PolicyName.PERSISTENCE,
PolicyName.RATE,
PolicyName.RETENTION,
// PolicyName.REPLICATION,
// PolicyName.REPLICATION_RATE,
PolicyName.SCHEMA_COMPATIBILITY_STRATEGY,
PolicyName.SUBSCRIPTION_AUTH_MODE,
PolicyName.SUBSCRIPTION_EXPIRATION_TIME,
PolicyName.ENCRYPTION,
PolicyName.TTL
// PolicyName.MAX_TOPICS,
// PolicyName.RESOURCEGROUP,
// PolicyName.ENTRY_FILTERS,
// PolicyName.SHADOW_TOPIC,
// PolicyName.DISPATCHER_PAUSE_ON_ACK_STATE_PERSISTENT,
));

public static final Set<String> WHITELISTED_POLICIES_ACTIONS = POLICIES.stream()
.flatMap(policy -> Arrays.stream(new String[]{String.format("%s_%s", policy.name().toUpperCase(), "READ"),
POLICIES_WHITELISTED_WRITES.contains(policy) ?
String.format("%s_%s", policy.name().toUpperCase(), "WRITE") : null}))
.filter(Objects::nonNull)
.collect(Collectors.toSet());
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void testNamespaceOperations() {

@Test
public void testPoliciesOperations() {
assertEquals("[\"all_read\",\"anti_affinity_read\",\"auto_subscription_creation_read\",\"auto_subscription_creation_write\",\"auto_topic_creation_read\",\"auto_topic_creation_write\",\"backlog_read\",\"backlog_write\",\"compaction_read\",\"compaction_write\",\"deduplication_read\",\"deduplication_snapshot_read\",\"deduplication_snapshot_write\",\"deduplication_write\",\"delayed_delivery_read\",\"delayed_delivery_write\",\"encryption_read\",\"encryption_write\",\"inactive_topic_read\",\"inactive_topic_write\",\"max_consumers_read\",\"max_producers_read\",\"max_subscriptions_read\",\"max_topics_read\",\"max_unacked_read\",\"max_unacked_write\",\"offload_read\",\"partition_read\",\"partition_write\",\"persistence_read\",\"persistence_write\",\"rate_read\",\"rate_write\",\"replication_rate_read\",\"replication_read\",\"resourcegroup_read\",\"resourcegroup_write\",\"retention_read\",\"retention_write\",\"schema_compatibility_strategy_read\",\"schema_compatibility_strategy_write\",\"subscription_auth_mode_read\",\"subscription_auth_mode_write\",\"subscription_expiration_time_read\",\"subscription_expiration_time_write\",\"ttl_read\",\"ttl_write\"]", policiesOperations);
assertEquals("[\"all_read\",\"anti_affinity_read\",\"auto_subscription_creation_read\",\"auto_subscription_creation_write\",\"auto_topic_creation_read\",\"auto_topic_creation_write\",\"backlog_read\",\"backlog_write\",\"compaction_read\",\"compaction_write\",\"deduplication_read\",\"deduplication_snapshot_read\",\"deduplication_snapshot_write\",\"deduplication_write\",\"delayed_delivery_read\",\"delayed_delivery_write\",\"encryption_read\",\"encryption_write\",\"entry_filters_read\",\"inactive_topic_read\",\"inactive_topic_write\",\"max_consumers_read\",\"max_producers_read\",\"max_subscriptions_read\",\"max_topics_read\",\"max_unacked_read\",\"max_unacked_write\",\"offload_read\",\"partition_read\",\"partition_write\",\"persistence_read\",\"persistence_write\",\"rate_read\",\"rate_write\",\"replication_rate_read\",\"replication_read\",\"resourcegroup_read\",\"retention_read\",\"retention_write\",\"schema_compatibility_strategy_read\",\"schema_compatibility_strategy_write\",\"shadow_topic_read\",\"subscription_auth_mode_read\",\"subscription_auth_mode_write\",\"subscription_expiration_time_read\",\"subscription_expiration_time_write\",\"ttl_read\",\"ttl_write\"]", policiesOperations);
}

@Test
Expand Down

0 comments on commit a31c3f6

Please sign in to comment.