emqx_authz.hrl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2020-2022 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. -define(APP, emqx_authz).
  17. -define(ALLOW_DENY(A), ((A =:= allow) orelse (A =:= <<"allow">>) orelse
  18. (A =:= deny) orelse (A =:= <<"deny">>)
  19. )).
  20. -define(PUBSUB(A), ((A =:= subscribe) orelse (A =:= <<"subscribe">>) orelse
  21. (A =:= publish) orelse (A =:= <<"publish">>) orelse
  22. (A =:= all) orelse (A =:= <<"all">>)
  23. )).
  24. %% authz_mnesia
  25. -define(ACL_TABLE, emqx_acl).
  26. %% authz_cmd
  27. -define(CMD_REPLACE, replace).
  28. -define(CMD_DELETE, delete).
  29. -define(CMD_PREPEND, prepend).
  30. -define(CMD_APPEND, append).
  31. -define(CMD_MOVE, move).
  32. -define(CMD_MOVE_TOP, <<"top">>).
  33. -define(CMD_MOVE_BOTTOM, <<"bottom">>).
  34. -define(CMD_MOVE_BEFORE(Before), {<<"before">>, Before}).
  35. -define(CMD_MOVE_AFTER(After), {<<"after">>, After}).
  36. -define(CONF_KEY_PATH, [authorization, sources]).
  37. -define(RE_PLACEHOLDER, "\\$\\{[a-z0-9_]+\\}").
  38. %% API examples
  39. -define(USERNAME_RULES_EXAMPLE, #{username => user1,
  40. rules => [ #{topic => <<"test/toopic/1">>,
  41. permission => <<"allow">>,
  42. action => <<"publish">>
  43. }
  44. , #{topic => <<"test/toopic/2">>,
  45. permission => <<"allow">>,
  46. action => <<"subscribe">>
  47. }
  48. , #{topic => <<"eq test/#">>,
  49. permission => <<"deny">>,
  50. action => <<"all">>
  51. }
  52. ]
  53. }).
  54. -define(CLIENTID_RULES_EXAMPLE, #{clientid => client1,
  55. rules => [ #{topic => <<"test/toopic/1">>,
  56. permission => <<"allow">>,
  57. action => <<"publish">>
  58. }
  59. , #{topic => <<"test/toopic/2">>,
  60. permission => <<"allow">>,
  61. action => <<"subscribe">>
  62. }
  63. , #{topic => <<"eq test/#">>,
  64. permission => <<"deny">>,
  65. action => <<"all">>
  66. }
  67. ]
  68. }).
  69. -define(ALL_RULES_EXAMPLE, #{rules => [ #{topic => <<"test/toopic/1">>,
  70. permission => <<"allow">>,
  71. action => <<"publish">>
  72. }
  73. , #{topic => <<"test/toopic/2">>,
  74. permission => <<"allow">>,
  75. action => <<"subscribe">>
  76. }
  77. , #{topic => <<"eq test/#">>,
  78. permission => <<"deny">>,
  79. action => <<"all">>
  80. }
  81. ]
  82. }).
  83. -define(META_EXAMPLE, #{ page => 1
  84. , limit => 100
  85. , count => 1
  86. }).
  87. -define(RESOURCE_GROUP, <<"emqx_authz">>).