Merge pull request #7898 from zhongwencool/replace-undefined-to-infinity
fix: infinity means never expire
This commit is contained in:
commit
5bae3e4907
|
@ -120,12 +120,12 @@ fields(app) ->
|
||||||
)},
|
)},
|
||||||
{expired_at,
|
{expired_at,
|
||||||
hoconsc:mk(
|
hoconsc:mk(
|
||||||
hoconsc:union([undefined, emqx_datetime:epoch_second()]),
|
hoconsc:union([infinity, emqx_datetime:epoch_second()]),
|
||||||
#{
|
#{
|
||||||
desc => "No longer valid datetime",
|
desc => "No longer valid datetime",
|
||||||
example => <<"2021-12-05T02:01:34.186Z">>,
|
example => <<"2021-12-05T02:01:34.186Z">>,
|
||||||
required => false,
|
required => false,
|
||||||
default => undefined
|
default => infinity
|
||||||
}
|
}
|
||||||
)},
|
)},
|
||||||
{created_at,
|
{created_at,
|
||||||
|
@ -219,7 +219,7 @@ api_key_by_name(put, #{bindings := #{name := Name}, body := Body}) ->
|
||||||
format(App = #{expired_at := ExpiredAt0, created_at := CreateAt}) ->
|
format(App = #{expired_at := ExpiredAt0, created_at := CreateAt}) ->
|
||||||
ExpiredAt =
|
ExpiredAt =
|
||||||
case ExpiredAt0 of
|
case ExpiredAt0 of
|
||||||
undefined -> <<"undefined">>;
|
infinity -> <<"infinity">>;
|
||||||
_ -> list_to_binary(calendar:system_time_to_rfc3339(ExpiredAt0))
|
_ -> list_to_binary(calendar:system_time_to_rfc3339(ExpiredAt0))
|
||||||
end,
|
end,
|
||||||
App#{
|
App#{
|
||||||
|
@ -228,4 +228,4 @@ format(App = #{expired_at := ExpiredAt0, created_at := CreateAt}) ->
|
||||||
}.
|
}.
|
||||||
|
|
||||||
ensure_expired_at(#{<<"expired_at">> := ExpiredAt}) when is_integer(ExpiredAt) -> ExpiredAt;
|
ensure_expired_at(#{<<"expired_at">> := ExpiredAt}) when is_integer(ExpiredAt) -> ExpiredAt;
|
||||||
ensure_expired_at(_) -> undefined.
|
ensure_expired_at(_) -> infinity.
|
||||||
|
|
|
@ -108,10 +108,10 @@ t_update(_Config) ->
|
||||||
),
|
),
|
||||||
Unexpired1 = maps:without([expired_at], Change),
|
Unexpired1 = maps:without([expired_at], Change),
|
||||||
{ok, Update2} = update_app(Name, Unexpired1),
|
{ok, Update2} = update_app(Name, Unexpired1),
|
||||||
?assertEqual(<<"undefined">>, maps:get(<<"expired_at">>, Update2)),
|
?assertEqual(<<"infinity">>, maps:get(<<"expired_at">>, Update2)),
|
||||||
Unexpired2 = Change#{expired_at => <<"undefined">>},
|
Unexpired2 = Change#{expired_at => <<"infinity">>},
|
||||||
{ok, Update3} = update_app(Name, Unexpired2),
|
{ok, Update3} = update_app(Name, Unexpired2),
|
||||||
?assertEqual(<<"undefined">>, maps:get(<<"expired_at">>, Update3)),
|
?assertEqual(<<"infinity">>, maps:get(<<"expired_at">>, Update3)),
|
||||||
|
|
||||||
?assertEqual({error, {"HTTP/1.1", 404, "Not Found"}}, update_app(<<"Not-Exist">>, Change)),
|
?assertEqual({error, {"HTTP/1.1", 404, "Not Found"}}, update_app(<<"Not-Exist">>, Change)),
|
||||||
ok.
|
ok.
|
||||||
|
@ -160,9 +160,9 @@ t_authorize(_Config) ->
|
||||||
},
|
},
|
||||||
?assertMatch({ok, #{<<"api_key">> := _, <<"enable">> := true}}, update_app(Name, Expired)),
|
?assertMatch({ok, #{<<"api_key">> := _, <<"enable">> := true}}, update_app(Name, Expired)),
|
||||||
?assertEqual(Unauthorized, emqx_mgmt_api_test_util:request_api(get, BanPath, BasicHeader)),
|
?assertEqual(Unauthorized, emqx_mgmt_api_test_util:request_api(get, BanPath, BasicHeader)),
|
||||||
UnExpired = #{expired_at => undefined},
|
UnExpired = #{expired_at => infinity},
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
{ok, #{<<"api_key">> := _, <<"expired_at">> := <<"undefined">>}},
|
{ok, #{<<"api_key">> := _, <<"expired_at">> := <<"infinity">>}},
|
||||||
update_app(Name, UnExpired)
|
update_app(Name, UnExpired)
|
||||||
),
|
),
|
||||||
{ok, _Status1} = emqx_mgmt_api_test_util:request_api(get, BanPath, BasicHeader),
|
{ok, _Status1} = emqx_mgmt_api_test_util:request_api(get, BanPath, BasicHeader),
|
||||||
|
@ -172,9 +172,9 @@ t_create_unexpired_app(_Config) ->
|
||||||
Name1 = <<"EMQX-UNEXPIRED-API-KEY-1">>,
|
Name1 = <<"EMQX-UNEXPIRED-API-KEY-1">>,
|
||||||
Name2 = <<"EMQX-UNEXPIRED-API-KEY-2">>,
|
Name2 = <<"EMQX-UNEXPIRED-API-KEY-2">>,
|
||||||
{ok, Create1} = create_unexpired_app(Name1, #{}),
|
{ok, Create1} = create_unexpired_app(Name1, #{}),
|
||||||
?assertMatch(#{<<"expired_at">> := <<"undefined">>}, Create1),
|
?assertMatch(#{<<"expired_at">> := <<"infinity">>}, Create1),
|
||||||
{ok, Create2} = create_unexpired_app(Name2, #{expired_at => <<"undefined">>}),
|
{ok, Create2} = create_unexpired_app(Name2, #{expired_at => <<"infinity">>}),
|
||||||
?assertMatch(#{<<"expired_at">> := <<"undefined">>}, Create2),
|
?assertMatch(#{<<"expired_at">> := <<"infinity">>}, Create2),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
list_app() ->
|
list_app() ->
|
||||||
|
|
Loading…
Reference in New Issue