]> Entropealabs - wampex_router.git/commitdiff
adds initial support for CockroachDB persistent store
authorChristopher <chris@entropealabs.com>
Thu, 19 Mar 2020 02:08:07 +0000 (21:08 -0500)
committerChristopher <chris@entropealabs.com>
Thu, 19 Mar 2020 02:08:07 +0000 (21:08 -0500)
config/config.exs
lib/router.ex
lib/router/authentication/realm.ex [new file with mode: 0644]
lib/router/authentication/repo.ex [new file with mode: 0644]
lib/router/ensure_default_realm.ex [new file with mode: 0644]
lib/wampex/router/authentication/repo.ex [new file with mode: 0644]
mix.exs
mix.lock

index 988fb251decd957746ffee0c46d934366bfdb39a..a47cc7169924f77ff52acc11afb51f28300e6847 100644 (file)
@@ -1,5 +1,11 @@
 use Mix.Config
 
+config :wampex, Wampex.Router.Authentication.Repo,
+  database: "authentication",
+  hostname: "localhost",
+  port: 26_257,
+  username: "root"
+
 config :cluster_kv,
   topologies: [
     kv: [
@@ -12,3 +18,5 @@ config :cluster_kv,
       list_nodes: {:erlang, :nodes, [:connected]}
     ]
   ]
+
+config :wampex, ecto_repos: [Wampex.Router.Authentication.Repo]
index 2909839661fe3de0937f49b3158a5e4f4a37b7ae..ef901af1b0b8234a3dfc52579055f6ec25d31a25 100644 (file)
@@ -1,7 +1,7 @@
 defmodule Wampex.Router do
   use Supervisor
 
