defra_ruby_mocks 4.2.1 → 4.2.2

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: 463dba0a1c6925c35c0265dfa65a55a6e1a8e7ec33c4e5dc793fa1e51f1b3c01
4
- data.tar.gz: 101fea584ee1cbbf481ebe591f1d1e280903a8be16834e3616697ee80be402b8
3
+ metadata.gz: 6394eef6671bf7402ae9086113fa641729b149df46d6f1fcb6a1d3281c19b742
4
+ data.tar.gz: 5e0606b7bb200a849cea22cd1abbee314cbbf0449fb7003de05b85be7ef57136
5
5
  SHA512:
6
- metadata.gz: eb946492539db155e729244008599522dfad177db1536696a8f4d1e7090e9f4a9f03df0f1622add82bb968ab07bba25056b1524f4a19799c2402cd59edd61362
7
- data.tar.gz: 70de2d5dfe16524ccc00c3d491a1dc933dce584b434877ab6b8d96c02d31729ff51dc5f9005b87b0301af6769cddc1d0ef22c253b3b2ed8779042f1007702d65
6
+ metadata.gz: 1dea451c6e0c2e98c913b8d8c5d0c67915a7548a0d3a648f1d891df3c0b4ca40b7c47d8c82ecc2a8b8d9e3a9ec290e07bb628452dfa37fea9e8fa940d381ef5e
7
+ data.tar.gz: 762b4407b39d0538f7386a3733b915a217dd810c787ca0080b4be8684ed4857349e6b26258e3eb4a7cf74eddf90cfa3c385a3b3df5235fe72dc9d100a9e8540a
data/README.md CHANGED
@@ -171,10 +171,10 @@ This Govpay mock replicates those 2 interactions with the following url
171
171
 
172
172
  #### Configuration
173
173
 
174
- In order to use the govpay mock you'll need to provide additional configuration details
174
+ In order to use the govpay mock you'll need to provide additional configuration details:
175
175
 
176
176
  ```ruby
177
- # config/initializers/defra_ruby_mocks.rb
177
+ config/initializers/defra_ruby_mocks.rb
178
178
  require "defra_ruby_mocks"
179
179
 
180
180
  DefraRubyMocks.configure do |config|
@@ -184,6 +184,26 @@ end
184
184
 
185
185
  The domain is used when generating the URL we tell the app to redirect users to. As this is just an engine and not a standalone service, we need to tell it what domain it is running from.
186
186
 
187
+ You'll also need to provide AWS configuration details for the mocks, for example:
188
+
189
+ ```ruby
190
+ require "defra_ruby/aws"
191
+
192
+ DefraRuby::Aws.configure do |c|
193
+ govpay_mocks_bucket = {
194
+ name: ENV.fetch("AWS_DEFRA_RUBY_MOCKS_BUCKET", nil),
195
+ region: ENV.fetch("AWS_REGION", nil),
196
+ credentials: {
197
+ access_key_id: ENV.fetch("AWS_DEFRA_RUBY_MOCKS_ACCESS_KEY_ID", nil),
198
+ secret_access_key: ENV.fetch("AWS_DEFRA_RUBY_MOCKS_SECRET_ACCESS_KEY", nil)
199
+ },
200
+ encrypt_with_kms: ENV.fetch("AWS_DEFRA_RUBY_MOCKS_ENCRYPT_WITH_KMS", nil)
201
+ }
202
+
203
+ c.buckets = [govpay_mocks_bucket]
204
+ end
205
+ ```
206
+
187
207
  ```ruby
188
208
  mount DefraRubyMocks::Engine => "/mocks"
189
209
  ```
@@ -60,7 +60,7 @@ module DefraRubyMocks
60
60
  private
61
61
 
62
62
  def s3_bucket_name
63
- @s3_bucket_name = ENV.fetch("GOVPAY_MOCKS_BUCKET", "defra-ruby-mocks-s3bkt001")
63
+ @s3_bucket_name = ENV.fetch("AWS_DEFRA_RUBY_MOCKS_BUCKET", nil)
64
64
  end
65
65
 
66
66
  def return_url_file_name
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "aws-sdk-s3"
3
4
  require "defra_ruby/aws"
4
5
 
5
6
  module DefraRubyMocks
@@ -18,6 +19,7 @@ module DefraRubyMocks
18
19
  def write(bucket_name, file_name, content)
19
20
  @bucket_name = bucket_name
20
21
  @file_name = file_name
22
+ Rails.logger.debug ":::::: mocks writing to S3"
21
23
 
22
24
  write_temp_file(content)
23
25
 
@@ -27,12 +29,18 @@ module DefraRubyMocks
27
29
  end
28
30
 
29
31
  def read(bucket_name, file_name)
30
- Rails.logger.warn ":::::: reading from S3"
31
-
32
- s3 = Aws::S3::Client.new
33
- s3.get_object(bucket: bucket_name, key: file_name)
34
- rescue Aws::S3::NoSuchBucket => e
35
- raise StandardError, e
32
+ @bucket_name = bucket_name
33
+ @file_name = file_name
34
+ Rails.logger.debug ":::::: mocks reading from S3"
35
+
36
+ s3 = Aws::S3::Client.new(
37
+ region: ENV.fetch("AWS_REGION", nil),
38
+ credentials: Aws::Credentials.new(
39
+ ENV.fetch("AWS_DEFRA_RUBY_MOCKS_ACCESS_KEY_ID", nil),
40
+ ENV.fetch("AWS_DEFRA_RUBY_MOCKS_SECRET_ACCESS_KEY", nil)
41
+ )
42
+ )
43
+ s3.get_object(bucket: bucket_name, key: file_name).body.read
36
44
  end
37
45
 
38
46
  private
@@ -42,12 +50,12 @@ module DefraRubyMocks
42
50
  end
43
51
 
44
52
  def write_temp_file(content)
45
- Rails.logger.warn ":::::: creating temp file for #{content}"
53
+ Rails.logger.debug ":::::: mocks creating temp file for #{content}"
46
54
  File.write(temp_filepath, content)
47
55
  end
48
56
 
49
57
  def load_temp_file_to_s3
50
- Rails.logger.warn ":::::: loading temp file to S3"
58
+ Rails.logger.debug ":::::: mocks loading temp file to S3 bucket #{bucket_name}"
51
59
 
52
60
  result = nil
53
61
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DefraRubyMocks
4
- VERSION = "4.2.1"
4
+ VERSION = "4.2.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defra_ruby_mocks
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.1
4
+ version: 4.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Defra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-23 00:00:00.000000000 Z
11
+ date: 2024-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails