-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add an agent to store distributino state (and avoid multiple pem deco…
…des when runtime configured)
- Loading branch information
Michael Guarino
committed
Jun 4, 2018
1 parent
1d61692
commit 726fbb9
Showing
6 changed files
with
47 additions
and
3 deletions.
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
defmodule CloudfrontSigner.Application do | ||
use Application | ||
import Supervisor.Spec | ||
|
||
def start(_type, _args) do | ||
children = [ | ||
worker(CloudfrontSigner.DistributionRegistry, []) | ||
] | ||
opts = [strategy: :one_for_one, name: CloudfrontSigner.Application.Supervisor] | ||
Supervisor.start_link(children, opts) | ||
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,20 @@ | ||
defmodule CloudfrontSigner.DistributionRegistry do | ||
@moduledoc """ | ||
Agent to store and fetch cloudfront distributions, to avoid expensive runtime pem decodes | ||
""" | ||
use Agent | ||
alias CloudfrontSigner.Distribution | ||
|
||
def start_link() do | ||
Agent.start_link(fn -> %{} end, name: __MODULE__) | ||
end | ||
|
||
def get_distribution(scope, key) do | ||
Agent.get_and_update(__MODULE__, &Map.get_and_update(&1, {scope, key}, fn | ||
nil -> | ||
dist = Distribution.from_config(scope, key) | ||
{dist, dist} | ||
dist -> {dist, dist} | ||
end)) | ||
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
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,11 @@ | ||
defmodule CloudfrontSigner.DistributionRegistryTest do | ||
use ExUnit.Case, async: true | ||
|
||
describe "#get_distribution/2" do | ||
test "It will get a registry and save it internally" do | ||
distribution = CloudfrontSigner.DistributionRegistry.get_distribution(:cloudfront_signer, CloudfrontSignerTest) | ||
|
||
assert distribution.domain == "https://somewhere.cloudfront.com" | ||
end | ||
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
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