emqx_auth_pgsql.schema 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. %%-*- mode: erlang -*-
  2. %% emqx_auth_pgsl config mapping
  3. {mapping, "auth.pgsql.server", "emqx_auth_pgsql.server", [
  4. {default, {"127.0.0.1", 5432}},
  5. {datatype, [integer, ip, string]}
  6. ]}.
  7. {mapping, "auth.pgsql.pool", "emqx_auth_pgsql.server", [
  8. {default, 8},
  9. {datatype, integer}
  10. ]}.
  11. {mapping, "auth.pgsql.database", "emqx_auth_pgsql.server", [
  12. {datatype, string}
  13. ]}.
  14. {mapping, "auth.pgsql.username", "emqx_auth_pgsql.server", [
  15. {default, ""},
  16. {datatype, string}
  17. ]}.
  18. {mapping, "auth.pgsql.password", "emqx_auth_pgsql.server", [
  19. {default, ""},
  20. {datatype, string}
  21. ]}.
  22. {mapping, "auth.pgsql.encoding", "emqx_auth_pgsql.server", [
  23. {default, utf8},
  24. {datatype, atom}
  25. ]}.
  26. {mapping, "auth.pgsql.ssl", "emqx_auth_pgsql.server", [
  27. {default, false},
  28. {datatype, {enum, [true, false]}}
  29. ]}.
  30. {mapping, "auth.pgsql.ssl_opts.keyfile", "emqx_auth_pgsql.server", [
  31. {datatype, string}
  32. ]}.
  33. {mapping, "auth.pgsql.ssl_opts.certfile", "emqx_auth_pgsql.server", [
  34. {datatype, string}
  35. ]}.
  36. {mapping, "auth.pgsql.ssl_opts.cacertfile", "emqx_auth_pgsql.server", [
  37. {datatype, string}
  38. ]}.
  39. {translation, "emqx_auth_pgsql.server", fun(Conf) ->
  40. {PgHost, PgPort} =
  41. case cuttlefish:conf_get("auth.pgsql.server", Conf) of
  42. {Ip, Port} -> {Ip, Port};
  43. S -> case string:tokens(S, ":") of
  44. [Domain] -> {Domain, 5432};
  45. [Domain, Port] -> {Domain, list_to_integer(Port)}
  46. end
  47. end,
  48. Pool = cuttlefish:conf_get("auth.pgsql.pool", Conf),
  49. Username = cuttlefish:conf_get("auth.pgsql.username", Conf),
  50. Passwd = cuttlefish:conf_get("auth.pgsql.password", Conf, ""),
  51. DB = cuttlefish:conf_get("auth.pgsql.database", Conf),
  52. Encoding = cuttlefish:conf_get("auth.pgsql.encoding", Conf),
  53. Ssl = cuttlefish:conf_get("auth.pgsql.ssl", Conf),
  54. Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end,
  55. SslOpts = fun(Prefix) ->
  56. Filter([{keyfile, cuttlefish:conf_get(Prefix ++ ".keyfile", Conf, undefined)},
  57. {certfile, cuttlefish:conf_get(Prefix ++ ".certfile", Conf, undefined)},
  58. {cacertfile, cuttlefish:conf_get(Prefix ++ ".cacertfile", Conf, undefined)}])
  59. end,
  60. TempHost = case inet:parse_address(PgHost) of
  61. {ok, IpAddr} ->
  62. IpAddr;
  63. _ ->
  64. PgHost
  65. end,
  66. [{pool_size, Pool},
  67. {auto_reconnect, 1},
  68. {host, TempHost},
  69. {port, PgPort},
  70. {username, Username},
  71. {password, Passwd},
  72. {database, DB},
  73. {encoding, Encoding},
  74. {ssl, Ssl},
  75. {ssl_opts, SslOpts("auth.pgsql.ssl_opts")}]
  76. end}.
  77. {mapping, "auth.pgsql.auth_query", "emqx_auth_pgsql.auth_query", [
  78. {datatype, string}
  79. ]}.
  80. {mapping, "auth.pgsql.password_hash", "emqx_auth_pgsql.password_hash", [
  81. {datatype, string}
  82. ]}.
  83. {mapping, "auth.pgsql.pbkdf2_macfun", "emqx_auth_pgsql.pbkdf2_macfun", [
  84. {datatype, atom}
  85. ]}.
  86. {mapping, "auth.pgsql.pbkdf2_iterations", "emqx_auth_pgsql.pbkdf2_iterations", [
  87. {datatype, integer}
  88. ]}.
  89. {mapping, "auth.pgsql.pbkdf2_dklen", "emqx_auth_pgsql.pbkdf2_dklen", [
  90. {datatype, integer}
  91. ]}.
  92. {mapping, "auth.pgsql.super_query", "emqx_auth_pgsql.super_query", [
  93. {datatype, string}
  94. ]}.
  95. {mapping, "auth.pgsql.acl_query", "emqx_auth_pgsql.acl_query", [
  96. {datatype, string}
  97. ]}.
  98. {translation, "emqx_auth_pgsql.password_hash", fun(Conf) ->
  99. HashValue = cuttlefish:conf_get("auth.pgsql.password_hash", Conf),
  100. case string:tokens(HashValue, ",") of
  101. [Hash] -> list_to_atom(Hash);
  102. [Prefix, Suffix] -> {list_to_atom(Prefix), list_to_atom(Suffix)};
  103. [Hash, MacFun, Iterations, Dklen] -> {list_to_atom(Hash), list_to_atom(MacFun), list_to_integer(Iterations), list_to_integer(Dklen)};
  104. _ -> plain
  105. end
  106. end}.