tn_s3_file_uploader 0.1.6 → 0.1.8

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
  SHA1:
3
- metadata.gz: 57b2e3f098206b3194879ade9ab5cc75c6bd4ec9
4
- data.tar.gz: 2f93dd63c4030a697f1c349f6865410809365b87
3
+ metadata.gz: 7eaa24797da8fe43d9f3c72169f9d41686eaec5e
4
+ data.tar.gz: 855f649660e7ddd96c0d2e26663b92cfc546e92d
5
5
  SHA512:
6
- metadata.gz: e71475027f97915edf5def8c2c88b4adcd6c10d0fd6c23bfe99a15d75c6bbf8facf1b80a8e4779ebb2d710cbba0fb4f0f91e461ba28a2cad27824a3b6e5af6c6
7
- data.tar.gz: e0f808c0cc1423a0fe71cf79b657c7023bc2d456641c219966187ba2c4d07d141b8e3fa07deb217564804ac7b82ec6ea563ec96a3ce885d030beaa6df8c00496
6
+ metadata.gz: 40d472d1a25293fa8f057fa06b8d8b9b9339ec279f1cb8c8202dd16885be22b8c11ff6477416be77ddeddd4ba5601c44a71c5242543d9a292b23e10758a92931
7
+ data.tar.gz: 96335682165b4ecd26d0f7a9bc3ab33017c5134b6a6301e101d0cced5d7489d678a459f2849495ed39570689f22f4ed97bc87795111cccba4724ae034d380f82
@@ -1,4 +1,5 @@
1
1
  require 'honeybadger'
2
+ require 'net/http'
2
3
 
3
4
  module TnS3FileUploader
4
5
 
@@ -7,8 +8,11 @@ module TnS3FileUploader
7
8
 
8
9
  # Configure honeybadger with provided api-key. Assumes api-key is not null
9
10
  def initialize(api_key)
11
+ # configure the hostname on EC2 instances
12
+ hostname = Net::HTTP.get('169.254.169.254', '/latest/meta-data/hostname') rescue nil
10
13
  Honeybadger.configure do |config|
11
14
  config.api_key = api_key
15
+ config.hostname = hostname if hostname # don't set
12
16
  end
13
17
  end
14
18
 
@@ -17,4 +21,4 @@ module TnS3FileUploader
17
21
  end
18
22
  end
19
23
 
20
- end
24
+ end
@@ -15,10 +15,9 @@ module TnS3FileUploader
15
15
  # date = Wed Jun 18 19:03:40 UTC 2014
16
16
  class FilePathGenerator
17
17
 
18
- def initialize(time, options)
18
+ def initialize(options)
19
19
  #Find the last rotation window
20
20
  @options = options
21
- @time = previous_rotation_window(time)
22
21
  end
23
22
 
24
23
 
@@ -26,15 +25,15 @@ module TnS3FileUploader
26
25
  # Assumes input file 'file' and s3_output_pattern option are both valid.
27
26
  # This method removes the bucket (everything until the first '/', including the '/') from the s3_output_pattern
28
27
  # while applying the datetime/macro/substitutions
29
- def dest_full_path_for(file)
30
-
28
+ def dest_full_path_for(time, file)
29
+ time = previous_rotation_window(time)
31
30
  output_file_pattern = remove_bucket(@options[:s3_output_pattern])
32
31
 
33
32
  # Time#strftime is removing '%' characters on our macros. Our macro substitution must run first
34
- subs = build_substitutions(file)
33
+ subs = build_substitutions(file, time)
35
34
  replace_macros!(output_file_pattern, subs)
36
35
 
37
- substitute_datetime_macros(output_file_pattern)
36
+ substitute_datetime_macros(time, output_file_pattern)
38
37
  end
39
38
 
40
39
  private
@@ -48,13 +47,13 @@ module TnS3FileUploader
48
47
  # Given s3_output_pattern y=%Y/m=%m/d=%d/h=%H
49
48
  # and time: Thu Jun 12 23:57:49 UTC 2014
