swirl 1.7.4 → 1.7.5
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 +15 -7
 - data/bin/swirl +13 -42
 - data/lib/swirl/aws.rb +15 -5
 - data/test/aws_test.rb +15 -0
 - metadata +5 -3
 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,14 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            Swirl
         
     | 
| 
       2 
2 
     | 
    
         
             
            =====
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            Swirl is an EC2 version agnostic client for EC2  
     | 
| 
      
 4 
     | 
    
         
            +
            Swirl is an EC2 version agnostic client for EC2 written in Ruby. It gets
         
     | 
| 
       5 
5 
     | 
    
         
             
            out of your way.
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
            The secret is it's simple input extraction and output compacting.  Your
         
     | 
| 
       8 
8 
     | 
    
         
             
            input parameters and `expand`ed and EC2's (terrible) xml output is
         
     | 
| 
       9 
9 
     | 
    
         
             
            `compact`ed.
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
11 
     | 
    
         
             
            Some simple examples:
         
     | 
| 
       13 
12 
     | 
    
         | 
| 
       14 
13 
     | 
    
         
             
                # Input
         
     | 
| 
         @@ -37,7 +36,7 @@ and 
     | 
|
| 
       37 
36 
     | 
    
         
             
                  }
         
     | 
| 
       38 
37 
     | 
    
         
             
                }
         
     | 
| 
       39 
38 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
            and it's  
     | 
| 
      
 39 
     | 
    
         
            +
            and it's variations are now `compact`ed to:
         
     | 
| 
       41 
40 
     | 
    
         | 
| 
       42 
