emqx_authz.hrl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. -include_lib("emqx/include/emqx_access_control.hrl").
  17. -define(APP, emqx_authz).
  18. -define(ALLOW_DENY(A),
  19. ((A =:= allow) orelse (A =:= <<"allow">>) orelse
  20. (A =:= deny) orelse (A =:= <<"deny">>))
  21. ).
  22. -define(PUBSUB(A),
  23. ((A =:= subscribe) orelse (A =:= <<"subscribe">>) orelse
  24. (A =:= publish) orelse (A =:= <<"publish">>) orelse
  25. (A =:= all) orelse (A =:= <<"all">>))
  26. ).
  27. %% authz_mnesia
  28. -define(ACL_TABLE, emqx_acl).
  29. %% authz_cmd
  30. -define(CMD_REPLACE, replace).
  31. -define(CMD_DELETE, delete).
  32. -define(CMD_PREPEND, prepend).
  33. -define(CMD_APPEND, append).
  34. -define(CMD_MOVE, move).
  35. -define(CMD_MOVE_FRONT, front).
  36. -define(CMD_MOVE_REAR, rear).
  37. -define(CMD_MOVE_BEFORE(Before), {before, Before}).
  38. -define(CMD_MOVE_AFTER(After), {'after', After}).
  39. -define(CONF_KEY_PATH, [authorization, sources]).
  40. -define(RE_PLACEHOLDER, "\\$\\{[a-z0-9_]+\\}").
  41. %% has to be the same as the root field name defined in emqx_schema
  42. -define(CONF_NS, ?EMQX_AUTHORIZATION_CONFIG_ROOT_NAME).
  43. -define(CONF_NS_ATOM, ?EMQX_AUTHORIZATION_CONFIG_ROOT_NAME_ATOM).
  44. -define(CONF_NS_BINARY, ?EMQX_AUTHORIZATION_CONFIG_ROOT_NAME_BINARY).
  45. %% API examples
  46. -define(USERNAME_RULES_EXAMPLE, #{
  47. username => user1,
  48. rules => [
  49. #{
  50. topic => <<"test/toopic/1">>,
  51. permission => <<"allow">>,
  52. action => <<"publish">>
  53. },
  54. #{
  55. topic => <<"test/toopic/2">>,
  56. permission => <<"allow">>,
  57. action => <<"subscribe">>
  58. },
  59. #{
  60. topic => <<"eq test/#">>,
  61. permission => <<"deny">>,
  62. action => <<"all">>
  63. }
  64. ]
  65. }).
  66. -define(CLIENTID_RULES_EXAMPLE, #{
  67. clientid => client1,
  68. rules => [
  69. #{
  70. topic => <<"test/toopic/1">>,
  71. permission => <<"allow">>,
  72. action => <<"publish">>
  73. },
  74. #{
  75. topic => <<"test/toopic/2">>,
  76. permission => <<"allow">>,
  77. action => <<"subscribe">>
  78. },
  79. #{
  80. topic => <<"eq test/#">>,
  81. permission => <<"deny">>,
  82. action => <<"all">>
  83. }
  84. ]
  85. }).
  86. -define(ALL_RULES_EXAMPLE, #{
  87. rules => [
  88. #{
  89. topic => <<"test/toopic/1">>,
  90. permission => <<"allow">>,
  91. action => <<"publish">>
  92. },
  93. #{
  94. topic => <<"test/toopic/2">>,
  95. permission => <<"allow">>,
  96. action => <<"subscribe">>
  97. },
  98. #{
  99. topic => <<"eq test/#">>,
  100. permission => <<"deny">>,
  101. action => <<"all">>
  102. }
  103. ]
  104. }).
  105. -define(META_EXAMPLE, #{
  106. page => 1,
  107. limit => 100,
  108. count => 1
  109. }).
  110. -define(RESOURCE_GROUP, <<"emqx_authz">>).