uc3-dmp-s3 0.0.1 → 0.0.3

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: 012b85ca0ad4be2d1cc1ee135f15198316202b5ff52f8192831838fd62f576a4
4
- data.tar.gz: ca34a6e7221a1290f8a50224b60c5e2b33255b5a348460c5cb43d7fc52f596cd
3
+ metadata.gz: c92a65afbb3240d8b8f8c743335c59f39251d969c9b4a68b2181af490fb08b62
4
+ data.tar.gz: 39ea2a070012dac95f25a22e02941037fbc699e61705c5c0f277d1d70659f68d
5
5
  SHA512:
6
- metadata.gz: ad81d5cc37ffccafdcebb9e8d7c695055e2b929ae401f807f207d9599b93101114dc5f514fb732ece2b4743556c8bf8ef726c3364d31598b7b8981852701302c
7
- data.tar.gz: 35d294452bbd39c6f183cdd9f57d3698f12a799c085bd11d4a585b2aad4fb4fdf33e1cf1f42cf15abac4f163ca6548209532f52bd71759b5f4241f35fabad9c5
6
+ metadata.gz: 36e24653e806818a64ec7cee55eb97b95697e7aa277305ccb33cc6efe6c022fe04588c3d861669f021145264fc24175c7968e4b0b815662c6b2ed741a5430db9
7
+ data.tar.gz: 9f834984c644f01f5a2c1b011ad49bdbe9c4a19889ebef49147c481795e7af34ee23788e441e40fc9bd1db789e3e954e98a2c6190779b579d410f37947dec122
@@ -20,30 +20,29 @@ module Uc3DmpS3
20
20
  class Client
21
21
  NARRATIVE_KEY_PREFIX = 'narratives/'
22
22
 
23
- MSG_S3_FAILURE = 'Unable to save the PDF file at this time'
23
+ MSG_S3_FAILURE = 'Unable to save the object at this time'
24
24
 
25
25
  class << self
26
26
  # Put the narrative file into the S3 bucket
27
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
28
27
  def put_narrative(document:, dmp_id: nil, base64: false)
29
28
  return nil if !document.is_a?(String) || document.strip.empty? || ENV['S3_BUCKET'].nil?
30
29
 
31
30
  key = "#{NARRATIVE_KEY_PREFIX}#{SecureRandom.hex(8)}.pdf"
32
- tg = dmp_id.nil? ? "PRE-DMP_ID=#{Time.now.strftime('%Y-%m-%d')}" : "DMP_ID=#{CGI.escape(dmp_id)}"
31
+ tg = "DMP_ID=#{CGI.escape(dmp_id)}" unless dmp_id.nil?
33
32
  body = base64 ? Base64.decode64(document) : document
34
33
 
35
- _put_object(key: key, tags: tg, payload: body)
34
+ _put_object(key:, tags: tg, payload: body)
36
35
  rescue Aws::Errors::ServiceError => e
37
- msg = "Unable to write PDF narrative to S3 bucket (dmp_id: #{dmp_id.nil? ? 'PRE-DMP_ID' : dmp_id})"
36
+ msg = "Unable to write PDF narrative to S3 bucket (dmp_id: #{dmp_id})"
38
37
  raise ClientError, "#{msg} - #{e.message}"
39
38
  end
40
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
41
39
 
42
40
  # Fetch the narrative file from the S3 bucket
43
41
  def get_narrative(key:)
44
42
  return nil unless key.is_a?(String) && !key.strip.empty? && !ENV['S3_BUCKET'].nil?
45
43
 
46
- _get_object(key: key.start_with?(NARRATIVE_KEY_PREFIX) ? key : "#{NARRATIVE_KEY_PREFIX}#{key}")
44
+ obj = _get_object(key: key.start_with?(NARRATIVE_KEY_PREFIX) ? key : "#{NARRATIVE_KEY_PREFIX}#{key}")
45
+ Base64.encode64(obj)
47
46
  rescue Aws::Errors::ServiceError => e
48
47
  raise ClientError, "Unable to fetch PDF narrative from S3 bucket (key: #{key}) - #{e.message}"
49
48
  end
@@ -56,7 +55,7 @@ module Uc3DmpS3
56
55
 
57
56
  client = Aws::S3::Client.new(region: ENV.fetch('AWS_REGION', nil))
58
57
  bucket = ENV['S3_BUCKET'].gsub('arn:aws:s3:::', '')
59
- resp = client.put_object({ body: payload, bucket: bucket, key: key, tagging: tags })
58
+ resp = client.put_object({ body: payload, bucket:, key:, tagging: tags })
60
59
  resp.successful? ? key : nil
61
60
  end
62
61
 
@@ -67,7 +66,7 @@ module Uc3DmpS3
67
66
 
68
67
  client = Aws::S3::Client.new(region: ENV.fetch('AWS_REGION', 'us-west-2'))
69
68
  bucket = ENV['S3_BUCKET'].gsub('arn:aws:s3:::', '')
70
- resp = client.get_object({ bucket: bucket, key: key })
69
+ resp = client.get_object({ bucket:, key: })
71
70
  return nil if resp.nil? || !resp.content_length.positive?
72
71
 
73
72
  resp.body.is_a?(String) ? resp.body : resp.body.read
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpS3
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uc3-dmp-s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Riley
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-16 00:00:00.000000000 Z
11
+ date: 2023-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3
@@ -138,7 +138,7 @@ licenses:
138
138
  - MIT
139
139
  metadata:
140
140
  rubygems_mfa_required: 'false'
141
- post_install_message:
141
+ post_install_message:
142
142
  rdoc_options: []
143
143
  require_paths:
144
144
  - lib
@@ -146,15 +146,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
146
  requirements:
147
147
  - - ">="
148
148
  - !ruby/object:Gem::Version
149
- version: '2.7'
149
+ version: '3.2'
150
150
  required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  requirements:
152
152
  - - ">="
153
153
  - !ruby/object:Gem::Version
154
154
  version: '0'
155
155
  requirements: []
156
- rubygems_version: 3.1.6
157
- signing_key:
156
+ rubygems_version: 3.4.10
157
+ signing_key:
158
158
  specification_version: 4
159
159
  summary: DMPTool gem that provides general support for accessing the DMPTool S3 Bucket
160
160
  test_files: []