aws_info 0.2.0 → 0.3.0

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: 00e55aa41f5e36b0e398d0b4e719954aa22fcf65
4
- data.tar.gz: 8cddd9e4c292e9242c4dcfe114f6a59f9c56bb6a
3
+ metadata.gz: 1dc98127c424626815792480e2a2cf267b92cbc2
4
+ data.tar.gz: 5585ef58f1e8a35cba2a09f303c857368e79c00f
5
5
  SHA512:
6
- metadata.gz: 1a8701455eb700a23e96a727eb3c0d0860284013d3a5fbe139243d566595ee4d0c2a65c763a41b2a7b17bff7c545fbea399b961f83bfcfba63ad054fa71b4726
7
- data.tar.gz: 5d86453769569040db6281d04c8407257f0483d2c83b27a36683fd19227aff60a3407ff767dcf387dc335e140ed3137a3f91411b4a1f41b80d25cdfe40474e1b
6
+ metadata.gz: 02fcb2c0c6d807fd27b984bfa9d545174448599876fefd5ac936c9ea8c25ba1cef4ba7c27e1547ebfc6164a829a40373dd7783e7da53fae514c0c5f31251440d
7
+ data.tar.gz: 82325b19e6bcb73899e96fd10c6a0405f367e0c52bc150c7c69d1e6d8acaccd16a95b179a72eb96e5e9631cd59ec0151af40b66333cffbf8099a3b3bfbd86a2d
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .ruby-gemset
11
+ .ruby-version
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # AwsInfo
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/aws_info`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ A gem to provide an easy way to load the AWS information from a given AWS instance. Automatically detect server IP, Region, Availability Zone, etc. as well as instance tags.
4
+
5
+ Under the hood this gem uses the aws meta data lookup url for instance information:
6
+ http://169.254.169.254/latest/dynamic/instance-identity/document
7
+
8
+ And it uses aws describe tags command on the aws server to get a list of tags: "aws ec2 describe-tags ..."
4
9
 
5
- TODO: Delete this and the text above, and describe your gem
6
10
 
7
11
  ## Installation
8
12
 
@@ -22,17 +26,65 @@ Or install it yourself as:
22
26
 
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ ```ruby
30
+ require 'aws_info'
31
+
32
+ AwsInfo.region
33
+ #=> "us-east-1"
34
+
35
+ AwsInfo.ip
36
+ #=> "10.10.10.10"
37
+
38
+ AwsInfo.availability_zone
39
+ #=> "us-east-1b"
40
+
41
+ AwsInfo.instance_id
42
+ #=> "i-00000000"
43
+
44
+ AwsInfo.instance_type
45
+ #=> "t2.micro"
46
+
47
+ AwsInfo.version
48
+ #=> "2015-1-21"
49
+
50
+ AwsInfo.dev_pay_product_codes
51
+ #=> nil
26
52
 
27
- ## Development
53
+ AwsInfo.billing_products
54
+ #=> nil
55
+
56
+ AwsInfo.account_id
57
+ #=> "00000000000"
58
+
59
+ AwsInfo.pending_time
60
+ #=> "2015-09-04T19:03:47Z"
61
+
62
+ AwsInfo.image_id
63
+ #=> "ami-c8888888"
64
+
65
+ AwsInfo.kernel_id
66
+ #=> nil
67
+
68
+ AwsInfo.ram_disk_id
69
+ #=> nil
70
+
71
+ AwsInfo.architecture
72
+ #=> "x86_64"
73
+
74
+ AwsInfo.tags
75
+ #=> { 'my_tag' => 'my tag's value!'}
76
+
77
+ # Access a single tag
78
+ AwsInfo.tags['my_tag']
79
+ #=> "my tag's value!"
80
+
81
+ ```
28
82
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
83
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
84
 
33
85
  ## Contributing
34
86
 
35
- 1. Fork it ( https://github.com/[my-github-username]/aws_info/fork )
87
+ 1. Fork it ( https://github.com/thomas07vt/aws_info/fork )
36
88
  2. Create your feature branch (`git checkout -b my-new-feature`)
37
89
  3. Commit your changes (`git commit -am 'Add some feature'`)
38
90
  4. Push to the branch (`git push origin my-new-feature`)
@@ -1,5 +1,6 @@
1
1
  require 'net/http'
2
2
  require 'json'
3
+ require 'timeout'
3
4
 
4
5
  module AwsInfo
5
6
 
@@ -74,7 +75,7 @@ module AwsInfo
74
75
  private
75
76
 
76
77
  def load_tag_data
77
- tag_array = JSON.parse(query_tag_data)["Tags"]
78
+ tag_array = JSON.parse(query_tag_data)["Tags"] rescue []
78
79
  tag_array.inject({}) { |tags, e| tags[e["Key"]] = e["Value"]; tags }
79
80
  end
80
81
 
@@ -90,7 +91,10 @@ module AwsInfo
90
91
  end
91
92
 
92
93
  def query_instance_identity
93
- Net::HTTP.get(URI.parse('http://169.254.169.254/latest/dynamic/instance-identity/document'))
94
+ Timeout::timeout(5) {
95
+ url = 'http://169.254.169.254/latest/dynamic/instance-identity/document'
96
+ Net::HTTP.get(URI.parse(url))
97
+ }
94
98
  end
95
99
 
96
100
  end # End class methods
@@ -1,3 +1,3 @@
1
1
  module AwsInfo
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Thomas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-08 00:00:00.000000000 Z
11
+ date: 2015-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler