ace-client 0.0.12 → 0.0.13

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.0.13
data/lib/ace-client.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'ace-client/base'
2
2
  require 'ace-client/query2'
3
+ require 'ace-client/query3'
3
4
  require 'ace-client/query4'
4
5
 
5
6
  module AceClient
@@ -22,6 +22,7 @@ module AceClient
22
22
  @endpoint = options[:endpoint] || ENV['ACE_ENDPOINT']
23
23
  @http_proxy = options[:http_proxy] || ENV['HTTP_PROXY']
24
24
  @http_method = options[:http_method] || :post
25
+ @access_key_id_key = options[:access_key_id_key] || ENV['ACE_ACCESS_KEY_ID_KEY'] || 'AWSAccessKeyId'
25
26
  if options.key?(:use_ssl)
26
27
  @use_ssl = options[:use_ssl]
27
28
  elsif ENV['ACE_USE_SSL']
@@ -34,7 +34,7 @@ module AceClient
34
34
  @params.update(
35
35
  'SignatureVersion' => '2',
36
36
  'SignatureMethod' => @signature_method,
37
- 'AWSAccessKeyId' => @access_key_id,
37
+ @access_key_id_key => @access_key_id,
38
38
  'Timestamp' => Time.now.getutc.iso8601.sub(/Z/, sprintf(".%03dZ",(Time.now.getutc.usec/1000)))
39
39
  )
40
40
  @params['Version'] = @version if @version
@@ -71,7 +71,7 @@ module AceClient
71
71
 
72
72
  def sample_request(request)
73
73
  query = (request.options[:query] || request.options[:body]).dup
74
- variable_keys = %w(Version SignatureVersion SignatureMethod Timestamp AWSAccessKeyId Signature)
74
+ variable_keys = %W(Version SignatureVersion SignatureMethod Timestamp #{access_key_id_key} Signature)
75
75
  variables = {}
76
76
  variable_keys.each do |key|
77
77
  variables[key] = query.delete(key)
@@ -0,0 +1,85 @@
1
+ require 'openssl'
2
+ require 'cgi'
3
+ require 'nokogiri'
4
+ require 'time'
5
+
6
+ module AceClient
7
+ class Query3 < Base
8
+ attr_accessor :http_method
9
+ attr_accessor :signature_method # TODO: HMAC-SHA256 or HMAC-SHA1
10
+ attr_accessor :sampler
11
+
12
+ format :xml
13
+
14
+ def initialize(options={})
15
+ super(options)
16
+ @signature_method = options[:signature_method] || 'HmacSHA256'
17
+ @authorization_key = options[:authorization_key] || 'authorization'
18
+ @date_key = options[:date_key] || 'x-date'
19
+ @nonce_key = options[:nonce_key] || 'x-amz-nonce'
20
+ @authorization_prefix = options[:authorization_prefix] || 'AWS3-HTTPS'
21
+ @nonce = options[:nonce]
22
+
23
+ @sampler = options[:sampler]
24
+ @before_signature = options[:before_signature]
25
+ @before_request = options[:before_request]
26
+ end
27
+
28
+ def action(action, params={})
29
+ params.update('Action' => action)
30
+ execute(params)
31
+ end
32
+
33
+ def dryrun(action, params={})
34
+ params.update('Action' => action)
35
+ execute(params, true)
36
+ end
37
+
38
+ def execute(params={}, dryrun=false)
39
+ @params = params
40
+ @params['Version'] = @version if @version
41
+
42
+ @before_signature.call(@params) if @before_signature
43
+
44
+ signature = create_signature
45
+
46
+ options = self.class.default_options.dup
47
+ options[:headers] = {}
48
+ options[:headers]['Date'] = date
49
+ options[:headers][@authorization_key] = "#{@authorization_prefix} #{@access_key_id_key}=#{access_key_id},Algorithm=#{signature_method},Signature=#{signature}"
50
+ options[:headers]['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
51
+ options[:headers]['User-Agent'] = @user_agent if @user_agent
52
+ options[:headers][@nonce_key] = @nonce if @nonce
53
+
54
+ if http_method == :get
55
+ options[:query] = @params
56
+ http_method_class = Net::HTTP::Get
57
+ elsif http_method == :post
58
+ options[:body] = @params
59
+ http_method_class = Net::HTTP::Post
60
+ end
61
+
62
+ @before_request.call(@params) if @before_request
63
+
64
+ request = HTTParty::Request.new(http_method_class, endpoint_url + @path, options)
65
+ if dryrun
66
+ request
67
+ else
68
+ record_response { request.perform }
69
+ end
70
+ end
71
+
72
+ def create_signature
73
+ digest = OpenSSL::Digest::Digest.new(@signature_method.downcase.gsub(/hmac/, ''))
74
+ Base64.encode64(OpenSSL::HMAC.digest(digest, secret_access_key, string_to_sign)).strip
75
+ end
76
+
77
+ def string_to_sign
78
+ @nonce ? date + @nonce : date
79
+ end
80
+
81
+ def date
82
+ @date ||= Time.now.utc.rfc822.gsub(/[\-\+]\d{4}$/, 'GMT')
83
+ end
84
+ end
85
+ end
@@ -8,7 +8,6 @@ module AceClient
8
8
  attr_accessor :query
9
9
 
10
10
  format :xml
11
- #debug_output $stdout
12
11
 
13
12
  def initialize(options)
14
13
  super(options)
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.12
4
+ version: 0.0.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-12 00:00:00.000000000 Z
12
+ date: 2014-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -142,6 +142,7 @@ files:
142
142
  - lib/ace-client.rb
143
143
  - lib/ace-client/base.rb
144
144
  - lib/ace-client/query2.rb
145
+ - lib/ace-client/query3.rb
145
146
  - lib/ace-client/query4.rb
146
147
  - spec/ace-client_spec.rb
147
148
  - spec/spec_helper.rb
@@ -160,7 +161,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
161
  version: '0'
161
162
  segments:
162
163
  - 0
163
- hash: -4203289481347981661
164
+ hash: -3740157810782966641
164
165
  required_rubygems_version: !ruby/object:Gem::Requirement
165
166
  none: false
166
167
  requirements: