]> Entropealabs - wampex_router.git/commitdiff
user Peer instead of User
authorChristopher <chris@entropealabs.com>
Sat, 21 Mar 2020 15:26:02 +0000 (10:26 -0500)
committerChristopher <chris@entropealabs.com>
Sat, 21 Mar 2020 15:26:02 +0000 (10:26 -0500)
lib/router/admin.ex
lib/router/authentication.ex
lib/router/authentication/ensure_default_admin.ex
lib/router/authentication/peer.ex [moved from lib/router/authentication/user.ex with 87% similarity]
lib/router/realms.ex
priv/repo/migrations/20200319210508_create_realms.exs
test/wampex_test.exs

index f20906e8c99ae0b65e494cf1065b7542c5fbbb59..77e9c2c73e3cd7cf2c65ad48f7b1e86e15a0dbe4 100644 (file)
@@ -4,11 +4,11 @@ defmodule Wampex.Router.Admin do
   require Logger
   alias Wampex.Roles.Dealer.{Invocation, Result}
   alias Wampex.Roles.Peer.Error
-  alias Wampex.Router.Authentication.{User, Realm}
+  alias Wampex.Router.Authentication.{Peer, Realm}
   alias Wampex.Router.{Realms, Session}
 
   @procedures [
-    "admin.create_user",
+    "admin.create_peer",
     "admin.create_realm"
   ]
 
@@ -39,12 +39,12 @@ defmodule Wampex.Router.Admin do
         {req_id,
          %Invocation{
            arg_kw: %{"realm" => realm, "authid" => authid, "password" => password},
-           options: %{"procedure" => "admin.create_user"}
+           options: %{"procedure" => "admin.create_peer"}
          } = event, {pid, node}},
         %{proxy: proxy} = state
       ) do
     with realm <- Realm.get(uri: realm),
-         %User{id: id} <- User.create(authid: authid, password: password, realm: realm) do
+         %Peer{id: id} <- Peer.create(authid: authid, password: password, realm: realm) do
       Logger.info("Admin handled event: #{inspect(event)}")
 
       send({proxy, node}, {%Result{request_id: req_id, arg_list: [id]}, pid})
index 40a59e9f0c3155e7ed8b00c8c68daf8a2bce1e6a..87bc3490775618db18d51e58ba2c8656683c75db 100644 (file)
@@ -5,7 +5,7 @@ defmodule Wampex.Router.Authentication do
 
   alias Wampex.Crypto
   alias Wampex.Serializers.JSON
-  alias Wampex.Router.Authentication.{Realm, User}
+  alias Wampex.Router.Authentication.{Realm, Peer}
 
   @wampcra "wampcra"
   @auth_provider "userdb"
@@ -19,7 +19,7 @@ defmodule Wampex.Router.Authentication do
 
   def challenge(realm, authid, session_id) do
     %Realm{} = realm = Realm.get(uri: realm)
