ace-client 0.0.2 → 0.0.3
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 +72 -4
- data/VERSION +1 -1
- data/lib/ace-client/base.rb +3 -0
- data/lib/ace-client/query2.rb +60 -10
- metadata +13 -13
data/README.md
CHANGED
@@ -90,15 +90,83 @@ you can specify your http method with :http_method option (Default is :post).
|
|
90
90
|
p sqs.last_response # currently HTTParty::Response object
|
91
91
|
p sqs.last_response_time # returned in seconds (Float object)
|
92
92
|
|
93
|
+
### Dry-Run Mode
|
94
|
+
|
95
|
+
If you want to get request information rather than sending actual request, use `dryrun` instead of `action`.
|
96
|
+
`dryrun` returns HTTParty::Request object that would have been performed if you have used `action`.
|
97
|
+
On HTTParty::Request class, see HTTParty's document.
|
98
|
+
|
99
|
+
sqs = AceClient::Query2.new(
|
100
|
+
:http_method => :get,
|
101
|
+
:endpoint => 'sqs.ap-northeast-1.amazonaws.com',
|
102
|
+
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
|
103
|
+
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
|
104
|
+
)
|
105
|
+
req = sqs.dryrun('CreateQueue', 'QueueName' => 'queue001')
|
106
|
+
puts req.uri.to_s
|
107
|
+
# => https://sqs.ap-northeast-1.amazonaws.com/?QueueName=queue001&Action=CreateQueue&SignatureVersion=2&SignatureMethod=HmacSHA256&AWSAccessKeyId=XXXXXXXXXXXXXXXXXXXX&Timestamp=2013-11-19T08%3A53%3A40.115Z&Version=2012-11-05&Signature=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
|
108
|
+
|
109
|
+
### Setting User-Agent in HTTP Request Header
|
110
|
+
|
111
|
+
Specify `:user_agent` option in your constructor.
|
112
|
+
|
113
|
+
AceClient::Query2.new(
|
114
|
+
:endpoint => 'sqs.ap-northeast-1.amazonaws.com',
|
115
|
+
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
|
116
|
+
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
|
117
|
+
:user_agent => "ace-client v#{AceClient::VERSION}"
|
118
|
+
)
|
119
|
+
|
120
|
+
### Output Sample Request/Response Log
|
121
|
+
|
122
|
+
Set :sampler option to output AWS-document-like logs.
|
123
|
+
|
124
|
+
If you write code like this:
|
125
|
+
|
126
|
+
sqs = AceClient::Query2.new(
|
127
|
+
:endpoint => 'sqs.ap-northeast-1.amazonaws.com',
|
128
|
+
:version => '2012-11-05',
|
129
|
+
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
|
130
|
+
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
|
131
|
+
:sampler => {
|
132
|
+
:output => STDOUT,
|
133
|
+
:echo => {
|
134
|
+
'AWSAccessKeyId' => '<AWS Access Key Id>',
|
135
|
+
'Signature' => '<Signature>'
|
136
|
+
}
|
137
|
+
}
|
138
|
+
)
|
139
|
+
sqs.action('CreateQueue', 'QueueName' => 'queue001')
|
140
|
+
|
141
|
+
Then output would be:
|
142
|
+
|
143
|
+
# CreateQueue
|
144
|
+
## request
|
145
|
+
https://sqs.ap-northeast-1.amazonaws.com/
|
146
|
+
?Action=CreateQueue
|
147
|
+
&QueueName=queue001
|
148
|
+
&Version=2012-11-05
|
149
|
+
&SignatureVersion=2
|
150
|
+
&SignatureMethod=HmacSHA256
|
151
|
+
&Timestamp=2013-11-19T10%3A51%3A46.110Z
|
152
|
+
&AWSAccessKeyId=<AWS Access Key Id>
|
153
|
+
&Signature=<Signature>
|
154
|
+
## response
|
155
|
+
<?xml version="1.0"?>
|
156
|
+
<CreateQueueResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/">
|
157
|
+
<CreateQueueResult>
|
158
|
+
<QueueUrl>https://sqs.ap-northeast-1.amazonaws.com/370162190418/queue001</QueueUrl>
|
159
|
+
</CreateQueueResult>
|
160
|
+
<ResponseMetadata>
|
161
|
+
<RequestId>1406b1f3-c3e5-51ac-a291-faf686e77b1e</RequestId>
|
162
|
+
</ResponseMetadata>
|
163
|
+
</CreateQueueResponse>
|
164
|
+
|
93
165
|
## TODO
|
94
166
|
|
95
|
-
* user agent support
|
96
167
|
* query + sig4 support
|
97
168
|
* json + sig4 support
|
98
|
-
* dry run mode (for genarating signatures)
|
99
169
|
* logging
|
100
|
-
* human readable 'Sample Request & Response' format
|
101
|
-
* masking access_key_id and signature
|
102
170
|
* handle redirects
|
103
171
|
* socket/connection timeout configuration
|
104
172
|
* rewrite query and header before/after genrating signature (maybe hook-like interface)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/ace-client/base.rb
CHANGED
@@ -11,7 +11,9 @@ module AceClient
|
|
11
11
|
attr_accessor :http_proxy
|
12
12
|
attr_accessor :http_method
|
13
13
|
attr_accessor :use_ssl
|
14
|
+
attr_accessor :last_response
|
14
15
|
attr_accessor :last_response_time
|
16
|
+
attr_accessor :user_agent
|
15
17
|
|
16
18
|
def initialize(options)
|
17
19
|
@access_key_id = options[:access_key_id]
|
@@ -22,6 +24,7 @@ module AceClient
|
|
22
24
|
@use_ssl = options[:use_ssl] || true
|
23
25
|
@version = options[:version]
|
24
26
|
@path = options[:path] || '/'
|
27
|
+
@user_agent = options[:user_agent]
|
25
28
|
set_http_proxy
|
26
29
|
end
|
27
30
|
|
data/lib/ace-client/query2.rb
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
require 'openssl'
|
2
2
|
require 'cgi'
|
3
|
+
require 'nokogiri'
|
3
4
|
|
4
5
|
module AceClient
|
5
6
|
class Query2 < Base
|
6
7
|
attr_accessor :http_method
|
7
8
|
attr_accessor :signature_method # TODO: HMAC-SHA256 or HMAC-SHA1
|
9
|
+
attr_accessor :sampler
|
8
10
|
|
9
11
|
format :xml
|
10
|
-
|
12
|
+
debug_output $stderr
|
11
13
|
|
12
14
|
def initialize(options={})
|
13
15
|
super(options)
|
14
16
|
@signature_method = options[:signature_method] || 'HmacSHA256'
|
17
|
+
@sampler = options[:sampler]
|
15
18
|
end
|
16
19
|
|
17
20
|
def action(action, params={})
|
@@ -19,7 +22,12 @@ module AceClient
|
|
19
22
|
execute(params)
|
20
23
|
end
|
21
24
|
|
22
|
-
def
|
25
|
+
def dryrun(action, params={})
|
26
|
+
params.update('Action' => action)
|
27
|
+
execute(params, true)
|
28
|
+
end
|
29
|
+
|
30
|
+
def execute(params={}, dryrun=false)
|
23
31
|
@params = params
|
24
32
|
@params.update(
|
25
33
|
'SignatureVersion' => '2',
|
@@ -30,15 +38,57 @@ module AceClient
|
|
30
38
|
@params['Version'] = @version if @version
|
31
39
|
@params['Signature'] = create_signature
|
32
40
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
41
|
+
options = {
|
42
|
+
:headers => {
|
43
|
+
'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8'
|
44
|
+
},
|
45
|
+
:query => @params
|
46
|
+
}
|
47
|
+
options[:headers]['User-Agent'] = @user_agent if @user_agent
|
48
|
+
|
49
|
+
if http_method == :get
|
50
|
+
http_method_class = Net::HTTP::Get
|
51
|
+
elsif http_method == :post
|
52
|
+
http_method_class = Net::HTTP::Post
|
40
53
|
end
|
41
|
-
|
54
|
+
|
55
|
+
request = HTTParty::Request.new(http_method_class, endpoint_url + @path, options)
|
56
|
+
if dryrun
|
57
|
+
request
|
58
|
+
else
|
59
|
+
sample_request(request) if @sampler
|
60
|
+
response = record_response { request.perform }
|
61
|
+
sample_response(response) if @sampler
|
62
|
+
response
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def sample_request(request)
|
67
|
+
query = request.options[:query].dup
|
68
|
+
variable_keys = %w(Version SignatureVersion SignatureMethod Timestamp AWSAccessKeyId Signature)
|
69
|
+
variables = {}
|
70
|
+
variable_keys.each do |key|
|
71
|
+
variables[key] = query.delete(key)
|
72
|
+
end
|
73
|
+
action = query.delete('Action')
|
74
|
+
@sampler[:output].puts "# #{action}"
|
75
|
+
@sampler[:output].puts "## request"
|
76
|
+
@sampler[:output].puts "#{request.path.to_s}"
|
77
|
+
@sampler[:output].puts " ?Action=#{action}"
|
78
|
+
query.each do |key, value|
|
79
|
+
@sampler[:output].puts " &#{key}=#{CGI.escape(value)}"
|
80
|
+
end
|
81
|
+
variable_keys.each do |key|
|
82
|
+
if variables[key]
|
83
|
+
value = @sampler[:echo][key] || CGI.escape(variables[key])
|
84
|
+
@sampler[:output].puts " &#{key}=#{value}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def sample_response(response)
|
90
|
+
@sampler[:output].puts "## response"
|
91
|
+
@sampler[:output].puts Nokogiri::XML(response.body).to_xml(:indent => 4)
|
42
92
|
end
|
43
93
|
|
44
94
|
def endpoint_url
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ace-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
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: 2013-11-
|
12
|
+
date: 2013-11-19 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &14649500 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.8.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *14649500
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rdoc
|
27
|
-
requirement: &
|
27
|
+
requirement: &14631440 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '3.12'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *14631440
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &14629720 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '1.0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *14629720
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &14628680 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.8.7
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *14628680
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rcov
|
60
|
-
requirement: &
|
60
|
+
requirement: &14626240 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *14626240
|
69
69
|
description: Simple ACE(Amazon Compatible Environment) Client
|
70
70
|
email: tily05@gmail.com
|
71
71
|
executables: []
|
@@ -101,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
segments:
|
103
103
|
- 0
|
104
|
-
hash:
|
104
|
+
hash: 2867422504911211089
|
105
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|