0

Here is my quesion,

I have a feature switch with a custom strategy named "UserActivationStrategy". All it does is, it has a hard coded value as 'user' in Id field and a 'IpAddress' as param and some logic to return true/false in isActive(state,user).

So strategy to be invoked is determined based on hard coded Id. Here is my application.properties with those defined

CustomFeature = true
CustomFeature.strategy= user
CustomFeature.param.IpAddress= xx.xx.xxx

The above tells that ....UserActivationStrategy is invoked based on Id('user') which is hard coded in strategy. In UserActivationStrategy I am verfying the Ipaddress and returning true/false.

So what if I need to perform same logic on different users with different IpAddress. Its like combinations. Certain user's have access to certain IpAddress.

I cannot create feature switch for each user or for each IPAddress. It would creates many feature switches.

If I add users and IPAddress as params in a strategy. I end up creating many params in single strategy which is not good.

Any solution to this is appreciated. Thanks.

karthik
  • 773
  • 2
  • 11
  • 19

2 Answers2

1

I'm not sure if I fully understand what you are trying to achieve. So you have a single feature flag and if activated, it should evaluate to true if and only if a certain combination of user and IP address are present?

If so, you should perhaps create a single strategy which can be configured using a string which encodes all allowed combinations. Something like:

user1=127.0.0.1, user2=127.0.0.2, user3=127.0.0.3

You can then configure this configuration string in the admin console. Or directly add it to the configuration file:

CustomFeature = true
CustomFeature.strategy= user
CustomFeature.param.combintations=user1=127.0.0.1, user2=127.0.0.2

The strategy would have to parse this representation and check for one of the allowed combinations.

chkal
  • 5,598
  • 21
  • 26
  • Thanks @chkal for looking into this. It seems you got what I am trying to say. But slight change its many to many mappings which I need to define. So user1=127.0.0.1,127.0.0.2,127.0.0.3,127.0.0.4...so on and user2 = 127.0.0.1,127.0.0.2 and user3 = 127.0.0.1,127.0.0.2,127.0.0.3 ...in this way i have many to many combinations that i need to define for feature switch. so how should i define configuration and strategy for this scenario's – karthik Feb 11 '17 at 22:37
  • You could also encode the many to many relationship in a strategy parameter. Something like: user1=127.0.0.1,127.0.0.2;user2=127.0.0.1... – chkal Feb 13 '17 at 11:58
  • However, please note that I'm not completely sure whether or not this is really a use case for Togglz. This sound a bit more like a permission requirement. – chkal Feb 13 '17 at 11:59
0

So I figured out the solution for this. In my features.properties I have list of users as param.

Example:

CustomFeature.param.user1=127.0.0.1,127.0.0.2
CustomFeature.param.user2=127.0.0.1,127.0.0.3

So I am getting the featurestate.getparameter(user1) in my activation strategy that returns all the IPAddress. So based on that IPaddress iam enabling/disabling the feature switch.

So this startegy avoid me from creating many params/feature swtiches.

karthik
  • 773
  • 2
  • 11
  • 19