Merge pull request #8073 from terry-xiaoyu/rule_name_optional

fix: make 'name' field optional
This commit is contained in:
Xinyu Liu 2022-05-29 11:58:58 +08:00 committed by GitHub
commit 4bc58548aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 21 deletions

View File

@ -106,10 +106,13 @@ end).
start() ->
application:ensure_all_started(grpc),
[start_channel(), start_server()].
[ensure_channel(), start_server()].
start_channel() ->
grpc_client_sup:create_channel_pool(ct_test_channel, "http://127.0.0.1:9100", #{}).
ensure_channel() ->
case grpc_client_sup:create_channel_pool(ct_test_channel, "http://127.0.0.1:9100", #{}) of
{error, {already_started, Pid}} -> {ok, Pid};
{ok, Pid} -> {ok, Pid}
end.
start_server() ->
Services = #{

View File

@ -28,7 +28,7 @@
desc/1
]).
-export([validate_sql/1, validate_rule_name/1]).
-export([validate_sql/1]).
namespace() -> rule_engine.
@ -187,26 +187,11 @@ rule_name() ->
#{
desc => ?DESC("rules_name"),
default => "",
required => true,
example => "foo",
validator => fun ?MODULE:validate_rule_name/1
required => false,
example => "foo"
}
)}.
validate_rule_name(Name) ->
RE = "^[A-Za-z0-9]+[A-Za-z0-9-_]*$",
try re:run(Name, RE) of
{match, _} ->
ok;
_Nomatch ->
Reason = list_to_binary(io_lib:format("Bad rule name ~p, expect ~p", [Name, RE])),
{error, Reason}
catch
_:_ ->
Reason = list_to_binary(io_lib:format("Bad rule name ~p, expect ~p", [Name, RE])),
{error, Reason}
end.
actions() ->
[
binary(),