neiam
/apollos_crib
It's Apollo's Crib
public · Issues · Pulls 1 · Labels · Forks · Compare · Actions failure · Badges · Packages
⭐
Log in to mark this repository.
add short-circuit to allow when the env auth is passed back
3411654 · gmorell · 2023-03-07 06:16
Files changed
modified
apps/room_hermes/config/runtime.exs
+2
−0
@@ -12,6 +12,8 @@ if System.get_env("PHX_SERVER") && System.get_env("RELEASE_NAME") do
| 12 | 12 | config :room_hermes, RoomHermesWeb.Endpoint, server: true |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | +config :room_hermes, :rabbit, username: System.get_env("RABBIT_USER"), password: System.get_env("RABBIT_PASS") | |
| 16 | + | |
| 15 | 17 | if config_env() == :prod do |
| 16 | 18 | database_url = |
| 17 | 19 | System.get_env("DATABASE_URL") || |
modified
apps/room_hermes/lib/room_hermes_web/controllers/user_controller.ex
+15
−8
@@ -6,14 +6,21 @@ defmodule RoomHermesWeb.UserController do
| 6 | 6 | |
| 7 | 7 | action_fallback RoomHermesWeb.FallbackController |
| 8 | 8 | |
| 9 | − def create(conn, %{"username" => username, "password" => password, "client_id" => client_id}) do | |
| 10 | − case client_id == username do | |
| 11 | − true -> | |
| 12 | − case Accounts.find_rabbit_user(username, password) do | |
| 13 | − nil -> send_resp(conn, :ok, "deny") | |
| 14 | − val -> send_resp(conn, :ok, "allow") | |
| 9 | + def create(conn, %{"username" => username, "password" => password} = args) do | |
| 10 | + # rabbit decided to misbehave and pass even the local auth thru rabbitauth so we're doing a short circuit | |
| 11 | + envauth = Application.get_env(:room_hermes, :rabbit) | |
| 12 | + cond do | |
| 13 | + username == envauth[:username] && password == envauth[:password] -> send_resp(conn, :ok, "allow") | |
| 14 | + true -> | |
| 15 | + case args["client_id"] == username do | |
| 16 | + true -> | |
| 17 | + case Accounts.find_rabbit_user(username, password) do | |
| 18 | + nil -> send_resp(conn, :ok, "deny") | |
| 19 | + val -> send_resp(conn, :ok, "allow") | |
| 20 | + end | |
| 21 | + false -> send_resp(conn, :ok, "deny") | |
| 22 | + end | |
| 15 | 23 | end |
| 16 | − false -> send_resp(conn, :ok, "deny") | |
| 17 | − end | |
| 24 | + | |
| 18 | 25 | end |
| 19 | 26 | end |
modified
config/runtime.exs
+2
−0
@@ -13,6 +13,8 @@ if System.get_env("PHX_SERVER") && System.get_env("RELEASE_NAME") do
| 13 | 13 | config :room_hermes, RoomHermesWeb.Endpoint, server: true |
| 14 | 14 | end |
| 15 | 15 | |
| 16 | +config :room_hermes, :rabbit, username: System.get_env("RABBIT_USER"), password: System.get_env("RABBIT_PASS") | |
| 17 | + | |
| 16 | 18 | if config_env() == :prod do |
| 17 | 19 | # The secret key base is used to sign/encrypt cookies and other secrets. |
| 18 | 20 | # A default value is used in config/dev.exs and config/test.exs but you |
Parents: b6d4917