jaxx 0.0.7 → 0.0.8

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.
data/README.md CHANGED
@@ -44,6 +44,14 @@ Or install it yourself as:
44
44
  -h, --help
45
45
  ```
46
46
 
47
+ ### About Me
48
+ ```
49
+ jaxx-aboutme -h
50
+ jaxx-aboutme [options]
51
+ -d, --display
52
+ -h, --help
53
+ ```
54
+
47
55
  ## Examples
48
56
 
49
57
  ### Upload from local machine
@@ -71,6 +79,11 @@ Or install it yourself as:
71
79
  jaxx-upload -b test-bucket -f vapour.txt -k MY_KEY -s MY_SECRET -p public
72
80
  ```
73
81
 
82
+ ### Get information on the instance you are currently on
83
+ ```
84
+ jaxx-aboutme -d
85
+ ```
86
+
74
87
  ## Contributing
75
88
 
76
89
  1. Fork it
data/bin/jaxx-aboutme ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'jaxx/cli'
5
+ Jaxx::CLI.execute(:aboutme, ARGV)
@@ -0,0 +1,6 @@
1
+ Feature: About Me
2
+
3
+ Scenario:
4
+ When I run `jaxx-aboutme -h`
5
+ Then the exit status should be 0
6
+ And the output should contain "jaxx-aboutme [options]"
@@ -0,0 +1,38 @@
1
+ require 'jaxx/environment'
2
+ require 'jaxx/api_mapper'
3
+
4
+ module Jaxx
5
+ class AboutMe
6
+ extend ApiMapper
7
+
8
+ host "169.254.169.254"
9
+ base_path "/latest/meta-data"
10
+
11
+ attribute_via_path :ami_id
12
+ attribute_via_path :ami_launch_index
13
+ attribute_via_path :ami_manifest_path
14
+ attribute_via_path :hostname
15
+ attribute_via_path :instance_action
16
+ attribute_via_path :instance_id
17
+ attribute_via_path :instance_type
18
+ attribute_via_path :kernel_id
19
+ attribute_via_path :local_hostname
20
+ attribute_via_path :local_ipv4
21
+ attribute_via_path :mac
22
+ attribute_via_path :profile
23
+ attribute_via_path :public_hostname
24
+ attribute_via_path :public_ipv4
25
+ attribute_via_path :reservation_id
26
+ attribute_via_path :security_groups
27
+ attribute_via_path :az, 'placement/availability-zone'
28
+
29
+ def to_hash
30
+ self.class.api_attributes.inject({}) {|hsh, at| hsh[at] = send(at); hsh }
31
+ end
32
+
33
+ def inspect
34
+ self.to_hash.to_s
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,54 @@
1
+ require 'timeout'
2
+
3
+ module Jaxx
4
+
5
+ module ApiMapper
6
+
7
+ def self.extended klass
8
+ klass.extend(ClassMethods)
9
+ klass.class_eval { include(InstanceMethods) }
10
+ end
11
+
12
+ module ClassMethods
13
+
14
+ def api_attributes
15
+ @api_attibutes ||= []
16
+ end
17
+
18
+ def attribute_via_path meth, path = nil
19
+ path ||= meth.to_s.gsub('_', '-')
20
+ define_method(meth.to_sym) { make_request path }
21
+ api_attributes.push(meth.to_sym)
22
+ end
23
+
24
+ def host h = nil
25
+ @host = h if h
26
+ @host
27
+ end
28
+
29
+ def base_path bp = nil
30
+ @base_path = bp if bp
31
+ @base_path
32
+ end
33
+
34
+ end
35
+
36
+ module InstanceMethods
37
+
38
+ private
39
+
40
+ def make_request path
41
+ u = URI::HTTP.build :host => self.class.host, :path => full_path_for(path)
42
+ Timeout.timeout(1) do
43
+ Net::HTTP.get u.host, u.path
44
+ end
45
+ end
46
+
47
+ def full_path_for partial
48
+ [self.class.base_path, partial].compact.flatten.join('/').gsub('//', '/')
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+ end
data/lib/jaxx/cli.rb CHANGED
@@ -5,13 +5,23 @@ module Jaxx
5
5
  module CLI
6
6
 
7
7
  def self.execute meth, args
8
- parser.parse!(args)
9
- options.empty? ? (Jaxx.logger.write(parser) and exit) : Jaxx.send(meth, options)
8
+
9
+ case meth
10
+ when :upload, :download
11
+ default_parser.parse!(args)
12
+ (Jaxx.logger.write(default_parser) and exit) if options.empty?
13
+ when :aboutme
14
+ aboutme_parser.parse!(args)
15
+ (Jaxx.logger.write(aboutme_parser) and exit) unless options['display']
16
+ end
17
+
18
+ Jaxx.send(meth, options)
10
19
  rescue RuntimeError => exc
