refactor: add template_str type

This commit is contained in:
zmstone 2024-04-17 15:10:26 +02:00
parent 5c014f4c29
commit 5a4bfff9e5
5 changed files with 20 additions and 8 deletions

View File

@ -62,6 +62,7 @@
-type url() :: binary().
-type json_binary() :: binary().
-type template() :: binary().
-type template_str() :: string().
-typerefl_from_string({duration/0, emqx_schema, to_duration}).
-typerefl_from_string({duration_s/0, emqx_schema, to_duration_s}).
@ -80,6 +81,7 @@
-typerefl_from_string({url/0, emqx_schema, to_url}).
-typerefl_from_string({json_binary/0, emqx_schema, to_json_binary}).
-typerefl_from_string({template/0, emqx_schema, to_template}).
-typerefl_from_string({template_str/0, emqx_schema, to_template_str}).
-type parsed_server() :: #{
hostname := string(),
@ -123,7 +125,8 @@
to_comma_separated_atoms/1,
to_url/1,
to_json_binary/1,
to_template/1
to_template/1,
to_template_str/1
]).
-export([
@ -164,7 +167,8 @@
url/0,
json_binary/0,
port_number/0,
template/0
template/0,
template_str/0
]).
-export([namespace/0, roots/0, roots/1, fields/1, desc/1, tags/0]).
@ -2601,6 +2605,9 @@ to_json_binary(Str) ->
to_template(Str) ->
{ok, iolist_to_binary(Str)}.
to_template_str(Str) ->
{ok, unicode:characters_to_list(Str, utf8)}.
%% @doc support the following format:
%% - 127.0.0.1:1883
%% - ::1:1883

View File

@ -76,6 +76,12 @@ readable("template()") ->
dashboard => #{type => string, is_template => true},
docgen => #{type => "String", desc => ?DESC(template)}
};
readable("template_str()") ->
#{
swagger => #{type => string},
dashboard => #{type => string, is_template => true},
docgen => #{type => "String", desc => ?DESC(template)}
};
readable("binary()") ->
#{
swagger => #{type => string},

View File

@ -103,7 +103,7 @@ put_object(Client, Key, Value) ->
-spec put_object(client(), key(), upload_options(), iodata()) -> ok_or_error(term()).
put_object(
#{bucket := Bucket0, headers := BaseHeaders, aws_config := AwsConfig = #aws_config{}},
#{bucket := Bucket, headers := BaseHeaders, aws_config := AwsConfig = #aws_config{}},
Key,
UploadOpts,
Content
@ -111,7 +111,6 @@ put_object(
ECKey = erlcloud_key(Key),
ECOpts = erlcloud_upload_options(UploadOpts),
Headers = join_headers(BaseHeaders, maps:get(headers, UploadOpts, undefined)),
Bucket = to_list_string(Bucket0),
try erlcloud_s3:put_object(Bucket, ECKey, Content, ECOpts, Headers, AwsConfig) of
Props when is_list(Props) ->
ok

View File

@ -74,7 +74,7 @@ fields(s3_upload) ->
[
{bucket,
mk(
emqx_schema:template(),
emqx_schema:template_str(),
#{
desc => ?DESC("bucket"),
required => true
@ -82,7 +82,7 @@ fields(s3_upload) ->
)},
{key,
mk(
emqx_schema:template(),
emqx_schema:template_str(),
#{
desc => ?DESC("key"),
required => true

View File

@ -20,7 +20,7 @@ all() ->
t_minimal_config(_Config) ->
?assertMatch(
#{
bucket := <<"bucket">>,
bucket := "bucket",
host := "s3.us-east-1.endpoint.com",
port := 443,
min_part_size := 5242880,
@ -45,7 +45,7 @@ t_full_config(_Config) ->
#{
access_key_id := "access_key_id",
acl := public_read,
bucket := <<"bucket">>,
bucket := "bucket",
host := "s3.us-east-1.endpoint.com",
min_part_size := 10485760,
port := 443,