41 
     | 
    
         
             
              {
         
     | 
| 
       43 
42 
     | 
    
         
             
                "reservationSet" => {
         
     | 
| 
         @@ -46,18 +45,17 @@ and it's varations are now `compact`ed to: 
     | 
|
| 
       46 
45 
     | 
    
         
             
              }
         
     | 
| 
       47 
46 
     | 
    
         | 
| 
       48 
47 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
            Some things worth  
     | 
| 
      
 48 
     | 
    
         
            +
            Some things worth noting is that compact ignores Symbols.  This
         
     | 
| 
       50 
49 
     | 
    
         
             
            allows you to pass the params into `call` and use them later
         
     | 
| 
       51 
     | 
    
         
            -
            without affecting the API call (i.e. chain of  
     | 
| 
      
 50 
     | 
    
         
            +
            without affecting the API call (i.e. chain of responsibility); a
         
     | 
| 
       52 
51 
     | 
    
         
             
            nifty trick we use in (Rack)[http://github.com/rack/rack]
         
     | 
| 
       53 
52 
     | 
    
         | 
| 
       54 
53 
     | 
    
         
             
            Use
         
     | 
| 
       55 
54 
     | 
    
         
             
            ---
         
     | 
| 
       56 
55 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
                require 'rubygems' # if you're using rubygems
         
     | 
| 
       58 
56 
     | 
    
         
             
                require 'swirl/aws'
         
     | 
| 
       59 
57 
     | 
    
         | 
| 
       60 
     | 
    
         
            -
                ec2 = Swirl:: 
     | 
| 
      
 58 
     | 
    
         
            +
                ec2 = Swirl::AWS.new(:ec2)
         
     | 
| 
       61 
59 
     | 
    
         | 
| 
       62 
60 
     | 
    
         
             
                # Describe all instances
         
     | 
| 
       63 
61 
     | 
    
         
             
                ec2.call "DescribeInstances"
         
     | 
| 
         @@ -65,9 +63,19 @@ Use 
     | 
|
| 
       65 
63 
     | 
    
         
             
                # Describe specific instances
         
     | 
| 
       66 
64 
     | 
    
         
             
                ec2.call "DescribeInstances", "InstanceId" => ["i-38hdk2f", "i-93nndch"]
         
     | 
| 
       67 
65 
     | 
    
         | 
| 
      
 66 
     | 
    
         
            +
                # Talk to a different region
         
     | 
| 
      
 67 
     | 
    
         
            +
                ec2_asia = Swirl::AWS.new(:ec2, :region => 'ap-southeast-1')
         
     | 
| 
       68 
68 
     | 
    
         | 
| 
       69 
69 
     | 
    
         
             
            Shell
         
     | 
| 
       70 
70 
     | 
    
         
             
            ---
         
     | 
| 
      
 71 
     | 
    
         
            +
                $ swirl -h
         
     | 
| 
      
 72 
     | 
    
         
            +
                Usage: swirl [options]
         
     | 
| 
      
 73 
     | 
    
         
            +
                    -a ACCOUT                        Account name (default is default)
         
     | 
| 
      
 74 
     | 
    
         
            +
                    -c FILE                          Swirl file (default is ~/.swirl)
         
     | 
| 
      
 75 
     | 
    
         
            +
                    -s service                       The AWS service to use (default is ec2)
         
     | 
| 
      
 76 
     | 
    
         
            +
                    -r region                        The AWS region to use (default is up to AWS)
         
     | 
| 
      
 77 
     | 
    
         
            +
                    -h, --help
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
       71 
79 
     | 
    
         | 
| 
       72 
80 
     | 
    
         
             
                $ swirl
         
     | 
| 
       73 
81 
     | 
    
         
             
                >> c
         
     | 
    
        data/bin/swirl
    CHANGED
    
    | 
         @@ -1,28 +1,24 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #!/usr/bin/env ruby
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'irb'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'yaml'
         
     | 
| 
       4 
     | 
    
         
            -
            require 'swirl'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'swirl/aws'
         
     | 
| 
       5 
5 
     | 
    
         
             
            require 'optparse'
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
            interactive = false
         
     | 
| 
       8 
7 
     | 
    
         
             
            account = "default"
         
     | 
| 
       9 
8 
     | 
    
         
             
            etc = "#{ENV["HOME"]}/.swirl"
         
     | 
| 
      
 9 
     | 
    
         
            +
            service = :ec2
         
     | 
| 
      
 10 
     | 
    
         
            +
            region = nil
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
       11 
12 
     | 
    
         
             
            ARGV.options do |o|
         
     | 
| 
       12 
13 
     | 
    
         
             
              o.on("-a ACCOUT", "Account name (default is default)") {|s| account = s }
         
     | 
| 
       13 
14 
     | 
    
         
             
              o.on("-c FILE", "Swirl file (default is ~/.swirl)") {|s| etc = s }
         
     | 
| 
       14 
     | 
    
         
            -
              o.on("- 
     | 
| 
      
 15 
     | 
    
         
            +
              o.on("-s service", "The AWS service to use (default is ec2)") {|s| service = s }
         
     | 
| 
      
 16 
     | 
    
         
            +
              o.on("-r region", "The AWS region to use (default is up to AWS)") {|s| region = s }
         
     | 
| 
       15 
17 
     | 
    
         
             
              o.on("-h", "--help") { puts o; exit }
         
     | 
| 
       16 
18 
     | 
    
         
             
              o.parse!
         
     | 
| 
       17 
19 
     | 
    
         
             
            end
         
     | 
| 
       18 
20 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
            config =  
     | 
| 
       20 
     | 
    
         
            -
            if ENV["AWS_ACCESS_KEY_ID"] && ENV["AWS_SECRET_ACCESS_KEY"]
         
     | 
| 
       21 
     | 
    
         
            -
              {
         
     | 
| 
       22 
     | 
    
         
            -
                :aws_access_key_id => ENV["AWS_ACCESS_KEY_ID"],
         
     | 
| 
       23 
     | 
    
         
            -
                :aws_secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"]
         
     | 
| 
       24 
     | 
    
         
            -
              }
         
     | 
| 
       25 
     | 
    
         
            -
            else
         
     | 
| 
      
 21 
     | 
    
         
            +
            config = (
         
     | 
| 
       26 
22 
     | 
    
         
             
              account = account.to_sym
         
     | 
| 
       27 
23 
     | 
    
         
             
              data = YAML.load_file(etc)
         
     | 
| 
       28 
24 
     | 
    
         
             
              if data.key?(account)
         
     | 
| 
         @@ -30,38 +26,13 @@ else 
     | 
|
| 
       30 
26 
     | 
    
         
             
              else
         
     | 
| 
       31 
27 
     | 
    
         
             
                abort("I don't see the account you're looking for")
         
     | 
| 
       32 
28 
     | 
    
         
             
              end
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
      
 29 
     | 
    
         
            +
            )
         
     | 
| 
       34 
30 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
            c = Swirl:: 
     | 
| 
      
 31 
     | 
    
         
            +
            c = Swirl::AWS.new service.to_sym, config.merge(:region => region)
         
     | 
| 
       36 
32 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
            #  
     | 
| 
       38 
     | 
    
         
            -
            #  
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
              # Create sugar for working in the console.
         
     | 
| 
       41 
     | 
    
         
            -
              # >> c.call "DescribeInstances", ...
         
     | 
| 
       42 
     | 
    
         
            -
              Kernel.send(:define_method, :c) { c }
         
     | 
| 
      
 33 
     | 
    
         
            +
            # Create sugar for working in the console.
         
     | 
| 
      
 34 
     | 
    
         
            +
            # >> c.call "DescribeInstances", ...
         
     | 
| 
      
 35 
     | 
    
         
            +
            Kernel.send(:define_method, :c) { c }
         
     | 
| 
       43 
36 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
            else
         
     | 
| 
       47 
     | 
    
         
            -
              begin
         
     | 
| 
       48 
     | 
    
         
            -
                case cmd = ARGV[0] || "list"
         
     | 
| 
       49 
     | 
    
         
            -
                when "list"
         
     | 
| 
       50 
     | 
    
         
            -
                  resvs = c.call("DescribeInstances")["reservationSet"]
         
     | 
| 
       51 
     | 
    
         
            -
                  insts = resvs.map {|r| r["instancesSet"] }.flatten
         
     | 
| 
       52 
     | 
    
         
            -
                  insts.each do |ins|
         
     | 
| 
       53 
     | 
    
         
            -
                    data = [
         
     | 
| 
       54 
     | 
    
         
            -
                        ins["instanceState"]["name"],
         
     | 
| 
       55 
     | 
    
         
            -
                        ins["instanceId"],
         
     | 
| 
       56 
     | 
    
         
            -
                        ins["availabilityZone"],
         
     | 
| 
       57 
     | 
    
         
            -
                        ins["dnsName"],
         
     | 
| 
       58 
     | 
    
         
            -
                        ins["privateDnsName"],
         
     | 
| 
       59 
     | 
    
         
            -
                        ins["launchTime"]
         
     | 
| 
       60 
     | 
    
         
            -
                    ]
         
     | 
| 
       61 
     | 
    
         
            -
                    puts data * "\t"
         
     | 
| 
       62 
     | 
    
         
            -
                  end
         
     | 
| 
       63 
     | 
    
         
            -
                end
         
     | 
| 
       64 
     | 
    
         
            -
              rescue => e
         
     | 
| 
       65 
     | 
    
         
            -
                $stderr.puts "! " + e.to_s
         
     | 
| 
       66 
     | 
    
         
            -
              end
         
     | 
| 
       67 
     | 
    
         
            -
            end
         
     | 
| 
      
 37 
     | 
    
         
            +
            # Start the interactive session
         
     | 
| 
      
 38 
     | 
    
         
            +
            IRB.start
         
     | 
    
        data/lib/swirl/aws.rb
    CHANGED
    
    | 
         @@ -29,8 +29,10 @@ module Swirl 
     | 
|
| 
       29 
29 
     | 
    
         
             
                  @services[name] = { :url => url, :version => version }
         
     | 
| 
       30 
30 
     | 
    
         
             
                end
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
                # Default Services
         
     | 
| 
      
 32 
     | 
    
         
            +
                # Default Services (Region not included)
         
     | 
| 
       33 
33 
     | 
    
         
             
                service :ec2, "https://ec2.amazonaws.com", "2010-11-15"
         
     | 
| 
      
 34 
     | 
    
         
            +
                service :elb, "https://elasticloadbalancing.amazonaws.com", "2010-07-01"
         
     | 
| 
      
 35 
     | 
    
         
            +
                service :iam, "https://iam.amazonaws.com", "2010-05-08"
         
     | 
| 
       34 
36 
     | 
    
         | 
| 
       35 
37 
     | 
    
         | 
| 
       36 
38 
     | 
    
         
             
                def initialize(*args)
         
     | 
| 
         @@ -40,11 +42,14 @@ module Swirl 
     | 
|
| 
       40 
42 
     | 
    
         
             
                  service = self.class.services[name] || {}
         
     | 
| 
       41 
43 
     | 
    
         
             
                  opts    = service.merge(opts)
         
     | 
| 
       42 
44 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
                  @url = opts[:url] ||
         
     | 
| 
      
 45 
     | 
    
         
            +
                  @url = URI(opts[:url]) ||
         
     | 
| 
       44 
46 
     | 
    
         
             
                    raise(ArgumentError, "No url given")
         
     | 
| 
       45 
47 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
                   
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
      
 48 
     | 
    
         
            +
                  if region = opts[:region]
         
     | 
| 
      
 49 
     | 
    
         
            +
                    parts = URI.split(@url.to_s)
         
     | 
| 
      
 50 
     | 
    
         
            +
                    parts[2] = parts[2].split('.').insert(1, region).join('.')
         
     | 
| 
      
 51 
     | 
    
         
            +
                    @url = URI::HTTPS.new(*parts)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  end
         
     | 
| 
       48 
53 
     | 
    
         | 
| 
       49 
54 
     | 
    
         
             
                  @version = opts[:version] ||
         
     | 
| 
       50 
55 
     | 
    
         
             
                    raise(ArgumentError, "No version given")
         
     | 
| 
         @@ -62,6 +67,7 @@ module Swirl 
     | 
|
| 
       62 
67 
     | 
    
         
             
                  @hmac = HMAC::SHA256.new(@aws_secret_access_key)
         
     | 
| 
       63 
68 
     | 
    
         
             
                end
         
     | 
| 
       64 
69 
     | 
    
         | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
       65 
71 
     | 
    
         
             
                def escape(value)
         
     | 
| 
       66 
72 
     | 
    
         
             
                  CGI.escape(value).gsub(/\+/, "%20")
         
     | 
| 
       67 
73 
     | 
    
         
             
                end
         
     | 
| 
         @@ -92,7 +98,11 @@ module Swirl 
     | 
|
| 
       92 
98 
     | 
    
         
             
                    when 200
         
     | 
| 
       93 
99 
     | 
    
         
             
                      response = compact(data)
         
     | 
| 
       94 
100 
     | 
    
         
             
                    when 400...500
         
     | 
| 
       95 
     | 
    
         
            -
                      messages =  
     | 
| 
      
 101 
     | 
    
         
            +
                      messages = if data["Response"]
         
     | 
| 
      
 102 
     | 
    
         
            +
                        Array(data["Response"]["Errors"]).map {|_, e| e["Message"] }
         
     | 
| 
      
 103 
     | 
    
         
            +
                      elsif data["ErrorResponse"]
         
     | 
| 
      
 104 
     | 
    
         
            +
                        Array(data["ErrorResponse"]["Error"]["Code"])
         
     | 
| 
      
 105 
     | 
    
         
            +
                      end
         
     | 
| 
       96 
106 
     | 
    
         
             
                      raise InvalidRequest, messages.join(",")
         
     | 
| 
       97 
107 
     | 
    
         
             
                    else
         
     | 
| 
       98 
108 
     | 
    
         
             
                      msg = "unexpected response #{code} -> #{data.inspect}"
         
     | 
    
        data/test/aws_test.rb
    ADDED
    
    | 
         @@ -0,0 +1,15 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'contest'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'swirl/aws'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            class AwsTest < Test::Unit::TestCase
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              test "raises InvalidRequest on ErrorResponse" do
         
     | 
| 
      
 7 
     | 
    
         
            +
                e = Swirl::AWS.new(:elb, :aws_access_key_id => 'AKIA', :aws_secret_access_key => 'secret')
         
     | 
| 
      
 8 
     | 
    
         
            +
                def e.call!(*args, &blk)
         
     | 
| 
      
 9 
     | 
    
         
            +
                  doc = {"ErrorResponse"=>{"Error"=>{"Code"=>"CertificateNotFound", "Type"=>"Sender"}}}
         
     | 
| 
      
 10 
     | 
    
         
            +
                  blk.call [400, doc]
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
                assert_raise(Swirl::InvalidRequest) { e.call "CreateLoadBalancer", {} }
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,13 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: swirl
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              hash:  
     | 
| 
      
 4 
     | 
    
         
            +
              hash: 1
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
              segments: 
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 1
         
     | 
| 
       8 
8 
     | 
    
         
             
              - 7
         
     | 
| 
       9 
     | 
    
         
            -
              -  
     | 
| 
       10 
     | 
    
         
            -
              version: 1.7. 
     | 
| 
      
 9 
     | 
    
         
            +
              - 5
         
     | 
| 
      
 10 
     | 
    
         
            +
              version: 1.7.5
         
     | 
| 
       11 
11 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       12 
12 
     | 
    
         
             
            authors: 
         
     | 
| 
       13 
13 
     | 
    
         
             
            - Blake Mizerany
         
     | 
| 
         @@ -82,6 +82,7 @@ files: 
     | 
|
| 
       82 
82 
     | 
    
         
             
            - lib/swirl/ec2.rb
         
     | 
| 
       83 
83 
     | 
    
         
             
            - lib/swirl/helpers.rb
         
     | 
| 
       84 
84 
     | 
    
         
             
            - lib/swirl.rb
         
     | 
| 
      
 85 
     | 
    
         
            +
            - test/aws_test.rb
         
     | 
| 
       85 
86 
     | 
    
         
             
            - test/compactor_test.rb
         
     | 
| 
       86 
87 
     | 
    
         
             
            - test/expander_test.rb
         
     | 
| 
       87 
88 
     | 
    
         
             
            - test/slop_test.rb
         
     | 
| 
         @@ -126,6 +127,7 @@ signing_key: 
     | 
|
| 
       126 
127 
     | 
    
         
             
            specification_version: 2
         
     | 
| 
       127 
128 
     | 
    
         
             
            summary: A version agnostic EC2 ruby driver
         
     | 
| 
       128 
129 
     | 
    
         
             
            test_files: 
         
     | 
| 
      
 130 
     | 
    
         
            +
            - test/aws_test.rb
         
     | 
| 
       129 
131 
     | 
    
         
             
            - test/compactor_test.rb
         
     | 
| 
       130 
132 
     | 
    
         
             
            - test/expander_test.rb
         
     | 
| 
       131 
133 
     | 
    
         
             
            - test/slop_test.rb
         
     |