defra_ruby_mocks 4.2.1 → 5.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 463dba0a1c6925c35c0265dfa65a55a6e1a8e7ec33c4e5dc793fa1e51f1b3c01
4
- data.tar.gz: 101fea584ee1cbbf481ebe591f1d1e280903a8be16834e3616697ee80be402b8
3
+ metadata.gz: a608d402c9667f9aef72c67f4ae1edf115d0385b4315e37e6c926d1c79d92958
4
+ data.tar.gz: 2d8f253849caf74c2486777e82f2c5406bde65725d14078271452df3afdaab98
5
5
  SHA512:
6
- metadata.gz: eb946492539db155e729244008599522dfad177db1536696a8f4d1e7090e9f4a9f03df0f1622add82bb968ab07bba25056b1524f4a19799c2402cd59edd61362
7
- data.tar.gz: 70de2d5dfe16524ccc00c3d491a1dc933dce584b434877ab6b8d96c02d31729ff51dc5f9005b87b0301af6769cddc1d0ef22c253b3b2ed8779042f1007702d65
6
+ metadata.gz: b4550088184172df4cf64516baa91a60ae1f6fd496cb2a3d8dbbe9c3375dc1afc73e2dbea191217d059c34773d73de56cc4b5c8c854a1b1cb47869ca8cc8bd22
7
+ data.tar.gz: ec7ca0077154ced7847aa76947403b2a994a7b3f2460bc1451755abc4e31f16ed30407ca1c60588f1d04f66c28b9b075c6d64abdcf7021b7ad18775323d85faf
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
 
@@ -40,7 +40,7 @@ module DefraRubyMocks
40
40
  end
41
41
 
42
42
  def s3_bucket_name
43
- @s3_bucket_name = ENV.fetch("GOVPAY_MOCKS_BUCKET", "defra-ruby-mocks-s3bkt001")
43
+ @s3_bucket_name = ENV.fetch("AWS_DEFRA_RUBY_MOCKS_BUCKET", nil)
44
44
  end
45
45
 
46
46
  def timestamp_file_name
@@ -24,7 +24,7 @@ module DefraRubyMocks
24
24
  end
25
25
 
26
26
  def s3_bucket_name
27
- @s3_bucket_name = ENV.fetch("GOVPAY_MOCKS_BUCKET", "defra-ruby-mocks-s3bkt001")
27
+ @s3_bucket_name = ENV.fetch("AWS_DEFRA_RUBY_MOCKS_BUCKET", nil)
28
28
  end
29
29
 
30
30
  def timestamp_file_name
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DefraRubyMocks
4
- VERSION = "4.2.1"
4
+ VERSION = "5.0.0"
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: 5.0.0
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-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails