defra_ruby_aws 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/defra_ruby/aws/bucket.rb +1 -9
- data/lib/defra_ruby/aws/services/bucket_loader_service.rb +17 -3
- data/lib/defra_ruby/aws/version.rb +1 -1
- metadata +6 -154
- data/spec/defra_ruby_aws_spec.rb +0 -7
- data/spec/examples.txt +0 -48
- data/spec/features/upload_file_to_bucket_spec.rb +0 -51
- data/spec/lib/defra_ruby/aws/bucket_spec.rb +0 -241
- data/spec/lib/defra_ruby/aws/configuration_spec.rb +0 -23
- data/spec/lib/defra_ruby/aws/response_spec.rb +0 -81
- data/spec/lib/defra_ruby/aws/services/bucket_loader_service_spec.rb +0 -100
- data/spec/lib/defra_ruby/aws/services/delete_file_from_bucket_service_spec.rb +0 -94
- data/spec/lib/defra_ruby/aws/services/list_bucket_files_service_spec.rb +0 -60
- data/spec/lib/defra_ruby/aws/services/presigned_url_service_spec.rb +0 -45
- data/spec/spec_helper.rb +0 -83
- data/spec/support/aws_sdk_s3.rb +0 -4
- data/spec/support/defra_ruby_aws.rb +0 -4
- data/spec/support/dotenv.rb +0 -4
- data/spec/support/pry.rb +0 -7
- data/spec/support/simplecov.rb +0 -17
- data/spec/support/webmock.rb +0 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 615c2177dcd53df53e778f1f66c2b7773bd245cd5944160b8f24a7e077cd2d06
|
|
4
|
+
data.tar.gz: b9ebf33614bb98115f136f23d58038ecbe972d2ed0b4cd483b1dd9a2bc277179
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4badfeadc9868a51e4b17095bd32c2a322a457eadfb2d04df77ee7ce5c63a3ba4851c81daaca0a08e7343e0c1509e8cb0d64f59a108460098652f1a671917502
|
|
7
|
+
data.tar.gz: 730b22d1f17c17ac76b8d314eb8c3f80f4c7b0e47b321019a3e8bb0f4e28a779a59b8ea44cb8c377e59827418621f6dde9916ca256760c019a0559de04cb792f
|
|
@@ -9,7 +9,7 @@ module DefraRuby
|
|
|
9
9
|
@credentials = configs[:credentials]
|
|
10
10
|
@bucket_name = configs[:name]
|
|
11
11
|
@region = setup_region(configs[:region])
|
|
12
|
-
@encrypt_with_kms =
|
|
12
|
+
@encrypt_with_kms = configs[:encrypt_with_kms].to_s.downcase == "true"
|
|
13
13
|
|
|
14
14
|
validate!
|
|
15
15
|
end
|
|
@@ -56,14 +56,6 @@ module DefraRuby
|
|
|
56
56
|
"eu-west-1"
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
def setup_encrypt_with_kms(encrypt_with_kms)
|
|
60
|
-
return false if encrypt_with_kms.nil?
|
|
61
|
-
|
|
62
|
-
# Handle the argument being either a string or a boolean, or some other
|
|
63
|
-
# value e.g. "foo"
|
|
64
|
-
encrypt_with_kms.to_s.downcase == "true"
|
|
65
|
-
end
|
|
66
|
-
|
|
67
59
|
def validate!
|
|
68
60
|
validate_presence_of_name!
|
|
69
61
|
validate_presence_of_credentials!
|
|
@@ -25,12 +25,26 @@ module DefraRuby
|
|
|
25
25
|
|
|
26
26
|
def response_exe
|
|
27
27
|
lambda do
|
|
28
|
-
|
|
29
|
-
.
|
|
30
|
-
|
|
28
|
+
transfer_manager.upload_file(
|
|
29
|
+
file.path,
|
|
30
|
+
bucket: bucket.bucket_name,
|
|
31
|
+
key: destination,
|
|
32
|
+
server_side_encryption: bucket.encryption_type
|
|
33
|
+
)
|
|
31
34
|
end
|
|
32
35
|
end
|
|
33
36
|
|
|
37
|
+
def transfer_manager
|
|
38
|
+
::Aws::S3::TransferManager.new(client: s3_client)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def s3_client
|
|
42
|
+
::Aws::S3::Client.new(
|
|
43
|
+
region: bucket.region,
|
|
44
|
+
credentials: aws_credentials
|
|
45
|
+
)
|
|
46
|
+
end
|
|
47
|
+
|
|
34
48
|
def destination
|
|
35
49
|
[*dir, File.basename(file.path)].compact.join("/")
|
|
36
50
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
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.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Defra
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: aws-sdk-s3
|
|
@@ -24,118 +23,6 @@ dependencies:
|
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '0'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: defra_ruby_style
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - ">="
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: dotenv
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - ">="
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '0'
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - ">="
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '0'
|
|
55
|
-
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: github_changelog_generator
|
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
|
58
|
-
requirements:
|
|
59
|
-
- - ">="
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0'
|
|
62
|
-
type: :development
|
|
63
|
-
prerelease: false
|
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
-
requirements:
|
|
66
|
-
- - ">="
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0'
|
|
69
|
-
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: pry-byebug
|
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
|
72
|
-
requirements:
|
|
73
|
-
- - ">="
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
version: '0'
|
|
76
|
-
type: :development
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - ">="
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: '0'
|
|
83
|
-
- !ruby/object:Gem::Dependency
|
|
84
|
-
name: rake
|
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
|
86
|
-
requirements:
|
|
87
|
-
- - ">="
|
|
88
|
-
- !ruby/object:Gem::Version
|
|
89
|
-
version: '0'
|
|
90
|
-
type: :development
|
|
91
|
-
prerelease: false
|
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
-
requirements:
|
|
94
|
-
- - ">="
|
|
95
|
-
- !ruby/object:Gem::Version
|
|
96
|
-
version: '0'
|
|
97
|
-
- !ruby/object:Gem::Dependency
|
|
98
|
-
name: rspec
|
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
|
100
|
-
requirements:
|
|
101
|
-
- - "~>"
|
|
102
|
-
- !ruby/object:Gem::Version
|
|
103
|
-
version: '3.0'
|
|
104
|
-
type: :development
|
|
105
|
-
prerelease: false
|
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
-
requirements:
|
|
108
|
-
- - "~>"
|
|
109
|
-
- !ruby/object:Gem::Version
|
|
110
|
-
version: '3.0'
|
|
111
|
-
- !ruby/object:Gem::Dependency
|
|
112
|
-
name: simplecov
|
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
|
114
|
-
requirements:
|
|
115
|
-
- - "~>"
|
|
116
|
-
- !ruby/object:Gem::Version
|
|
117
|
-
version: 0.17.1
|
|
118
|
-
type: :development
|
|
119
|
-
prerelease: false
|
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
-
requirements:
|
|
122
|
-
- - "~>"
|
|
123
|
-
- !ruby/object:Gem::Version
|
|
124
|
-
version: 0.17.1
|
|
125
|
-
- !ruby/object:Gem::Dependency
|
|
126
|
-
name: webmock
|
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
|
128
|
-
requirements:
|
|
129
|
-
- - ">="
|
|
130
|
-
- !ruby/object:Gem::Version
|
|
131
|
-
version: '0'
|
|
132
|
-
type: :development
|
|
133
|
-
prerelease: false
|
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
-
requirements:
|
|
136
|
-
- - ">="
|
|
137
|
-
- !ruby/object:Gem::Version
|
|
138
|
-
version: '0'
|
|
139
26
|
description: Package of AWS features commonly used in Defra Rails based digital services
|
|
140
27
|
email:
|
|
141
28
|
- alan.cruikshanks@environment-agency.gov.uk
|
|
@@ -158,29 +45,12 @@ files:
|
|
|
158
45
|
- lib/defra_ruby/aws/services/list_bucket_files_service.rb
|
|
159
46
|
- lib/defra_ruby/aws/services/presigned_url_service.rb
|
|
160
47
|
- lib/defra_ruby/aws/version.rb
|
|
161
|
-
- spec/defra_ruby_aws_spec.rb
|
|
162
|
-
- spec/examples.txt
|
|
163
|
-
- spec/features/upload_file_to_bucket_spec.rb
|
|
164
|
-
- spec/lib/defra_ruby/aws/bucket_spec.rb
|
|
165
|
-
- spec/lib/defra_ruby/aws/configuration_spec.rb
|
|
166
|
-
- spec/lib/defra_ruby/aws/response_spec.rb
|
|
167
|
-
- spec/lib/defra_ruby/aws/services/bucket_loader_service_spec.rb
|
|
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
|
|
170
|
-
- spec/lib/defra_ruby/aws/services/presigned_url_service_spec.rb
|
|
171
|
-
- spec/spec_helper.rb
|
|
172
|
-
- spec/support/aws_sdk_s3.rb
|
|
173
|
-
- spec/support/defra_ruby_aws.rb
|
|
174
|
-
- spec/support/dotenv.rb
|
|
175
|
-
- spec/support/pry.rb
|
|
176
|
-
- spec/support/simplecov.rb
|
|
177
|
-
- spec/support/webmock.rb
|
|
178
48
|
homepage: https://github.com/DEFRA/defra-ruby-aws
|
|
179
49
|
licenses:
|
|
180
|
-
-
|
|
50
|
+
- Open Government Licence v3.0
|
|
181
51
|
metadata:
|
|
182
52
|
allowed_push_host: https://rubygems.org
|
|
183
|
-
|
|
53
|
+
rubygems_mfa_required: 'true'
|
|
184
54
|
rdoc_options: []
|
|
185
55
|
require_paths:
|
|
186
56
|
- lib
|
|
@@ -195,25 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
195
65
|
- !ruby/object:Gem::Version
|
|
196
66
|
version: '0'
|
|
197
67
|
requirements: []
|
|
198
|
-
rubygems_version: 3.
|
|
199
|
-
signing_key:
|
|
68
|
+
rubygems_version: 3.6.9
|
|
200
69
|
specification_version: 4
|
|
201
70
|
summary: Defra ruby on rails AWS helpers
|
|
202
|
-
test_files:
|
|
203
|
-
- spec/defra_ruby_aws_spec.rb
|
|
204
|
-
- spec/spec_helper.rb
|
|
205
|
-
- spec/examples.txt
|
|
206
|
-
- spec/features/upload_file_to_bucket_spec.rb
|
|
207
|
-
- spec/support/defra_ruby_aws.rb
|
|
208
|
-
- spec/support/aws_sdk_s3.rb
|
|
209
|
-
- spec/support/simplecov.rb
|
|
210
|
-
- spec/support/webmock.rb
|
|
211
|
-
- spec/support/pry.rb
|
|
212
|
-
- spec/support/dotenv.rb
|
|
213
|
-
- spec/lib/defra_ruby/aws/configuration_spec.rb
|
|
214
|
-
- spec/lib/defra_ruby/aws/response_spec.rb
|
|
215
|
-
- spec/lib/defra_ruby/aws/bucket_spec.rb
|
|
216
|
-
- spec/lib/defra_ruby/aws/services/bucket_loader_service_spec.rb
|
|
217
|
-
- spec/lib/defra_ruby/aws/services/delete_file_from_bucket_service_spec.rb
|
|
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
|
|
71
|
+
test_files: []
|
data/spec/defra_ruby_aws_spec.rb
DELETED
data/spec/examples.txt
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
example_id | status | run_time |
|
|
2
|
-
------------------------------------------------------------------------------------- | ------ | --------------- |
|
|
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 |
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.describe "Defra Ruby AWS" do
|
|
6
|
-
it "Upload a file to an AWS bucket" do
|
|
7
|
-
configure_gem
|
|
8
|
-
stub_successful_request
|
|
9
|
-
|
|
10
|
-
bucket = DefraRuby::Aws.get_bucket("bulk-test")
|
|
11
|
-
response = bucket.load(Tempfile.new("test-bucket-load.test"))
|
|
12
|
-
|
|
13
|
-
expect(response).to be_successful
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "fails gracefully" do
|
|
17
|
-
configure_gem
|
|
18
|
-
stub_failing_request
|
|
19
|
-
|
|
20
|
-
bucket = DefraRuby::Aws.get_bucket("bulk-test")
|
|
21
|
-
response = bucket.load(Tempfile.new("test-bucket-load.test"))
|
|
22
|
-
|
|
23
|
-
expect(response).to_not be_successful
|
|
24
|
-
expect(response.error).to be_a(Aws::S3::Errors::Forbidden)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def configure_gem
|
|
28
|
-
DefraRuby::Aws.configure do |config|
|
|
29
|
-
config.buckets = [{
|
|
30
|
-
name: "bulk-test",
|
|
31
|
-
credentials: {
|
|
32
|
-
access_key_id: "ACCESS_KEY_ID",
|
|
33
|
-
secret_access_key: "SECRET_ACCESS_KEY"
|
|
34
|
-
}
|
|
35
|
-
}]
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def stub_successful_request
|
|
40
|
-
stub_request(:put, %r{https://bulk-test\.s3\.eu-west-1\.amazonaws\.com/test-bucket-load\..+})
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def stub_failing_request
|
|
44
|
-
stub_request(
|
|
45
|
-
:put,
|
|
46
|
-
%r{https://bulk-test\.s3\.eu-west-1\.amazonaws\.com/test-bucket-load\..+}
|
|
47
|
-
).to_return(
|
|
48
|
-
status: 403
|
|
49
|
-
)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
module DefraRuby
|
|
6
|
-
module Aws
|
|
7
|
-
RSpec.describe Bucket do
|
|
8
|
-
subject(:bucket) { described_class.new(configs) }
|
|
9
|
-
|
|
10
|
-
let(:credentials) { { access_key_id: "access_key", secret_access_key: "secret" } }
|
|
11
|
-
|
|
12
|
-
describe "#initialize" do
|
|
13
|
-
context "when a name configuration is missing" do
|
|
14
|
-
let(:configs) do
|
|
15
|
-
{
|
|
16
|
-
name: nil,
|
|
17
|
-
credentials: {}
|
|
18
|
-
}
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "raises an error" do
|
|
22
|
-
expect { bucket }.to raise_error("DefraRuby::Aws buckets configurations: missing bucket name")
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
context "when credentials configuration is missing" do
|
|
27
|
-
let(:configs) do
|
|
28
|
-
{
|
|
29
|
-
name: "foo",
|
|
30
|
-
credentials: {}
|
|
31
|
-
}
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "raises an error" do
|
|
35
|
-
expect { bucket }.to raise_error("DefraRuby::Aws buckets configurations: missing credentials for bucket foo")
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
context "when credentials access key id is missing" do
|
|
40
|
-
let(:configs) do
|
|
41
|
-
{
|
|
42
|
-
name: "foo",
|
|
43
|
-
credentials: {
|
|
44
|
-
secret_access_key: "secret"
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "raises an error" do
|
|
50
|
-
expect { bucket }.to raise_error("DefraRuby::Aws buckets configurations: missing access key id for bucket foo")
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
context "when credentials secret access key is missing" do
|
|
55
|
-
let(:configs) do
|
|
56
|
-
{
|
|
57
|
-
name: "foo",
|
|
58
|
-
credentials: {
|
|
59
|
-
access_key_id: "access_key"
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it "raises an error" do
|
|
65
|
-
expect { bucket }.to raise_error("DefraRuby::Aws buckets configurations: missing secret access key for bucket foo")
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
context "when 'region' is not set" do
|
|
70
|
-
context "because it has not been added to the config" do
|
|
71
|
-
let(:configs) do
|
|
72
|
-
{
|
|
73
|
-
name: "foo",
|
|
74
|
-
credentials: credentials
|
|
75
|
-
}
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it "defaults the region to 'eu-west-1'" do
|
|
79
|
-
expect(bucket.region).to eq("eu-west-1")
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
context "because its value is an empty string" do
|
|
84
|
-
let(:configs) do
|
|
85
|
-
{
|
|
86
|
-
name: "foo",
|
|
87
|
-
credentials: credentials,
|
|
88
|
-
region: ""
|
|
89
|
-
}
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
it "defaults the region to 'eu-west-1'" do
|
|
93
|
-
expect(bucket.region).to eq("eu-west-1")
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
context "when 'region' is set" do
|
|
99
|
-
let(:region) { "eu-west-2" }
|
|
100
|
-
let(:configs) do
|
|
101
|
-
{
|
|
102
|
-
name: "foo",
|
|
103
|
-
credentials: credentials,
|
|
104
|
-
region: region
|
|
105
|
-
}
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
it "sets the region to match" do
|
|
109
|
-
expect(bucket.region).to eq(region)
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
context "when 'encrypt_with_kms' is not set" do
|
|
114
|
-
context "because it has not been added to the config" do
|
|
115
|
-
let(:configs) do
|
|
116
|
-
{
|
|
117
|
-
name: "foo",
|
|
118
|
-
credentials: credentials
|
|
119
|
-
}
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
it "defaults encrypt_with_kms to false" do
|
|
123
|
-
expect(bucket.encrypt_with_kms).to be false
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
it "sets encryption_type to :AES256" do
|
|
127
|
-
expect(bucket.encryption_type).to eq(:AES256)
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
context "because its value is an empty string" do
|
|
132
|
-
let(:configs) do
|
|
133
|
-
{
|
|
134
|
-
name: "foo",
|
|
135
|
-
credentials: credentials,
|
|
136
|
-
encrypt_with_kms: ""
|
|
137
|
-
}
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
it "defaults encrypt_with_kms to false" do
|
|
141
|
-
expect(bucket.encrypt_with_kms).to be false
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
it "sets encryption_type to :AES256" do
|
|
145
|
-
expect(bucket.encryption_type).to eq(:AES256)
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
context "when 'encrypt_with_kms' is set" do
|
|
151
|
-
let(:encrypt_with_kms) { true }
|
|
152
|
-
let(:configs) do
|
|
153
|
-
{
|
|
154
|
-
name: "foo",
|
|
155
|
-
credentials: credentials,
|
|
156
|
-
encrypt_with_kms: encrypt_with_kms
|
|
157
|
-
}
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
context "to true as a boolean" do
|
|
161
|
-
let(:encrypt_with_kms) { true }
|
|
162
|
-
|
|
163
|
-
it "defaults encrypt_with_kms to true" do
|
|
164
|
-
expect(bucket.encrypt_with_kms).to be true
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
it "sets encryption_type to aws:kms" do
|
|
168
|
-
expect(bucket.encryption_type).to eq("aws:kms")
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
context "to true as a string" do
|
|
173
|
-
let(:encrypt_with_kms) { "true" }
|
|
174
|
-
|
|
175
|
-
it "defaults encrypt_with_kms to true" do
|
|
176
|
-
expect(bucket.encrypt_with_kms).to be true
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
it "sets encryption_type to aws:kms" do
|
|
180
|
-
expect(bucket.encryption_type).to eq("aws:kms")
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
context "to false as a boolean" do
|
|
185
|
-
let(:encrypt_with_kms) { false }
|
|
186
|
-
|
|
187
|
-
it "defaults encrypt_with_kms to false" do
|
|
188
|
-
expect(bucket.encrypt_with_kms).to be false
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
it "sets encryption_type to aws:kms" do
|
|
192
|
-
expect(bucket.encryption_type).to eq(:AES256)
|
|
193
|
-
end
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
context "to false as a string" do
|
|
197
|
-
let(:encrypt_with_kms) { "false" }
|
|
198
|
-
|
|
199
|
-
it "defaults encrypt_with_kms to false" do
|
|
200
|
-
expect(bucket.encrypt_with_kms).to be false
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
it "sets encryption_type to aws:kms" do
|
|
204
|
-
expect(bucket.encryption_type).to eq(:AES256)
|
|
205
|
-
end
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
context "to something not recognised" do
|
|
209
|
-
let(:encrypt_with_kms) { "bar" }
|
|
210
|
-
|
|
211
|
-
it "defaults encrypt_with_kms to false" do
|
|
212
|
-
expect(bucket.encrypt_with_kms).to be false
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
it "sets encryption_type to :AES256" do
|
|
216
|
-
expect(bucket.encryption_type).to eq(:AES256)
|
|
217
|
-
end
|
|
218
|
-
end
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
describe "#load" do
|
|
223
|
-
let(:configs) do
|
|
224
|
-
{
|
|
225
|
-
name: "foo",
|
|
226
|
-
credentials: credentials
|
|
227
|
-
}
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
it "loads the given file to the s3 bucket" do
|
|
231
|
-
result = double(:result)
|
|
232
|
-
file = double(:file)
|
|
233
|
-
options = double(:options)
|
|
234
|
-
|
|
235
|
-
expect(BucketLoaderService).to receive(:run).with(bucket, file, options).and_return(result)
|
|
236
|
-
expect(bucket.load(file, options)).to eq(result)
|
|
237
|
-
end
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
-
end
|
|
241
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
module DefraRuby
|
|
6
|
-
module Aws
|
|
7
|
-
RSpec.describe Configuration do
|
|
8
|
-
subject(:configuration) { described_class.new }
|
|
9
|
-
|
|
10
|
-
describe "#buckets=" do
|
|
11
|
-
let(:buckets) { %i[foo bar baz] }
|
|
12
|
-
|
|
13
|
-
it "creates a list of buckets" do
|
|
14
|
-
expect(Bucket).to receive(:new).with(:foo)
|
|
15
|
-
expect(Bucket).to receive(:new).with(:bar)
|
|
16
|
-
expect(Bucket).to receive(:new).with(:baz)
|
|
17
|
-
|
|
18
|
-
configuration.buckets = buckets
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
module DefraRuby
|
|
6
|
-
module Aws
|
|
7
|
-
RSpec.describe Response do
|
|
8
|
-
subject(:response) { described_class.new(response_exe) }
|
|
9
|
-
|
|
10
|
-
describe "#successful?" do
|
|
11
|
-
context "when the response throws an error" do
|
|
12
|
-
let(:response_exe) { -> { raise "Boom!" } }
|
|
13
|
-
|
|
14
|
-
it "returns false" do
|
|
15
|
-
expect(response).to_not be_successful
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
context "when the response don't throw an error" do
|
|
20
|
-
let(:response_exe) { -> { true } }
|
|
21
|
-
|
|
22
|
-
it "returns true" do
|
|
23
|
-
expect(response).to be_successful
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context "when the response returns a nil object" do
|
|
28
|
-
let(:response_exe) { -> { nil } }
|
|
29
|
-
|
|
30
|
-
it "returns false" do
|
|
31
|
-
expect(response).to_not be_successful
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
context "when the response returns false" do
|
|
36
|
-
let(:response_exe) { -> { false } }
|
|
37
|
-
|
|
38
|
-
it "returns false" do
|
|
39
|
-
expect(response).to_not be_successful
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
context "when the response returns an object" do
|
|
44
|
-
let(:response_exe) { -> { "I am an object" } }
|
|
45
|
-
|
|
46
|
-
it "returns true" do
|
|
47
|
-
expect(response).to be_successful
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
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
|
-
|
|
62
|
-
describe "#error" do
|
|
63
|
-
context "when the response throws an error" do
|
|
64
|
-
let(:response_exe) { -> { raise StandardError, "Boom!" } }
|
|
65
|
-
|
|
66
|
-
it "returns the error" do
|
|
67
|
-
expect(response.error).to be_a(StandardError)
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
context "when the response don't throw an error" do
|
|
72
|
-
let(:response_exe) { -> { true } }
|
|
73
|
-
|
|
74
|
-
it "returns a nil object" do
|
|
75
|
-
expect(response.error).to be_nil
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
module DefraRuby
|
|
6
|
-
module Aws
|
|
7
|
-
RSpec.describe BucketLoaderService do
|
|
8
|
-
|
|
9
|
-
describe "#run" do
|
|
10
|
-
let(:credentials) { { access_key_id: "key_id", secret_access_key: "secret" } }
|
|
11
|
-
let(:bucket) { Bucket.new(configs) }
|
|
12
|
-
|
|
13
|
-
context "when 'encrypt_with_kms' is not set" do
|
|
14
|
-
let(:configs) do
|
|
15
|
-
{
|
|
16
|
-
credentials: credentials,
|
|
17
|
-
name: "bulk"
|
|
18
|
-
}
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "loads the given file to the s3 bucket using :AES256" do
|
|
22
|
-
aws_resource = double(:aws_resource)
|
|
23
|
-
s3_bucket = double(:s3_bulk_bucket)
|
|
24
|
-
file = double(:file, path: "foo/bar/baz/test.csv")
|
|
25
|
-
s3_object = double(:s3_object)
|
|
26
|
-
result = double(:result)
|
|
27
|
-
|
|
28
|
-
expect(::Aws::S3::Resource).to receive(:new).and_return(aws_resource)
|
|
29
|
-
expect(aws_resource).to receive(:bucket).with("bulk").and_return(s3_bucket)
|
|
30
|
-
expect(s3_bucket).to receive(:object).with("test.csv").and_return(s3_object)
|
|
31
|
-
expect(s3_object).to receive(:upload_file).with("foo/bar/baz/test.csv", server_side_encryption: :AES256).and_return(result)
|
|
32
|
-
|
|
33
|
-
expect(described_class.run(bucket, file)).to be_a(Response)
|
|
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
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
context "when 'encrypt_with_kms' is set" do
|
|
56
|
-
let(:configs) do
|
|
57
|
-
{
|
|
58
|
-
credentials: credentials,
|
|
59
|
-
name: "bulk",
|
|
60
|
-
encrypt_with_kms: true
|
|
61
|
-
}
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it "loads the given file to the s3 bucket using AWS:KMS" do
|
|
65
|
-
aws_resource = double(:aws_resource)
|
|
66
|
-
s3_bucket = double(:s3_bulk_bucket)
|
|
67
|
-
file = double(:file, path: "foo/bar/baz/test.csv")
|
|
68
|
-
s3_object = double(:s3_object)
|
|
69
|
-
result = double(:result)
|
|
70
|
-
|
|
71
|
-
expect(::Aws::S3::Resource).to receive(:new).and_return(aws_resource)
|
|
72
|
-
expect(aws_resource).to receive(:bucket).with("bulk").and_return(s3_bucket)
|
|
73
|
-
expect(s3_bucket).to receive(:object).with("test.csv").and_return(s3_object)
|
|
74
|
-
expect(s3_object).to receive(:upload_file).with("foo/bar/baz/test.csv", server_side_encryption: "aws:kms").and_return(result)
|
|
75
|
-
|
|
76
|
-
expect(described_class.run(bucket, file)).to be_a(Response)
|
|
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
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
module DefraRuby
|
|
6
|
-
module Aws
|
|
7
|
-
RSpec.describe DeleteFileFromBucketService 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
|
-
it "returns a successful response" do
|
|
21
|
-
aws_resource = double(:aws_resource)
|
|
22
|
-
s3_bucket = double(:s3_bulk_bucket)
|
|
23
|
-
file_name = "test.csv"
|
|
24
|
-
s3_object = double(:s3_object)
|
|
25
|
-
result = double(:result, request_charged: "present")
|
|
26
|
-
|
|
27
|
-
expect(::Aws::S3::Resource).to receive(:new).and_return(aws_resource)
|
|
28
|
-
expect(aws_resource).to receive(:bucket).with("bulk").and_return(s3_bucket)
|
|
29
|
-
expect(s3_bucket).to receive(:object).with("test.csv").and_return(s3_object)
|
|
30
|
-
expect(s3_object).to receive(:delete).and_return(result)
|
|
31
|
-
|
|
32
|
-
response = described_class.run(bucket, file_name)
|
|
33
|
-
expect(response).to be_successful
|
|
34
|
-
end
|
|
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
|
-
|
|
55
|
-
context "when the response body returns an empty charged requests" do
|
|
56
|
-
it "returns a non successful response" do
|
|
57
|
-
aws_resource = double(:aws_resource)
|
|
58
|
-
s3_bucket = double(:s3_bulk_bucket)
|
|
59
|
-
file_name = "test.csv"
|
|
60
|
-
s3_object = double(:s3_object)
|
|
61
|
-
result = double(:result, request_charged: "")
|
|
62
|
-
|
|
63
|
-
expect(::Aws::S3::Resource).to receive(:new).and_return(aws_resource)
|
|
64
|
-
expect(aws_resource).to receive(:bucket).with("bulk").and_return(s3_bucket)
|
|
65
|
-
expect(s3_bucket).to receive(:object).with("test.csv").and_return(s3_object)
|
|
66
|
-
expect(s3_object).to receive(:delete).and_return(result)
|
|
67
|
-
|
|
68
|
-
response = described_class.run(bucket, file_name)
|
|
69
|
-
expect(response).to_not be_successful
|
|
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
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
@@ -1,60 +0,0 @@
|
|
|
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
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
module DefraRuby
|
|
6
|
-
module Aws
|
|
7
|
-
RSpec.describe PresignedUrlService do
|
|
8
|
-
describe ".run" do
|
|
9
|
-
let(:configs) do
|
|
10
|
-
{
|
|
11
|
-
name: "test",
|
|
12
|
-
credentials: {
|
|
13
|
-
access_key_id: "123",
|
|
14
|
-
secret_access_key: "Secret"
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
end
|
|
18
|
-
let(:bucket) { Bucket.new(configs) }
|
|
19
|
-
let(:presigned_url) { described_class.run(bucket, "testfile.csv") }
|
|
20
|
-
|
|
21
|
-
it "returns a presigned url for a given file in the bucket" do
|
|
22
|
-
expect(presigned_url).to include("https://test.s3.eu-west-1.amazonaws.com/testfile.csv")
|
|
23
|
-
expect(presigned_url).to include("response-content-disposition=attachment")
|
|
24
|
-
expect(presigned_url).to include("response-content-type=text%2Fcsv")
|
|
25
|
-
expect(presigned_url).to include("Amz-Expires")
|
|
26
|
-
expect(presigned_url).to include("Amz-Credential")
|
|
27
|
-
expect(presigned_url).to include("Amz-Signature")
|
|
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
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "bundler/setup"
|
|
4
|
-
|
|
5
|
-
# Require and run our simplecov initializer as the very first thing we do.
|
|
6
|
-
# This is as per its docs https://github.com/colszowka/simplecov#getting-started
|
|
7
|
-
require "./spec/support/simplecov"
|
|
8
|
-
|
|
9
|
-
# Requires supporting ruby files with custom matchers and macros, etc, in
|
|
10
|
-
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
|
11
|
-
# run as spec files by default. This means that files in spec/support that end
|
|
12
|
-
# in _spec.rb will both be required and run as specs, causing the specs to be
|
|
13
|
-
# run twice. It is recommended that you do not name files matching this glob to
|
|
14
|
-
# end with _spec.rb. You can configure this pattern with the --pattern
|
|
15
|
-
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
|
16
|
-
#
|
|
17
|
-
# We make an exception for simplecov because that will already have been
|
|
18
|
-
# required and run at the very top of spec_helper.rb
|
|
19
|
-
support_files = Dir["./spec/support/**/*.rb"].reject { |file| file == "./spec/support/simplecov.rb" }
|
|
20
|
-
support_files.each { |f| require f }
|
|
21
|
-
|
|
22
|
-
RSpec.configure do |config|
|
|
23
|
-
# rspec-expectations config goes here. You can use an alternate
|
|
24
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
|
25
|
-
# assertions if you prefer.
|
|
26
|
-
config.expect_with :rspec do |expectations|
|
|
27
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
|
28
|
-
# and `failure_message` of custom matchers include text for helper methods
|
|
29
|
-
# defined using `chain`, e.g.:
|
|
30
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
|
31
|
-
# # => "be bigger than 2 and smaller than 4"
|
|
32
|
-
# ...rather than:
|
|
33
|
-
# # => "be bigger than 2"
|
|
34
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
|
38
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
|
39
|
-
config.mock_with :rspec do |mocks|
|
|
40
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
|
41
|
-
# a real object. This is generally recommended, and will default to
|
|
42
|
-
# `true` in RSpec 4.
|
|
43
|
-
mocks.verify_partial_doubles = true
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
|
47
|
-
# have no way to turn it off -- the option exists only for backwards
|
|
48
|
-
# compatibility in RSpec 3). It causes shared context metadata to be
|
|
49
|
-
# inherited by the metadata hash of host groups and examples, rather than
|
|
50
|
-
# triggering implicit auto-inclusion in groups with matching metadata.
|
|
51
|
-
config.shared_context_metadata_behavior = :apply_to_host_groups
|
|
52
|
-
|
|
53
|
-
# This allows you to limit a spec run to individual examples or groups
|
|
54
|
-
# you care about by tagging them with `:focus` metadata. When nothing
|
|
55
|
-
# is tagged with `:focus`, all examples get run. RSpec also provides
|
|
56
|
-
# aliases for `it`, `describe`, and `context` that include `:focus`
|
|
57
|
-
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
|
58
|
-
config.filter_run_when_matching :focus
|
|
59
|
-
|
|
60
|
-
# Allows RSpec to persist some state between runs in order to support
|
|
61
|
-
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
|
62
|
-
# you configure your source control system to ignore this file.
|
|
63
|
-
config.example_status_persistence_file_path = "spec/examples.txt"
|
|
64
|
-
|
|
65
|
-
# Limits the available syntax to the non-monkey patched syntax that is
|
|
66
|
-
# recommended. For more details, see:
|
|
67
|
-
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
|
68
|
-
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
|
69
|
-
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
|
70
|
-
config.disable_monkey_patching!
|
|
71
|
-
|
|
72
|
-
# Run specs in random order to surface order dependencies. If you find an
|
|
73
|
-
# order dependency and want to debug it, you can fix the order by providing
|
|
74
|
-
# the seed, which is printed after each run.
|
|
75
|
-
# --seed 1234
|
|
76
|
-
config.order = :random
|
|
77
|
-
|
|
78
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
|
79
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
|
80
|
-
# test failures related to randomization by passing the same `--seed` value
|
|
81
|
-
# as the one that triggered the failure.
|
|
82
|
-
Kernel.srand config.seed
|
|
83
|
-
end
|
data/spec/support/aws_sdk_s3.rb
DELETED
data/spec/support/dotenv.rb
DELETED
data/spec/support/pry.rb
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Support debugging in the tests. Add `binding.pry` wherever you want execution
|
|
4
|
-
# to stop and the debugger to kick in.
|
|
5
|
-
# Details on the debugging commands can be found here
|
|
6
|
-
# https://github.com/deivid-rodriguez/pry-byebug#commands
|
|
7
|
-
require "pry-byebug"
|
data/spec/support/simplecov.rb
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "simplecov"
|
|
4
|
-
|
|
5
|
-
# We start it with the rails param to ensure it includes coverage for all code
|
|
6
|
-
# started by the rails app, and not just the files touched by our unit tests.
|
|
7
|
-
# This gives us the most accurate assessment of our unit test coverage
|
|
8
|
-
# https://github.com/colszowka/simplecov#getting-started
|
|
9
|
-
SimpleCov.start do
|
|
10
|
-
# We filter the spec folder, mainly to ensure that any dummy apps don't get
|
|
11
|
-
# included in the coverage report. However our intent is that nothing in the
|
|
12
|
-
# spec folder should be included
|
|
13
|
-
add_filter "/spec/"
|
|
14
|
-
# The version file is simply just that, so we do not feel the need to ensure
|
|
15
|
-
# we have a test for it
|
|
16
|
-
add_filter "lib/defra_ruby/aws/version"
|
|
17
|
-
end
|
data/spec/support/webmock.rb
DELETED