right_aws_api 0.1.0

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.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/HISTORY +2 -0
  3. data/LICENSE +19 -0
  4. data/README.md +164 -0
  5. data/Rakefile +38 -0
  6. data/lib/cloud/aws/as/manager.rb +118 -0
  7. data/lib/cloud/aws/base/helpers/utils.rb +328 -0
  8. data/lib/cloud/aws/base/manager.rb +186 -0
  9. data/lib/cloud/aws/base/parsers/response_error.rb +117 -0
  10. data/lib/cloud/aws/base/routines/request_signer.rb +80 -0
  11. data/lib/cloud/aws/cf/manager.rb +171 -0
  12. data/lib/cloud/aws/cf/routines/request_signer.rb +70 -0
  13. data/lib/cloud/aws/cf/wrappers/default.rb +213 -0
  14. data/lib/cloud/aws/cfm/manager.rb +90 -0
  15. data/lib/cloud/aws/cw/manager.rb +113 -0
  16. data/lib/cloud/aws/eb/manager.rb +87 -0
  17. data/lib/cloud/aws/ec/manager.rb +91 -0
  18. data/lib/cloud/aws/ec2/manager.rb +222 -0
  19. data/lib/cloud/aws/elb/manager.rb +120 -0
  20. data/lib/cloud/aws/emr/manager.rb +86 -0
  21. data/lib/cloud/aws/iam/manager.rb +100 -0
  22. data/lib/cloud/aws/rds/manager.rb +110 -0
  23. data/lib/cloud/aws/route53/manager.rb +177 -0
  24. data/lib/cloud/aws/route53/routines/request_signer.rb +70 -0
  25. data/lib/cloud/aws/route53/wrappers/default.rb +132 -0
  26. data/lib/cloud/aws/s3/manager.rb +373 -0
  27. data/lib/cloud/aws/s3/parsers/response_error.rb +76 -0
  28. data/lib/cloud/aws/s3/routines/request_signer.rb +243 -0
  29. data/lib/cloud/aws/s3/wrappers/default.rb +315 -0
  30. data/lib/cloud/aws/sdb/manager.rb +150 -0
  31. data/lib/cloud/aws/sns/manager.rb +96 -0
  32. data/lib/cloud/aws/sqs/manager.rb +335 -0
  33. data/lib/right_aws_api.rb +45 -0
  34. data/lib/right_aws_api_version.rb +40 -0
  35. data/right_aws_api.gemspec +55 -0
  36. data/spec/describe_calls.rb +92 -0
  37. metadata +118 -0
