1
0
Fork 0
mirror of https://github.com/processone/ejabberd synced 2025-10-04 02:09:33 +02:00

Allow specifying tag for listener for api_permission purposes

This commit will allow adding tag to http listeners:

listener:
  - port: 4000
  - module: ejabberd_http
  - tag: "magic_listener"

that later can be used to have special api_permission just for it:

api_permissions:
  "magic_access":
    from:
      - tag: "magic_listener"
    who: all
    what: "*"
This commit is contained in:
Paweł Chmielowski 2019-01-30 12:56:52 +01:00
parent 23e5b3756c
commit 62ad1e5e4f
3 changed files with 22 additions and 14 deletions

View file

@ -137,7 +137,7 @@ depends(_Host, _Opts) ->
%% basic auth
%% ----------
extract_auth(#request{auth = HTTPAuth, ip = {IP, _}}) ->
extract_auth(#request{auth = HTTPAuth, ip = {IP, _}, opts = Opts}) ->
Info = case HTTPAuth of
{SJID, Pass} ->
try jid:decode(SJID) of
@ -163,13 +163,15 @@ extract_auth(#request{auth = HTTPAuth, ip = {IP, _}}) ->
end,
case Info of
Map when is_map(Map) ->
Map#{caller_module => ?MODULE, ip => IP};
Tag = proplists:get_value(tag, Opts, <<>>),
Map#{caller_module => ?MODULE, ip => IP, tag => Tag};
_ ->
?DEBUG("Invalid auth data: ~p", [Info]),
Info
end;
extract_auth(#request{ip = IP}) ->
#{ip => IP, caller_module => ?MODULE}.
extract_auth(#request{ip = IP, opts = Opts}) ->
Tag = proplists:get_value(tag, Opts, <<>>),
#{ip => IP, caller_module => ?MODULE, tag => Tag}.
%% ------------------
%% command processing