defra_ruby_aws 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e35f8c64d2e528faf5a59987c833be7a8c53c5a68694fe842f042ae1ec174f82
4
- data.tar.gz: acadc8305a896c1895f7cdbba00cb0e3181e9caf0693b31c89b5f06d141b5e3d
3
+ metadata.gz: 1da7a16c3acdb14eb8690cdebe2586e93ec72acc9a93f3a4ad9f2f9ce315334c
4
+ data.tar.gz: 5a65b5bc761856abb099cbdf26da4335eba87d0afb443338e2529cfa6f30f863
5
5
  SHA512:
6
- metadata.gz: dfc64c44e01e4f61df59a018aeba7054c34ca061a60406b17e41267467689df4bc0d5c1496eed445ec823cbdbf1b8cce8aafec25935b175ad5a5df9f52c564e5
7
- data.tar.gz: 5113bbd9312b32f23a6a0b725d64cf94c73714ae1c8e03675166f2b7f8679a95032478f38373970b23f85db04b0e448099aadc6590362509dbc7b20fb1972349
6
+ metadata.gz: 6f382ccf1699597d1040a9978eadf01c7e96c9b7fa1826dd8c2ac96f1bdd58f96286fe83809e8a9ab2be4cc4843e4db607d27290797270a758b47e4097830a81
7
+ data.tar.gz: 518b0337d6568a44c4fce640e4ebc0775147503dd78df1b2bafb79195ca708855c204ed843906d759ef0de9451f47dfb8026d975c8eb7007c8fc64855d2a652a
@@ -38,6 +38,10 @@ module DefraRuby
38
38
  DeleteFileFromBucketService.run(self, file_name, options)
39
39
  end
40
40
 
41
+ def list_files(directory_name, options = {})
42
+ ListBucketFilesService.run(self, directory_name, options)
43
+ end
44
+
41
45
  private
42
46
 
43
47
  attr_writer :region
@@ -5,11 +5,12 @@ module DefraRuby
5
5
  class UnsuccessfulOperation < StandardError; end
6
6
 
7
7
  class Response
8
- attr_reader :error
8
+ attr_reader :error, :result
9
9
 
10
10
  def initialize(response_exe)
11
11
  @success = true
12
12
  @error = nil
13
+ @result = nil
13
14
 
14
15
  capture_response(response_exe)
15
16
  end
@@ -23,7 +24,8 @@ module DefraRuby
23
24
  attr_reader :success
24
25
 
25
26
  def capture_response(response_exe)
26
- raise UnsuccessfulOperation unless response_exe.call
27
+ @result = response_exe.call
28
+ raise UnsuccessfulOperation unless @result
27
29
  rescue StandardError => e
28
30
  @error = e
29
31
  @success = false
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DefraRuby
4
+ module Aws
5
+ class ListBucketFilesService
6
+ include HasAwsBucketConfiguration
7
+
8
+ def self.run(bucket, folder, options = {})
9
+ new(bucket, folder, options).run
10
+ end
11
+
12
+ def initialize(bucket, folder, options)
13
+ @bucket = bucket
14
+ @folder = folder
15
+ @dir = options[:s3_directory]
16
+ end
17
+
18
+ def run
19
+ Response.new(response_exe)
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :bucket, :dir
25
+
26
+ def response_exe
27
+ lambda do
28
+ s3_bucket.objects(prefix: @folder).collect(&:key)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module DefraRuby
4
4
  module Aws
5
- VERSION = "0.4.1"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
@@ -8,6 +8,7 @@ require_relative "aws/services/concerns/has_aws_bucket_configuration"
8
8
  require_relative "aws/services/bucket_loader_service"
9
9
  require_relative "aws/services/presigned_url_service"
10
10
  require_relative "aws/services/delete_file_from_bucket_service"
11
+ require_relative "aws/services/list_bucket_files_service"
11
12
 
12
13
  module DefraRuby
13
14
  module Aws
data/spec/examples.txt CHANGED
@@ -1,45 +1,48 @@
1
1
  example_id | status | run_time |
2
2
  ------------------------------------------------------------------------------------- | ------ | --------------- |
