Module: Miasma::Contrib::AwsApiCore::ApiCommon
- Included in:
- Models::AutoScale::Aws, Models::Compute::Aws, Models::LoadBalancer::Aws, Models::Orchestration::Aws, Models::Storage::Aws
- Defined in:
- lib/miasma/contrib/aws.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#api_for(type) ⇒ Api
Build new API for specified type using current provider / creds.
-
#connect ⇒ Object
Setup for API connections.
-
#connection ⇒ HTTP
Connection for requests (forces headers).
-
#endpoint ⇒ String
Endpoint for request.
-
#make_request(connection, http_method, request_args) ⇒ HTTP::Response
Override to inject signature.
-
#update_request(con, opts) ⇒ TrueClass
Simple callback to allow request option adjustments prior to signature calculation.
-
#uri_escape(string) ⇒ String
Custom escape for aws compat.
Class Method Details
.included(klass) ⇒ Object
327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/miasma/contrib/aws.rb', line 327 def self.included(klass) klass.class_eval do attribute :aws_access_key_id, String, :required => true attribute :aws_secret_access_key, String, :required => true attribute :aws_region, String, :required => true attribute :aws_host, String attribute :aws_bucket_region, String # @return [Contrib::AwsApiCore::SignatureV4] attr_reader :signer end end |
Instance Method Details
#api_for(type) ⇒ Api
Build new API for specified type using current provider / creds
344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/miasma/contrib/aws.rb', line 344 def api_for(type) memoize(type) do creds = attributes.dup creds.delete(:aws_host) Miasma.api( Smash.new( :type => type, :provider => provider, :credentials => creds ) ) end end |
#connect ⇒ Object
Setup for API connections
359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/miasma/contrib/aws.rb', line 359 def connect unless(aws_host) self.aws_host = [ self.class::API_SERVICE.downcase, aws_region, 'amazonaws.com' ].join('.') end @signer = Contrib::AwsApiCore::SignatureV4.new( aws_access_key_id, aws_secret_access_key, aws_region, self.class::API_SERVICE ) end |
#connection ⇒ HTTP
Returns connection for requests (forces headers).
378 379 380 381 382 383 |
# File 'lib/miasma/contrib/aws.rb', line 378 def connection super.with_headers( 'Host' => aws_host, 'X-Amz-Date' => Contrib::AwsApiCore.time_iso8601 ) end |
#endpoint ⇒ String
Returns endpoint for request.
386 387 388 |
# File 'lib/miasma/contrib/aws.rb', line 386 def endpoint "https://#{aws_host}" end |
#make_request(connection, http_method, request_args) ⇒ HTTP::Response
Note:
if http_method is :post, params will be automatically removed and placed into :form
Override to inject signature
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/miasma/contrib/aws.rb', line 398 def make_request(connection, http_method, request_args) dest, = request_args path = URI.parse(dest).path = ? .to_smash : Smash.new [:params] = .fetch(:params, Smash.new).to_smash.deep_merge('Version' => self.class::API_VERSION) if(http_method.to_sym == :post) if([:form]) [:form].merge(.delete(:params)) else [:form] = .delete(:params) end end update_request(connection, ) signature = signer.generate( http_method, path, .merge( Smash.new( :headers => Smash[ connection.default_headers.to_a ] ) ) ) = Hash[.map{|k,v|[k.to_sym,v]}] connection.auth(signature).send(http_method, dest, ) end |
#update_request(con, opts) ⇒ TrueClass
Simple callback to allow request option adjustments prior to signature calculation
429 430 431 |
# File 'lib/miasma/contrib/aws.rb', line 429 def update_request(con, opts) true end |
#uri_escape(string) ⇒ String
Returns custom escape for aws compat.
373 374 375 |
# File 'lib/miasma/contrib/aws.rb', line 373 def uri_escape(string) signer.safe_escape(string) end |