-    %User{} = user = User.get(authid: authid, realm: realm)
+    %Peer{} = user = Peer.get(authid: authid, realm: realm)
     now = DateTime.to_iso8601(DateTime.utc_now())
 
     %{
@@ -56,7 +56,7 @@ defmodule Wampex.Router.Authentication do
 
   defp get_secret(authid, uri) do
     realm = Realm.get(uri: uri)
-    %User{password: password} = User.get(authid: authid, realm: realm)
+    %Peer{password: password} = Peer.get(authid: authid, realm: realm)
     password
   end
 
index 9052191680f72dfd7d5961cfdedc0ef8a1346e3e..6a72096bde7891e485295e41e3662bf01d529ff7 100644 (file)
@@ -3,7 +3,7 @@ defmodule Wampex.Router.Authentication.EnsureDefaultAdmin do
   require Logger
   use GenServer
 
-  alias Wampex.Router.Authentication.{Realm, User}
+  alias Wampex.Router.Authentication.{Realm, Peer}
 
   def start_link(uri: uri, authid: authid, password: password) do
     GenServer.start_link(__MODULE__, {uri, authid, password})
@@ -11,9 +11,9 @@ defmodule Wampex.Router.Authentication.EnsureDefaultAdmin do
 
   def init({uri, authid, password}) do
     %Realm{} = realm = Realm.create(uri: uri)
-    %User{} = user = User.create(authid: authid, password: password, realm: realm)
-    Logger.info("Realm: #{inspect(realm)}")
-    Logger.info("User: #{inspect(user)}")
+    %Peer{} = user = Peer.create(authid: authid, password: password, realm: realm)
+    Logger.debug("Realm: #{inspect(realm)}")
+    Logger.debug("Peer: #{inspect(user)}")
     :ignore
   end
 end
similarity index 87%
rename from lib/router/authentication/user.ex
rename to lib/router/authentication/peer.ex
index 8d3e8a2d2ed431380bbc49fe2502e440b306e468..ad6ed5fca15158899da9ef01dd48de0cb5b09395 100644 (file)
@@ -1,12 +1,13 @@
-defmodule Wampex.Router.Authentication.User do
+defmodule Wampex.Router.Authentication.Peer do
   @moduledoc """
-  CREATE TABLE authentication.users (
+  CREATE TABLE authentication.peers (
         id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
         authid STRING(255) NOT NULL,
         password STRING NOT NULL,
         salt STRING NOT NULL,
         iterations INT NOT NULL,
         keylen INT NOT NULL,
+        cidr STRING,
         realm_id UUID NOT NULL REFERENCES authentication.realms (id) ON DELETE CASCADE,
         inserted_at TIMESTAMP NOT NULL,
         updated_at TIMESTAMP NOT NULL,
@@ -23,12 +24,13 @@ defmodule Wampex.Router.Authentication.User do
 
   @primary_key {:id, :binary_id, autogenerate: false, read_after_writes: true}
   @foreign_key_type :binary_id
-  schema "users" do
+  schema "peers" do
     field(:authid, :string)
     field(:password, :string)
     field(:salt, :string)
     field(:iterations, :integer)
     field(:keylen, :integer)
+    field(:cidr, :string)
     belongs_to(:realm, Realm)
     timestamps()
   end
@@ -38,7 +40,7 @@ defmodule Wampex.Router.Authentication.User do
   end
 
   def get(authid: authid, realm: realm) do
-    Repo.get_by(User, authid: authid, realm_id: realm.id)
+    Repo.get_by(Peer, authid: authid, realm_id: realm.id)
   end
 
   def create(authid: authid, password: password, realm: realm) do
@@ -50,7 +52,7 @@ defmodule Wampex.Router.Authentication.User do
       password = Crypto.pbkdf2(password, salt, iterations, keylen)
 
       {:ok, u} =
-        %User{
+        %Peer{
           authid: authid,
           password: password,
           realm: realm,
index 06625c692a72277825b4f0cc429665b9e263b1c3..1348d76a847714004b528d96dbd3b90f7e04c6c0 100644 (file)
@@ -14,7 +14,6 @@ defmodule Wampex.Router.Realms do
       {DynamicSupervisor, strategy: :one_for_one, name: realm_supervisor_name(name)}
     ]
 
-    Logger.info("Starting Realms Supervisor: #{inspect(children)}")
     Supervisor.init(children, strategy: :one_for_one)
   end
 
index 86f165b78a109574044d8ea7bdcb78ba7f891a26..d694b1ffd5c3ff02fb97c5532098e19a0368930e 100644 (file)
@@ -11,18 +11,19 @@ defmodule Wampex.Router.Authentication.Repo.Migrations.CreateRealms do
 
     create(unique_index(:realms, [:uri]))
 
-    create table("users", primary_key: false) do
+    create table("peers", primary_key: false) do
       add(:id, :binary_id, primary_key: true, default: fragment("gen_random_uuid()"))
       add(:authid, :string, null: false)
       add(:password, :string, null: false)
       add(:salt, :string, null: false)
       add(:iterations, :integer, null: false)
       add(:keylen, :integer, null: false)
+      add(:cidr, :string)
       add(:realm_id, references(:realms, type: :binary_id, on_delete: :delete_all), null: false)
       timestamps()
     end
 
-    create(index(:users, [:authid]))
-    create(unique_index(:users, [:authid, :realm_id]))
+    create(index(:peers, [:authid]))
+    create(unique_index(:peers, [:authid, :realm_id]))
   end
 end
index c49677324761e087bd0c1d99e94e5f0d183e8820..c7782abde7a9c2c9604fceb910f9e2fc30efb448 100644 (file)
@@ -335,7 +335,7 @@ defmodule WampexTest do
       Client.send_request(
         caller_name,
         Caller.call(%Call{
-          procedure: "admin.create_user",
+          procedure: "admin.create_peer",
           arg_kw: %{authid: "chris", password: "woot!", realm: @realm_uri}
         })
       )
@@ -352,7 +352,7 @@ defmodule WampexTest do
              Client.send_request(
                caller_name,
                Caller.call(%Call{
-                 procedure: "admin.create_user",
+                 procedure: "admin.create_peer",
                  arg_kw: %{authid: "chris", password: "woot!", realm: "not.real"}
                })
              )