gridium 1.0.19 → 1.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/s3.rb +20 -12
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ffa161263791dc0459f8181368f180f6381d8ba
4
- data.tar.gz: c9f91bbb2e3a531f4db07a083e86ac4bc0d59c9b
3
+ metadata.gz: 8010d8048c38955a0650c3c4fa3dce2167e5caec
4
+ data.tar.gz: 23738f1cd0a55f6b4155e2821c45a883cd998d29
5
5
  SHA512:
6
- metadata.gz: 9a1fd396f8e9325fa1702356aa7b15c2e1a310c30be8b293972a502ebb96574c1a5b5e707b2e15c7f62ba25fdf61d1891160011c8b72b838e30900b61652f341
7
- data.tar.gz: cf15ddb6982fd07785b8513575d7d34e01b871795001391c8e1cb8588c50c3e4cc307f9f111931eb9ffc9d374682a67cad036cd417c7736acf4645f06b5c14ad
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
- @bucket.object(destination_name).upload_file(absolute_path_of_file)
24
- @bucket.object(destination_name).wait_until_exists
25
- _verify_upload(destination_name, absolute_path_of_file)
26
- # @bucket.object(s3_name).presigned_url(:get, expires_in: 3600) #uncomment this if public url ends up not working out OPREQ-83850
27
- @bucket.object(destination_name).public_url
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("attmepting to validate #{path_to_file} as a legitimate path")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gridium
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.19
4
+ version: 1.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Urban