feat(s3): make acl optional

This commit is contained in:
Ilya Averyanov 2023-04-13 19:47:12 +03:00
parent a99eb082d1
commit e22c1c01ec
4 changed files with 19 additions and 6 deletions

View File

@ -199,10 +199,12 @@ format(#{aws_config := AwsConfig} = Client) ->
%% Internal functions
%%--------------------------------------------------------------------
upload_options(Config) ->
upload_options(#{acl := Acl}) when Acl =/= undefined ->
[
{acl, maps:get(acl, Config)}
].
{acl, Acl}
];
upload_options(#{}) ->
[].
headers(#{headers := Headers}) ->
headers_user_to_erlcloud_request(Headers);

View File

@ -198,7 +198,7 @@ client_config(ProfileConfig, PoolName) ->
port => maps:get(port, ProfileConfig),
url_expire_time => maps:get(url_expire_time, ProfileConfig),
headers => maps:get(headers, HTTPOpts, #{}),
acl => maps:get(acl, ProfileConfig),
acl => maps:get(acl, ProfileConfig, undefined),
bucket => maps:get(bucket, ProfileConfig),
access_key_id => maps:get(access_key_id, ProfileConfig, undefined),
secret_access_key => maps:get(secret_access_key, ProfileConfig, undefined),

View File

@ -105,7 +105,7 @@ fields(s3) ->
#{
default => private,
desc => ?DESC("acl"),
required => true
required => false
}
)},
{transport_options,

View File

@ -60,7 +60,8 @@ init_per_testcase(_TestCase, Config0) ->
ok = erlcloud_s3:create_bucket(Bucket, TestAwsConfig),
Config1 = [
{key, emqx_s3_test_helpers:unique_key()},
{bucket, Bucket}
{bucket, Bucket},
{aws_config, TestAwsConfig}
| Config0
],
{ok, PoolName} = emqx_s3_profile_conf:start_http_pool(?PROFILE_ID, profile_config(Config1)),
@ -131,6 +132,16 @@ t_url(Config) ->
httpc:request(Url)
).
t_no_acl(Config) ->
Key = ?config(key, Config),
ClientConfig = emqx_s3_profile_conf:client_config(
profile_config(Config), ?config(ehttpc_pool_name, Config)
),
Client = emqx_s3_client:create(maps:without([acl], ClientConfig)),
ok = emqx_s3_client:put_object(Client, Key, <<"data">>).
%%--------------------------------------------------------------------
%% Helpers
%%--------------------------------------------------------------------