3
- ./spec/defra_ruby_aws_spec.rb[1:1] | passed | 0.00091 seconds |
4
- ./spec/features/upload_file_to_bucket_spec.rb[1:1] | passed | 0.00642 seconds |
5
- ./spec/features/upload_file_to_bucket_spec.rb[1:2] | passed | 0.0188 seconds |
6
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:1:1] | passed | 0.00012 seconds |
7
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:2:1] | passed | 0.0001 seconds |
8
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:3:1] | passed | 0.0001 seconds |
9
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:4:1] | passed | 0.00099 seconds |
10
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:5:1:1] | passed | 0.00014 seconds |
11
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:5:2:1] | passed | 0.00008 seconds |
12
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:6:1] | passed | 0.00008 seconds |
13
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:7:1:1] | passed | 0.00007 seconds |
14
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:7:1:2] | passed | 0.00013 seconds |
15
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:7:2:1] | passed | 0.0001 seconds |
16
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:7:2:2] | passed | 0.00009 seconds |
17
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:1:1] | passed | 0.00018 seconds |
18
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:1:2] | passed | 0.0001 seconds |
19
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:2:1] | passed | 0.00009 seconds |
20
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:2:2] | passed | 0.00017 seconds |
21
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:3:1] | passed | 0.00023 seconds |
22
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:3:2] | passed | 0.00014 seconds |
23
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:4:1] | passed | 0.0002 seconds |
24
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:4:2] | passed | 0.0001 seconds |
25
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:5:1] | passed | 0.00071 seconds |
26
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:5:2] | passed | 0.00019 seconds |
27
- ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:2:1] | passed | 0.00092 seconds |
28
- ./spec/lib/defra_ruby/aws/configuration_spec.rb[1:1:1] | passed | 0.00064 seconds |
29
- ./spec/lib/defra_ruby/aws/response_spec.rb[1:1:1:1] | passed | 0.00021 seconds |
30
- ./spec/lib/defra_ruby/aws/response_spec.rb[1:1:2:1] | passed | 0.00012 seconds |
31
- ./spec/lib/defra_ruby/aws/response_spec.rb[1:1:3:1] | passed | 0.00012 seconds |
32
- ./spec/lib/defra_ruby/aws/response_spec.rb[1:1:4:1] | passed | 0.00013 seconds |
33
- ./spec/lib/defra_ruby/aws/response_spec.rb[1:1:5:1] | passed | 0.00015 seconds |
34
- ./spec/lib/defra_ruby/aws/response_spec.rb[1:2:1:1] | passed | 0.00062 seconds |
35
- ./spec/lib/defra_ruby/aws/response_spec.rb[1:2:2:1] | passed | 0.00012 seconds |
36
- ./spec/lib/defra_ruby/aws/services/bucket_loader_service_spec.rb[1:1:1:1] | passed | 0.00088 seconds |
37
- ./spec/lib/defra_ruby/aws/services/bucket_loader_service_spec.rb[1:1:1:2:1] | passed | 0.00072 seconds |
38
- ./spec/lib/defra_ruby/aws/services/bucket_loader_service_spec.rb[1:1:2:1] | passed | 0.00076 seconds |
39
- ./spec/lib/defra_ruby/aws/services/bucket_loader_service_spec.rb[1:1:2:2:1] | passed | 0.00239 seconds |
40
- ./spec/lib/defra_ruby/aws/services/delete_file_from_bucket_service_spec.rb[1:1:1] | passed | 0.00676 seconds |
41
- ./spec/lib/defra_ruby/aws/services/delete_file_from_bucket_service_spec.rb[1:1:2:1] | passed | 0.00064 seconds |
42
- ./spec/lib/defra_ruby/aws/services/delete_file_from_bucket_service_spec.rb[1:1:3:1] | passed | 0.00069 seconds |
43
- ./spec/lib/defra_ruby/aws/services/delete_file_from_bucket_service_spec.rb[1:1:3:2:1] | passed | 0.00059 seconds |
44
- ./spec/lib/defra_ruby/aws/services/presigned_url_service_spec.rb[1:1:1] | passed | 0.01032 seconds |
45
- ./spec/lib/defra_ruby/aws/services/presigned_url_service_spec.rb[1:1:2:1] | passed | 0.00982 seconds |
3
+ ./spec/defra_ruby_aws_spec.rb[1:1] | passed | 0.00115 seconds |
4
+ ./spec/features/upload_file_to_bucket_spec.rb[1:1] | passed | 0.00635 seconds |
5
+ ./spec/features/upload_file_to_bucket_spec.rb[1:2] | passed | 0.00572 seconds |
6
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:1:1] | passed | 0.00014 seconds |
7
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:2:1] | passed | 0.00012 seconds |
8
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:3:1] | passed | 0.00013 seconds |
9
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:4:1] | passed | 0.00174 seconds |
10
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:5:1:1] | passed | 0.00011 seconds |
11
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:5:2:1] | passed | 0.0001 seconds |
12
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:6:1] | passed | 0.00011 seconds |
13
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:7:1:1] | passed | 0.00016 seconds |
14
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:7:1:2] | passed | 0.00012 seconds |
15
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:7:2:1] | passed | 0.00011 seconds |
16
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:7:2:2] | passed | 0.00012 seconds |
17
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:1:1] | passed | 0.0001 seconds |
18
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:1:2] | passed | 0.00012 seconds |
19
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:2:1] | passed | 0.00012 seconds |
20
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:2:2] | passed | 0.00011 seconds |
21
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:3:1] | passed | 0.0001 seconds |
22
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:3:2] | passed | 0.00011 seconds |
23
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:4:1] | passed | 0.00011 seconds |
24
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:4:2] | passed | 0.00011 seconds |
25
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:5:1] | passed | 0.00012 seconds |
26
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:5:2] | passed | 0.0001 seconds |
27
+ ./spec/lib/defra_ruby/aws/bucket_spec.rb[1:2:1] | passed | 0.00056 seconds |
28
+ ./spec/lib/defra_ruby/aws/configuration_spec.rb[1:1:1] | passed | 0.00058 seconds |
29
+ ./spec/lib/defra_ruby/aws/response_spec.rb[1:1:1:1] | passed | 0.00193 seconds |
30
+ ./spec/lib/defra_ruby/aws/response_spec.rb[1:1:2:1] | passed | 0.00015 seconds |
31
+ ./spec/lib/defra_ruby/aws/response_spec.rb[1:1:3:1] | passed | 0.0001 seconds |
32
+ ./spec/lib/defra_ruby/aws/response_spec.rb[1:1:4:1] | passed | 0.00012 seconds |
33
+ ./spec/lib/defra_ruby/aws/response_spec.rb[1:1:5:1] | passed | 0.00011 seconds |
34
+ ./spec/lib/defra_ruby/aws/response_spec.rb[1:2:1:1] | passed | 0.00066 seconds |
35
+ ./spec/lib/defra_ruby/aws/response_spec.rb[1:3:1:1] | passed | 0.0001 seconds |
36
+ ./spec/lib/defra_ruby/aws/response_spec.rb[1:3:2:1] | passed | 0.00009 seconds |
37
+ ./spec/lib/defra_ruby/aws/services/bucket_loader_service_spec.rb[1:1:1:1] | passed | 0.00849 seconds |
38
+ ./spec/lib/defra_ruby/aws/services/bucket_loader_service_spec.rb[1:1:1:2:1] | passed | 0.00065 seconds |
39
+ ./spec/lib/defra_ruby/aws/services/bucket_loader_service_spec.rb[1:1:2:1] | passed | 0.0006 seconds |
40
+ ./spec/lib/defra_ruby/aws/services/bucket_loader_service_spec.rb[1:1:2:2:1] | passed | 0.0006 seconds |
41
+ ./spec/lib/defra_ruby/aws/services/delete_file_from_bucket_service_spec.rb[1:1:1] | passed | 0.00089 seconds |
42
+ ./spec/lib/defra_ruby/aws/services/delete_file_from_bucket_service_spec.rb[1:1:2:1] | passed | 0.00078 seconds |
43
+ ./spec/lib/defra_ruby/aws/services/delete_file_from_bucket_service_spec.rb[1:1:3:1] | passed | 0.00079 seconds |
44
+ ./spec/lib/defra_ruby/aws/services/delete_file_from_bucket_service_spec.rb[1:1:3:2:1] | passed | 0.00077 seconds |
45
+ ./spec/lib/defra_ruby/aws/services/list_bucket_files_service_spec.rb[1:1:1:1] | passed | 0.00247 seconds |
46
+ ./spec/lib/defra_ruby/aws/services/list_bucket_files_service_spec.rb[1:1:2:1] | passed | 0.00093 seconds |
47
+ ./spec/lib/defra_ruby/aws/services/presigned_url_service_spec.rb[1:1:1] | passed | 0.02254 seconds |
48
+ ./spec/lib/defra_ruby/aws/services/presigned_url_service_spec.rb[1:1:2:1] | passed | 0.00314 seconds |
@@ -49,6 +49,16 @@ module DefraRuby
49
49
  end
