Skip to content

Commit

Permalink
Add API Key reset API
Browse files Browse the repository at this point in the history
  • Loading branch information
rjsamson committed Jun 24, 2016
1 parent 9fba71f commit 09925e3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/stackfooter/api_key_registry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@ defmodule Stackfooter.ApiKeyRegistry do
end
end

def reset_api_keys(pid) do
GenServer.call(pid, :reset)
end

def handle_call(:reset, _from, api_keys) do
:ets.delete_all_objects(api_keys)
{:reply, :ok, api_keys}
end

def handle_call({:add_key, api_key, account}, _from, api_keys) do
:ets.insert(api_keys, {api_key, account})

{:reply, {:ok, {api_key, account}}, api_keys}
end
end
8 changes: 8 additions & 0 deletions test/otp/api_key_registry_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule Stackfooter.ApiKeyRegistryTest do
alias Stackfooter.ApiKeyRegistry

setup do
Stackfooter.ApiKeyRegistry.reset_api_keys(Stackfooter.ApiKeyRegistry)
Stackfooter.ApiKeyRegistry.add_key(Stackfooter.ApiKeyRegistry, "4cy7uf63Lw2Sx6652YmLwBKy662weU4q", "admin")
Stackfooter.ApiKeyRegistry.add_key(Stackfooter.ApiKeyRegistry, "7eWeGhc8n0va5bjT66C0Vl1fBw2618BJ", "rjsamson")

Expand All @@ -14,4 +15,11 @@ defmodule Stackfooter.ApiKeyRegistryTest do

assert all_accounts == ["RJSAMSON", "ADMIN"]
end

test "resets all API keys" do
Stackfooter.ApiKeyRegistry.reset_api_keys(Stackfooter.ApiKeyRegistry)
all_accounts = ApiKeyRegistry.all_account_names(ApiKeyRegistry)

assert all_accounts == []
end
end

0 comments on commit 09925e3

Please sign in to comment.