Permalink
Browse files

Fixed Repo.exists? to not throw;Taught Cog.BusEnforcer to use it

  • Loading branch information...
Kevin Smith Matthew Peck
Kevin Smith authored and Matthew Peck committed Mar 31, 2016
1 parent 5f73d1d commit 866d685beb7be1fe96017881002d005918224750
@@ -16,7 +16,7 @@ init(_) ->
check_acl({_Client, publish, _}, _State) ->
allow;
check_acl({Client, subscribe, Topic}, _State) ->
case 'Elixir.Cog.BusCredentials':'subscription_allowed?'(Client, Topic) of
case 'Elixir.Cog.BusEnforcer':'subscription_allowed?'(Client, Topic) of
false ->
deny;
true ->
@@ -16,7 +16,7 @@ description() ->
check(Client, Password, _) ->
case 'Elixir.Cog.BusCredentials':'connect_allowed?'(Client, Password) of
case 'Elixir.Cog.BusEnforcer':'connect_allowed?'(Client, Password) of
true ->
ok;
false ->
@@ -1,4 +1,4 @@
defmodule Cog.BusCredentials do
defmodule Cog.BusEnforcer do
@moduledoc """
Checks credentials for connecting MQTT clients and
enforces subscription ACLs for Relays
@@ -9,6 +9,7 @@ defmodule Cog.BusCredentials do
alias Cog.Repo
alias Cog.Queries
alias Cog.Models.Relay
alias Cog.Passwords
Record.defrecord :mqtt_client, Record.extract(:mqtt_client, from_lib: "emqttd/include/emqttd.hrl")
@@ -32,7 +33,7 @@ defmodule Cog.BusCredentials do
false
end
username ->
case Queries.Relay.exists?(username) do
case Repo.exists?(Relay, username) do
false ->
false
true ->
View
@@ -1,12 +1,12 @@
defmodule Cog.Repo do
use Ecto.Repo, otp_app: :cog
alias Cog.Queries.Repo, as: Queries
def exists?(model, id) do
case one!(Queries.count_by_id(model, id)) do
1 -> true
_ -> false
case get(model, id) do
nil ->
false
_ ->
true
end
end

0 comments on commit 866d685

Please sign in to comment.