emqx_authn_postgresql_schema.erl 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2020-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing, software
  11. %% distributed under the License is distributed on an "AS IS" BASIS,
  12. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. %% See the License for the specific language governing permissions and
  14. %% limitations under the License.
  15. %%--------------------------------------------------------------------
  16. -module(emqx_authn_postgresql_schema).
  17. -include("emqx_auth_postgresql.hrl").
  18. -include_lib("hocon/include/hoconsc.hrl").
  19. -behaviour(emqx_authn_schema).
  20. -export([
  21. namespace/0,
  22. fields/1,
  23. desc/1,
  24. refs/0,
  25. select_union_member/1
  26. ]).
  27. namespace() -> "authn".
  28. select_union_member(
  29. #{
  30. <<"mechanism">> := ?AUTHN_MECHANISM_BIN, <<"backend">> := ?AUTHN_BACKEND_BIN
  31. }
  32. ) ->
  33. refs();
  34. select_union_member(#{<<"backend">> := ?AUTHN_BACKEND_BIN}) ->
  35. throw(#{
  36. reason => "unknown_mechanism",
  37. expected => ?AUTHN_MECHANISM
  38. });
  39. select_union_member(_) ->
  40. undefined.
  41. fields(postgresql) ->
  42. [
  43. {mechanism, emqx_authn_schema:mechanism(?AUTHN_MECHANISM)},
  44. {backend, emqx_authn_schema:backend(?AUTHN_BACKEND)},
  45. {password_hash_algorithm, fun emqx_authn_password_hashing:type_ro/1},
  46. {query, fun query/1}
  47. ] ++
  48. emqx_authn_schema:common_fields() ++
  49. proplists:delete(prepare_statement, emqx_postgresql:fields(config)).
  50. desc(postgresql) ->
  51. ?DESC(postgresql);
  52. desc(_) ->
  53. undefined.
  54. query(type) -> string();
  55. query(desc) -> ?DESC(?FUNCTION_NAME);
  56. query(required) -> true;
  57. query(_) -> undefined.
  58. refs() ->
  59. [hoconsc:ref(?MODULE, postgresql)].