emqx_authz_postgresql_schema.erl 1.9 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_authz_postgresql_schema).
  17. -include("emqx_auth_postgresql.hrl").
  18. -include_lib("hocon/include/hoconsc.hrl").
  19. -behaviour(emqx_authz_schema).
  20. -export([
  21. namespace/0,
  22. type/0,
  23. fields/1,
  24. desc/1,
  25. source_refs/0,
  26. select_union_member/1
  27. ]).
  28. namespace() -> "authz".
  29. type() -> ?AUTHZ_TYPE.
  30. fields(postgresql) ->
  31. emqx_authz_schema:authz_common_fields(?AUTHZ_TYPE) ++
  32. emqx_postgresql:fields(config) ++
  33. [{query, query()}].
  34. desc(postgresql) ->
  35. ?DESC(postgresql);
  36. desc(_) ->
  37. undefined.
  38. source_refs() ->
  39. [?R_REF(postgresql)].
  40. select_union_member(#{<<"type">> := ?AUTHZ_TYPE_BIN}) ->
  41. ?R_REF(postgresql);
  42. select_union_member(_Value) ->
  43. undefined.
  44. %%--------------------------------------------------------------------
  45. %% Internal Functions
  46. %%--------------------------------------------------------------------
  47. query() ->
  48. ?HOCON(binary(), #{
  49. desc => ?DESC(query),
  50. required => true,
  51. validator => fun(S) ->
  52. case size(S) > 0 of
  53. true -> ok;
  54. _ -> {error, "Request query"}
  55. end
  56. end
  57. }).