uc3-dmp-s3 0.0.3 → 0.0.5

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: c92a65afbb3240d8b8f8c743335c59f39251d969c9b4a68b2181af490fb08b62
4
- data.tar.gz: 39ea2a070012dac95f25a22e02941037fbc699e61705c5c0f277d1d70659f68d
3
+ metadata.gz: d4777a819ac1d24ba32e2d4e1110db3356741957d5aee5e50da7cf503e8be424
4
+ data.tar.gz: 2b28808d7652c94eee7971c259173428ca39bd8f1517db0d7f5a0b22bb2d63c6
5
5
  SHA512:
6
- metadata.gz: 36e24653e806818a64ec7cee55eb97b95697e7aa277305ccb33cc6efe6c022fe04588c3d861669f021145264fc24175c7968e4b0b815662c6b2ed741a5430db9
7
- data.tar.gz: 9f834984c644f01f5a2c1b011ad49bdbe9c4a19889ebef49147c481795e7af34ee23788e441e40fc9bd1db789e3e954e98a2c6190779b579d410f37947dec122
6
+ metadata.gz: f05df072a1b7dbff40cdd98edf346811322a0dc9d969f459f19c79a47c0492d1057f836378e903df73cb9d57dd07a4ccee946a671bb61e02d07c2643b45e5c29
7
+ data.tar.gz: 3638037edd2dbad88417df2fa7ba38064fa4bfc56a873a002d3360ff780f05581658a60435fac359c5edfd071e26943736c23bc4ca930b9ccded49351bf25ca0
@@ -19,10 +19,35 @@ module Uc3DmpS3
19
19
  #
20
20
  class Client
21
21
  NARRATIVE_KEY_PREFIX = 'narratives/'
22
+ RESOURCE_KEY_PREFIX = 'external_resources/'
22
23
 
23
24
  MSG_S3_FAILURE = 'Unable to save the object at this time'
24
25
 
25
26
  class << self
27
+ # Put the narrative file into the S3 bucket
28
+ def put_resource_file(file:, explorer_details:)
29
+ return nil if File.nil? || !explorer_details.is_a?(Hash) || ENV['S3_BUCKET'].nil? ||
30
+ explorer_details.fetch('file_metadata', {})['filename'].nil?
31
+
32
+ filename = "#{explorer_details['ID']}_#{explorer_details['file_metadata']['filename']}"
33
+ key = "#{RESOURCE_KEY_PREFIX}#{filename}"
34
+ tg = "RESOURCE_TYPE=#{explorer_details['RESOURCE_TYPE']}&ID=#{explorer_details['ID']}&tstamp=#{file.mtime}"
35
+
36
+ _put_object(key:, tags: tg, payload: file)
37
+ rescue Aws::Errors::ServiceError => e
38
+ msg = "Unable to write External Resource file to S3 bucket (#{tg})"
39
+ raise ClientError, "#{msg} - #{e.message}"
40
+ end
41
+
42
+ # Fetch the narrative file from the S3 bucket
43
+ def get_resource_file(key:)
44
+ return nil unless key.is_a?(String) && !key.strip.empty? && !ENV['S3_BUCKET'].nil?
45
+
46
+ obj = _get_object(key: key.start_with?(RESOURCE_KEY_PREFIX) ? key : "#{RESOURCE_KEY_PREFIX}#{key}")
47
+ rescue Aws::Errors::ServiceError => e
48
+ raise ClientError, "Unable to fetch External Resource file from S3 bucket (key: #{key}) - #{e.message}"
49
+ end
50
+
26
51
  # Put the narrative file into the S3 bucket
27
52
  def put_narrative(document:, dmp_id: nil, base64: false)
28
53
  return nil if !document.is_a?(String) || document.strip.empty? || ENV['S3_BUCKET'].nil?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpS3
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.5'
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.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Riley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-04 00:00:00.000000000 Z
11
+ date: 2023-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3