Skip to content

Commit

Permalink
Merge pull request #24 from emqtt/emq20
Browse files Browse the repository at this point in the history
  • Loading branch information
Feng Lee committed Oct 31, 2016
2 parents fdf71d9 + 34f2b0e commit cf6fde7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion etc/emq_auth_pgsql.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## PostgreSQL Auth/ACL Plugin
##--------------------------------------------------------------------

## Postgre Server
## Postgre Server: 5432, 127.0.0.1:5432, localhost:5432
auth.pgsql.server = 127.0.0.1:5432

auth.pgsql.pool = 8
Expand Down
16 changes: 12 additions & 4 deletions priv/emq_auth_pgsql.schema
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
%%-*- mode: erlang -*-
%% emq_auth_pgsl config mapping

{mapping, "auth.pgsql.server", "emq_auth_pgsql.server", [
{default, {"127.0.0.1", 5432}},
{datatype, [integer, ip]}
{datatype, [integer, ip, string]}
]}.

{mapping, "auth.pgsql.pool", "emq_auth_pgsql.server", [
Expand Down Expand Up @@ -35,7 +36,14 @@
]}.

{translation, "emq_auth_pgsql.server", fun(Conf) ->
{Host, Port} = cuttlefish:conf_get("auth.pgsql.server", Conf),
{PgHost, PgPort} =
case cuttlefish:conf_get("auth.pgsql.server", Conf) of
{Ip, Port} -> {Ip, Port};
S -> case string:tokens(S, ":") of
[Domain] -> {Domain, 5432};
[Domain, Port] -> {Domain, list_to_integer(Port)}
end
end,
Pool = cuttlefish:conf_get("auth.pgsql.pool", Conf),
Username = cuttlefish:conf_get("auth.pgsql.username", Conf),
Passwd = cuttlefish:conf_get("auth.pgsql.password", Conf, ""),
Expand All @@ -44,8 +52,8 @@
Ssl = cuttlefish:conf_get("auth.pgsql.ssl", Conf),
[{pool_size, Pool},
{auto_reconnect, 1},
{host, Host},
{port, Port},
{host, PgHost},
{port, PgPort},
{username, Username},
{password, Passwd},
{database, DB},
Expand Down

0 comments on commit cf6fde7

Please sign in to comment.