|
|
@@ -13,11 +13,14 @@
|
|
|
namespace/0,
|
|
|
api_spec/0,
|
|
|
paths/0,
|
|
|
- schema/1
|
|
|
+ schema/1,
|
|
|
+ fields/1
|
|
|
]).
|
|
|
+-define(LICENSE_TAGS, [<<"License">>]).
|
|
|
|
|
|
-export([
|
|
|
- '/license'/2
|
|
|
+ '/license'/2,
|
|
|
+ '/license/setting'/2
|
|
|
]).
|
|
|
|
|
|
-define(BAD_REQUEST, 'BAD_REQUEST').
|
|
|
@@ -29,14 +32,15 @@ api_spec() ->
|
|
|
|
|
|
paths() ->
|
|
|
[
|
|
|
- "/license"
|
|
|
+ "/license",
|
|
|
+ "/license/setting"
|
|
|
].
|
|
|
|
|
|
schema("/license") ->
|
|
|
#{
|
|
|
'operationId' => '/license',
|
|
|
get => #{
|
|
|
- tags => [<<"license">>],
|
|
|
+ tags => ?LICENSE_TAGS,
|
|
|
summary => <<"Get license info">>,
|
|
|
description => ?DESC("desc_license_info_api"),
|
|
|
responses => #{
|
|
|
@@ -51,18 +55,16 @@ schema("/license") ->
|
|
|
}
|
|
|
},
|
|
|
post => #{
|
|
|
- tags => [<<"license">>],
|
|
|
+ tags => ?LICENSE_TAGS,
|
|
|
summary => <<"Update license key">>,
|
|
|
description => ?DESC("desc_license_key_api"),
|
|
|
'requestBody' => emqx_dashboard_swagger:schema_with_examples(
|
|
|
- emqx_license_schema:key_license(),
|
|
|
+ hoconsc:ref(?MODULE, key_license),
|
|
|
#{
|
|
|
license_key => #{
|
|
|
summary => <<"License key string">>,
|
|
|
value => #{
|
|
|
- <<"key">> => <<"xxx">>,
|
|
|
- <<"connection_low_watermark">> => "75%",
|
|
|
- <<"connection_high_watermark">> => "80%"
|
|
|
+ <<"key">> => <<"xxx">>
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -79,6 +81,28 @@ schema("/license") ->
|
|
|
400 => emqx_dashboard_swagger:error_codes([?BAD_REQUEST], <<"Bad license key">>)
|
|
|
}
|
|
|
}
|
|
|
+ };
|
|
|
+schema("/license/setting") ->
|
|
|
+ #{
|
|
|
+ 'operationId' => '/license/setting',
|
|
|
+ get => #{
|
|
|
+ tags => ?LICENSE_TAGS,
|
|
|
+ summary => <<"Get license setting">>,
|
|
|
+ description => ?DESC("desc_license_setting_api"),
|
|
|
+ responses => #{
|
|
|
+ 200 => setting()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ post => #{
|
|
|
+ tags => ?LICENSE_TAGS,
|
|
|
+ summary => <<"Update license setting">>,
|
|
|
+ description => ?DESC("desc_license_setting_api"),
|
|
|
+ 'requestBody' => setting(),
|
|
|
+ responses => #{
|
|
|
+ 200 => setting(),
|
|
|
+ 400 => emqx_dashboard_swagger:error_codes([?BAD_REQUEST], <<"Bad setting value">>)
|
|
|
+ }
|
|
|
+ }
|
|
|
}.
|
|
|
|
|
|
sample_license_info_response() ->
|
|
|
@@ -117,3 +141,38 @@ error_msg(Code, Msg) ->
|
|
|
end;
|
|
|
'/license'(post, _Params) ->
|
|
|
{400, error_msg(?BAD_REQUEST, <<"Invalid request params">>)}.
|
|
|
+
|
|
|
+'/license/setting'(get, _Params) ->
|
|
|
+ {200, maps:remove(<<"key">>, emqx_config:get_raw([license]))};
|
|
|
+'/license/setting'(post, #{body := Setting}) ->
|
|
|
+ case emqx_license:update_setting(Setting) of
|
|
|
+ {error, Error} ->
|
|
|
+ ?SLOG(error, #{
|
|
|
+ msg => "bad_license_setting",
|
|
|
+ reason => Error
|
|
|
+ }),
|
|
|
+ {400, error_msg(?BAD_REQUEST, <<"Bad license setting">>)};
|
|
|
+ {ok, _} ->
|
|
|
+ ?SLOG(info, #{msg => "updated_license_setting"}),
|
|
|
+ '/license/setting'(get, undefined)
|
|
|
+ end.
|
|
|
+
|
|
|
+fields(key_license) ->
|
|
|
+ Key = lists:keyfind(key, 1, emqx_license_schema:fields(key_license)),
|
|
|
+ [
|
|
|
+ Key,
|
|
|
+ %% FIXME: remove when 5.2.0
|
|
|
+ {connection_low_watermark, #{
|
|
|
+ type => emqx_schema:percent(),
|
|
|
+ deprecated => true,
|
|
|
+ desc => ?DESC(connection_low_watermark_field_deprecated)
|
|
|
+ }},
|
|
|
+ {connection_high_watermark, #{
|
|
|
+ type => emqx_schema:percent(),
|
|
|
+ deprecated => true,
|
|
|
+ desc => ?DESC(connection_high_watermark_field_deprecated)
|
|
|
+ }}
|
|
|
+ ].
|
|
|
+
|
|
|
+setting() ->
|
|
|
+ lists:keydelete(key, 1, emqx_license_schema:fields(key_license)).
|