Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] #215 | Add soft-deletion support for Varadhi Resources #218

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
88 changes: 83 additions & 5 deletions common/src/main/java/com/flipkart/varadhi/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,68 @@

import com.flipkart.varadhi.entities.TopicCapacityPolicy;

/**
* Constants class contains various constant values used throughout the application.
* This class is not meant to be instantiated.
*/
public class Constants {
// Length of the random partition key
public static final int RANDOM_PARTITION_KEY_LENGTH = 5;
// Context key for the body
public static final String CONTEXT_KEY_BODY = "varadhi.body";
// Context key for resource hierarchy
public static final String CONTEXT_KEY_RESOURCE_HIERARCHY = "varadhi.resourceHierarchy";
// Context key to check if the user is a super-user
public static final String CONTEXT_KEY_IS_SUPER_USER = "varadhi.isSuperUser";

// TODO: this header is only for testing and x_ convention may cause it to be sent to the destination during consume
// TODO: This header is intended for testing purposes only. The "x_" prefix may result in it being sent to the destination during consumption.
// Header for user ID, intended for testing purposes only
Comment on lines +19 to +20
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Address security concern in USER_ID_HEADER.

The TODO comment indicates a potential security risk where the "x_" prefixed header might be forwarded to the destination during consumption. This could lead to information leakage.

Consider:

