defra_ruby_aws 0.3.1 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/defra_ruby/aws/bucket.rb +6 -6
- data/lib/defra_ruby/aws/services/bucket_loader_service.rb +10 -5
- data/lib/defra_ruby/aws/services/delete_file_from_bucket_service.rb +10 -5
- data/lib/defra_ruby/aws/services/presigned_url_service.rb +10 -5
- data/lib/defra_ruby/aws/version.rb +1 -1
- data/spec/examples.txt +45 -40
- data/spec/lib/defra_ruby/aws/bucket_spec.rb +3 -2
- data/spec/lib/defra_ruby/aws/services/bucket_loader_service_spec.rb +36 -0
- data/spec/lib/defra_ruby/aws/services/delete_file_from_bucket_service_spec.rb +38 -0
- data/spec/lib/defra_ruby/aws/services/presigned_url_service_spec.rb +13 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e35f8c64d2e528faf5a59987c833be7a8c53c5a68694fe842f042ae1ec174f82
|
4
|
+
data.tar.gz: acadc8305a896c1895f7cdbba00cb0e3181e9caf0693b31c89b5f06d141b5e3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfc64c44e01e4f61df59a018aeba7054c34ca061a60406b17e41267467689df4bc0d5c1496eed445ec823cbdbf1b8cce8aafec25935b175ad5a5df9f52c564e5
|
7
|
+
data.tar.gz: 5113bbd9312b32f23a6a0b725d64cf94c73714ae1c8e03675166f2b7f8679a95032478f38373970b23f85db04b0e448099aadc6590362509dbc7b20fb1972349
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Defra Ruby Aws
|
2
2
|
|
3
|
-
|
3
|
+
![Build Status](https://github.com/DEFRA/defra-ruby-aws/workflows/CI/badge.svg?branch=main)
|
4
4
|
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=DEFRA_defra-ruby-aws&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=DEFRA_defra-ruby-aws)
|
5
5
|
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=DEFRA_defra-ruby-aws&metric=coverage)](https://sonarcloud.io/dashboard?id=DEFRA_defra-ruby-aws)
|
6
6
|
[![security](https://hakiri.io/github/DEFRA/defra-ruby-aws/main.svg)](https://hakiri.io/github/DEFRA/defra-ruby-aws/main)
|
@@ -26,16 +26,16 @@ module DefraRuby
|
|
26
26
|
@_encryption_type ||= @encrypt_with_kms ? "aws:kms" : :AES256
|
27
27
|
end
|
28
28
|
|
29
|
-
def load(file)
|
30
|
-
BucketLoaderService.run(self, file)
|
29
|
+
def load(file, options = {})
|
30
|
+
BucketLoaderService.run(self, file, options)
|
31
31
|
end
|
32
32
|
|
33
|
-
def presigned_url(file_name)
|
34
|
-
PresignedUrlService.run(self, file_name)
|
33
|
+
def presigned_url(file_name, options = {})
|
34
|
+
PresignedUrlService.run(self, file_name, options)
|
35
35
|
end
|
36
36
|
|
37
|
-
def delete(file_name)
|
38
|
-
DeleteFileFromBucketService.run(self, file_name)
|
37
|
+
def delete(file_name, options = {})
|
38
|
+
DeleteFileFromBucketService.run(self, file_name, options)
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
@@ -5,13 +5,14 @@ module DefraRuby
|
|
5
5
|
class BucketLoaderService
|
6
6
|
include HasAwsBucketConfiguration
|
7
7
|
|
8
|
-
def self.run(bucket, file)
|
9
|
-
new(bucket, file).run
|
8
|
+
def self.run(bucket, file, options = {})
|
9
|
+
new(bucket, file, options).run
|
10
10
|
end
|
11
11
|
|
12
|
-
def initialize(bucket, file)
|
12
|
+
def initialize(bucket, file, options)
|
13
13
|
@bucket = bucket
|
14
14
|
@file = file
|
15
|
+
@dir = options[:s3_directory]
|
15
16
|
end
|
16
17
|
|
17
18
|
def run
|
@@ -20,15 +21,19 @@ module DefraRuby
|
|
20
21
|
|
21
22
|
private
|
22
23
|
|
23
|
-
attr_reader :bucket, :file
|
24
|
+
attr_reader :bucket, :file, :dir
|
24
25
|
|
25
26
|
def response_exe
|
26
27
|
lambda do
|
27
28
|
s3_bucket
|
28
|
-
.object(
|
29
|
+
.object(destination)
|
29
30
|
.upload_file(file.path, server_side_encryption: bucket.encryption_type)
|
30
31
|
end
|
31
32
|
end
|
33
|
+
|
34
|
+
def destination
|
35
|
+
[*dir, File.basename(file.path)].compact.join("/")
|
36
|
+
end
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
@@ -5,13 +5,14 @@ module DefraRuby
|
|
5
5
|
class DeleteFileFromBucketService
|
6
6
|
include HasAwsBucketConfiguration
|
7
7
|
|
8
|
-
def self.run(bucket, file_name)
|
9
|
-
new(bucket, file_name).run
|
8
|
+
def self.run(bucket, file_name, options = {})
|
9
|
+
new(bucket, file_name, options).run
|
10
10
|
end
|
11
11
|
|
12
|
-
def initialize(bucket, file_name)
|
12
|
+
def initialize(bucket, file_name, options)
|
13
13
|
@bucket = bucket
|
14
14
|
@file_name = file_name
|
15
|
+
@dir = options[:s3_directory]
|
15
16
|
end
|
16
17
|
|
17
18
|
def run
|
@@ -20,15 +21,19 @@ module DefraRuby
|
|
20
21
|
|
21
22
|
private
|
22
23
|
|
23
|
-
attr_reader :bucket, :file_name
|
24
|
+
attr_reader :bucket, :file_name, :dir
|
24
25
|
|
25
26
|
def response_exe
|
26
27
|
lambda do
|
27
|
-
delete_object_output = s3_bucket.object(
|
28
|
+
delete_object_output = s3_bucket.object(destination).delete
|
28
29
|
|
29
30
|
delete_object_output.request_charged.length.positive?
|
30
31
|
end
|
31
32
|
end
|
33
|
+
|
34
|
+
def destination
|
35
|
+
[*dir, file_name].compact.join("/")
|
36
|
+
end
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
@@ -5,17 +5,18 @@ module DefraRuby
|
|
5
5
|
class PresignedUrlService
|
6
6
|
include HasAwsBucketConfiguration
|
7
7
|
|
8
|
-
def self.run(bucket, file_name)
|
9
|
-
new(bucket, file_name).run
|
8
|
+
def self.run(bucket, file_name, options = {})
|
9
|
+
new(bucket, file_name, options).run
|
10
10
|
end
|
11
11
|
|
12
|
-
def initialize(bucket, file_name)
|
12
|
+
def initialize(bucket, file_name, options)
|
13
13
|
@bucket = bucket
|
14
14
|
@file_name = file_name
|
15
|
+
@dir = options[:s3_directory]
|
15
16
|
end
|
16
17
|
|
17
18
|
def run
|
18
|
-
s3_bucket.object(
|
19
|
+
s3_bucket.object(destination).presigned_url(
|
19
20
|
:get,
|
20
21
|
expires_in: 20 * 60, # 20 minutes in seconds
|
21
22
|
secure: true,
|
@@ -26,7 +27,11 @@ module DefraRuby
|
|
26
27
|
|
27
28
|
private
|
28
29
|
|
29
|
-
attr_reader :bucket, :file_name
|
30
|
+
attr_reader :bucket, :file_name, :dir
|
31
|
+
|
32
|
+
def destination
|
33
|
+
[*dir, file_name].compact.join("/")
|
34
|
+
end
|
30
35
|
end
|
31
36
|
end
|
32
37
|
end
|
data/spec/examples.txt
CHANGED
@@ -1,40 +1,45 @@
|
|
1
|
-
example_id
|
2
|
-
|
3
|
-
./spec/defra_ruby_aws_spec.rb[1:1]
|
4
|
-
./spec/features/upload_file_to_bucket_spec.rb[1:1]
|
5
|
-
./spec/features/upload_file_to_bucket_spec.rb[1:2]
|
6
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:1:1]
|
7
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:2:1]
|
8
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:3:1]
|
9
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:4:1]
|
10
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:5:1:1]
|
11
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:5:2:1]
|
12
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:6:1]
|
13
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:7:1:1]
|
14
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:7:1:2]
|
15
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:7:2:1]
|
16
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:7:2:2]
|
17
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:1:1]
|
18
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:1:2]
|
19
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:2:1]
|
20
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:2:2]
|
21
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:3:1]
|
22
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:3:2]
|
23
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:4:1]
|
24
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:4:2]
|
25
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:5:1]
|
26
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:1:8:5:2]
|
27
|
-
./spec/lib/defra_ruby/aws/bucket_spec.rb[1:2:1]
|
28
|
-
./spec/lib/defra_ruby/aws/configuration_spec.rb[1:1:1]
|
29
|
-
./spec/lib/defra_ruby/aws/response_spec.rb[1:1:1:1]
|
30
|
-
./spec/lib/defra_ruby/aws/response_spec.rb[1:1:2:1]
|
31
|
-
./spec/lib/defra_ruby/aws/response_spec.rb[1:1:3:1]
|
32
|
-
./spec/lib/defra_ruby/aws/response_spec.rb[1:1:4:1]
|
33
|
-
./spec/lib/defra_ruby/aws/response_spec.rb[1:1:5:1]
|
34
|
-
./spec/lib/defra_ruby/aws/response_spec.rb[1:2:1:1]
|
35
|
-
./spec/lib/defra_ruby/aws/response_spec.rb[1:2:2:1]
|
36
|
-
./spec/lib/defra_ruby/aws/services/bucket_loader_service_spec.rb[1:1:1:1]
|
37
|
-
./spec/lib/defra_ruby/aws/services/bucket_loader_service_spec.rb[1:1:2:1] | passed | 0.
|
38
|
-
./spec/lib/defra_ruby/aws/services/
|
39
|
-
./spec/lib/defra_ruby/aws/services/
|
40
|
-
./spec/lib/defra_ruby/aws/services/
|
1
|
+
example_id | status | run_time |
|
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 |
|
@@ -230,9 +230,10 @@ module DefraRuby
|
|
230
230
|
it "loads the given file to the s3 bucket" do
|
231
231
|
result = double(:result)
|
232
232
|
file = double(:file)
|
233
|
+
options = double(:options)
|
233
234
|
|
234
|
-
expect(BucketLoaderService).to receive(:run).with(bucket, file).and_return(result)
|
235
|
-
expect(bucket.load(file)).to eq(result)
|
235
|
+
expect(BucketLoaderService).to receive(:run).with(bucket, file, options).and_return(result)
|
236
|
+
expect(bucket.load(file, options)).to eq(result)
|
236
237
|
end
|
237
238
|
end
|
238
239
|
end
|
@@ -32,6 +32,24 @@ module DefraRuby
|
|
32
32
|
|
33
33
|
expect(described_class.run(bucket, file)).to be_a(Response)
|
34
34
|
end
|
35
|
+
|
36
|
+
context "when an s3_directory is provided" do
|
37
|
+
it "loads the given file to the s3 bucket at the correct location using AWS:KMS" do
|
38
|
+
aws_resource = double(:aws_resource)
|
39
|
+
s3_bucket = double(:s3_bulk_bucket)
|
40
|
+
file = double(:file, path: "foo/bar/baz/test.csv")
|
41
|
+
s3_object = double(:s3_object)
|
42
|
+
result = double(:result)
|
43
|
+
options = { s3_directory: "directory" }
|
44
|
+
|
45
|
+
expect(::Aws::S3::Resource).to receive(:new).and_return(aws_resource)
|
46
|
+
expect(aws_resource).to receive(:bucket).with("bulk").and_return(s3_bucket)
|
47
|
+
expect(s3_bucket).to receive(:object).with("directory/test.csv").and_return(s3_object)
|
48
|
+
expect(s3_object).to receive(:upload_file).with("foo/bar/baz/test.csv", server_side_encryption: :AES256).and_return(result)
|
49
|
+
|
50
|
+
expect(described_class.run(bucket, file, options)).to be_a(Response)
|
51
|
+
end
|
52
|
+
end
|
35
53
|
end
|
36
54
|
|
37
55
|
context "when 'encrypt_with_kms' is set" do
|
@@ -57,6 +75,24 @@ module DefraRuby
|
|
57
75
|
|
58
76
|
expect(described_class.run(bucket, file)).to be_a(Response)
|
59
77
|
end
|
78
|
+
|
79
|
+
context "when an s3_directory is provided" do
|
80
|
+
it "loads the given file to the s3 bucket at the correct location using AWS:KMS" do
|
81
|
+
aws_resource = double(:aws_resource)
|
82
|
+
s3_bucket = double(:s3_bulk_bucket)
|
83
|
+
file = double(:file, path: "foo/bar/baz/test.csv")
|
84
|
+
s3_object = double(:s3_object)
|
85
|
+
result = double(:result)
|
86
|
+
options = { s3_directory: %w[directory second_directory] }
|
87
|
+
|
88
|
+
expect(::Aws::S3::Resource).to receive(:new).and_return(aws_resource)
|
89
|
+
expect(aws_resource).to receive(:bucket).with("bulk").and_return(s3_bucket)
|
90
|
+
expect(s3_bucket).to receive(:object).with("directory/second_directory/test.csv").and_return(s3_object)
|
91
|
+
expect(s3_object).to receive(:upload_file).with("foo/bar/baz/test.csv", server_side_encryption: "aws:kms").and_return(result)
|
92
|
+
|
93
|
+
expect(described_class.run(bucket, file, options)).to be_a(Response)
|
94
|
+
end
|
95
|
+
end
|
60
96
|
end
|
61
97
|
end
|
62
98
|
end
|
@@ -33,6 +33,25 @@ module DefraRuby
|
|
33
33
|
expect(response).to be_successful
|
34
34
|
end
|
35
35
|
|
36
|
+
context "when an s3_directory is provided" do
|
37
|
+
it "returns a successful response" do
|
38
|
+
aws_resource = double(:aws_resource)
|
39
|
+
s3_bucket = double(:s3_bulk_bucket)
|
40
|
+
file_name = "test.csv"
|
41
|
+
s3_object = double(:s3_object)
|
42
|
+
result = double(:result, request_charged: "present")
|
43
|
+
options = { s3_directory: "directory" }
|
44
|
+
|
45
|
+
expect(::Aws::S3::Resource).to receive(:new).and_return(aws_resource)
|
46
|
+
expect(aws_resource).to receive(:bucket).with("bulk").and_return(s3_bucket)
|
47
|
+
expect(s3_bucket).to receive(:object).with("directory/test.csv").and_return(s3_object)
|
48
|
+
expect(s3_object).to receive(:delete).and_return(result)
|
49
|
+
|
50
|
+
response = described_class.run(bucket, file_name, options)
|
51
|
+
expect(response).to be_successful
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
36
55
|
context "when the response body returns an empty charged requests" do
|
37
56
|
it "returns a non successful response" do
|
38
57
|
aws_resource = double(:aws_resource)
|
@@ -49,6 +68,25 @@ module DefraRuby
|
|
49
68
|
response = described_class.run(bucket, file_name)
|
50
69
|
expect(response).to_not be_successful
|
51
70
|
end
|
71
|
+
|
72
|
+
context "when an s3_directory is provided" do
|
73
|
+
it "returns a non successful response" do
|
74
|
+
aws_resource = double(:aws_resource)
|
75
|
+
s3_bucket = double(:s3_bulk_bucket)
|
76
|
+
file_name = "test.csv"
|
77
|
+
s3_object = double(:s3_object)
|
78
|
+
result = double(:result, request_charged: "")
|
79
|
+
options = { s3_directory: %w[directory second_directory] }
|
80
|
+
|
81
|
+
expect(::Aws::S3::Resource).to receive(:new).and_return(aws_resource)
|
82
|
+
expect(aws_resource).to receive(:bucket).with("bulk").and_return(s3_bucket)
|
83
|
+
expect(s3_bucket).to receive(:object).with("directory/second_directory/test.csv").and_return(s3_object)
|
84
|
+
expect(s3_object).to receive(:delete).and_return(result)
|
85
|
+
|
86
|
+
response = described_class.run(bucket, file_name, options)
|
87
|
+
expect(response).to_not be_successful
|
88
|
+
end
|
89
|
+
end
|
52
90
|
end
|
53
91
|
end
|
54
92
|
end
|
@@ -26,6 +26,19 @@ module DefraRuby
|
|
26
26
|
expect(presigned_url).to include("Amz-Credential")
|
27
27
|
expect(presigned_url).to include("Amz-Signature")
|
28
28
|
end
|
29
|
+
|
30
|
+
context "when an s3_directory is provided" do
|
31
|
+
let(:presigned_url) { described_class.run(bucket, "testfile.csv", { s3_directory: "directory" }) }
|
32
|
+
|
33
|
+
it "returns a presigned url for a given file in the bucket" do
|
34
|
+
expect(presigned_url).to include("https://test.s3.eu-west-1.amazonaws.com/directory/testfile.csv")
|
35
|
+
expect(presigned_url).to include("response-content-disposition=attachment")
|
36
|
+
expect(presigned_url).to include("response-content-type=text%2Fcsv")
|
37
|
+
expect(presigned_url).to include("Amz-Expires")
|
38
|
+
expect(presigned_url).to include("Amz-Credential")
|
39
|
+
expect(presigned_url).to include("Amz-Signature")
|
40
|
+
end
|
41
|
+
end
|
29
42
|
end
|
30
43
|
end
|
31
44
|
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
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Defra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07
|
11
|
+
date: 2020-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-s3
|
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
requirements: []
|
196
|
-
rubygems_version: 3.
|
196
|
+
rubygems_version: 3.1.2
|
197
197
|
signing_key:
|
198
198
|
specification_version: 4
|
199
199
|
summary: Defra ruby on rails AWS helpers
|