20
+ Jaxx.logger.write "An error occurred: #{exc.message}\n"
11
21
  exit 1
12
22
  end
13
23
 
14
- def self.parser
24
+ def self.default_parser
15
25
  OptionParser.new do |o|
16
26
  o.banner = "jaxx [options]"
17
27
 
@@ -19,11 +29,19 @@ module Jaxx
19
29
  o.on('-k', '--access-key [ACCESS_KEY]') { |k| options['access_key'] = k }
20
30
  o.on('-s', '--access-secret [ACCESS_SECRET]') { |s| options['access_secret'] = s }
21
31
  o.on('-f', '--file [FILE]') { |f| options['file'] = f }
22
- o.on('-p', '--privacy [PRIVACY]') { |p| options['privacy'] = p }
32
+ o.on('-p', '--privacy [privacy]') { |p| options['privacy'] = p }
23
33
  o.on('-h', '--help') { o }
24
34
  end
25
35
  end
26
36
 
37
+ def self.aboutme_parser
38
+ OptionParser.new do |o|
39
+ o.banner = "jaxx-aboutme [options]"
40
+ o.on('-d', '--display') { |d| options['display'] = d }
41
+ o.on('-h', '--help') { o }
42
+ end
43
+ end
44
+
27
45
  def self.options
28
46
  @options ||= {}
29
47
  end
data/lib/jaxx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jaxx
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/jaxx.rb CHANGED
@@ -2,10 +2,15 @@ require "jaxx/version"
2
2
  require "jaxx/environment"
3
3
  require "jaxx/upload"
4
4
  require "jaxx/download"
5
+ require "jaxx/about_me"
5
6
  require "logger"
6
7
 
7
8
  module Jaxx
8
9
 
10
+ def self.aboutme args = {}
11
+ Jaxx::AboutMe.new.to_hash.each {|k,v| logger.write "#{k} : #{v}" }
12
+ end
13
+
9
14
  def self.upload args = {}
10
15
  Jaxx::Upload.new(args).execute
11
16
  end
@@ -1,4 +1,5 @@
1
1
  require 'fakeweb'
2
+ require 'jaxx/about_me'
2
3
 
3
4
  module ServiceHelper
4
5
 
@@ -10,4 +11,27 @@ module ServiceHelper
10
11
  })
11
12
  end
12
13
 
14
+ def stub_meta_request path, body
15
+ uri = if path.kind_of?(String)
16
+ URI::HTTP.build(:host => Jaxx::AboutMe.host, :path => [Jaxx::AboutMe.base_path, path].join('/'))
17
+ else
18
+ path
19
+ end
20
+ FakeWeb.register_uri :get, uri, :body => body
21
+ end
22
+
23
+ def stub_meta_request_by_method meth, body
24
+ path = meth.to_s.gsub('_', '-')
25
+ stub_meta_request path, body
26
+ end
27
+
28
+ def ensure_api_response meth, expected_response = "", path = nil
29
+ if path
30
+ stub_meta_request path, expected_response
31
+ else
32
+ stub_meta_request_by_method meth, expected_response
33
+ end
34
+
35
+ subject.send(meth).should == expected_response
36
+ end
13
37
  end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+