50
50
  end
51
51
 
52
+ describe "#result" do
53
+ context "when the response includes a result object" do
54
+ let(:response_exe) { -> { "I am an object" } }
55
+
56
+ it "returns the s3 result object" do
57
+ expect(described_class.new(response_exe).result).to eq "I am an object"
58
+ end
59
+ end
60
+ end
61
+
52
62
  describe "#error" do
53
63
  context "when the response throws an error" do
54
64
  let(:response_exe) { -> { raise StandardError, "Boom!" } }
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ module DefraRuby
6
+ module Aws
7
+ RSpec.describe ListBucketFilesService do
8
+ describe "#run" do
9
+ let(:configs) do
10
+ {
11
+ credentials: {
12
+ access_key_id: "key_id",
13
+ secret_access_key: "secret"
14
+ },
15
+ name: "bulk"
16
+ }
17
+ end
18
+ let(:bucket) { Bucket.new(configs) }
19
+
20
+ context "when an s3_directory is provided" do
21
+ it "returns a successful response" do
22
+ aws_resource = double(:aws_resource)
23
+ s3_bucket = double(:s3_bulk_bucket)
24
+ s3_object1 = double(:s3_object)
25
+ s3_object2 = double(:s3_object)
26
+ s3_objects = [s3_object1, s3_object2]
27
+ s3_directory = "/a_directory"
28
+ options = {}
29
+
30
+ expect(::Aws::S3::Resource).to receive(:new).and_return(aws_resource)
31
+ expect(aws_resource).to receive(:bucket).with("bulk").and_return(s3_bucket)
32
+ expect(s3_bucket).to receive(:objects).with(prefix: s3_directory).and_return(s3_objects)
33
+ expect(s3_object1).to receive(:key).and_return("object1").at_least(:once)
34
+ expect(s3_object2).to receive(:key).and_return("object2").at_least(:once)
35
+
36
+ response = described_class.run(bucket, s3_directory, options)
37
+ expect(response).to be_successful
38
+ expect(response.result).to match_array([s3_object1.key, s3_object2.key])
39
+ end
40
+ end
41
+
42
+ context "when an s3_directory is not provided" do
43
+ it "returns a non successful response" do
44
+ aws_resource = double(:aws_resource)
45
+ s3_bucket = double(:s3_bulk_bucket)
46
+ s3_directory = nil
47
+
48
+ expect(::Aws::S3::Resource).to receive(:new).and_return(aws_resource)
49
+ expect(aws_resource).to receive(:bucket).with("bulk").and_return(s3_bucket)
50
+ expect(s3_bucket).to receive(:objects).with(prefix: s3_directory).and_return(nil)
51
+
52
+ response = described_class.run(bucket, s3_directory)
53
+ expect(response).to_not be_successful
54
+ expect(response.result).to be_nil
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defra_ruby_aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Defra
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-07 00:00:00.000000000 Z
11
+ date: 2022-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3
@@ -155,6 +155,7 @@ files:
155
155
  - lib/defra_ruby/aws/services/bucket_loader_service.rb
