Skip to content

Commit

Permalink
Fixed Repo.exists? to not throw;Taught Cog.BusEnforcer to use it
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Smith authored and Matthew Peck committed Apr 11, 2016
1 parent 5f73d1d commit 866d685
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion emqttd_plugins/emqttd_acl_cog_internal.erl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ init(_) ->
check_acl({_Client, publish, _}, _State) -> check_acl({_Client, publish, _}, _State) ->
allow; allow;
check_acl({Client, subscribe, Topic}, _State) -> 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 -> false ->
deny; deny;
true -> true ->
Expand Down
2 changes: 1 addition & 1 deletion emqttd_plugins/emqttd_auth_cog_internal.erl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ description() ->




check(Client, Password, _) -> check(Client, Password, _) ->
case 'Elixir.Cog.BusCredentials':'connect_allowed?'(Client, Password) of case 'Elixir.Cog.BusEnforcer':'connect_allowed?'(Client, Password) of
true -> true ->
ok; ok;
false -> false ->
Expand Down
5 changes: 3 additions & 2 deletions lib/cog/bus_creds.ex → lib/cog/bus_enforcer.ex
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Cog.BusCredentials do defmodule Cog.BusEnforcer do
@moduledoc """ @moduledoc """
Checks credentials for connecting MQTT clients and Checks credentials for connecting MQTT clients and
enforces subscription ACLs for Relays enforces subscription ACLs for Relays
Expand All @@ -9,6 +9,7 @@ defmodule Cog.BusCredentials do


alias Cog.Repo alias Cog.Repo
alias Cog.Queries alias Cog.Queries
alias Cog.Models.Relay
alias Cog.Passwords alias Cog.Passwords


Record.defrecord :mqtt_client, Record.extract(:mqtt_client, from_lib: "emqttd/include/emqttd.hrl") Record.defrecord :mqtt_client, Record.extract(:mqtt_client, from_lib: "emqttd/include/emqttd.hrl")
Expand All @@ -32,7 +33,7 @@ defmodule Cog.BusCredentials do
false false
end end
username -> username ->
case Queries.Relay.exists?(username) do case Repo.exists?(Relay, username) do
false -> false ->
false false
true -> true ->
Expand Down
10 changes: 5 additions & 5 deletions lib/cog/repo.ex
Original file line number Original file line Diff line number Diff line change
@@ -1,12 +1,12 @@
defmodule Cog.Repo do defmodule Cog.Repo do
use Ecto.Repo, otp_app: :cog use Ecto.Repo, otp_app: :cog


alias Cog.Queries.Repo, as: Queries

def exists?(model, id) do def exists?(model, id) do
case one!(Queries.count_by_id(model, id)) do case get(model, id) do
1 -> true nil ->
_ -> false false
_ ->
true
end end
end end


Expand Down

0 comments on commit 866d685

Please sign in to comment.