|
|
@@ -16,36 +16,32 @@
|
|
|
|
|
|
-module(emqx_authz_api_schema).
|
|
|
|
|
|
+-include("emqx_authz.hrl").
|
|
|
-include_lib("typerefl/include/types.hrl").
|
|
|
-include_lib("emqx_connector/include/emqx_connector.hrl").
|
|
|
|
|
|
-import(hoconsc, [mk/2, enum/1]).
|
|
|
-import(emqx_schema, [mk_duration/2]).
|
|
|
|
|
|
--export([fields/1, authz_sources_types/1]).
|
|
|
+-export([
|
|
|
+ fields/1,
|
|
|
+ authz_sources_types/1
|
|
|
+]).
|
|
|
|
|
|
-fields(http) ->
|
|
|
- authz_common_fields(http) ++
|
|
|
- [
|
|
|
- {url, fun url/1},
|
|
|
- {method, #{
|
|
|
- type => enum([get, post]),
|
|
|
- default => get,
|
|
|
- required => true
|
|
|
- }},
|
|
|
- {headers, fun headers/1},
|
|
|
- {body, map([{fuzzy, term(), binary()}])},
|
|
|
- {request_timeout, mk_duration("Request timeout", #{default => "30s"})}
|
|
|
- ] ++
|
|
|
- maps:to_list(
|
|
|
- maps:without(
|
|
|
- [
|
|
|
- base_url,
|
|
|
- pool_type
|
|
|
- ],
|
|
|
- maps:from_list(emqx_connector_http:fields(config))
|
|
|
- )
|
|
|
- );
|
|
|
+%%------------------------------------------------------------------------------
|
|
|
+%% Hocon Schema
|
|
|
+%%------------------------------------------------------------------------------
|
|
|
+
|
|
|
+fields(http_get) ->
|
|
|
+ [
|
|
|
+ {method, #{type => get, default => get, required => true}},
|
|
|
+ {headers, fun headers_no_content_type/1}
|
|
|
+ ] ++ authz_http_common_fields();
|
|
|
+fields(http_post) ->
|
|
|
+ [
|
|
|
+ {method, #{type => post, default => post, required => true}},
|
|
|
+ {headers, fun headers/1}
|
|
|
+ ] ++ authz_http_common_fields();
|
|
|
fields(built_in_database) ->
|
|
|
authz_common_fields(built_in_database);
|
|
|
fields(mongo_single) ->
|
|
|
@@ -101,6 +97,23 @@ fields(position) ->
|
|
|
%%------------------------------------------------------------------------------
|
|
|
%% http type funcs
|
|
|
|
|
|
+authz_http_common_fields() ->
|
|
|
+ authz_common_fields(http) ++
|
|
|
+ [
|
|
|
+ {url, fun url/1},
|
|
|
+ {body, map([{fuzzy, term(), binary()}])},
|
|
|
+ {request_timeout, mk_duration("Request timeout", #{default => "30s"})}
|
|
|
+ ] ++
|
|
|
+ maps:to_list(
|
|
|
+ maps:without(
|
|
|
+ [
|
|
|
+ base_url,
|
|
|
+ pool_type
|
|
|
+ ],
|
|
|
+ maps:from_list(emqx_connector_http:fields(config))
|
|
|
+ )
|
|
|
+ ).
|
|
|
+
|
|
|
url(type) -> binary();
|
|
|
url(validator) -> [?NOT_EMPTY("the value of the field 'url' cannot be empty")];
|
|
|
url(required) -> true;
|
|
|
@@ -119,6 +132,19 @@ headers(default) ->
|
|
|
headers(_) ->
|
|
|
undefined.
|
|
|
|
|
|
+headers_no_content_type(type) ->
|
|
|
+ map();
|
|
|
+headers_no_content_type(desc) ->
|
|
|
+ "List of HTTP headers.";
|
|
|
+headers_no_content_type(converter) ->
|
|
|
+ fun(Headers) ->
|
|
|
+ maps:merge(default_headers_no_content_type(), transform_header_name(Headers))
|
|
|
+ end;
|
|
|
+headers_no_content_type(default) ->
|
|
|
+ default_headers_no_content_type();
|
|
|
+headers_no_content_type(_) ->
|
|
|
+ undefined.
|
|
|
+
|
|
|
%% headers
|
|
|
default_headers() ->
|
|
|
maps:put(
|
|
|
@@ -208,9 +234,11 @@ enable(_) -> undefined.
|
|
|
authz_sources_types(Type) ->
|
|
|
case Type of
|
|
|
simple ->
|
|
|
- [mongodb, redis];
|
|
|
+ [http, mongodb, redis];
|
|
|
detailed ->
|
|
|
[
|
|
|
+ http_get,
|
|
|
+ http_post,
|
|
|
mongo_single,
|
|
|
mongo_rs,
|
|
|
mongo_sharded,
|
|
|
@@ -220,7 +248,6 @@ authz_sources_types(Type) ->
|
|
|
]
|
|
|
end ++
|
|
|
[
|
|
|
- http,
|
|
|
built_in_database,
|
|
|
mysql,
|
|
|
postgresql,
|