-  alias Wampex.Router.{Proxy, REST}
+  alias Wampex.Router.{EnsureDefaultRealm, Authentication, Proxy, REST}
   alias Wampex.Router.Transports.WebSocket
 
   @spec start_link(
@@ -22,6 +22,8 @@ defmodule Wampex.Router do
           {:ok, {:supervisor.sup_flags(), [:supervisor.child_spec()]}} | :ignore
   def init({name, port, topologies, replicas, quorum}) do
     children = [
+      Authentication.Repo,
+      {EnsureDefaultRealm, [uri: "org.entropealabs"]},
       {ClusterKV,
        [
          name: db_name(name),
diff --git a/lib/router/authentication/realm.ex b/lib/router/authentication/realm.ex
new file mode 100644 (file)
index 0000000..e5e2ea6
--- /dev/null
@@ -0,0 +1,8 @@
+defmodule Wampex.Router.Authentication.Realm do
+  @moduledoc false
+  use Ecto.Schema
+  @primary_key {:uri, :string, autogenerate: false, read_after_writes: true}
+  schema "realms" do
+    field(:parent, :string)
+  end
+end
diff --git a/lib/router/authentication/repo.ex b/lib/router/authentication/repo.ex
new file mode 100644 (file)
index 0000000..9fe8e40
--- /dev/null
@@ -0,0 +1,5 @@
+defmodule Wampex.Router.Authentication.Repo do
+  use Ecto.Repo,
+    otp_app: :wampex,
+    adapter: Ecto.Adapters.Postgres
+end
diff --git a/lib/router/ensure_default_realm.ex b/lib/router/ensure_default_realm.ex
new file mode 100644 (file)
index 0000000..bc5e8a3
--- /dev/null
@@ -0,0 +1,27 @@
+defmodule Wampex.Router.EnsureDefaultRealm do
+  @moduledoc false
+  require Logger
+  use GenServer
+
+  alias Wampex.Router.Authentication.{Realm, Repo}
+
+  def start_link(uri: uri) do
+    GenServer.start_link(__MODULE__, uri)
+  end
+
+  def init(uri) do
+    try do
+      %Realm{uri: uri}
+      |> Repo.insert()
+    rescue
+      er -> Logger.warn("#{inspect(er)}")
+    end
+
+    %Realm{uri: _uri} =
+      Realm
+      |> Ecto.Query.first()
+      |> Repo.one()
+
+    :ignore
+  end
+end
diff --git a/lib/wampex/router/authentication/repo.ex b/lib/wampex/router/authentication/repo.ex
new file mode 100644 (file)
index 0000000..9fe8e40
--- /dev/null
@@ -0,0 +1,5 @@
+defmodule Wampex.Router.Authentication.Repo do
+  use Ecto.Repo,
+    otp_app: :wampex,
+    adapter: Ecto.Adapters.Postgres
+end
diff --git a/mix.exs b/mix.exs
index 15dfcb858018d06ef510bf32fa9a289564be32e0..33ccc3e47a730b78af2f7f5cefe369b5fb6ff622 100644 (file)
--- a/mix.exs
+++ b/mix.exs
@@ -44,12 +44,14 @@ defmodule Wampex.MixProject do
       {:cors_plug, "~> 2.0"},
       {:credo, "~> 1.2", only: [:dev, :test], runtime: false},
       {:dialyxir, "~> 0.5.1", only: [:dev, :test], runtime: false},
+      {:ecto_sql, "~> 3.0"},
       {:ex_doc, "~> 0.21", only: :dev, runtime: false},
       {:excoveralls, "~> 0.12.2", only: [:dev, :test], runtime: false},
       {:jason, "~> 1.1"},
       {:msgpack, "~> 0.7.0"},
       {:pbkdf2, "~> 2.0"},
       {:plug_cowboy, "~> 2.1"},
+      {:postgrex, ">= 0.0.0"},
       {:states_language, "~> 0.2"},
       {:websockex, "~> 0.4"}
     ]
index c629b4f9011ed756142c605237fcc2a78a897a2b..3bae761f4922dc3c1e0b64eee6d235d3307f0135 100644 (file)
--- a/mix.lock
+++ b/mix.lock
@@ -2,14 +2,19 @@
   "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
   "certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "805abd97539caf89ec6d4732c91e62ba9da0cda51ac462380bbd28ee697a8c42"},
   "cluster_kv": {:git, "https://gitlab.com/entropealabs/cluster_kv.git", "4c36b8d68f40711cd167edb9917d32a992f49561", [tag: "4c36b8d68f40711cd167edb9917d32a992f49561"]},
+  "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm", "4a0850c9be22a43af9920a71ab17c051f5f7d45c209e40269a1938832510e4d9"},
   "conv_case": {:hex, :conv_case, "0.2.2", "5a98b74ab8f7ddbad670e5c7bb39ff280e60699aa3b25c7062ceccf48137433c", [:mix], [], "hexpm", "561c550ab6d55b2a4d4c14449e58c9957798613eb26ea182e14a962965377bca"},
   "cors_plug": {:hex, :cors_plug, "2.0.2", "2b46083af45e4bc79632bd951550509395935d3e7973275b2b743bd63cc942ce", [:mix], [{:plug, "~> 1.8", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "f0d0e13f71c51fd4ef8b2c7e051388e4dfb267522a83a22392c856de7e46465f"},
   "coveralls": {:hex, :coveralls, "2.1.0", "b44cea21202c0e1994dfced8cedbff66bcd03eeeb565484345b28afacda0559b", [:rebar3], [{:jsx, "2.10.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm", "bbfbe2a7bebb2d22db15a657e6c1733243e1501714d60fe14a14790d96e7c3b2"},
   "cowboy": {:hex, :cowboy, "2.7.0", "91ed100138a764355f43316b1d23d7ff6bdb0de4ea618cb5d8677c93a7a2f115", [:rebar3], [{:cowlib, "~> 2.8.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "04fd8c6a39edc6aaa9c26123009200fc61f92a3a94f3178c527b70b767c6e605"},
   "cowlib": {:hex, :cowlib, "2.8.0", "fd0ff1787db84ac415b8211573e9a30a3ebe71b5cbff7f720089972b2319c8a4", [:rebar3], [], "hexpm", "79f954a7021b302186a950a32869dbc185523d99d3e44ce430cd1f3289f41ed4"},
   "credo": {:hex, :credo, "1.2.2", "f57faf60e0a12b0ba9fd4bad07966057fde162b33496c509b95b027993494aab", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8f2623cd8c895a6f4a55ef10f3fdf6a55a9ca7bef09676bd835551687bf8a740"},
+  "db_connection": {:hex, :db_connection, "2.2.1", "caee17725495f5129cb7faebde001dc4406796f12a62b8949f4ac69315080566", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "2b02ece62d9f983fcd40954e443b7d9e6589664380e5546b2b9b523cd0fb59e1"},
+  "decimal": {:hex, :decimal, "1.8.1", "a4ef3f5f3428bdbc0d35374029ffcf4ede8533536fa79896dd450168d9acdf3c", [:mix], [], "hexpm", "3cb154b00225ac687f6cbd4acc4b7960027c757a5152b369923ead9ddbca7aec"},
   "dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm", "6c32a70ed5d452c6650916555b1f96c79af5fc4bf286997f8b15f213de786f73"},
   "earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm", "8cf8a291ebf1c7b9539e3cddb19e9cef066c2441b1640f13c34c1d3cfc825fec"},
+  "ecto": {:hex, :ecto, "3.3.4", "95b05c82ae91361475e5491c9f3ac47632f940b3f92ae3988ac1aad04989c5bb", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "9b96cbb83a94713731461ea48521b178b0e3863d310a39a3948c807266eebd69"},
+  "ecto_sql": {:hex, :ecto_sql, "3.3.4", "aa18af12eb875fbcda2f75e608b3bd534ebf020fc4f6448e4672fcdcbb081244", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4 or ~> 3.3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5eccbdbf92e3c6f213007a82d5dbba4cd9bb659d1a21331f89f408e4c0efd7a8"},
   "elixpath": {:hex, :elixpath, "0.1.0", "f860e931db7bda6856dc68145694ca429643cc068ef30d7ff6b4096d4357963e", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "30ce06079b41f1f5216ea2cd11605cfe4c82239628555cb3fde9f10055a6eb67"},
   "ex_doc": {:hex, :ex_doc, "0.21.3", "857ec876b35a587c5d9148a2512e952e24c24345552259464b98bfbb883c7b42", [:mix], [{:earmark, "~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "0db1ee8d1547ab4877c5b5dffc6604ef9454e189928d5ba8967d4a58a801f161"},
   "excoveralls": {:hex, :excoveralls, "0.12.2", "a513defac45c59e310ac42fcf2b8ae96f1f85746410f30b1ff2b710a4b6cd44b", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "151c476331d49b45601ffc45f43cb3a8beb396b02a34e3777fea0ad34ae57d89"},
@@ -33,6 +38,7 @@
   "plug_cowboy": {:hex, :plug_cowboy, "2.1.2", "8b0addb5908c5238fac38e442e81b6fcd32788eaa03246b4d55d147c47c5805e", [:mix], [{:cowboy, "~> 2.5", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "7d722581ce865a237e14da6d946f92704101740a256bd13ec91e63c0b122fc70"},
   "plug_crypto": {:hex, :plug_crypto, "1.1.2", "bdd187572cc26dbd95b87136290425f2b580a116d3fb1f564216918c9730d227", [:mix], [], "hexpm", "6b8b608f895b6ffcfad49c37c7883e8df98ae19c6a28113b02aa1e9c5b22d6b5"},
   "poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm", "dad79704ce5440f3d5a3681c8590b9dc25d1a561e8f5a9c995281012860901e3"},
+  "postgrex": {:hex, :postgrex, "0.15.3", "5806baa8a19a68c4d07c7a624ccdb9b57e89cbc573f1b98099e3741214746ae4", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "4737ce62a31747b4c63c12b20c62307e51bb4fcd730ca0c32c280991e0606c90"},
   "ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm", "451d8527787df716d99dc36162fca05934915db0b6141bbdac2ea8d3c7afc7d7"},
   "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.5", "6eaf7ad16cb568bb01753dbbd7a95ff8b91c7979482b95f38443fe2c8852a79b", [:make, :mix, :rebar3], [], "hexpm", "13104d7897e38ed7f044c4de953a6c28597d1c952075eb2e328bc6d6f2bfc496"},
   "states_language": {:hex, :states_language, "0.2.8", "f9dfd3c0bd9a9d7bda25ef315f2d90944cd6b2022a7f3c403deb1d4ec451825e", [:mix], [{:elixpath, "~> 0.1.0", [hex: :elixpath, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:json_xema, "~> 0.4.0", [hex: :json_xema, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:xema, "~> 0.11.0", [hex: :xema, repo: "hexpm", optional: false]}], "hexpm", "a5231691e7cb37fe32dc7de54c2dc86d1d60e84c4f0379f3246e55be2a85ec78"},