-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
17 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
defmodule Unleash.Strategies do | ||
alias Unleash.Strategy.{ActiveForUsersWithId, GradualRolloutRandom} | ||
alias Unleash.Strategy.{ActiveForUsersWithId, GradualRolloutRandom, RemoteAddress} | ||
|
||
def strategies do | ||
[ | ||
{"ActiveForUsersWithId", ActiveForUsersWithId}, | ||
{"GradualRolloutRandom", GradualRolloutRandom}, | ||
{"RemoteAddress", RemoteAddress} | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
defmodule Unleash.Strategy.RemoteAddress do | ||
use Unleash.Strategy, name: "RemoteAddress" | ||
|
||
@impl Strategy | ||
def enabled?(%{ips: list}, %{remote_address: address}) | ||
when is_binary(list) and is_binary(address) do | ||
result = | ||
list | ||
|> String.split(",") | ||
|> Stream.map(&String.trim/1) | ||
|> Enum.member?(address) | ||
|
||
{result, %{ips: list, remote_address: address}} | ||
end | ||
end |