simple_aws 0.0.1a

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/lib/aws/ec2.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'aws/api'
2
+ require 'aws/call_types/action_param'
3
+
4
+ module AWS
5
+
6
+ ##
7
+ # Amazon's Elastic Computing Cloud
8
+ #
9
+ # http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html
10
+ #
11
+ # All requests are POST and always through HTTPS. Use the third parameter to
12
+ # #initialize if you need to talk to a region other than us-east-1.
13
+ ##
14
+ class EC2 < API
15
+ endpoint "ec2"
16
+ use_https true
17
+ version "2011-11-01"
18
+
19
+ include CallTypes::ActionParam
20
+ end
21
+
22
+ end
data/lib/aws/elb.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'aws/api'
2
+ require 'aws/call_types/action_param'
3
+
4
+ module AWS
5
+
6
+ ##
7
+ # Amazon's Elastic Load Balancing API
8
+ #
9
+ # http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference/
10
+ #
11
+ # All requests are POST and always through HTTPS. Use the third parameter to
12
+ # #initialize if you need to talk to a region other than us-east-1.
13
+ ##
14
+ class ELB < API
15
+ endpoint "elasticloadbalancing"
16
+ use_https true
17
+ version "2011-11-15"
18
+
19
+ include CallTypes::ActionParam
20
+ end
21
+ end
data/lib/aws/iam.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'aws/api'
2
+ require 'aws/call_types/action_param'
3
+
4
+ module AWS
5
+
6
+ ##
7
+ # Amazon's Identity and Access Management
8
+ #
9
+ # http://docs.amazonwebservices.com/IAM/latest/APIReference/
10
+ #
11
+ # All requests are POST and always through HTTPS. Use the third parameter to
12
+ # #initialize if you need to talk to a region other than us-east-1.
13
+ ##
14
+ class IAM < API
15
+ endpoint "iam"
16
+ use_https true
17
+ version "2010-05-08"
18
+
19
+ include CallTypes::ActionParam
20
+ end
21
+
22
+ end
data/samples/ec2.rb ADDED
@@ -0,0 +1,41 @@
1
+ $: << File.expand_path("../../lib", __FILE__)
2
+
3
+ require 'aws/ec2'
4
+
5
+ ##
6
+ # Expects your Amazon keys to be in the environment, something like
7
+ #
8
+ # export AWS_KEY="KEY"
9
+ # export AWS_SECRET="SECRET"
10
+ ##
11
+
12
+ ec2 = AWS::EC2.new ENV["AWS_KEY"], ENV["AWS_SECRET"]
13
+
14
+ puts "", "Standard Only Addresses", ""
15
+
16
+ ec2.describe_addresses("Filter" => {"Name" => "domain", "Value" => "standard"}).addresses_set.each do |address|
17
+ puts "IP: #{address.public_ip}"
18
+ puts "Instance ID: #{address.instance_id}"
19
+ puts "Domain: #{address.domain}"
20
+ puts ""
21
+ end
22
+
23
+ puts "", "VPC Only addresses", ""
24
+
25
+ ec2.describe_addresses("Filter" => {"Name" => "domain", "Value" => "vpc"}).addresses_set.each do |address|
26
+ puts "IP: #{address.public_ip}"
27
+ puts "Instance ID: #{address.instance_id}"
28
+ puts "Domain: #{address.domain}"
29
+ puts "Allocation ID: #{address.allocation_id}"
30
+ puts "Association ID: #{address.association_id}"
31
+ puts ""
32
+ end
33
+
34
+ puts "", "Ask for both explicitly", ""
35
+
36
+ ec2.describe_addresses("Filter" => {"Name" => "domain", "Value" => ["standard", "vpc"]}).addresses_set.each do |address|
37
+ puts "IP: #{address.public_ip}"
38
+ puts "Instance ID: #{address.instance_id}"
39
+ puts "Domain: #{address.domain}"
40
+ puts ""
41
+ end
data/samples/elb.rb ADDED
@@ -0,0 +1,26 @@
1
+ $: << File.expand_path("../../lib", __FILE__)
2
+
3
+ require 'aws/elb'
4
+
5
+ ##
6
+ # Expects your Amazon keys to be in the environment, something like
7
+ #
8
+ # export AWS_KEY="KEY"
9
+ # export AWS_SECRET="SECRET"
10
+ ##
11
+
12
+ $elb = AWS::ELB.new ENV["AWS_KEY"], ENV["AWS_SECRET"]
13
+
14
+ puts "", "Your Load Balancers", ""
15
+
16
+ $elb.describe_load_balancers.load_balancer_descriptions.each do |elb|
17
+ puts "Name: #{elb.load_balancer_name}"
18
+ puts "HealthCheck: #{elb.health_check.inspect}"
19
+
20
+ elb.listener_descriptions.each do |desc|
21
+ l = desc.listener
22
+ puts "Listener: #{l.protocol}:#{l.load_balancer_port} => #{l.instance_protocol}:#{l.instance_port}"
23
+ end
24
+
25
+ puts ""
26
+ end
data/samples/iam.rb ADDED
@@ -0,0 +1,30 @@
1
+ $: << File.expand_path("../../lib", __FILE__)
2
+
3
+ require 'aws/iam'
4
+
5
+ ##
6
+ # Expects your Amazon keys to be in the environment, something like
7
+ #
8
+ # export AWS_KEY="KEY"
9
+ # export AWS_SECRET="SECRET"
10
+ ##
11
+
12
+ $iam = AWS::IAM.new ENV["AWS_KEY"], ENV["AWS_SECRET"]
13
+
14
+ puts "", "You are", ""
15
+
16
+ user = $iam.get_user.user
17
+ puts "Id: #{user.user_id}"
18
+ puts "Name: #{user.user_name}"
19
+ puts "Arn: #{user.arn}"
20
+ puts "Create Date: #{Time.parse user.create_date}"
21
+
22
+ puts "", "Your SSL Certificates", ""
23
+
24
+ $iam.list_server_certificates.server_certificate_metadata_list.each do |cert|
25
+ puts "Id: #{cert.server_certificate_id}"
26
+ puts "Path: #{cert.path}"
27
+ puts "Arn: #{cert.arn}"
28
+ puts "UploadDate: #{cert.upload_date}"
29
+ puts ""
30
+ end
@@ -0,0 +1,21 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "simple_aws"
3
+ s.version = "0.0.1a"
4
+ s.platform = Gem::Platform::RUBY
5
+ s.authors = ["Jason Roelofs"]
6
+ s.email = ["jameskilton@gmail.com"]
7
+
8
+ # s.homepage = ""
9
+
10
+ s.summary = "The simplest and easiest to use and maintain AWS communication library"
11
+ s.description = "The simplest and easiest to use and maintain AWS communication library"
12
+
13
+ s.add_dependency "ox"
14
+ s.add_dependency "httparty"
15
+
16
+ s.add_dependency "jruby-openssl" if RUBY_PLATFORM == 'java'
17
+
18
+ s.files = `git ls-files`.split "\n"
19
+ s.test_files = `git ls-files -- test/*`.split "\n"
20
+ s.require_paths = ['lib']
21
+ end
@@ -0,0 +1,101 @@
1
+ require 'test_helper'
2
+ require 'aws/api'
3
+
4
+ describe AWS::API do
5
+
6
+ class TestAPI < AWS::API
7
+ end
8
+
9
+ describe ".endpoint" do
10
+ it "allows definition of an endpoint for an API implementation" do
11
+ TestAPI.endpoint "test-endpoint"
12
+ end
13
+ end
14
+
15
+ describe ".default_region" do
16
+ it "allows specification of a default endpoint" do
17
+ TestAPI.default_region "us-west-1"
18
+ end
19
+ end
20
+
21
+ describe ".use_https" do
22
+ it "can be told to use HTTPS over HTTP" do
23
+ TestAPI.use_https true
24
+ end
25
+ end
26
+
27
+ describe ".version" do
28
+ it "allows specifying version of the API" do
29
+ TestAPI.version "2011-01-04"
30
+ end
31
+ end
32
+
33
+ describe "#initialize" do
34
+ it "takes AWS key and secret on construction" do
35
+ obj = TestAPI.new "access_key", "secret_key"
36
+ obj.access_key.must_equal "access_key"
37
+ obj.secret_key.must_equal "secret_key"
38
+ end
39
+
40
+ it "can also take a region" do
41
+ obj = TestAPI.new "access_key", "secret_key", "region"
42
+ obj.region.must_equal "region"
43
+ end
44
+
45
+ it "makes version available" do
46
+ TestAPI.version "2011-02-02"
47
+ obj = TestAPI.new "access_key", "secret_key"
48
+ obj.version.must_equal "2011-02-02"
49
+ end
50
+ end
51
+
52
+ describe "#region" do
53
+ it "uses default region if none given on constructor" do
54
+ TestAPI.default_region "us-west-1"
55
+ obj = TestAPI.new "access_key", "secret_key"
56
+
57
+ obj.region.must_equal "us-west-1"
58
+ end
59
+ end
60
+
61
+ describe "#uri" do
62
+ before do
63
+ TestAPI.endpoint nil
64
+ TestAPI.default_region nil
65
+ TestAPI.use_https nil
66
+ end
67
+
68
+ it "returns the full URI to the API endpoint in question" do
69
+ TestAPI.endpoint "testing-endpoint"
70
+ TestAPI.default_region nil
71
+
72
+ obj = TestAPI.new "key", "secret"
73
+ obj.uri.must_equal "http://testing-endpoint.amazonaws.com"
74
+ end
75
+
76
+ it "adds the region to the URI if specified in default_region" do
77
+ TestAPI.endpoint "testing-endpoint"
78
+ TestAPI.default_region "us-east-1"
79
+
80
+ obj = TestAPI.new "key", "secret"
81
+ obj.uri.must_equal "http://testing-endpoint.us-east-1.amazonaws.com"
82
+ end
83
+
84
+ it "adds the region to the URI if specified in constructor" do
85
+ TestAPI.endpoint "testing-endpoint"
86
+ TestAPI.default_region "us-east-1"
87
+
88
+ obj = TestAPI.new "key", "secret", "eu-west-1"
89
+ obj.uri.must_equal "http://testing-endpoint.eu-west-1.amazonaws.com"
90
+ end
91
+
92
+ it "uses http/https according to use_https" do
93
+ TestAPI.endpoint "testing-endpoint"
94
+ TestAPI.default_region nil
95
+ TestAPI.use_https true
96
+
97
+ obj = TestAPI.new "key", "secret"
98
+ obj.uri.must_equal "https://testing-endpoint.amazonaws.com"
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,52 @@
1
+ require 'test_helper'
2
+ require 'aws/api'
3
+ require 'aws/call_types/action_param'
4
+
5
+ describe AWS::CallTypes::ActionParam do
6
+
7
+ class ActionParamTesting < AWS::API
8
+ endpoint "aptest"
9
+ version "2011-01-01"
10
+ use_https true
11
+
12
+ include AWS::CallTypes::ActionParam
13
+ end
14
+
15
+ it "builds and signs AWS requests on methods it doesn't know about" do
16
+ AWS::Connection.any_instance.expects(:call).with do |request|
17
+ request.method.must_equal :post
18
+ request.uri.must_equal "https://aptest.amazonaws.com/"
19
+
20
+ params = request.params
21
+ params.wont_be_nil
22
+
23
+ params["Action"].must_equal "DescribeInstances"
24
+ params["Version"].must_equal "2011-01-01"
25
+ params["AWSAccessKeyId"].must_equal "key"
26
+ params["SignatureMethod"].must_equal "HmacSHA256"
27
+ params["SignatureVersion"].must_equal "2"
28
+
29
+ params["Signature"].wont_be_nil
30
+
31
+ Time.parse(params["Timestamp"]).wont_be_nil
32
+ true
33
+ end.returns
34
+
35
+ obj = ActionParamTesting.new "key", "secret"
36
+ obj.describe_instances
37
+ end
38
+
39
+ it "takes a hash parameter and gives it to the request" do
40
+ AWS::Connection.any_instance.expects(:call).with do |request|
41
+
42
+ params = request.params
43
+ params["ParamA"].must_equal 1
44
+ params["ParamB"].must_equal "Death to Smoochy"
45
+
46
+ true
47
+ end.returns
48
+
49
+ obj = ActionParamTesting.new "key", "secret"
50
+ obj.describe_instances "ParamA" => 1, "ParamB" => "Death to Smoochy"
51
+ end
52
+ end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+ require 'aws/core/request'
3
+ require 'aws/core/response'
4
+ require 'aws/core/connection'
5
+
6
+ describe AWS::Connection do
7
+
8
+ describe "#call" do
9
+
10
+ before do
11
+ @connection = AWS::Connection.new
12
+ @http_response = stub_everything(:success? => true, :parsed_response => {"value" => {}})
13
+ end
14
+
15
+ it "takes a basic request and runs it" do
16
+ request = AWS::Request.new(:get, "host.com", "/")
17
+
18
+ AWS::HTTP.expects(:get).with {|uri, options|
19
+ uri.must_equal "host.com/"
20
+ }.returns(@http_response)
21
+
22
+ @connection.call request
23
+ end
24
+
25
+ it "returns the response wrapped in our Response object" do
26
+ request = AWS::Request.new(:get, "host.com", "/")
27
+
28
+ AWS::HTTP.expects(:get).returns(@http_response)
29
+
30
+ response = @connection.call request
31
+ response.must_be_kind_of AWS::Response
32
+ response.body.must_equal "value" => {}
33
+ end
34
+
35
+ it "pulls parameters into the request" do
36
+ request = AWS::Request.new(:get, "host.com", "/")
37
+ request.params["Param1"] = "Something"
38
+
39
+ AWS::HTTP.expects(:get).with {|uri, options|
40
+ options[:query].wont_be_nil
41
+ options[:query]["Param1"].must_equal "Something"
42
+ }.returns(@http_response)
43
+
44
+ @connection.call request
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,86 @@
1
+ require 'test_helper'
2
+ require 'aws/core/request'
3
+
4
+ describe AWS::Request do
5
+
6
+ before do
7
+ @request = AWS::Request.new :get, "https://example.com", "/action"
8
+ end
9
+
10
+ it "is constructed with a method, host and path" do
11
+ @request.wont_be_nil
12
+ end
13
+
14
+ it "builds full URI" do
15
+ @request.uri.must_equal "https://example.com/action"
16
+ end
17
+
18
+ it "knows it's HTTP method" do
19
+ @request.method.must_equal :get
20
+ end
21
+
22
+ it "can be given parameters to pass in" do
23
+ @request.params["Param1"] = "Value1"
24
+ @request.params["Param2"] = "Value2"
25
+
26
+ @request.params.must_equal "Param1" => "Value1", "Param2" => "Value2"
27
+ end
28
+
29
+ describe "hashes" do
30
+ it "converts hash params to AWS param names" do
31
+ @request.params["Filter"] = [
32
+ {"Name" => "filter1", "Value" => "value1"},
33
+ {"Name" => "filter2", "Value" => ["value14", "another filter"]}
34
+ ]
35
+
36
+ @request.params.must_equal({
37
+ "Filter.1.Name" => "filter1",
38
+ "Filter.1.Value" => "value1",
39
+ "Filter.2.Name" => "filter2",
40
+ "Filter.2.Value.1" => "value14",
41
+ "Filter.2.Value.2" => "another filter"
42
+ })
43
+ end
44
+
45
+ it "handles any depth of nesting" do
46
+ # Example of using EC2 AuthorizeSecurityGroupEgress
47
+ @request.params["IpPermissions"] = [
48
+ {"IpProtocol" => "udp", "FromPort" => 211, "ToPort" => 142,
49
+ "Groups" => [{"GroupId" => 28}, {"GroupId" => 14}],
50
+ "IpRanges" => [{"CidrIp" => 998}, {"CidrIp" => 12}]
51
+ }
52
+ ]
53
+
54
+ @request.params.must_equal({
55
+ "IpPermissions.1.IpProtocol" => "udp",
56
+ "IpPermissions.1.FromPort" => 211,
57
+ "IpPermissions.1.ToPort" => 142,
58
+ "IpPermissions.1.Groups.1.GroupId" => 28,
59
+ "IpPermissions.1.Groups.2.GroupId" => 14,
60
+ "IpPermissions.1.IpRanges.1.CidrIp" => 998,
61
+ "IpPermissions.1.IpRanges.2.CidrIp" => 12
62
+ })
63
+ end
64
+
65
+ it "wraps a singular hash into a single element array" do
66
+ @request.params["Filter"] = {"Name" => "filter1", "Value" => "value1"}
67
+
68
+ @request.params.must_equal({
69
+ "Filter.1.Name" => "filter1",
70
+ "Filter.1.Value" => "value1"
71
+ })
72
+ end
73
+ end
74
+
75
+ describe "arrays" do
76
+ it "converts array params to AWS param names" do
77
+ @request.params["Filter"] = ["value1", "value2", "value3"]
78
+
79
+ @request.params.must_equal({
80
+ "Filter.1" => "value1",
81
+ "Filter.2" => "value2",
82
+ "Filter.3" => "value3"
83
+ })
84
+ end
85
+ end
86
+ end