uc3-dmp-s3 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/uc3-dmp-s3/client.rb +21 -7
- data/lib/uc3-dmp-s3/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 806dbb2a9821958ce5b6d32219023f671ea6119e837ae1de29753a6d5acf4ce2
|
4
|
+
data.tar.gz: 2ff4c8cafe89cb3169dc44d0feaa8ea77268ad109213f58bede51a0a0c65ffd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea6d083e9e2b7f1907c019ac450232cb33cd0c060b0f71aa23a84099b9d45f8b476458598d2be36d9d4061da88f8b702cc9e8fbfcc38dd50446198d2f2741f22
|
7
|
+
data.tar.gz: 553ca24e53f1a98b30a782ae58d2a0005139675e1f6de23f6d2b0dae2d92553de690b6eb5642d6567204890c59a4be8ec1c15eff868963264951271b0c2c0cda
|
data/lib/uc3-dmp-s3/client.rb
CHANGED
@@ -19,25 +19,39 @@ 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
|
26
27
|
# Put the narrative file into the S3 bucket
|
27
|
-
|
28
|
+
def put_resource_file(file:, explorer_details:, base64: false)
|
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
|
+
# Put the narrative file into the S3 bucket
|
28
43
|
def put_narrative(document:, dmp_id: nil, base64: false)
|
29
44
|
return nil if !document.is_a?(String) || document.strip.empty? || ENV['S3_BUCKET'].nil?
|
30
45
|
|
31
46
|
key = "#{NARRATIVE_KEY_PREFIX}#{SecureRandom.hex(8)}.pdf"
|
32
|
-
tg =
|
47
|
+
tg = "DMP_ID=#{CGI.escape(dmp_id)}" unless dmp_id.nil?
|
33
48
|
body = base64 ? Base64.decode64(document) : document
|
34
49
|
|
35
|
-
_put_object(key
|
50
|
+
_put_object(key:, tags: tg, payload: body)
|
36
51
|
rescue Aws::Errors::ServiceError => e
|
37
|
-
msg = "Unable to write PDF narrative to S3 bucket (dmp_id: #{dmp_id
|
52
|
+
msg = "Unable to write PDF narrative to S3 bucket (dmp_id: #{dmp_id})"
|
38
53
|
raise ClientError, "#{msg} - #{e.message}"
|
39
54
|
end
|
40
|
-
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
41
55
|
|
42
56
|
# Fetch the narrative file from the S3 bucket
|
43
57
|
def get_narrative(key:)
|
@@ -57,7 +71,7 @@ module Uc3DmpS3
|
|
57
71
|
|
58
72
|
client = Aws::S3::Client.new(region: ENV.fetch('AWS_REGION', nil))
|
59
73
|
bucket = ENV['S3_BUCKET'].gsub('arn:aws:s3:::', '')
|
60
|
-
resp = client.put_object({ body: payload, bucket
|
74
|
+
resp = client.put_object({ body: payload, bucket:, key:, tagging: tags })
|
61
75
|
resp.successful? ? key : nil
|
62
76
|
end
|
63
77
|
|
@@ -68,7 +82,7 @@ module Uc3DmpS3
|
|
68
82
|
|
69
83
|
client = Aws::S3::Client.new(region: ENV.fetch('AWS_REGION', 'us-west-2'))
|
70
84
|
bucket = ENV['S3_BUCKET'].gsub('arn:aws:s3:::', '')
|
71
|
-
resp = client.get_object({ bucket
|
85
|
+
resp = client.get_object({ bucket:, key: })
|
72
86
|
return nil if resp.nil? || !resp.content_length.positive?
|
73
87
|
|
74
88
|
resp.body.is_a?(String) ? resp.body : resp.body.read
|
data/lib/uc3-dmp-s3/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.4
|
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-
|
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
|
@@ -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
|
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.
|
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: []
|