156
156
  - lib/defra_ruby/aws/services/concerns/has_aws_bucket_configuration.rb
157
157
  - lib/defra_ruby/aws/services/delete_file_from_bucket_service.rb
158
+ - lib/defra_ruby/aws/services/list_bucket_files_service.rb
158
159
  - lib/defra_ruby/aws/services/presigned_url_service.rb
159
160
  - lib/defra_ruby/aws/version.rb
160
161
  - spec/defra_ruby_aws_spec.rb
@@ -165,6 +166,7 @@ files:
165
166
  - spec/lib/defra_ruby/aws/response_spec.rb
166
167
  - spec/lib/defra_ruby/aws/services/bucket_loader_service_spec.rb
167
168
  - spec/lib/defra_ruby/aws/services/delete_file_from_bucket_service_spec.rb
169
+ - spec/lib/defra_ruby/aws/services/list_bucket_files_service_spec.rb
168
170
  - spec/lib/defra_ruby/aws/services/presigned_url_service_spec.rb
169
171
  - spec/spec_helper.rb
170
172
  - spec/support/aws_sdk_s3.rb
@@ -178,7 +180,7 @@ licenses:
178
180
  - The Open Government Licence (OGL) Version 3
179
181
  metadata:
180
182
  allowed_push_host: https://rubygems.org
181
- post_install_message:
183
+ post_install_message:
182
184
  rdoc_options: []
183
185
  require_paths:
184
186
  - lib
@@ -194,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
196
  version: '0'
195
197
  requirements: []
196
198
  rubygems_version: 3.1.2
197
- signing_key:
199
+ signing_key:
198
200
  specification_version: 4
199
201
  summary: Defra ruby on rails AWS helpers
200
202
  test_files:
@@ -214,3 +216,4 @@ test_files:
214
216
  - spec/lib/defra_ruby/aws/services/bucket_loader_service_spec.rb
215
217
  - spec/lib/defra_ruby/aws/services/delete_file_from_bucket_service_spec.rb
216
218
  - spec/lib/defra_ruby/aws/services/presigned_url_service_spec.rb
219
+ - spec/lib/defra_ruby/aws/services/list_bucket_files_service_spec.rb