gridium 1.0.19 → 1.0.20
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 +4 -4
- data/lib/s3.rb +20 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8010d8048c38955a0650c3c4fa3dce2167e5caec
|
4
|
+
data.tar.gz: 23738f1cd0a55f6b4155e2821c45a883cd998d29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 885bf3d7c5ba920f7af465b1d6f6c8d921fa46060944674d4482ee452c1aedaf3f96d4ec31897050973e3fcd047cca6b9160507925b261a65c706db58431267b
|
7
|
+
data.tar.gz: 8ce8829350bcb7974c352b214bcd919c744a827d2e6ddda54db04ce78c84721f9802f9a8af45d9ae7ad439e321ceae78138843f067f86df0c0e41558ef739cfa
|
data/lib/s3.rb
CHANGED
@@ -6,7 +6,7 @@ module Gridium
|
|
6
6
|
DELIMITER = "/"
|
7
7
|
|
8
8
|
def initialize(project_name, subdirectory_name='screenshots')
|
9
|
-
Log.debug("initializing GridiumS3 with #{project_name} and #{subdirectory_name}")
|
9
|
+
Log.debug("[GRIDIUM::S3] initializing GridiumS3 with #{project_name} and #{subdirectory_name}")
|
10
10
|
Aws.config.update({ credentials: Aws::Credentials.new(ENV['S3_ACCESS_KEY_ID'], ENV['S3_SECRET_ACCESS_KEY']) , region: ENV['S3_DEFAULT_REGION']})
|
11
11
|
_validate_string(project_name)
|
12
12
|
_validate_string(subdirectory_name)
|
@@ -16,15 +16,23 @@ module Gridium
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def save_file(absolute_path_of_file)
|
19
|
-
Log.debug("attempting to save #{absolute_path_of_file} to s3")
|
19
|
+
Log.debug("[GRIDIUM::S3] attempting to save #{absolute_path_of_file} to s3")
|
20
20
|
_validate_path(absolute_path_of_file)
|
21
21
|
file_name = File.basename(absolute_path_of_file)
|
22
22
|
destination_name = create_s3_name(file_name)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
begin
|
24
|
+
@bucket.object(destination_name).upload_file(absolute_path_of_file)
|
25
|
+
@bucket.object(destination_name).wait_until_exists
|
26
|
+
_verify_upload(destination_name, absolute_path_of_file)
|
27
|
+
# @bucket.object(s3_name).presigned_url(:get, expires_in: 3600) #uncomment this if public url ends up not working out OPREQ-83850
|
28
|
+
return @bucket.object(destination_name).public_url
|
29
|
+
rescue Aws::S3::Errors::InvalidAccessKeyId
|
30
|
+
Log.error("[GRIDIUM::S3] unable to save file to s3 due to Aws::S3::Errors::InvalidAccessKeyId")
|
31
|
+
rescue Seahorse::Client::NetworkingError => error
|
32
|
+
Log.error("[GRIDIUM::S3] unable to save file to s3 due to underlying network error: #{error}")
|
33
|
+
rescue StandardErrer => error
|
34
|
+
Log.error("[GRIDIUM::S3] unable to save file to s3 due to unexpected error: #{error}")
|
35
|
+
end
|
28
36
|
end
|
29
37
|
|
30
38
|
def create_s3_name(file_name)
|
@@ -41,23 +49,23 @@ module Gridium
|
|
41
49
|
end
|
42
50
|
|
43
51
|
def _validate_string(input_string)
|
44
|
-
Log.debug("attempting to validate #{input_string} for use as a name")
|
52
|
+
Log.debug("[GRIDIUM::S3] attempting to validate #{input_string} for use as a name")
|
45
53
|
if input_string.empty? or input_string.strip().empty? then
|
46
|
-
raise(ArgumentError, "empty and/or whitespace file names are not wanted here.")
|
54
|
+
raise(ArgumentError, "[GRIDIUM::S3] empty and/or whitespace file names are not wanted here.")
|
47
55
|
end
|
48
56
|
end
|
49
57
|
|
50
58
|
def _validate_path(path_to_file)
|
51
|
-
Log.debug("
|
59
|
+
Log.debug("[GRIDIUM::S3] attempting to validate #{path_to_file} as a legitimate path")
|
52
60
|
if not File.exist? path_to_file then
|
53
|
-
raise(ArgumentError, "this path doesn't resolve #{path_to_file}")
|
61
|
+
raise(ArgumentError, "[GRIDIUM::S3] this path doesn't resolve #{path_to_file}")
|
54
62
|
end
|
55
63
|
end
|
56
64
|
|
57
65
|
def _verify_upload(s3_name, local_absolute_path)
|
58
66
|
upload_size = @bucket.object(s3_name).content_length
|
59
67
|
local_size = File.size local_absolute_path
|
60
|
-
Log.debug("file upload verified: #{upload_size == local_size}. upload size is #{upload_size} and local size is #{local_size}")
|
68
|
+
Log.debug("[GRIDIUM::S3] file upload verified: #{upload_size == local_size}. upload size is #{upload_size} and local size is #{local_size}")
|
61
69
|
upload_size == local_size
|
62
70
|
end
|
63
71
|
end
|