4
+ module Jaxx
5
+ describe AboutMe do
6
+
7
+ it "#ami_id" do
8
+ ensure_api_response :ami_id, "ami-123"
9
+ end
10
+
11
+ it "#ami_launch_index" do
12
+ ensure_api_response :ami_id, "0"
13
+ end
14
+
15
+ it "#ami-manifest-path" do
16
+ ensure_api_response :ami_id, "manifest.xml"
17
+ end
18
+
19
+ it "#block-device-mapping"
20
+
21
+ it "#hostname" do
22
+ ensure_api_response :hostname, "ip-123-123"
23
+ end
24
+
25
+ it "#instance_action" do
26
+ ensure_api_response :instance_action, "none"
27
+ end
28
+
29
+ it "#instance_id" do
30
+ ensure_api_response :instance_id, "123"
31
+ end
32
+
33
+ it "#instance_type" do
34
+ ensure_api_response :instance_type, "m1.small"
35
+ end
36
+
37
+ it "#kernel_id" do
38
+ ensure_api_response :kernel_id, "aki-123"
39
+ end
40
+
41
+ it "#local_hostname" do
42
+ ensure_api_response :local_hostname, "ip-123"
43
+ end
44
+
45
+ it "#local_ipv4" do
46
+ ensure_api_response :local_ipv4, "127.0.0.1"
47
+ end
48
+
49
+ it "#mac" do
50
+ ensure_api_response :mac, "123-456-78"
51
+ end
52
+
53
+ it "#metrics"
54
+
55
+ it "#network"
56
+
57
+ it "#placement" do
58
+ ensure_api_response :az, "us-east-1", "placement/availability-zone"
59
+ end
60
+
61
+ it "#profile" do
62
+ ensure_api_response :profile, "default"
63
+ end
64
+
65
+ it "#public_hostname" do
66
+ ensure_api_response :public_hostname, "ec2-1223.com"
67
+ end
68
+
69
+ it "#public_ipv4" do
70
+ ensure_api_response :public_ipv4, "52.51.52.51"
71
+ end
72
+
73
+ it "#public_keys"
74
+
75
+ it "#reservation_id" do
76
+ ensure_api_response :reservation_id, "r-123"
77
+ end
78
+
79
+ it "#security_groups" do
80
+ ensure_api_response :security_groups, "default"
81
+ end
82
+
83
+ it "#to_hash" do
84
+ stub_meta_request /#{described_class.host}/, ""
85
+ hsh = subject.to_hash
86
+
87
+ hsh.should be_kind_of(Hash)
88
+ hsh.keys.should == subject.class.api_attributes
89
+ end
90
+ end
91
+ end
data/spec/spec_helper.rb CHANGED
@@ -7,7 +7,6 @@ require 'rspec'
7
7
 
8
8
  Jaxx.logger StringIO.new
9
9
 
10
-
11
10
  require_relative 'helpers/service'
12
11
 
13
12
  RSpec.configure do |c|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jaxx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-04 00:00:00.000000000 Z
12
+ date: 2013-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
@@ -159,6 +159,7 @@ description: Command line wrapper for pushing files to S3
159
159
  email:
160
160
  - marcky.sharky@googlemail.com
161
161
  executables:
162
+ - jaxx-aboutme
162
163
  - jaxx-download
163
164
  - jaxx-upload
164
165
  extensions: []
@@ -171,14 +172,18 @@ files:
171
172
  - LICENSE
172
173
  - README.md
173
174
  - Rakefile
175
+ - bin/jaxx-aboutme
174
176
  - bin/jaxx-download
175
177
  - bin/jaxx-upload
178
+ - features/about_me.feature
176
179
  - features/download.feature
177
180
  - features/step_definitions/global_steps.rb
178
181
  - features/support/env.rb
179
182
  - features/upload.feature
180
183
  - jaxx.gemspec
181
184
  - lib/jaxx.rb
185
+ - lib/jaxx/about_me.rb
186
+ - lib/jaxx/api_mapper.rb
182
187
  - lib/jaxx/cli.rb
183
188
  - lib/jaxx/download.rb
184
189
  - lib/jaxx/environment.rb
@@ -186,6 +191,7 @@ files:
186
191
  - lib/jaxx/upload.rb
187
192
  - lib/jaxx/version.rb
188
193
  - spec/helpers/service.rb
194
+ - spec/lib/jaxx/aboutme_spec.rb
189
195
  - spec/lib/jaxx/download_spec.rb
190
196
  - spec/lib/jaxx/environment_spec.rb
191
197
  - spec/lib/jaxx/process_spec.rb
@@ -206,7 +212,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
206
212
  version: '0'
207
213
  segments:
208
214
  - 0
209
- hash: -3593103380560459674
215
+ hash: 125363151703119624
210
216
  required_rubygems_version: !ruby/object:Gem::Requirement
211
217
  none: false
212
218
  requirements:
@@ -215,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
221
  version: '0'
216
222
  segments:
217
223
  - 0
218
- hash: -3593103380560459674
224
+ hash: 125363151703119624
219
225
  requirements: []
220
226
  rubyforge_project:
221
227
  rubygems_version: 1.8.25
@@ -223,11 +229,13 @@ signing_key:
223
229
  specification_version: 3
224
230
  summary: RubyGems to allow any file to be pushed to S3 in the simplist way
225
231
  test_files:
232
+ - features/about_me.feature
226
233
  - features/download.feature
227
234
  - features/step_definitions/global_steps.rb
228
235
  - features/support/env.rb
229
236
  - features/upload.feature
230
237
  - spec/helpers/service.rb
238
+ - spec/lib/jaxx/aboutme_spec.rb
231
239
  - spec/lib/jaxx/download_spec.rb
232
240
  - spec/lib/jaxx/environment_spec.rb
233
241
  - spec/lib/jaxx/process_spec.rb