  1. Using a different prefix that won't be forwarded
  2. Implementing header filtering before forwarding
  3. Documenting this limitation in security documentation

public static final String USER_ID_HEADER = "x_user_id";

public static final TopicCapacityPolicy DefaultTopicCapacity = new TopicCapacityPolicy(100, 400, 2);
public static String SYSTEM_IDENTITY = "System";
// Default topic capacity policy
public static final TopicCapacityPolicy DEFAULT_TOPIC_CAPACITY = new TopicCapacityPolicy(100, 400, 2);
// System identity constant
public static final String SYSTEM_IDENTITY = "System";

private Constants() {
// Private constructor to prevent instantiation
}

/**
* PathParams class contains constants for various path parameters.
* This class is not meant to be instantiated.
*/
public static class PathParams {
public static final String PATH_PARAM_ORG = "org";
public static final String PATH_PARAM_TEAM = "team";
public static final String PATH_PARAM_PROJECT = "project";
public static final String PATH_PARAM_TOPIC = "topic";
public static final String PATH_PARAM_SUBSCRIPTION = "subscription";

private PathParams() {
// Private constructor to prevent instantiation
}
}

/**
* QueryParams class contains constants for various query parameters.
* This class is not meant to be instantiated.
*/
public static class QueryParams {
public static final String QUERY_PARAM_DELETION_TYPE = "deletionType";
public static final String QUERY_PARAM_IGNORE_CONSTRAINTS = "ignoreConstraints";
public static final String QUERY_PARAM_INCLUDE_INACTIVE = "includeInactive";
public static final String QUERY_PARAM_MESSAGE = "message";

private QueryParams() {
// Private constructor to prevent instantiation
}
}

/**
* Tags class contains constants for various tags used in the application.
* This class is not meant to be instantiated.
*/
public static class Tags {
public static final String TAG_REGION = "region";
public static final String TAG_ORG = "org";
Expand All @@ -30,25 +72,58 @@ public static class Tags {
public static final String TAG_TOPIC = "topic";
public static final String TAG_SUBSCRIPTION = "subscription";
public static final String TAG_IDENTITY = "identity";
public static final String TAG_REMOTEHOST = "host";
public static final String TAG_REMOTE_HOST = "host";
public static final String TAG_PRODUCE_RESULT = "result";
public static final String TAG_VALUE_RESULT_SUCCESS = "success";
public static final String TAG_VALUE_RESULT_FAILED = "failed";

private Tags() {
// Private constructor to prevent instantiation
}
}

/**
* HttpCodes class contains constants for various HTTP status codes.
* This class is not meant to be instantiated.
*/
public static class HttpCodes {
public static final int HTTP_RATE_LIMITED = 429;
public static final int HTTP_UNPROCESSABLE_ENTITY = 422;

private HttpCodes() {
// Private constructor to prevent instantiation
}
}

/**
* Meters class contains constants for various meters used in the application.
* This class is not meant to be instantiated.
*/
public static class Meters {

/**
* Produce class contains constants for produce meters.
* This class is not meant to be instantiated.
*/
public static class Produce {
public static final String BYTES_METER = "produce.bytes";
public static final String LATENCY_METER = "produce.latency";

private Produce() {
// Private constructor to prevent instantiation
}
}

private Meters() {
// Private constructor to prevent instantiation
}
}

public static class REST_DEFAULTS {
/**
* RestDefaults class contains default values for REST configurations.
* This class is not meant to be instantiated.
*/
public static class RestDefaults {
public static final int PAYLOAD_SIZE_MAX = 5 * 1024 * 1024;
public static final int HEADERS_ALLOWED_MAX = 10;
public static final int HEADER_NAME_SIZE_MAX = 64;
Expand All @@ -57,5 +132,8 @@ public static class REST_DEFAULTS {
public static final String DEFAULT_TEAM = "public";
public static final String DEFAULT_PROJECT = "public";

private RestDefaults() {
// Private constructor to prevent instantiation
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void setup() {
@Test
public void testAssignShards() throws Exception {
VaradhiSubscription sub1 =
SubscriptionUtils.getBuilder().setNumShards(2).build("project1.sub1", "project1", "project1.topic1");
SubscriptionUtils.builder().setNumShards(2).build("project1.sub1", "project1", "project1.topic1");
List<SubscriptionUnitShard> shards = SubscriptionUtils.shardsOf(sub1);
List<ConsumerNode> nodes = NodeProvider.getConsumerNodes(3);
nodes.forEach(this::addConsumerNode);
Expand Down Expand Up @@ -85,7 +85,7 @@ public void testAssignShards() throws Exception {
@Test
public void testAssignShards_StoreThrows() {
VaradhiSubscription sub1 =
SubscriptionUtils.getBuilder().setNumShards(2).build("project1.sub1", "project1", "project1.topic1");
SubscriptionUtils.builder().setNumShards(2).build("project1.sub1", "project1", "project1.topic1");
List<SubscriptionUnitShard> shards = SubscriptionUtils.shardsOf(sub1);
List<ConsumerNode> nodes = NodeProvider.getConsumerNodes(3);
nodes.forEach(this::addConsumerNode);
Expand Down Expand Up @@ -123,7 +123,7 @@ public void testAssignShards_StoreThrows() {
@Test
public void testUnAssignShards() throws Exception {
VaradhiSubscription sub1 =
SubscriptionUtils.getBuilder().setNumShards(2).build("project1.sub1", "project1", "project1.topic1");
SubscriptionUtils.builder().setNumShards(2).build("project1.sub1", "project1", "project1.topic1");
List<SubscriptionUnitShard> shards = SubscriptionUtils.shardsOf(sub1);
List<ConsumerNode> nodes = NodeProvider.getConsumerNodes(3);
nodes.forEach(this::addConsumerNode);
Expand Down Expand Up @@ -183,7 +183,7 @@ public void testUnAssignShards() throws Exception {
@Test
public void testUnAssignShards_Throws() throws Exception {
VaradhiSubscription sub1 =
SubscriptionUtils.getBuilder().setNumShards(2).build("project1.sub1", "project1", "project1.topic1");
SubscriptionUtils.builder().setNumShards(2).build("project1.sub1", "project1", "project1.topic1");
List<SubscriptionUnitShard> shards = SubscriptionUtils.shardsOf(sub1);
List<ConsumerNode> nodes = NodeProvider.getConsumerNodes(3);
nodes.forEach(this::addConsumerNode);
Expand Down Expand Up @@ -220,7 +220,7 @@ public void testUnAssignShards_Throws() throws Exception {
@Test
public void testReAssign() throws Exception {
VaradhiSubscription sub1 =
SubscriptionUtils.getBuilder().setNumShards(2).build("project1.sub1", "project1", "project1.topic1");
SubscriptionUtils.builder().setNumShards(2).build("project1.sub1", "project1", "project1.topic1");
List<SubscriptionUnitShard> shards = SubscriptionUtils.shardsOf(sub1);
List<ConsumerNode> nodes = NodeProvider.getConsumerNodes(3);
nodes.forEach(this::addConsumerNode);
Expand All @@ -241,7 +241,7 @@ public void testReAssign() throws Exception {
@Test
public void testReAssign_Throws() throws Exception {
VaradhiSubscription sub1 =
SubscriptionUtils.getBuilder().setNumShards(2).build("project1.sub1", "project1", "project1.topic1");
SubscriptionUtils.builder().setNumShards(2).build("project1.sub1", "project1", "project1.topic1");
List<SubscriptionUnitShard> shards = SubscriptionUtils.shardsOf(sub1);
List<ConsumerNode> nodes = NodeProvider.getConsumerNodes(3);
nodes.forEach(this::addConsumerNode);
Expand Down
Loading
Loading