@@ -0,0 +1,186 @@
1
+ #--
2
+ # Copyright (c) 2013 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require "cloud/aws/base/helpers/utils"
25
+ require "cloud/aws/base/routines/request_signer"
26
+ require "cloud/aws/base/parsers/response_error"
27
+
28
+
29
+ module RightScale
30
+ module CloudApi
31
+
32
+ # AWS namespace
33
+ module AWS
34
+
35
+ # Thread safe parent class for almost all the AWS services.
36
+ class Manager < CloudApi::Manager
37
+ end
38
+
39
+ # Thread un-safe parent class for almost all the AWS services.
40
+ class ApiManager < CloudApi::ApiManager
41
+
42
+ # Standard AWS errors
43
+ class Error < CloudApi::Error
44
+ end
45
+
46
+ # A list of common AWS API params
47
+ COMMON_QUERY_PARAMS = [
48
+ 'Action',
49
+ 'AWSAccessKeyId',
50
+ 'Expires',
51
+ 'SecurityToken',
52
+ 'Signature',
53
+ 'SignatureMethod',
54
+ 'SignatureVersion',
55
+ 'Timestamp',
56
+ 'Version',
57
+ ]
58
+
59
+ include Mixin::QueryApiPatterns
60
+
61
+ set_routine CloudApi::RetryManager
62
+ set_routine CloudApi::RequestInitializer
63
+ set_routine AWS::RequestSigner
64
+ set_routine CloudApi::RequestGenerator
65
+ set_routine CloudApi::RequestAnalyzer
66
+ set_routine CloudApi::ConnectionProxy
67
+ set_routine CloudApi::ResponseAnalyzer
68
+ set_routine CloudApi::CacheValidator
69
+ set_routine CloudApi::ResponseParser
70
+ set_routine CloudApi::ResultWrapper
71
+
72
+ set :response_error_parser => Parser::AWS::ResponseErrorV1
73
+
74
+ # Constructor
75
+ #
76
+ # @abstract
77
+ #
78
+ # @param [String] aws_access_key_id Amazon AWS access key id.
79
+ # @param [String] aws_secret_access_key Amazon secret AWS access key.
80
+ # @param [String] endpoint Cloud endpoint.
81
+ # @param [Hash] options
82
+ # see https://github.com/rightscale/right_cloud_api_base/blob/master/lib/base/api_manager.rb
83
+ #
84
+ # @example
85
+ # new(key_id, secret, 'https://ec2.awsamazon.com', :cache => true)
86
+ #
87
+ def initialize(aws_access_key_id, aws_secret_access_key, endpoint, options={})
88
+ credentials = { :aws_access_key_id => aws_access_key_id,
89
+ :aws_secret_access_key => aws_secret_access_key }
90
+ super(credentials, endpoint, options)
91
+ end
92
+
93
+
94
+ # Makes a raw API call to AWS compatible service by the method name
95
+ #
96
+ # @param [String] action Depends on the selected service/endpoint.
97
+ # See {http://aws.amazon.com/documentation/}
98
+ # @param [Hash] params A set or extra parameters.
99
+ # @option params [Hash,String] :body The request body.
100
+ # @option params [Hash] :headers The request headers.
101
+ # @option params [Hash] :options The request options (RightScale::CloudApi::ApiManager.process_api_request).
102
+ # @option params [Hash] :params The extra set of URL params.
103
+ #
104
+ # @return [Object] Usually a Hash with data.
105
+ #
106
+ # @example
107
+ # ec2.api('DescribeImages')
108
+ #
109
+ # @example
110
+ # ec2.api('DescribeInstances', 'InstanceId' => ['i-00000001', 'i-00000002'])
111
+ #
112
+ def api(action, params={}, &block)
113
+ params['Action'] ||= action.to_s._snake_case._camelize
114
+ opts = {}
115
+ opts[:body] = params.delete(:body)
116
+ opts[:headers] = params.delete(:headers) || {}
117
+ opts[:options] = params.delete(:options) || {}
118
+ opts[:params] = parametrize(params)
119
+ process_api_request(:get, '', opts, &block)
120
+ end
121
+
122
+
123
+ # Parametrize data to the format that Amazon EC2 and compatible services accept
124
+ #
125
+ # See {RightScale::CloudApi::Utils::AWS.parametrize} for more examples.
126
+ #
127
+ # @return [Hash] A hash of data in the format Amazon want to get.
128
+ #
129
+ # @example
130
+ # parametrize( 'ParamA' => 'a',
131
+ # 'ParamB' => ['b', 'c'],
132
+ # 'ParamC.?.Something' => ['d', 'e'],
133
+ # 'Filter' => [ { 'Key' => 'A', 'Value' => ['aa','ab']},
134
+ # { 'Key' => 'B', 'Value' => ['ba','bb']}] ) #=>
135
+ # {
136
+ # "Filter.1.Key" => "A",
137
+ # "Filter.1.Value.1" => "aa",
138
+ # "Filter.1.Value.2" => "ab",
139
+ # "Filter.2.Key" => "B",
140
+ # "Filter.2.Value.1" => "ba",
141
+ # "Filter.2.Value.2" => "bb",
142
+ # "ParamA" => "a",
143
+ # "ParamB.1" => "b",
144
+ # "ParamB.2" => "c",
145
+ # "ParamC.1.Something" => "d",
146
+ # "ParamC.2.Something" => "e"
147
+ # }
148
+ #
149
+ def parametrize(*args)
150
+ Utils::AWS.parametrize(*args)
151
+ end
152
+
153
+
154
+ # @api public
155
+ alias_method :p9e, :parametrize
156
+
157
+
158
+ # Provides an ability to call methods by their API action names
159
+ #
160
+ # @param [String,Symbol] method_name
161
+ # @param [Objects] args
162
+ #
163
+ # @return [Object]
164
+ #
165
+ # @example
166
+ # # the calls below produce the same result:
167
+ # # way #1
168
+ # ec2.api('DescribeInstances', 'InstanceId' => ['i-00000001', 'i-00000002'])
169
+ # # way #2
170
+ # ec2.DescribeInstances('InstanceId' => ['i-00000001', 'i-00000002'])
171
+ #
172
+ def method_missing(method_name, *args, &block)
173
+ begin
174
+ invoke_query_api_pattern_method(method_name, *args, &block)
175
+ rescue PatternNotFoundError
176
+ if method_name.to_s[/\A[A-Z]/]
177
+ api(method_name, *args, &block)
178
+ else
179
+ super
180
+ end
181
+ end
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,117 @@
1
+ #--
2
+ # Copyright (c) 2013 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ module RightScale
25
+ module CloudApi
26
+ # Parsers namespace
27
+ module Parser
28
+ # AWS parsers namespace
29
+ module AWS
30
+
31
+ # AWS response error parser, case 1
32
+ #
33
+ class ResponseErrorV1
34
+
35
+ # Parse HTTP error message from a response body
36
+ #
37
+ # @param [RightScale::CloudApi::HTTPResponse] response
38
+ # @param [Hash] options
39
+ # @option options [Class] :xml_parser
40
+ #
41
+ # @return [String]
42
+ #
43
+ # @example
44
+ # # For the call below:
45
+ # ec2.DescribeInstances('InstanceId' => 'hohoho')
46
+ # # Generates an XML error:
47
+ # <?xml version="1.0" encoding="UTF-8"?>
48
+ # <Response>
49
+ # <Errors>
50
+ # <Error>
51
+ # <Code>InvalidInstanceID.Malformed</Code>
52
+ # <Message>Invalid id: "hohoho"</Message>
53
+ # </Error>
54
+ # </Errors>
55
+ # <RequestID>84bb3005-0b9f-4a1f-9f78-8fbc2a41a401</RequestID>
56
+ # </Response>
57
+ # # And the method parse all above into:
58
+ # 400: InvalidInstanceID.Malformed: Invalid id: "hohoho" (RequestID: 84bb3005-0b9f-4a1f-9f78-8fbc2a41a401)
59
+ #
60
+ def self.parse(response, options={})
61
+ result = "#{response.code}: "
62
+ body = response.body.to_s
63
+ if response['content-type'].to_s[/xml/] || body[/\A<\?xml /]
64
+ hash = Utils::get_xml_parser_class(options[:xml_parser]).parse(body)
65
+ if hash["Response"] && hash["Response"]["Errors"]
66
+ errors = hash["Response"]["Errors"]["Error"]
67
+ errors = [ errors ] if errors.is_a?(Hash)
68
+ result += errors.map{ |error| "#{error['Code']}: #{error['Message']}" }.join('; ')
69
+ # Display a RequestId here
70
+ result << " (RequestID: #{hash["Response"]["RequestID"]})"
71
+ end
72
+ else
73
+ result << "#{body}" unless body._blank?
74
+ end
75
+ result
76
+ end
77
+ end
78
+
79
+
80
+ # AWS response error parser, case 2
81
+ #
82
+ class ResponseErrorV2
83
+
84
+ # Parse HTTP error message from a response body
85
+ #
86
+ # @param [RightScale::CloudApi::HTTPResponse] response
87
+ # @param [Hash] options
88
+ # @option options [Class] :xml_parser
89
+ #
90
+ # @return a String to be displayed/logged.
91
+ #
92
+ # @example
93
+ # # error is a response from ELB
94
+ # parse(error) #=>
95
+ # 400: ErrorName: SomethingIsWrong (RequestID: 32455505-2345-43245-f432-34543523451)
96
+ #
97
+ # @return [String]
98
+ #
99
+ def self.parse(response, options={})
100
+ result = "#{response.code}: "
101
+ body = response.body.to_s
102
+ if response['content-type'].to_s[/xml/] || body[/\A<\?xml /]
103
+ hash = Utils::get_xml_parser_class(options[:xml_parser]).parse(body)
104
+ error = hash["ErrorResponse"] && hash["ErrorResponse"]["Error"]
105
+ if error
106
+ request_id = hash["ErrorResponse"]["RequestID"] || hash["ErrorResponse"]["RequestId"]
107
+ result += "#{error['Type']}.#{error['Code']}: #{error['Message']} (RequestId: #{request_id})"
108
+ end
109
+ end
110
+ result
111
+ end
112
+ end
113
+
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,80 @@
1
+ #--
2
+ # Copyright (c) 2013 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ module RightScale
25
+ module CloudApi
26
+ module AWS
27
+
28
+ # Request signer for AWS services.
29
+ class RequestSigner < CloudApi::Routine
30
+
31
+ # RequestSigner error
32
+ class Error < CloudApi::Error
33
+ end
34
+
35
+ # Use POST verb if GET's path is getting too big.
36
+ MAX_GET_REQUEST_PATH_LENGTH = 2000
37
+
38
+ # Authenticates an AWS request
39
+ #
40
+ # @return [void]
41
+ #
42
+ # @example
43
+ # no example
44
+ #
45
+ def process
46
+ # Make sure all the required params are set
47
+ @data[:request][:params]['AWSAccessKeyId'] = @data[:credentials][:aws_access_key_id]
48
+ @data[:request][:params]['Version'] ||= @data[:options][:api_version]
49
+ # Compile a final request path
50
+ @data[:request][:path] = Utils::join_urn(@data[:connection][:uri].path, @data[:request][:relative_path])
51
+ # Sign the request
52
+ sign_proc = Proc::new do |data|
53
+ Utils::AWS::sign_v2_signature( data[:credentials][:aws_secret_access_key],
54
+ data[:request][:params] || {},
55
+ data[:request][:verb],
56
+ data[:connection][:uri].host,
57
+ data[:request][:path] )
58
+ end
59
+ signed_path = sign_proc.call(@data)
60
+ # Rebuild the request as POST if its path is too long
61
+ if signed_path.size > MAX_GET_REQUEST_PATH_LENGTH && @data[:request][:verb] == :get
62
+ @data[:request][:verb] = :post
63
+ signed_path = sign_proc.call(@data)
64
+ end
65
+ # Set new path or body and content-type
66
+ case @data[:request][:verb]
67
+ when :get
68
+ @data[:request][:path] << "?#{signed_path}"
69
+ when :post
70
+ @data[:request][:body] = signed_path
71
+ @data[:request][:headers]['content-type'] = 'application/x-www-form-urlencoded; charset=utf-8'
72
+ else
73
+ fail Error::new("Unsupported HTTP verb: #{@data[:request][:verb]}")
74
+ end
75
+ end
76
+ end
77
+
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,171 @@
1
+ #--
2
+ # Copyright (c) 2013 RightScale, Inc.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # 'Software'), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ require "cloud/aws/base/helpers/utils"
25
+ require "cloud/aws/base/parsers/response_error"
26
+ require "cloud/aws/cf/routines/request_signer"
27
+ require "cloud/aws/cf/wrappers/default"
28
+
29
+ module RightScale
30
+ module CloudApi
31
+ module AWS
32
+
33
+ # Cloud Front namespace
34
+ #
35
+ # @api public
36
+ #
37
+ module CF
38
+
39
+ # Amazon Cloud Front (CF) compatible manager (thread safe)
40
+ #
41
+ # @example
42
+ # require "right_aws_api"
43
+ #
44
+ # cf = RightScale::CloudApi::AWS::CF::Manager::new(key, secret, 'https://cloudfront.amazonaws.com')
45
+ #
46
+ # cf.GetDistributionList('MaxItems' => 2) #=>
47
+ # {"DistributionList"=>
48
+ # {"IsTruncated"=>"true",
49
+ # "NextMarker"=>"E20O0ZWO4WRF3I",
50
+ # "Marker"=>nil,
51
+ # "MaxItems"=>"2",
52
+ # "DistributionSummary"=>
53
+ # [{"Status"=>"Deployed",
54
+ # "Comment"=>"test",
55
+ # "Enabled"=>"true",
56
+ # "LastModifiedTime"=>"2008-10-23T15:17:24.447Z",
57
+ # "CNAME"=>["c1.test.com", "c2.test.com"],
58
+ # "Id"=>"E2FLHADADBK2P9",
59
+ # "DomainName"=>"d2kia27jveea52.cloudfront.net",
60
+ # "S3Origin"=>{"DNSName"=>"aws-test.s3.amazonaws.com"}},
61
+ # {"Status"=>"Deployed",
62
+ # "Comment"=>
63
+ # "Distribution created for the blog demo, can be deleted anytime.",
64
+ # "Enabled"=>"false",
65
+ # "LastModifiedTime"=>"2009-04-20T07:05:37.257Z",
66
+ # "CNAME"=>"blog-demo.rightscale.com",
67
+ # "Id"=>"E20O0ZWO4WRF3I",
68
+ # "DomainName"=>"dc5eg4un365fp.cloudfront.net",
69
+ # "S3Origin"=>{"DNSName"=>"aws-test.s3.amazonaws.com"}}],
70
+ # "@xmlns"=>"http://cloudfront.amazonaws.com/doc/2010-11-01/"}}
71
+ #
72
+ # @example
73
+ # cf.GetDistribution('DistributionId' => 'E2FLHADADBK2P9') #=>
74
+ # {"Distribution"=>
75
+ # {"Status"=>"Deployed",
76
+ # "LastModifiedTime"=>"2008-10-23T15:17:24.447Z",
77
+ # "InProgressInvalidationBatches"=>"0",
78
+ # "Id"=>"E2FLHADADBK2P9",
79
+ # "DistributionConfig"=>
80
+ # {"Comment"=>"test",
81
+ # "Enabled"=>"true",
82
+ # "CallerReference"=>"200810231517246798821075",
83
+ # "CNAME"=>["c1.test.com", "c2.test.com"],
84
+ # "S3Origin"=>{"DNSName"=>"aws-test.s3.amazonaws.com"}},
85
+ # "DomainName"=>"d2kia27jveea52.cloudfront.net",
86
+ # "@xmlns"=>"http://cloudfront.amazonaws.com/doc/2010-11-01/"}}
87
+ #
88
+ # @see ApiManager
89
+ # @see Wrapper::DEFAULT.extended Wrapper::DEFAULT.extended (click [View source])
90
+ # @see http://docs.aws.amazon.com/AmazonCloudFront/latest/APIReference/Welcome.html
91
+ #
92
+ class Manager < CloudApi::Manager
93
+ end
94
+
95
+ # Amazon Cloud Front (CF) compatible manager (thread unsafe)
96
+ #
97
+ # @see Manager
98
+ #
99
+ class ApiManager < CloudApi::ApiManager
100
+
101
+ # CF Error
102
+ class Error < CloudApi::Error
103
+ end
104
+
105
+ # Default API version for CloudFront service
106
+ #
107
+ # To override the API version use :api_version key when instantiating a manager.
108
+ #
109
+ DEFAULT_API_VERSION = '2012-07-01'
110
+
111
+ include Mixin::QueryApiPatterns
112
+
113
+ set_routine CloudApi::RetryManager
114
+ set_routine CloudApi::RequestInitializer
115
+ set_routine AWS::CF::RequestSigner
116
+ set_routine CloudApi::RequestGenerator
117
+ set_routine CloudApi::ConnectionProxy
118
+ set_routine CloudApi::ResponseAnalyzer
119
+ set_routine CloudApi::ResponseParser
120
+ set_routine CloudApi::ResultWrapper
121
+
122
+ set :response_error_parser => Parser::AWS::ResponseErrorV2
123
+
124
+
125
+ # Initializes Amazon CloudFront service manager
126
+ #
127
+ # @param [String] aws_access_key_id
128
+ # @param [String] aws_secret_access_key
129
+ # @param [String] endpoint
130
+ # @param [Hash] options
131
+ #
132
+ # @return [RightScale::CloudApi::AWS::CF::ApiManager]
133
+ #
134
+ # @example
135
+ # # see Manager class for example
136
+ #
137
+ # @see Manager
138
+ #
139
+ def initialize(aws_access_key_id, aws_secret_access_key, endpoint, options={})
140
+ credentials = { :aws_access_key_id => aws_access_key_id,
141
+ :aws_secret_access_key => aws_secret_access_key }
142
+ super(credentials, endpoint, options)
143
+ end
144
+
145
+
146
+ # Makes an API call to AWS Cloud Front compatible cloud
147
+ #
148
+ # @param [String,Symbol] verb
149
+ # @param [Objects] args
150
+ #
151
+ # @return [Object]
152
+ #
153
+ # @example
154
+ # api(verb, opts={})
155
+ # api(verb, 'distribution', opts={})
156
+ # # Where opts may have next keys: :options, :headers, :params
157
+ # api(verb, 'distribution/path', opts={})
158
+ #
159
+ def api(verb, *args, &block)
160
+ relative_path = args.first.is_a?(String) ? args.shift : ''
161
+ opts = args.shift || {}
162
+ raise Error::new("Opts must be Hash not #{opts.class.name}") unless opts.is_a?(Hash)
163
+ process_api_request(verb, relative_path, opts, &block)
164
+ end
165
+
166
+ end
167
+
168
+ end
169
+ end
170
+ end
171
+ end