emqx_authn_postgresql_schema.erl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. fields/1,
  22. desc/1,
  23. refs/0,
  24. select_union_member/1
  25. ]).
  26. select_union_member(
  27. #{
  28. <<"mechanism">> := ?AUTHN_MECHANISM_BIN, <<"backend">> := ?AUTHN_BACKEND_BIN
  29. }
  30. ) ->
  31. refs();
  32. select_union_member(#{<<"backend">> := ?AUTHN_BACKEND_BIN}) ->
  33. throw(#{
  34. reason => "unknown_mechanism",
  35. expected => ?AUTHN_MECHANISM
  36. });
  37. select_union_member(_) ->
  38. undefined.
  39. fields(postgresql) ->
  40. [
  41. {mechanism, emqx_authn_schema:mechanism(?AUTHN_MECHANISM)},
  42. {backend, emqx_authn_schema:backend(?AUTHN_BACKEND)},
  43. {password_hash_algorithm, fun emqx_authn_password_hashing:type_ro/1},
  44. {query, fun query/1}
  45. ] ++
  46. emqx_authn_schema:common_fields() ++
  47. proplists:delete(prepare_statement, emqx_connector_pgsql:fields(config)).
  48. desc(postgresql) ->
  49. ?DESC(postgresql);
  50. desc(_) ->
  51. undefined.
  52. query(type) -> string();
  53. query(desc) -> ?DESC(?FUNCTION_NAME);
  54. query(required) -> true;
  55. query(_) -> undefined.
  56. refs() ->
  57. [hoconsc:ref(?MODULE, postgresql)].