@@ -66,6 +66,19 @@ def with_client(*, auto_close = true, & : EasyAwscr::S3::Client -> Nil)
6666 end
6767end
6868
69+ def with_native_awscr_s3_client (& : Awscr ::S3 ::Client - > Nil )
70+ with_aws_api do |api |
71+ cred = api.credential_provider.credentials
72+ yield Awscr ::S3 ::Client .new(
73+ api.region,
74+ cred.access_key_id,
75+ cred.secret_access_key,
76+ cred.session_token,
77+ endpoint: api.endpoint
78+ )
79+ end
80+ end
81+
6982class SafeKeyGen
7083 getter keys_used
7184
@@ -283,4 +296,51 @@ describe EasyAwscr::S3::Client do
283296 end
284297 end
285298 end
299+
300+ describe " allow to use your own awscr-s3 client" do
301+ describe " #constructor" do
302+ it " should use the client_provider if configured" do
303+ with_native_awscr_s3_client do |awscr_s3_client |
304+ call_count = 0
305+ client_provider = - > (_force_new : Bool ) do
306+ call_count += 1
307+ awscr_s3_client
308+ end
309+
310+ client = EasyAwscr ::S3 ::Client .new(client_provider: client_provider, region: " us-east-1" , lazy_init: true )
311+ call_count.should eq(0 )
312+
313+ list1 = client.list_buckets
314+ call_count.should eq(1 )
315+ list2 = client.list_buckets
316+ call_count.should eq(2 )
317+
318+ list1.buckets.should eq(list2.buckets)
319+ end
320+ end
321+ end
322+
323+ describe " #from_native_client" do
324+ it " should be support to wrap a single call" do
325+ with_native_awscr_s3_client do |awscr_s3_client |
326+ list1 = EasyAwscr ::S3 ::Client .from_native_client(awscr_s3_client).list_buckets
327+ list2 = EasyAwscr ::S3 ::Client .from_native_client(awscr_s3_client).list_buckets
328+ list1.buckets.should eq(list2.buckets)
329+ end
330+ end
331+
332+ it " should integrate with the normal client" do
333+ with_client do |client |
334+ with_temp_test_bucket(client) do |bucket |
335+ with_native_awscr_s3_client do |awscr_s3_client |
336+ native_client = EasyAwscr ::S3 ::Client .from_native_client(awscr_s3_client)
337+
338+ client.head_bucket(bucket).should be_true
339+ native_client.head_bucket(bucket).should be_true
340+ end
341+ end
342+ end
343+ end
344+ end
345+ end
286346end
0 commit comments