tn_s3_file_uploader 0.1.8 → 0.1.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7eaa24797da8fe43d9f3c72169f9d41686eaec5e
4
- data.tar.gz: 855f649660e7ddd96c0d2e26663b92cfc546e92d
3
+ metadata.gz: 7f60a16847c7c072d148a3accaf2ed48b1535aeb
4
+ data.tar.gz: fe05f935dec58056e2a7717d9f21bfab031751c5
5
5
  SHA512:
6
- metadata.gz: 40d472d1a25293fa8f057fa06b8d8b9b9339ec279f1cb8c8202dd16885be22b8c11ff6477416be77ddeddd4ba5601c44a71c5242543d9a292b23e10758a92931
7
- data.tar.gz: 96335682165b4ecd26d0f7a9bc3ab33017c5134b6a6301e101d0cced5d7489d678a459f2849495ed39570689f22f4ed97bc87795111cccba4724ae034d380f82
6
+ metadata.gz: 3ae8a26d5339599ac657cccbcbdc19ae71fcfb8f1a81bc360976679e78e9d17786e3a4df3c07666065210d3c99cca0549d263de52c4ee930e906d9a86cb461a9
7
+ data.tar.gz: 0080d296b62139eb18c30d329f76769b9912655a6f9cfb0ab5c873ff76c79f0ed3fef675d61f413b4780939c57238ec2939bb58b84d93d5e389618a0fd81739d
@@ -50,13 +50,11 @@ module TnS3FileUploader
50
50
  opts.on("--aws-secret-access-key AWS-SECRET-ACCESS-KEY", "Provide the AWS secret access key") do |aws_secret_access_key|
51
51
  options[:aws_secret_access_key] = aws_secret_access_key
52
52
  end
53
-
54
- # Default: Google's static IP
55
- options[:udp_resolve_ip] = '64.233.187.99'
56
- opts.on("--udp_resolve_ip RESOLVE-IP", "Lookup IP to determine active network interface local IP.") do |resolve_ip|
57
- if resolve_ip =~ /\d+\.\d+\.\d+\.\d+/
58
- options[:udp_resolve_ip] = resolve_ip
59
- end
53
+
54
+ options[:use_ec2_metadata_flag] = true
55
+ opts.on("--use-ec2-metadata [USE_EC2_METADATA]", "The flag for using the ec2 instance metadata endpoint to lookup the local IP."\
56
+ "It is an optional parameter, default is true.") do |use_ec2_metadata|
57
+ options[:use_ec2_metadata_flag] = use_ec2_metadata
60
58
  end
61
59
 
62
60
  opts.on("-v", "--verbose", "Display verbose output") do |v|
@@ -1,4 +1,5 @@
1
1
  require 'rubygems'
2
+ require 'net/http'
2
3
 
3
4
  module TnS3FileUploader
4
5
 
@@ -15,6 +16,8 @@ module TnS3FileUploader
15
16
  # date = Wed Jun 18 19:03:40 UTC 2014
16
17
  class FilePathGenerator
17
18
 
19
+ EC2_INSTANCE_METADATA_IP='169.254.169.254'
20
+
18
21
  def initialize(options)
19
22
  #Find the last rotation window
20
23
  @options = options
@@ -62,16 +65,15 @@ module TnS3FileUploader
62
65
  end
63
66
  end
64
67
 
65
- # First tries to find local IP using UDPSocket technique.
68
+ # First tries to find local IP using the EC2 instance metadata endpoint.
66
69
  # In the event of a failure, we will revert to using the old
67
70
  # method of local ip retrieval. In the event that both techniques
68
71
  # fail, we return a default value
69
72
  def local_ip
70
- resolve_ip = @options[:udp_resolve_ip]
71
73
  ip_address = nil
72
-
73
- unless resolve_ip.nil?
74
- ip_address = udp_resolve_ip(resolve_ip)
74
+
75
+ if @options[:use_ec2_metadata_flag]
76
+ ip_address = ec2_instance_metadata_local_ip
75
77
  end
76
78
 
77
79
  unless ip_address.nil? or valid_ip?(ip_address)
@@ -81,27 +83,14 @@ module TnS3FileUploader
81
83
  unless valid_ip?(ip_address)
82
84
  ip_address = '0.0.0.0'
83
85
  end
84
-
86
+
85
87
  ip_address
86
88
  end
87
89
 
88
- # Finds public local IP by tracing a UDP route.
89
- # Note: This code does NOT make a connection or send any packets to the listed resolve_ip
90
- # UDP is a stateless protocol, the connect method makes
91
- # a system call to determine packet routing based on address and what interface it
92
- # should bind to. addr returns an array containing the family, local port and local address
93
- # The local address is the last element in the addr array.
94
- def udp_resolve_ip(resolve_ip)
95
- orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
96
-
97
- UDPSocket.open do |s|
98
- s.connect resolve_ip, 1
99
- s.addr.last
100
- end
101
- ensure
102
- Socket.do_not_reverse_lookup = orig
90
+ def ec2_instance_metadata_local_ip
91
+ Net::HTTP.get(EC2_INSTANCE_METADATA_IP, '/latest/meta-data/local-ipv4') rescue nil
103
92
  end
104
-
93
+
105
94
  def hostname_resolve_ip
106
95
  IPSocket.getaddress(Socket.gethostname)
107
96
  end
@@ -1,3 +1,3 @@
1
1
  module TnS3FileUploader
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tn_s3_file_uploader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thinknear.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-05 00:00:00.000000000 Z
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: honeybadger
@@ -61,7 +61,7 @@ files:
61
61
  - lib/tn_s3_file_uploader/version.rb
62
62
  homepage: http://www.thinknear.com
63
63
  licenses:
64
- - Copyright (c) ThinkNear 2014, Licensed under APLv2.0
64
+ - Copyright (c) ThinkNear 2014-2015, Licensed under APLv2.0
65
65
  metadata: {}
66
66
  post_install_message:
67
67
  rdoc_options: []