-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
msf 2 makes execution of setup user possible from outside containers (#…
…2422) * msf 1, allow setup_user to build super * concept for external commands * typo oops * wrap in transaction * update CL * use migrator with_repo * fix dialzyer
- Loading branch information
1 parent
079e4cf
commit 5256122
Showing
5 changed files
with
110 additions
and
70 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
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,78 @@ | ||
defmodule Lightning.Setup do | ||
@moduledoc """ | ||
Demo encapsulates logic for setting up a demonstration site. | ||
""" | ||
|
||
alias Lightning.SetupUtils | ||
|
||
@doc """ | ||
This makes it possible to run setup_user as an external command | ||
See: Lightning.SetupUtils.setup_user() for more docs. | ||
## Examples | ||
iex> kubectl exec -it deploy/demo-web -- /app/bin/lightning eval Lightning.Setup.setup_user(%{email: "[email protected]", first_name: "taylor", last_name: "downs", password: "shh12345!"}) | ||
:ok | ||
""" | ||
@spec setup_user(map(), String.t() | nil, list(map()) | nil) :: | ||
{:ok, any(), any()} | {:error, any()} | ||
def setup_user(user, token \\ nil, credentials \\ nil) do | ||
{:ok, _pid} = Lightning.Setup.ensure_minimum_setup() | ||
|
||
{:ok, _, _} = | ||
Ecto.Migrator.with_repo(Lightning.Repo, fn _repo -> | ||
SetupUtils.setup_user(user, token, credentials) | ||
end) | ||
end | ||
|
||
@doc """ | ||
Set up the bare minimum so that commands can be executed against the repo. | ||
""" | ||
def ensure_minimum_setup do | ||
Lightning.Release.load_app() | ||
|
||
children = | ||
[ | ||
{Phoenix.PubSub, | ||
name: Lightning.PubSub, adapter: Lightning.Setup.FakePubSub}, | ||
{Lightning.Vault, Application.get_env(:lightning, Lightning.Vault, [])} | ||
] | ||
|> Enum.reject(fn {mod, _} -> Process.whereis(mod) end) | ||
|
||
Supervisor.start_link(children, strategy: :one_for_one) | ||
end | ||
|
||
defmodule FakePubSub do | ||
@moduledoc false | ||
|
||
# FakePubSub is a Phoenix.PubSub adapter that does nothing. | ||
# The purpose of this adapter is to allow the demo to run without | ||
# the whole application running. | ||
|
||
@behaviour Phoenix.PubSub.Adapter | ||
|
||
@impl true | ||
def child_spec(_opts) do | ||
%{id: __MODULE__, start: {__MODULE__, :start_link, []}} | ||
end | ||
|
||
def start_link do | ||
{:ok, self()} | ||
end | ||
|
||
@impl true | ||
def node_name(_), do: nil | ||
|
||
@impl true | ||
def broadcast(_, _, _, _) do | ||
:ok | ||
end | ||
|
||
@impl true | ||
def direct_broadcast(_, _, _, _, _) do | ||
:ok | ||
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