simple_aws 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -2
- data/README.md +24 -23
- data/lib/simple_aws/api.rb +1 -1
- data/lib/simple_aws/auto_scaling.rb +1 -1
- data/lib/simple_aws/call_types/action_param.rb +7 -0
- data/lib/simple_aws/cloud_formation.rb +1 -1
- data/lib/simple_aws/cloud_front.rb +15 -15
- data/lib/simple_aws/cloud_watch.rb +1 -1
- data/lib/simple_aws/core/connection.rb +4 -0
- data/lib/simple_aws/core/request.rb +21 -21
- data/lib/simple_aws/core/response.rb +31 -23
- data/lib/simple_aws/dynamo_db.rb +114 -0
- data/lib/simple_aws/ec2.rb +1 -1
- data/lib/simple_aws/elasti_cache.rb +1 -1
- data/lib/simple_aws/elastic_beanstalk.rb +1 -1
- data/lib/simple_aws/elb.rb +1 -1
- data/lib/simple_aws/iam.rb +1 -1
- data/lib/simple_aws/map_reduce.rb +1 -1
- data/lib/simple_aws/mechanical_turk.rb +1 -1
- data/lib/simple_aws/rds.rb +1 -1
- data/lib/simple_aws/s3.rb +12 -12
- data/lib/simple_aws/ses.rb +0 -5
- data/lib/simple_aws/simple_db.rb +27 -0
- data/lib/simple_aws/sns.rb +1 -1
- data/lib/simple_aws/sqs.rb +2 -2
- data/lib/simple_aws/sts.rb +31 -0
- data/samples/dynamo_db.rb +23 -0
- data/samples/simple_db.rb +16 -0
- data/samples/sts.rb +14 -0
- data/simple_aws.gemspec +4 -4
- data/test/simple_aws/core/response_test.rb +38 -0
- data/test/simple_aws/core/util_test.rb +8 -31
- data/test/simple_aws/dynamo_db_test.rb +115 -0
- data/test/simple_aws/ses.rb +0 -6
- data/test/simple_aws/simple_db_test.rb +36 -0
- data/test/simple_aws/sts.rb +42 -0
- metadata +32 -10
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@ SimpleAWS [![Travis CI Build Status](https://secure.travis-ci.org/jameskilton/si
|
|
3
3
|
|
4
4
|
A thin, simple, forward compatible Ruby wrapper around the various Amazon Web Service APIs.
|
5
5
|
|
6
|
-
What
|
6
|
+
What? Why?!
|
7
7
|
-----------
|
8
8
|
|
9
9
|
Do we really need another Ruby library to talk to Amazon Web Services? Aren't there enough libraries out there that could just use some more help to make them better? What about [fog](http://fog.io), or [aws-sdk](http://rubygems.org/gems/aws-sdk), or [aws](http://rubygems.org/gems/aws), or [right_aws](http://rubygems.org/gems/right_aws)?
|
@@ -20,13 +20,13 @@ Outside of the pervasive complexity of these libraries, what finally drove me to
|
|
20
20
|
|
21
21
|
Amazon constantly updates AWS APIs, adding parameters and actions, and at times entire new APIs. An AWS library should work *with* the API in question, not fight against it. The only thing a hard-coded parameter list does is add confusion. When you have to figure out how AWS parameters map to library parameters, or hash keys, your productivity drops. When you have to figure out how an object is calling an AWS library, and how you're supposed to use that object, your productivity drops. Likewise when you finally realize that the library does not currently support the action, parameter, or API you're trying to use at the time, your productivity is now at a complete stop.
|
22
22
|
|
23
|
-
SimpleAWS simply says no, no more leaky abstractions and confusing APIs. Just use the names of the API methods and parameters as defined in Amazon's documentation! If a new parameter is added to the API you're using, just use it. The name SimpleAWS isn't a wish or hope, it
|
23
|
+
SimpleAWS simply says no, no more leaky abstractions and confusing APIs. Just use the names of the API methods and parameters as defined in Amazon's documentation! If a new parameter is added to the API you're using, just use it. The name SimpleAWS isn't a wish or hope, it is the core philosophy. This library focuses on being a very thin communication layer between your Ruby code and Amazon's AWS APIs. Let SimpleAWS handle the messy communication details so your code can do what it needs to do letting you be more productive.
|
24
24
|
|
25
25
|
|
26
26
|
Surely SimpleAWS isn't just `curl`?
|
27
27
|
-----------------------------------
|
28
28
|
|
29
|
-
It
|
29
|
+
It is well know that AWS has its share of warts and wtfs. SimpleAWS doesn't try to fix these. What SimpleAWS does do is add as little logic as possible to make you productive and to ensure it follows the Principle of Least Surprise.
|
30
30
|
|
31
31
|
### Calling
|
32
32
|
|
@@ -101,28 +101,32 @@ Implemented APIs
|
|
101
101
|
|
102
102
|
These are the Amazon APIs that SimpleAWS currently handles:
|
103
103
|
|
104
|
-
* {SimpleAWS::S3 S3}
|
105
|
-
* {SimpleAWS::EC2 EC2}
|
106
|
-
* {SimpleAWS::ELB ELB}
|
107
|
-
* {SimpleAWS::IAM IAM}
|
108
|
-
* {SimpleAWS::MapReduce MapReduce}
|
109
104
|
* {SimpleAWS::AutoScaling Auto Scaling}
|
110
|
-
* {SimpleAWS::RDS RDS}
|
111
|
-
* {SimpleAWS::ElastiCache ElastiCache}
|
112
|
-
* {SimpleAWS::ElasticBeanstalk Elastic Beanstalk}
|
113
105
|
* {SimpleAWS::CloudFormation CloudFormation}
|
114
|
-
* {SimpleAWS::SNS SNS}
|
115
|
-
* {SimpleAWS::CloudWatch CloudWatch}
|
116
|
-
* {SimpleAWS::ImportExport ImportExport}
|
117
|
-
* {SimpleAWS::MechanicalTurk MechanicalTurk}
|
118
|
-
* {SimpleAWS::SQS SQS}
|
119
|
-
* {SimpleAWS::SES SES}
|
120
106
|
* {SimpleAWS::CloudFront CloudFront}
|
121
|
-
|
122
|
-
|
107
|
+
* {SimpleAWS::CloudWatch CloudWatch}
|
108
|
+
* {SimpleAWS::DynamoDB DynamoDB}
|
109
|
+
* {SimpleAWS::ElasticBeanstalk Elastic Beanstalk}
|
110
|
+
* {SimpleAWS::ELB Elastic Load Balancing (ELB)}
|
111
|
+
* {SimpleAWS::MapReduce Elastic MapReduce}
|
112
|
+
* {SimpleAWS::ElastiCache ElastiCache}
|
113
|
+
* {SimpleAWS::EC2 Elastic Compute Cloud (EC2)}
|
114
|
+
* {SimpleAWS::IAM Identity and Access Management (IAM)}
|
115
|
+
* {SimpleAWS::ImportExport Import/Export}
|
116
|
+
* {SimpleAWS::MechanicalTurk Mechanical Turk}
|
117
|
+
* {SimpleAWS::RDS Relational Database Service (RDS)}
|
118
|
+
* {SimpleAWS::SimpleDB SimpleDB}
|
119
|
+
* {SimpleAWS::SES Simple Email Service (SES)}
|
120
|
+
* {SimpleAWS::SNS Simple Notification Service (SNS)}
|
121
|
+
* {SimpleAWS::SQS Simple Queue Service (SQS)}
|
122
|
+
* {SimpleAWS::S3 Simple Storage Service (S3)}
|
123
|
+
* {SimpleAWS::STS Security Token Service (STS)}
|
124
|
+
|
125
|
+
Not currently implemented
|
123
126
|
-------------------------
|
124
127
|
|
125
|
-
*
|
128
|
+
* Simple Workflow Service
|
129
|
+
|
126
130
|
|
127
131
|
Currently Out-Of-Scope
|
128
132
|
----------------------
|
@@ -145,9 +149,6 @@ SimpleAWS is built to work under all major Ruby versions:
|
|
145
149
|
* 1.9.3
|
146
150
|
* ree
|
147
151
|
* HEAD
|
148
|
-
|
149
|
-
The following are waiting on a release of Nokogiri to fix some issues:
|
150
|
-
|
151
152
|
* jruby
|
152
153
|
* rubinius
|
153
154
|
|
data/lib/simple_aws/api.rb
CHANGED
@@ -10,7 +10,7 @@ module SimpleAWS
|
|
10
10
|
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/Welcome.html
|
11
11
|
#
|
12
12
|
# All requests are POST and always through HTTPS. Use the third parameter to
|
13
|
-
#
|
13
|
+
# `initialize` if you need to talk to a region other than us-east-1.
|
14
14
|
#
|
15
15
|
# @see SimpleAWS::CallTypes::ActionParam Calling rules
|
16
16
|
# @see SimpleAWS::Response Response handling
|
@@ -14,6 +14,13 @@ module SimpleAWS
|
|
14
14
|
# with either the Ruby-fied name, or the full CamelCase name, and pass in
|
15
15
|
# options required as the parameters.
|
16
16
|
#
|
17
|
+
# @example
|
18
|
+
# ec2 = SimpleAWS::EC2.new access_key, secret_key
|
19
|
+
#
|
20
|
+
# # These two are equivalent
|
21
|
+
# ec2.list_instances
|
22
|
+
# ec2.ListInstances
|
23
|
+
#
|
17
24
|
# All responses will be wrapped up in an {SimpleAWS::Response SimpleAWS::Response} object.
|
18
25
|
##
|
19
26
|
module ActionParam
|
@@ -10,7 +10,7 @@ module SimpleAWS
|
|
10
10
|
# http://docs.amazonwebservices.com/AWSCloudFormation/latest/APIReference/
|
11
11
|
#
|
12
12
|
# All requests are POST and always through HTTPS. Use the third parameter to
|
13
|
-
#
|
13
|
+
# `initialize` if you need to talk to a region other than us-east-1.
|
14
14
|
#
|
15
15
|
# @see SimpleAWS::CallTypes::ActionParam Calling rules
|
16
16
|
# @see SimpleAWS::Response Response handling
|
@@ -9,7 +9,7 @@ module SimpleAWS
|
|
9
9
|
# http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/Welcome.html
|
10
10
|
#
|
11
11
|
# As CloudFront is much closer to a RESTful service than the other AWS APIs, all
|
12
|
-
# calls through this API are done through these four HTTP
|
12
|
+
# calls through this API are done through these four HTTP methods:
|
13
13
|
# GET, PUT, DELETE, and POST.
|
14
14
|
#
|
15
15
|
# The paths for all request get the version prepended on to them, you do not
|
@@ -19,40 +19,40 @@ module SimpleAWS
|
|
19
19
|
#
|
20
20
|
# So "GET Distribution List" is
|
21
21
|
#
|
22
|
-
#
|
22
|
+
# cloud_front.get "/distribution"
|
23
23
|
#
|
24
24
|
# For requests that need extra parameters, use the :params option
|
25
25
|
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
26
|
+
# cloud_front.get "/distribution", :params => {
|
27
|
+
# "MaxItems" => 10
|
28
|
+
# }
|
29
29
|
#
|
30
30
|
# Like :params, use :headers to add headers to the request
|
31
31
|
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
32
|
+
# cloud_front.get "/distribution", :headers => {
|
33
|
+
# "x-amz-security-token" => "security string"
|
34
|
+
# }
|
35
35
|
#
|
36
36
|
# The details of CloudFront requests are all passed through XML bodies.
|
37
37
|
# To make this as simple and painless as possible, this API supports the
|
38
38
|
# :xml option to turn a Hash into an XML string
|
39
39
|
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
40
|
+
# cloud_front.post "/distribution", :xml => {
|
41
|
+
# :DistributionConfig => {
|
42
|
+
# ...
|
43
|
+
# }
|
43
44
|
# }
|
44
|
-
# }
|
45
45
|
#
|
46
46
|
# Do note that this XML building is very simple, does not support attributes,
|
47
|
-
# and will only work on Hashes, Arrays, and objects that can be easily
|
47
|
+
# and will only work on Hashes, Arrays, and objects that can be easily `to_s`-ed.
|
48
48
|
# Anything else will error out or might result in invalid request bodies.
|
49
49
|
#
|
50
50
|
# If you already have the XML string and just need to give it to the
|
51
51
|
# request, you can use :body to set the raw value of the request body:
|
52
52
|
#
|
53
|
-
#
|
53
|
+
# cloud_front.post "/distribution", :body => raw_body_xml
|
54
54
|
#
|
55
|
-
# All responses are wrapped in
|
55
|
+
# All responses are wrapped in a SimpleAWS::Response object.
|
56
56
|
##
|
57
57
|
class CloudFront < API
|
58
58
|
endpoint "cloudfront"
|
@@ -10,7 +10,7 @@ module SimpleAWS
|
|
10
10
|
# http://docs.amazonwebservices.com/AmazonCloudWatch/latest/APIReference/Welcome.html
|
11
11
|
#
|
12
12
|
# All requests are POST and always through HTTPS. Use the third parameter to
|
13
|
-
#
|
13
|
+
# `initialize` if you need to talk to a region other than us-east-1.
|
14
14
|
#
|
15
15
|
# @see SimpleAWS::CallTypes::ActionParam Calling rules
|
16
16
|
# @see SimpleAWS::Response Response handling
|
@@ -33,6 +33,10 @@ module SimpleAWS
|
|
33
33
|
# Custom response parser to handle the various craziness of the AWS API
|
34
34
|
##
|
35
35
|
class SimpleAWSParser < HTTParty::Parser
|
36
|
+
SupportedFormats.merge!(
|
37
|
+
{"application/x-amz-json-1.0" => :json}
|
38
|
+
)
|
39
|
+
|
36
40
|
def parse
|
37
41
|
if supports_format?
|
38
42
|
super
|
@@ -1,50 +1,50 @@
|
|
1
1
|
module SimpleAWS
|
2
2
|
|
3
3
|
##
|
4
|
-
# Defines
|
4
|
+
# Defines a request to an Amazon API.
|
5
5
|
#
|
6
6
|
# Requests need to know a number of attributes to work, including the host,
|
7
7
|
# path, the HTTP method, and any params or POST bodies. Most of this is
|
8
8
|
# straight forward through the constructor and setter methods defined below.
|
9
9
|
#
|
10
10
|
# One of the more interesting aspects of the AWS API are the indexed parameters.
|
11
|
-
# These are the parameters in the document defined
|
11
|
+
# These are the parameters in the document defined thusly:
|
12
12
|
#
|
13
|
-
#
|
14
|
-
#
|
13
|
+
# Filter.n.Name
|
14
|
+
# Filter.n.Value.m
|
15
15
|
#
|
16
16
|
# This class has special handling to facilitate building these parameters
|
17
17
|
# from regular Ruby Hashes and Arrays, but does not prevent you from specifying
|
18
|
-
# these parameters exactly as defined. For the example above, here are the
|
18
|
+
# these parameters exactly as defined. For the example above, here are the
|
19
19
|
# ways you can set these parameters:
|
20
20
|
#
|
21
|
-
# By yourself, filling in the
|
21
|
+
# By yourself, filling in the `n` and `m` as you need:
|
22
22
|
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
23
|
+
# request.params.merge({
|
24
|
+
# "Filter.1.Name" => "domain",
|
25
|
+
# "Filter.1.Value" => "vpc",
|
26
|
+
# "Filter.2.Name" => "ids",
|
27
|
+
# "Filter.2.Value.1" => "i-1234",
|
28
|
+
# "Filter.2.Value.2" => "i-8902"
|
29
|
+
# })
|
30
30
|
#
|
31
31
|
# Or let Request handle the indexing and numbering for you:
|
32
32
|
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
33
|
+
# request.params["Filter"] = [
|
34
|
+
# {"Name" => "domain", "Value" => "vpc"},
|
35
|
+
# {"Name" => "ids", "Value" => ["i-1234", "i-8902"]}
|
36
|
+
# ]
|
37
37
|
#
|
38
38
|
# Straight arrays are handled as well:
|
39
39
|
#
|
40
|
-
#
|
40
|
+
# request.params["InstanceId"] = ["i-1234", "i-8970"]
|
41
41
|
#
|
42
42
|
# In an effort to make this library as transparent as possible when working
|
43
43
|
# directly with the AWS API, the keys of the hashes must be the values
|
44
|
-
# specified in the API, and the values must be Hashes
|
45
|
-
#
|
44
|
+
# specified in the API, and the values must be Hashes and/or Arrays who contain
|
45
|
+
# easily String-serializable keys and values.
|
46
46
|
#
|
47
|
-
# A more detailed example can be found in test/simple_aws/request_test.rb where you
|
47
|
+
# A more detailed example can be found in `test/simple_aws/request_test.rb` where you can
|
48
48
|
# see how to use many levels of nesting to build your AWS request.
|
49
49
|
##
|
50
50
|
class Request
|
@@ -40,39 +40,43 @@ module SimpleAWS
|
|
40
40
|
# returned by the AWS API in question. For some APIs, like EC2, the response is
|
41
41
|
# a relatively flat:
|
42
42
|
#
|
43
|
-
#
|
44
|
-
# <
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
43
|
+
# <pre>
|
44
|
+
# <DataRequestResponse>
|
45
|
+
# <requestId>...</requestId>
|
46
|
+
# <dataRequested>
|
47
|
+
# ...
|
48
|
+
# </dataRequested>
|
49
|
+
# </DataRequestResponse>
|
50
|
+
# </pre>
|
49
51
|
#
|
50
|
-
# In this case, your querying will start inside of
|
51
|
-
# method you'll probably call is
|
52
|
+
# In this case, your querying will start inside of `<DataRequestResponse>`, ala the first
|
53
|
+
# method you'll probably call is `data_requested`. For other APIs, the response
|
52
54
|
# object is a little deeper and looks like this:
|
53
55
|
#
|
54
|
-
#
|
55
|
-
# <
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
# <
|
62
|
-
#
|
63
|
-
#
|
56
|
+
# <pre>
|
57
|
+
# <DataRequestResponse>
|
58
|
+
# <DataRequestedResult>
|
59
|
+
# <DataRequested>
|
60
|
+
# ...
|
61
|
+
# </DataRequested>
|
62
|
+
# </DataRequestedResult>
|
63
|
+
# <ResponseMetadata>
|
64
|
+
# <RequestId>...</RequestId>
|
65
|
+
# </ResponseMetadata>
|
66
|
+
# </DataRequestResponse>
|
67
|
+
# </pre>
|
64
68
|
#
|
65
|
-
# For these response structures, your query will start inside of
|
66
|
-
# ala your first method call will be
|
67
|
-
# both of these structures, simply use
|
69
|
+
# For these response structures, your query will start inside of `<DataRequestedResult>`,
|
70
|
+
# ala your first method call will be `data_requested`. To get access to the request id of
|
71
|
+
# both of these structures, simply use `request_id` on the base response. You'll also
|
68
72
|
# notice the case differences of the XML tags, this class tries to ensure that case doesn't
|
69
73
|
# matter when you're querying with methods. If you're using raw hash access then yes the
|
70
74
|
# case of the keys in question need to match.
|
71
75
|
#
|
72
76
|
# This class does ensure that any collection is always an Array, given that
|
73
|
-
# when AWS returns a single item in a collection, the xml
|
77
|
+
# when AWS returns a single item in a collection, the xml-to-hash parser gives a
|
74
78
|
# single hash back instead of an array. This class will also look for
|
75
|
-
# array indicators from AWS, like
|
79
|
+
# array indicators from AWS, like `<item>` or `<member>` and squash them.
|
76
80
|
#
|
77
81
|
# If AWS returns an error code, instead of getting a Response back the library
|
78
82
|
# will instead throw an UnsuccessfulResponse error with the pertinent information.
|
@@ -259,6 +263,10 @@ module SimpleAWS
|
|
259
263
|
body["Error"]
|
260
264
|
elsif body.has_key? "Response"
|
261
265
|
body["Response"]["Errors"]["Error"]
|
266
|
+
elsif body.has_key?("__type")
|
267
|
+
body["Message"] = body["message"] if body.has_key?("message")
|
268
|
+
body["Code"] = body["__type"]
|
269
|
+
body
|
262
270
|
else
|
263
271
|
raise UnknownErrorResponse.new body
|
264
272
|
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'simple_aws/api'
|
2
|
+
require 'simple_aws/signing/version3'
|
3
|
+
require 'simple_aws/sts'
|
4
|
+
require 'multi_json'
|
5
|
+
|
6
|
+
module SimpleAWS
|
7
|
+
|
8
|
+
##
|
9
|
+
# Amazon's DynamoDB NoSQL Store
|
10
|
+
#
|
11
|
+
# http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/Introduction.html
|
12
|
+
#
|
13
|
+
# All requests are POST and always through HTTPS. Use the third parameter to
|
14
|
+
# `initialize` if you need to talk to a region other than us-east-1.
|
15
|
+
#
|
16
|
+
# This module hooks up the `method_missing` functionality as described in the
|
17
|
+
# README. To call methods on APIs including this module, simply call a method
|
18
|
+
# with either the Ruby-fied name, or the full CamelCase name, and pass in
|
19
|
+
# options required as the parameters.
|
20
|
+
#
|
21
|
+
# As all API calls to DynamoDB require a session token header garnered through STS,
|
22
|
+
# you don't have to worry about it. This API will take care of the STS hop and ensure
|
23
|
+
# the proper credentials are passed into DynamoDB as needed.
|
24
|
+
#
|
25
|
+
# With that, the only parameter you need to pass into your API call directly is the
|
26
|
+
# body of the request, which can be a Hash containing keys and values serializable
|
27
|
+
# to JSON or a raw JSON string that will be sent directly to Amazon:
|
28
|
+
#
|
29
|
+
# dynamo_db.delete_table "TableName" => "Table1"
|
30
|
+
#
|
31
|
+
# dynamo_db.delete_table "{'TableName': 'Table1'}"
|
32
|
+
#
|
33
|
+
# Note: It is possible right now that if you have a single instance of this API
|
34
|
+
# for a long period that the `session_token` will eventually expire. If this becomes
|
35
|
+
# and issue please open an Issue on Github and I'll look at making this handling
|
36
|
+
# more robust. You can always recreate a new instance of SimpleAWS::DynamoDB
|
37
|
+
# to get new STS credentials as needed.
|
38
|
+
#
|
39
|
+
# @see SimpleAWS::Response Response handling
|
40
|
+
##
|
41
|
+
class DynamoDB < API
|
42
|
+
endpoint "dynamodb"
|
43
|
+
default_region "us-east-1"
|
44
|
+
use_https true
|
45
|
+
version "2011-12-05"
|
46
|
+
|
47
|
+
attr_reader :sts, :session_token
|
48
|
+
|
49
|
+
##
|
50
|
+
# Initialize a new instance of this API, swapping out `access_key` and
|
51
|
+
# `secret_key` with values from the Security Token Service (STS).
|
52
|
+
# This also will grab and store the session_token value for use in
|
53
|
+
# DynamoDB API calls.
|
54
|
+
#
|
55
|
+
# @see SimpleAWS::API#initialize
|
56
|
+
##
|
57
|
+
def initialize(access_key, secret_key, region = nil)
|
58
|
+
@sts = SimpleAWS::STS.new access_key, secret_key
|
59
|
+
|
60
|
+
sts_response = @sts.get_session_token.credentials
|
61
|
+
@session_token = sts_response.session_token
|
62
|
+
|
63
|
+
super(sts_response.access_key_id, sts_response.secret_access_key, region)
|
64
|
+
end
|
65
|
+
|
66
|
+
def method_missing(name, *args)
|
67
|
+
request = SimpleAWS::Request.new :post, self.uri, "/"
|
68
|
+
target = "DynamoDB_#{self.version.gsub("-","")}"
|
69
|
+
request.headers["Content-Type"] = "application/x-amz-json-1.0"
|
70
|
+
|
71
|
+
request.headers["x-amz-target"] = "#{target}.#{SimpleAWS::Util.camelcase(name.to_s)}"
|
72
|
+
request.headers["x-amz-date"] = Time.now.rfc822
|
73
|
+
request.headers["x-amz-security-token"] = @session_token
|
74
|
+
|
75
|
+
body = args.first || {}
|
76
|
+
request.body = body.is_a?(String) ? body : MultiJson.encode(body)
|
77
|
+
|
78
|
+
request.headers["x-amzn-authorization"] =
|
79
|
+
"AWS3 AWSAccessKeyId=#{self.access_key}," +
|
80
|
+
"Algorithm=HmacSHA256," +
|
81
|
+
"Signature=#{build_signature_for(request)}"
|
82
|
+
|
83
|
+
connection = SimpleAWS::Connection.new
|
84
|
+
connection.call request
|
85
|
+
end
|
86
|
+
|
87
|
+
protected
|
88
|
+
|
89
|
+
def build_signature_for(request)
|
90
|
+
amazon_headers = request.headers.select {|k, v|
|
91
|
+
k =~ /^x-amz-/i
|
92
|
+
}.map {|k, v|
|
93
|
+
"#{k.downcase}:#{v}".chomp
|
94
|
+
}.sort
|
95
|
+
|
96
|
+
to_sign = [
|
97
|
+
request.method.to_s.upcase,
|
98
|
+
request.path,
|
99
|
+
"",
|
100
|
+
"host:#{URI.parse(request.host).host}",
|
101
|
+
amazon_headers,
|
102
|
+
"",
|
103
|
+
request.body
|
104
|
+
].flatten.join("\n")
|
105
|
+
|
106
|
+
digested = OpenSSL::Digest::SHA256.digest(to_sign)
|
107
|
+
Base64.encode64(
|
108
|
+
OpenSSL::HMAC.digest("sha256", self.secret_key, digested)
|
109
|
+
).chomp
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
data/lib/simple_aws/ec2.rb
CHANGED
@@ -10,7 +10,7 @@ module SimpleAWS
|
|
10
10
|
# http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html
|
11
11
|
#
|
12
12
|
# All requests are POST and always through HTTPS. Use the third parameter to
|
13
|
-
#
|
13
|
+
# `initialize` if you need to talk to a region other than us-east-1.
|
14
14
|
#
|
15
15
|
# @see SimpleAWS::CallTypes::ActionParam Calling rules
|
16
16
|
# @see SimpleAWS::Response Response handling
|
@@ -10,7 +10,7 @@ module SimpleAWS
|
|
10
10
|
# http://docs.amazonwebservices.com/AmazonElastiCache/latest/APIReference/
|
11
11
|
#
|
12
12
|
# All requests are POST and always through HTTPS. Use the third parameter to
|
13
|
-
#
|
13
|
+
# `initialize` if you need to talk to a region other than us-east-1.
|
14
14
|
#
|
15
15
|
# @see SimpleAWS::CallTypes::ActionParam Calling rules
|
16
16
|
# @see SimpleAWS::Response Response handling
|
@@ -10,7 +10,7 @@ module SimpleAWS
|
|
10
10
|
# http://docs.amazonwebservices.com/elasticbeanstalk/latest/api/
|
11
11
|
#
|
12
12
|
# All requests are POST and always through HTTPS. Use the third parameter to
|
13
|
-
#
|
13
|
+
# `initialize` if you need to talk to a region other than us-east-1.
|
14
14
|
#
|
15
15
|
# @see SimpleAWS::CallTypes::ActionParam Calling rules
|
16
16
|
# @see SimpleAWS::Response Response handling
|
data/lib/simple_aws/elb.rb
CHANGED
@@ -10,7 +10,7 @@ module SimpleAWS
|
|
10
10
|
# http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/APIReference/
|
11
11
|
#
|
12
12
|
# All requests are POST and always through HTTPS. Use the third parameter to
|
13
|
-
#
|
13
|
+
# `initializer` if you need to talk to a region other than us-east-1.
|
14
14
|
#
|
15
15
|
# @see SimpleAWS::CallTypes::ActionParam Calling rules
|
16
16
|
# @see SimpleAWS::Response Response handling
|
data/lib/simple_aws/iam.rb
CHANGED
@@ -10,7 +10,7 @@ module SimpleAWS
|
|
10
10
|
# http://docs.amazonwebservices.com/IAM/latest/APIReference/
|
11
11
|
#
|
12
12
|
# All requests are POST and always through HTTPS. Use the third parameter to
|
13
|
-
#
|
13
|
+
# `initialize` if you need to talk to a region other than us-east-1.
|
14
14
|
#
|
15
15
|
# @see SimpleAWS::CallTypes::ActionParam Calling rules
|
16
16
|
# @see SimpleAWS::Response Response handling
|
@@ -10,7 +10,7 @@ module SimpleAWS
|
|
10
10
|
# http://docs.amazonwebservices.com/ElasticMapReduce/latest/API/
|
11
11
|
#
|
12
12
|
# All requests are POST and always through HTTPS. Use the third parameter to
|
13
|
-
#
|
13
|
+
# `initialize` if you need to talk to a region other than us-east-1.
|
14
14
|
#
|
15
15
|
# @see SimpleAWS::CallTypes::ActionParam Calling rules
|
16
16
|
# @see SimpleAWS::Response Response handling
|
@@ -10,7 +10,7 @@ module SimpleAWS
|
|
10
10
|
#
|
11
11
|
# All requests are POST and always through HTTPS.
|
12
12
|
# Instead of regions, this API supports normal and sandbox mode. Use the third
|
13
|
-
# parameter of
|
13
|
+
# parameter of `initialize` to specify sandbox mode.
|
14
14
|
#
|
15
15
|
# For a more fleshed out object API for interacting with MechanicalTurk, you should
|
16
16
|
# give rturk a try here: https://github.com/mdp/rturk
|
data/lib/simple_aws/rds.rb
CHANGED
@@ -10,7 +10,7 @@ module SimpleAWS
|
|
10
10
|
# http://docs.amazonwebservices.com/AmazonRDS/latest/APIReference/
|
11
11
|
#
|
12
12
|
# All requests are POST and always through HTTPS. Use the third parameter to
|
13
|
-
#
|
13
|
+
# `initialize` if you need to talk to a region other than us-east-1.
|
14
14
|
#
|
15
15
|
# @see SimpleAWS::CallTypes::ActionParam Calling rules
|
16
16
|
# @see SimpleAWS::Response Response handling
|
data/lib/simple_aws/s3.rb
CHANGED
@@ -14,19 +14,19 @@ module SimpleAWS
|
|
14
14
|
#
|
15
15
|
# So "GET Service" is
|
16
16
|
#
|
17
|
-
#
|
17
|
+
# s3.get "/"
|
18
18
|
#
|
19
19
|
# When working with a specific bucket, pass in :bucket after the path:
|
20
20
|
#
|
21
|
-
#
|
21
|
+
# s3.get "/", :bucket => "bucket_name"
|
22
22
|
#
|
23
|
-
#
|
23
|
+
# s3.get "/?policy", :bucket => "bucket_name"
|
24
24
|
#
|
25
25
|
# For requests that need extra parameters, use the :params option:
|
26
26
|
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
27
|
+
# s3.get "/object/name", :bucket => "bucket_name", :params => {
|
28
|
+
# "response-content-disposition" => "attachment"
|
29
|
+
# }
|
30
30
|
#
|
31
31
|
# Also use params in the cases that AWS asks for form fields, such as
|
32
32
|
# "POST Object".
|
@@ -34,9 +34,9 @@ module SimpleAWS
|
|
34
34
|
# A lot of S3 communication happens through request and response headers.
|
35
35
|
# To specify a certian set of headers on the request, use :headers:
|
36
36
|
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
37
|
+
# s3.get "/", :bucket => "bucket_name", :headers => {
|
38
|
+
# "x-amz-security-token" => "security string"
|
39
|
+
# }
|
40
40
|
#
|
41
41
|
# Many of the PUT requests require a body of some sort, sometimes XML,
|
42
42
|
# sometimes JSON, and other times the raw file data. Use :body for this
|
@@ -44,7 +44,7 @@ module SimpleAWS
|
|
44
44
|
# JSON information, or an object that otherwise response to #read for file
|
45
45
|
# uploads. This API does not build XML or JSON for you right now.
|
46
46
|
#
|
47
|
-
#
|
47
|
+
# s3.put "/object/name.txt", :bucket => "bucket_name", :body => File.open()
|
48
48
|
#
|
49
49
|
# This API does ensure that file data is uploaded as efficiently as possible,
|
50
50
|
# streaming file data from disc to AWS without blowing up memory. If the
|
@@ -58,10 +58,10 @@ module SimpleAWS
|
|
58
58
|
# which parts to download next. You can see an example of this in samples/s3_batch_download.rb.
|
59
59
|
#
|
60
60
|
# Quality of Life note: if you forget the leading / (forward slash) in the path
|
61
|
-
# of a resource when# working with a bucket, this library will
|
61
|
+
# of a resource when# working with a bucket, this library will catch the omission and
|
62
62
|
# fix the path for you. Thus, the following is also a valid call:
|
63
63
|
#
|
64
|
-
#
|
64
|
+
# s3.put "object/name.txt", :bucket => "bucket_name", :body => File.open()
|
65
65
|
#
|
66
66
|
# Raw file data in a response will be available in the #body method on the Response
|
67
67
|
# returned by the method call.
|
data/lib/simple_aws/ses.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'simple_aws/api'
|
2
|
+
require 'simple_aws/call_types/action_param'
|
3
|
+
require 'simple_aws/signing/version2'
|
4
|
+
|
5
|
+
module SimpleAWS
|
6
|
+
|
7
|
+
##
|
8
|
+
# Amazon's SimpleDB
|
9
|
+
#
|
10
|
+
# http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide/Welcome.html
|
11
|
+
#
|
12
|
+
# All requests are POST and always through HTTPS. Use the third parameter to
|
13
|
+
# `initialize` if you need to talk to a region other than us-east-1.
|
14
|
+
#
|
15
|
+
# @see SimpleAWS::CallTypes::ActionParam Calling rules
|
16
|
+
# @see SimpleAWS::Response Response handling
|
17
|
+
##
|
18
|
+
class SimpleDB < API
|
19
|
+
endpoint "sdb"
|
20
|
+
use_https true
|
21
|
+
version "2009-04-15"
|
22
|
+
|
23
|
+
include CallTypes::ActionParam
|
24
|
+
include Signing::Version2
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/lib/simple_aws/sns.rb
CHANGED
@@ -10,7 +10,7 @@ module SimpleAWS
|
|
10
10
|
# http://docs.amazonwebservices.com/sns/latest/api/Welcome.html
|
11
11
|
#
|
12
12
|
# All requests are POST and always through HTTPS. Use the third parameter to
|
13
|
-
#
|
13
|
+
# `initialize` if you need to talk to a region other than us-east-1.
|
14
14
|
#
|
15
15
|
# @see SimpleAWS::CallTypes::ActionParam Calling rules
|
16
16
|
# @see SimpleAWS::Response Response handling
|
data/lib/simple_aws/sqs.rb
CHANGED
@@ -10,12 +10,12 @@ module SimpleAWS
|
|
10
10
|
# http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Welcome.html
|
11
11
|
#
|
12
12
|
# All requests are POST and always through HTTPS. Use the third parameter to
|
13
|
-
#
|
13
|
+
# `initialize` if you need to talk to a region other than us-east-1.
|
14
14
|
#
|
15
15
|
# For the requests that act on a queue directly, like SendMessage, pass in the QueueURL
|
16
16
|
# as the first parameter to the call:
|
17
17
|
#
|
18
|
-
#
|
18
|
+
# sqs.send_message queue_url, params
|
19
19
|
#
|
20
20
|
# In accordance with the AWS documentation, SimpleAWS does not try to reconstruct
|
21
21
|
# queue urls, use ListQueues or GetQueueUrl to get the correct queue url when needed.
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'simple_aws/api'
|
2
|
+
require 'simple_aws/call_types/action_param'
|
3
|
+
require 'simple_aws/signing/version2'
|
4
|
+
|
5
|
+
module SimpleAWS
|
6
|
+
|
7
|
+
##
|
8
|
+
# Amazon's Security Token Service
|
9
|
+
#
|
10
|
+
# http://docs.amazonwebservices.com/STS/latest/APIReference/Welcome.html
|
11
|
+
#
|
12
|
+
# All requests are POST and always through HTTPS.
|
13
|
+
#
|
14
|
+
# @see SimpleAWS::CallTypes::ActionParam Calling rules
|
15
|
+
# @see SimpleAWS::Response Response handling
|
16
|
+
##
|
17
|
+
class STS < API
|
18
|
+
endpoint "sts"
|
19
|
+
use_https true
|
20
|
+
version "2011-06-15"
|
21
|
+
|
22
|
+
# STS only has one HTTP endpoint
|
23
|
+
def initialize(key, secret)
|
24
|
+
super(key, secret)
|
25
|
+
end
|
26
|
+
|
27
|
+
include CallTypes::ActionParam
|
28
|
+
include Signing::Version2
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
$: << File.expand_path("../../lib", __FILE__)
|
2
|
+
|
3
|
+
require 'simple_aws/dynamo_db'
|
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
|
+
dynamo_db = SimpleAWS::DynamoDB.new ENV["AWS_KEY"], ENV["AWS_SECRET"]
|
13
|
+
|
14
|
+
##
|
15
|
+
# This call will fail with a LimitExceededException on ReadCapacityUnits
|
16
|
+
# If you get any other error then there's something wrong either with your credentials
|
17
|
+
# or with the library
|
18
|
+
##
|
19
|
+
p dynamo_db.create_table "TableName" => "SimpleAWSTestTable",
|
20
|
+
"KeySchema" => {
|
21
|
+
"HashKeyElement" => {"AttributeName" => "index","AttributeType" => "S"},
|
22
|
+
},
|
23
|
+
"ProvisionedThroughput" => {"ReadCapacityUnits" => 1, "WriteCapacityUnits" => 1}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
$: << File.expand_path("../../lib", __FILE__)
|
2
|
+
|
3
|
+
require 'simple_aws/simple_db'
|
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
|
+
sdb = SimpleAWS::SimpleDB.new ENV["AWS_KEY"], ENV["AWS_SECRET"]
|
13
|
+
|
14
|
+
puts "", "All Domains", ""
|
15
|
+
|
16
|
+
p sdb.list_domains
|
data/samples/sts.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$: << File.expand_path("../../lib", __FILE__)
|
2
|
+
|
3
|
+
require 'simple_aws/sts'
|
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
|
+
sts = SimpleAWS::STS.new ENV["AWS_KEY"], ENV["AWS_SECRET"]
|
13
|
+
|
14
|
+
p sts.get_session_token "DurationSeconds" => 3600
|
data/simple_aws.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "simple_aws"
|
3
|
-
s.version = "1.
|
3
|
+
s.version = "1.2.0"
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.authors = ["Jason Roelofs"]
|
6
|
-
s.email = ["
|
6
|
+
s.email = ["jasongroelofs@gmail.com"]
|
7
7
|
|
8
8
|
s.homepage = "http://github.com/jameskilton/simple_aws"
|
9
9
|
|
10
|
-
s.summary = "The simplest and easiest to use
|
11
|
-
s.description = "SimpleAWS is a clean, simple, and forward compatible library for talking to Amazon
|
10
|
+
s.summary = "The simplest and easiest to use AWS communication library"
|
11
|
+
s.description = "SimpleAWS is a clean, simple, and forward compatible library for talking to the Amazon Web Service APIs."
|
12
12
|
|
13
13
|
s.add_dependency "nokogiri", "~> 1.5.0"
|
14
14
|
s.add_dependency "httparty", "~> 0.8.0"
|
@@ -80,6 +80,44 @@ describe SimpleAWS::Response do
|
|
80
80
|
error.message.must_equal "AuthFailure (401): OH snap! String to Sign: \"SOME STRING\""
|
81
81
|
end
|
82
82
|
|
83
|
+
it "handles JSON errors (e.g. DynamoDB)" do
|
84
|
+
@error_response = { "__type" => "com.amazon.something.broke#OhNoesError",
|
85
|
+
"Message" => "This is a failure message!"
|
86
|
+
}
|
87
|
+
@http_response.stubs(:parsed_response).returns(@error_response)
|
88
|
+
|
89
|
+
error =
|
90
|
+
lambda {
|
91
|
+
SimpleAWS::Response.new @http_response
|
92
|
+
}.must_raise SimpleAWS::UnsuccessfulResponse
|
93
|
+
|
94
|
+
error.code.must_equal 401
|
95
|
+
error.error_type.must_equal "com.amazon.something.broke#OhNoesError"
|
96
|
+
error.error_message.must_equal "This is a failure message!"
|
97
|
+
|
98
|
+
error.message.must_equal "com.amazon.something.broke#OhNoesError (401): " +
|
99
|
+
"This is a failure message!"
|
100
|
+
end
|
101
|
+
|
102
|
+
it "handles JSON errors with bad casing" do
|
103
|
+
@error_response = { "__type" => "com.amazon.something.broke#OhNoesError",
|
104
|
+
"message" => "This is a failure message!"
|
105
|
+
}
|
106
|
+
@http_response.stubs(:parsed_response).returns(@error_response)
|
107
|
+
|
108
|
+
error =
|
109
|
+
lambda {
|
110
|
+
SimpleAWS::Response.new @http_response
|
111
|
+
}.must_raise SimpleAWS::UnsuccessfulResponse
|
112
|
+
|
113
|
+
error.code.must_equal 401
|
114
|
+
error.error_type.must_equal "com.amazon.something.broke#OhNoesError"
|
115
|
+
error.error_message.must_equal "This is a failure message!"
|
116
|
+
|
117
|
+
error.message.must_equal "com.amazon.something.broke#OhNoesError (401): " +
|
118
|
+
"This is a failure message!"
|
119
|
+
end
|
120
|
+
|
83
121
|
it "raises if it can't parse the error message" do
|
84
122
|
@error_response = { "Erroring" => "This is an error message" }
|
85
123
|
@http_response.stubs(:parsed_response).returns(@error_response)
|
@@ -3,16 +3,15 @@ require 'simple_aws/core/util'
|
|
3
3
|
|
4
4
|
describe SimpleAWS::Util do
|
5
5
|
|
6
|
+
def remove_whitespace_from(string)
|
7
|
+
string.gsub(/^\s*/, "").gsub(/\n/, "")
|
8
|
+
end
|
9
|
+
|
6
10
|
describe "#build_xml_from" do
|
7
11
|
it "takes a hash and builds XML" do
|
8
12
|
response = SimpleAWS::Util.build_xml_from :RootNode => { :InnerNode => "Value" }
|
9
13
|
|
10
|
-
response.must_equal
|
11
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
12
|
-
<RootNode>
|
13
|
-
<InnerNode>Value</InnerNode>
|
14
|
-
</RootNode>
|
15
|
-
END
|
14
|
+
remove_whitespace_from(response).must_equal %|<?xml version="1.0" encoding="UTF-8"?><RootNode><InnerNode>Value</InnerNode></RootNode>|
|
16
15
|
end
|
17
16
|
|
18
17
|
it "will add namespace to the root node" do
|
@@ -21,12 +20,7 @@ END
|
|
21
20
|
"http://cloudfront.amazonaws.com/doc/2010-11-01/"
|
22
21
|
)
|
23
22
|
|
24
|
-
response.must_equal
|
25
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
26
|
-
<RootNode xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/">
|
27
|
-
<InnerNode>Value</InnerNode>
|
28
|
-
</RootNode>
|
29
|
-
END
|
23
|
+
remove_whitespace_from(response).must_equal %|<?xml version="1.0" encoding="UTF-8"?><RootNode xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/"><InnerNode>Value</InnerNode></RootNode>|
|
30
24
|
end
|
31
25
|
|
32
26
|
it "works with arrays of items" do
|
@@ -34,14 +28,7 @@ END
|
|
34
28
|
{:RootNode => { :InnerNode => ["Value1", "Value2", "Value3"] }}
|
35
29
|
)
|
36
30
|
|
37
|
-
response.must_equal
|
38
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
39
|
-
<RootNode>
|
40
|
-
<InnerNode>Value1</InnerNode>
|
41
|
-
<InnerNode>Value2</InnerNode>
|
42
|
-
<InnerNode>Value3</InnerNode>
|
43
|
-
</RootNode>
|
44
|
-
END
|
31
|
+
remove_whitespace_from(response).must_equal %|<?xml version="1.0" encoding="UTF-8"?><RootNode><InnerNode>Value1</InnerNode><InnerNode>Value2</InnerNode><InnerNode>Value3</InnerNode></RootNode>|
|
45
32
|
end
|
46
33
|
|
47
34
|
it "works at any nestedness of hashes" do
|
@@ -54,17 +41,7 @@ END
|
|
54
41
|
}
|
55
42
|
)
|
56
43
|
|
57
|
-
response.must_equal
|
58
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
59
|
-
<RootNode>
|
60
|
-
<InnerNode>
|
61
|
-
<Child>Value1</Child>
|
62
|
-
</InnerNode>
|
63
|
-
<InnerNode>
|
64
|
-
<Child>Value2</Child>
|
65
|
-
</InnerNode>
|
66
|
-
</RootNode>
|
67
|
-
END
|
44
|
+
remove_whitespace_from(response).must_equal %|<?xml version="1.0" encoding="UTF-8"?><RootNode><InnerNode><Child>Value1</Child></InnerNode><InnerNode><Child>Value2</Child></InnerNode></RootNode>|
|
68
45
|
end
|
69
46
|
|
70
47
|
it "auto-strings all leaf nodes" do
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'simple_aws/dynamo_db'
|
3
|
+
|
4
|
+
describe SimpleAWS::DynamoDB do
|
5
|
+
|
6
|
+
before do
|
7
|
+
creds = stub :session_token => "session_token",
|
8
|
+
:access_key_id => "access_key_id",
|
9
|
+
:secret_access_key => "secret_access_key"
|
10
|
+
response = stub :credentials => creds
|
11
|
+
|
12
|
+
SimpleAWS::STS.any_instance.stubs(:get_session_token).returns response
|
13
|
+
|
14
|
+
@api = SimpleAWS::DynamoDB.new "key", "secret"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "forwards keys to STS, saves session token and new AWS keys for use" do
|
18
|
+
@api.sts.wont_be_nil
|
19
|
+
@api.access_key.must_equal "access_key_id"
|
20
|
+
@api.secret_key.must_equal "secret_access_key"
|
21
|
+
@api.session_token.must_equal "session_token"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "points to the endpoint" do
|
25
|
+
@api.uri.must_equal "https://dynamodb.us-east-1.amazonaws.com"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "properly builds region endpoints" do
|
29
|
+
api = SimpleAWS::DynamoDB.new "key", "secret", "eu-west-1"
|
30
|
+
api.uri.must_equal "https://dynamodb.eu-west-1.amazonaws.com"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "works with the current version" do
|
34
|
+
@api.version.must_equal "2011-12-05"
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "API calls" do
|
38
|
+
|
39
|
+
it "requires a security token as the first parameter and add it as a header" do
|
40
|
+
SimpleAWS::Connection.any_instance.expects(:call).with do |request|
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
obj = SimpleAWS::DynamoDB.new "key", "secret"
|
45
|
+
obj.create_table
|
46
|
+
end
|
47
|
+
|
48
|
+
it "adds the requested action as x-amz-target header" do
|
49
|
+
SimpleAWS::Connection.any_instance.expects(:call).with do |request|
|
50
|
+
header = request.headers["x-amz-target"]
|
51
|
+
header.must_equal "DynamoDB_20111205.CreateTable"
|
52
|
+
true
|
53
|
+
end
|
54
|
+
|
55
|
+
obj = SimpleAWS::DynamoDB.new "key", "secret"
|
56
|
+
obj.create_table
|
57
|
+
end
|
58
|
+
|
59
|
+
it "adds the json content type header" do
|
60
|
+
SimpleAWS::Connection.any_instance.expects(:call).with do |request|
|
61
|
+
header = request.headers["Content-Type"]
|
62
|
+
header.must_equal "application/x-amz-json-1.0"
|
63
|
+
true
|
64
|
+
end
|
65
|
+
|
66
|
+
obj = SimpleAWS::DynamoDB.new "key", "secret"
|
67
|
+
obj.create_table
|
68
|
+
end
|
69
|
+
|
70
|
+
it "takes any body and serializes into JSON" do
|
71
|
+
table_schema = {
|
72
|
+
"TableName" => "Table1", "KeySchema" => {
|
73
|
+
"HashKeyElement" => {"AttributeName" => "AttributeName1", "AttributeType" => "S"}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
SimpleAWS::Connection.any_instance.expects(:call).with do |request|
|
78
|
+
request.body.wont_be_nil
|
79
|
+
MultiJson.decode(request.body).must_equal table_schema
|
80
|
+
true
|
81
|
+
end
|
82
|
+
|
83
|
+
obj = SimpleAWS::DynamoDB.new "key", "secret"
|
84
|
+
obj.create_table table_schema
|
85
|
+
end
|
86
|
+
|
87
|
+
it "takes a string body and forwards it off raw" do
|
88
|
+
SimpleAWS::Connection.any_instance.expects(:call).with do |request|
|
89
|
+
request.body.must_equal %|{"string":"body"}|
|
90
|
+
true
|
91
|
+
end
|
92
|
+
|
93
|
+
obj = SimpleAWS::DynamoDB.new "key", "secret"
|
94
|
+
obj.create_table %|{"string":"body"}|
|
95
|
+
end
|
96
|
+
|
97
|
+
it "builds and signs the request and adds the session token" do
|
98
|
+
SimpleAWS::Connection.any_instance.expects(:call).with do |request|
|
99
|
+
header = request.headers["x-amzn-authorization"]
|
100
|
+
header.must_match(/^AWS3 /)
|
101
|
+
header.must_match(/AWSAccessKeyId=access_key_id/)
|
102
|
+
|
103
|
+
header = request.headers["x-amz-security-token"]
|
104
|
+
header.must_equal "session_token"
|
105
|
+
|
106
|
+
Time.parse(request.headers["x-amz-date"]).wont_be_nil
|
107
|
+
true
|
108
|
+
end
|
109
|
+
|
110
|
+
obj = SimpleAWS::DynamoDB.new "key", "secret"
|
111
|
+
obj.create_table
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
data/test/simple_aws/ses.rb
CHANGED
@@ -7,12 +7,6 @@ describe SimpleAWS::SES do
|
|
7
7
|
@api = SimpleAWS::SES.new "key", "secret"
|
8
8
|
end
|
9
9
|
|
10
|
-
it "only works on one endpoint" do
|
11
|
-
lambda {
|
12
|
-
SimpleAWS::SES.new "key", "secret", "us-west-1"
|
13
|
-
}.must_raise ArgumentError
|
14
|
-
end
|
15
|
-
|
16
10
|
it "points to the endpoint" do
|
17
11
|
@api.uri.must_equal "https://email.us-east-1.amazonaws.com"
|
18
12
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'simple_aws/simple_db'
|
3
|
+
|
4
|
+
describe SimpleAWS::SimpleDB do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@api = SimpleAWS::SimpleDB.new "key", "secret"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "points to the endpoint" do
|
11
|
+
@api.uri.must_equal "https://sdb.amazonaws.com"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "works with the current version" do
|
15
|
+
@api.version.must_equal "2009-04-15"
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "API calls" do
|
19
|
+
|
20
|
+
it "builds and signs calls with ActionParam rules" do
|
21
|
+
SimpleAWS::Connection.any_instance.expects(:call).with do |request|
|
22
|
+
params = request.params
|
23
|
+
params.wont_be_nil
|
24
|
+
|
25
|
+
params["Action"].must_equal "ListDomains"
|
26
|
+
params["Signature"].wont_be_nil
|
27
|
+
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
obj = SimpleAWS::SimpleDB.new "key", "secret"
|
32
|
+
obj.list_domains
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'simple_aws/sts'
|
3
|
+
|
4
|
+
describe SimpleAWS::STS do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@api = SimpleAWS::STS.new "key", "secret"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "points to the endpoint" do
|
11
|
+
@api.uri.must_equal "https://sts.amazonaws.com"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "only works on one endpoint" do
|
15
|
+
lambda {
|
16
|
+
SimpleAWS::STS.new "key", "secret", "us-west-1"
|
17
|
+
}.must_raise ArgumentError
|
18
|
+
end
|
19
|
+
|
20
|
+
it "works with the current version" do
|
21
|
+
@api.version.must_equal "2011-06-15"
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "API calls" do
|
25
|
+
|
26
|
+
it "builds and signs calls with ActionParam rules" do
|
27
|
+
SimpleAWS::Connection.any_instance.expects(:call).with do |request|
|
28
|
+
params = request.params
|
29
|
+
params.wont_be_nil
|
30
|
+
|
31
|
+
params["Action"].must_equal "GetSessionToken"
|
32
|
+
params["Signature"].wont_be_nil
|
33
|
+
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
obj = SimpleAWS::STS.new "key", "secret"
|
38
|
+
obj.get_session_token
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 1.5.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.5.0
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: httparty
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,11 +37,16 @@ dependencies:
|
|
32
37
|
version: 0.8.0
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.8.0
|
36
46
|
description: SimpleAWS is a clean, simple, and forward compatible library for talking
|
37
|
-
to Amazon
|
47
|
+
to the Amazon Web Service APIs.
|
38
48
|
email:
|
39
|
-
-
|
49
|
+
- jasongroelofs@gmail.com
|
40
50
|
executables: []
|
41
51
|
extensions: []
|
42
52
|
extra_rdoc_files: []
|
@@ -59,6 +69,7 @@ files:
|
|
59
69
|
- lib/simple_aws/core/request.rb
|
60
70
|
- lib/simple_aws/core/response.rb
|
61
71
|
- lib/simple_aws/core/util.rb
|
72
|
+
- lib/simple_aws/dynamo_db.rb
|
62
73
|
- lib/simple_aws/ec2.rb
|
63
74
|
- lib/simple_aws/elasti_cache.rb
|
64
75
|
- lib/simple_aws/elastic_beanstalk.rb
|
@@ -72,15 +83,20 @@ files:
|
|
72
83
|
- lib/simple_aws/ses.rb
|
73
84
|
- lib/simple_aws/signing/version2.rb
|
74
85
|
- lib/simple_aws/signing/version3.rb
|
86
|
+
- lib/simple_aws/simple_db.rb
|
75
87
|
- lib/simple_aws/sns.rb
|
76
88
|
- lib/simple_aws/sqs.rb
|
89
|
+
- lib/simple_aws/sts.rb
|
77
90
|
- samples/cloud_front.rb
|
91
|
+
- samples/dynamo_db.rb
|
78
92
|
- samples/ec2.rb
|
79
93
|
- samples/elb.rb
|
80
94
|
- samples/iam.rb
|
81
95
|
- samples/s3.rb
|
82
96
|
- samples/s3_batch_download.rb
|
97
|
+
- samples/simple_db.rb
|
83
98
|
- samples/sqs.rb
|
99
|
+
- samples/sts.rb
|
84
100
|
- samples/turk.rb
|
85
101
|
- simple_aws.gemspec
|
86
102
|
- test/simple_aws/api_test.rb
|
@@ -93,6 +109,7 @@ files:
|
|
93
109
|
- test/simple_aws/core/request_test.rb
|
94
110
|
- test/simple_aws/core/response_test.rb
|
95
111
|
- test/simple_aws/core/util_test.rb
|
112
|
+
- test/simple_aws/dynamo_db_test.rb
|
96
113
|
- test/simple_aws/ec2_test.rb
|
97
114
|
- test/simple_aws/elasti_cache_test.rb
|
98
115
|
- test/simple_aws/elastic_beanstalk_test.rb
|
@@ -106,8 +123,10 @@ files:
|
|
106
123
|
- test/simple_aws/ses.rb
|
107
124
|
- test/simple_aws/signing/version2_test.rb
|
108
125
|
- test/simple_aws/signing/version3.rb
|
126
|
+
- test/simple_aws/simple_db_test.rb
|
109
127
|
- test/simple_aws/sns_test.rb
|
110
128
|
- test/simple_aws/sqs.rb
|
129
|
+
- test/simple_aws/sts.rb
|
111
130
|
- test/test_helper.rb
|
112
131
|
homepage: http://github.com/jameskilton/simple_aws
|
113
132
|
licenses: []
|
@@ -129,10 +148,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
148
|
version: '0'
|
130
149
|
requirements: []
|
131
150
|
rubyforge_project:
|
132
|
-
rubygems_version: 1.8.
|
151
|
+
rubygems_version: 1.8.18
|
133
152
|
signing_key:
|
134
153
|
specification_version: 3
|
135
|
-
summary: The simplest and easiest to use
|
154
|
+
summary: The simplest and easiest to use AWS communication library
|
136
155
|
test_files:
|
137
156
|
- test/simple_aws/api_test.rb
|
138
157
|
- test/simple_aws/auto_scaling_test.rb
|
@@ -144,6 +163,7 @@ test_files:
|
|
144
163
|
- test/simple_aws/core/request_test.rb
|
145
164
|
- test/simple_aws/core/response_test.rb
|
146
165
|
- test/simple_aws/core/util_test.rb
|
166
|
+
- test/simple_aws/dynamo_db_test.rb
|
147
167
|
- test/simple_aws/ec2_test.rb
|
148
168
|
- test/simple_aws/elasti_cache_test.rb
|
149
169
|
- test/simple_aws/elastic_beanstalk_test.rb
|
@@ -157,7 +177,9 @@ test_files:
|
|
157
177
|
- test/simple_aws/ses.rb
|
158
178
|
- test/simple_aws/signing/version2_test.rb
|
159
179
|
- test/simple_aws/signing/version3.rb
|
180
|
+
- test/simple_aws/simple_db_test.rb
|
160
181
|
- test/simple_aws/sns_test.rb
|
161
182
|
- test/simple_aws/sqs.rb
|
183
|
+
- test/simple_aws/sts.rb
|
162
184
|
- test/test_helper.rb
|
163
185
|
has_rdoc:
|