Skip to content

Commit

Permalink
Add Remote Address Strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
afontaine committed Apr 2, 2019
1 parent e3c0903 commit a885f45
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/unleash/strategies.ex
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
15 changes: 15 additions & 0 deletions lib/unleash/strategy/remote_address.ex
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

0 comments on commit a885f45

Please sign in to comment.