50
49
  # it will produce the following folder structure: y=2014/m=06/d=12/h=23
51
- def substitute_datetime_macros(output_pattern)
52
- @time.strftime(output_pattern)
50
+ def substitute_datetime_macros(time, output_pattern)
51
+ time.strftime(output_pattern)
53
52
  end
54
53
 
55
54
  # Generates rounded off timestamp based on rotation_seconds
56
- def generate_file_timestamp
57
- @time.strftime('%Y%m%d%H%M%S')
55
+ def generate_file_timestamp(time)
56
+ time.strftime('%Y%m%d%H%M%S')
58
57
  end
59
58
 
60
59
  def replace_macros!(output_file_pattern, subs)
@@ -111,7 +110,7 @@ module TnS3FileUploader
111
110
  resolve_ip =~ /\d+\.\d+\.\d+\.\d+/
112
111
  end
113
112
 
114
- def build_substitutions(file)
113
+ def build_substitutions(file, time)
115
114
  file_components = file.split('/').last.split('.')
116
115
 
117
116
  if file_components.size == 1
@@ -124,7 +123,7 @@ module TnS3FileUploader
124
123
 
125
124
  ip_address = local_ip.gsub('.', '-')
126
125
 
127
- file_timestamp = generate_file_timestamp
126
+ file_timestamp = generate_file_timestamp(time)
128
127
 
129
128
  {
130
129
  '%{file-name}' => file_name,
@@ -21,13 +21,13 @@ module TnS3FileUploader
21
21
  def upload_log_files(options)
22
22
  raise ArgumentError, 's3_output_pattern cannot be empty' if blank?(options[:s3_output_pattern])
23
23
  bucket = check_bucket_dest_path(options[:s3_output_pattern])
24
- log_files = check_log_file(options[:input_file_pattern])
24
+ log_files = check_log_files(options[:input_file_pattern])
25
25
 
26
- now = Time.now.utc
27
- file_path_generator = FilePathGenerator.new(now, options)
26
+ file_path_generator = FilePathGenerator.new(options)
28
27
 
29
28
  log_files.each do |log_file|
30
- destination_full_path = file_path_generator.dest_full_path_for(log_file)
29
+ time = last_modified_time(log_file)
30
+ destination_full_path = file_path_generator.dest_full_path_for(time, log_file)
31
31
 
32
32
  puts "Found log file #{ log_file }, formatting file name for upload to S3 bucket #{ bucket } into folder #{ destination_full_path }"
33
33
 
@@ -45,7 +45,7 @@ module TnS3FileUploader
45
45
  end
46
46
 
47
47
  private
48
- def check_log_file(log_file_pattern)
48
+ def check_log_files(log_file_pattern)
49
49
  raise ArgumentError, 'log file pattern cannot be nil' if log_file_pattern == nil
50
50
 
51
51
  last_folder_separator = log_file_pattern.rindex('.')
@@ -63,6 +63,10 @@ module TnS3FileUploader
63
63
  path_components.first
64
64
  end
65
65
 
66
+ def last_modified_time(file)
67
+ File.mtime(file)
68
+ end
69
+
66
70
  def blank?(str)
67
71
  str.nil? || str == ""
68
72
  end
@@ -1,3 +1,3 @@
1
1
  module TnS3FileUploader
2
- VERSION = '0.1.6'
3
- end
2
+ VERSION = '0.1.8'
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tn_s3_file_uploader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thinknear.com
@@ -14,28 +14,28 @@ dependencies:
14
14
  name: honeybadger
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.15'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.15'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: aws-sdk
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.35'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.35'
41
41
  description: Amazon S3 file uploader that can build folder structures based on timestamp.
@@ -69,17 +69,17 @@ require_paths:
69
69
  - lib
70
70
  required_ruby_version: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - ">="
72
+ - - '>='
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  requirements:
77
- - - ">="
77
+ - - '>='
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0'
80
80
  requirements: []
81
81
  rubyforge_project:
82
- rubygems_version: 2.2.2
82
+ rubygems_version: 2.4.6
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: Amazon S3 file uploader