just need to add creating services, deploying them, and showing logs
This commit is contained in:
parent
a3a4af7965
commit
023ad47ae4
6 changed files with 99 additions and 29 deletions
|
|
@ -4,8 +4,7 @@ defmodule EzcontainerRailwayWeb.SessionController do
|
|||
|
||||
def token(conn, %{"railway_token" => token}) do
|
||||
case get_projects(token) do
|
||||
resp when is_map(resp) ->
|
||||
IO.inspect(resp)
|
||||
resp when is_list(resp) ->
|
||||
conn
|
||||
|> put_session(:railway_token, token)
|
||||
|> assign(:railway_token, token)
|
||||
|
|
@ -18,12 +17,11 @@ defmodule EzcontainerRailwayWeb.SessionController do
|
|||
end
|
||||
|
||||
defp get_projects(token) do
|
||||
resp = EzcontainerRailway.Railway.get_projects(token).body
|
||||
|
||||
if Railway.has_errors?(resp) do
|
||||
nil
|
||||
else
|
||||
resp["data"]
|
||||
case EzcontainerRailway.Railway.get_projects(token) do
|
||||
{:error, _} ->
|
||||
nil
|
||||
{:ok, data} ->
|
||||
data
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
26
lib/ezcontainer_railway_web/plugs/railway_check.ex
Normal file
26
lib/ezcontainer_railway_web/plugs/railway_check.ex
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
defmodule EzcontainerRailwayWeb.RailwayCheck do
|
||||
alias EzcontainerRailway.Projects
|
||||
alias EzcontainerRailway.Railway
|
||||
alias Phoenix.Controller
|
||||
import Plug.Conn
|
||||
|
||||
def init(default), do: default
|
||||
|
||||
def call(conn, _opts) do
|
||||
case get_session(conn, :railway_token) do
|
||||
nil ->
|
||||
conn
|
||||
|> Controller.put_flash(:error, "You need a railway token")
|
||||
|> Controller.redirect(to: "/")
|
||||
token ->
|
||||
p =
|
||||
case Projects.get_project_by_token(token) do
|
||||
nil -> Projects.create_project(token)
|
||||
p -> p
|
||||
end
|
||||
|
||||
conn
|
||||
|> put_session(:project_id, p)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -4,7 +4,7 @@ defmodule EzcontainerRailwayWeb.Router do
|
|||
pipeline :browser do
|
||||
plug :accepts, ["html"]
|
||||
plug :fetch_session
|
||||
#plug EzcontainerRailwayWeb.AnonSession
|
||||
plug EzcontainerRailwayWeb.AnonSession
|
||||
plug :fetch_live_flash
|
||||
plug :put_root_layout, html: {EzcontainerRailwayWeb.Layouts, :root}
|
||||
plug :protect_from_forgery
|
||||
|
|
@ -15,11 +15,20 @@ defmodule EzcontainerRailwayWeb.Router do
|
|||
plug :accepts, ["json"]
|
||||
end
|
||||
|
||||
pipeline :ensure_token do
|
||||
plug EzcontainerRailwayWeb.RailwayCheck
|
||||
end
|
||||
|
||||
scope "/", EzcontainerRailwayWeb do
|
||||
pipe_through :browser
|
||||
|
||||
get "/", PageController, :home
|
||||
post "/token", SessionController, :token
|
||||
end
|
||||
|
||||
scope "/", EzcontainerRailwayWeb do
|
||||
pipe_through :browser
|
||||
pipe_through :ensure_token
|
||||
|
||||
live "/containers", ContainerCreateLive
|
||||
resources("/containers", ContainerController, only: [:create, :show])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue