mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[core] Move XML/JSON code up out of core
Rather than embedding XML and JSON support within fog-core, this is the start of extracting them to exist alongside core. That will move the responsibility to each provider to declare if they want XML or JSON services. Goal being as we move towards a modular fog this allows providers to require core and either JSON or XML gems and not pick up dependencies only required by the other.
This commit is contained in:
parent
e172362b45
commit
f6280910f8
5 changed files with 44 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
|||
require 'fog/core/json'
|
||||
require "fog/json"
|
||||
|
||||
module Fog
|
||||
module AWS
|
||||
module CredentialFetcher
|
||||
|
@ -14,7 +15,7 @@ module Fog
|
|||
|
||||
session = Fog::JSON.decode(role_data)
|
||||
credentials = {}
|
||||
credentials[:aws_access_key_id] = session['AccessKeyId']
|
||||
credentials[:aws_access_key_id] = session['AccessKeyId']
|
||||
credentials[:aws_secret_access_key] = session['SecretAccessKey']
|
||||
credentials[:aws_session_token] = session['Token']
|
||||
credentials[:aws_credentials_expire_at] = Time.xmlschema session['Expiration']
|
||||
|
@ -31,7 +32,7 @@ module Fog
|
|||
end
|
||||
|
||||
module ConnectionMethods
|
||||
|
||||
|
||||
def refresh_credentials_if_expired
|
||||
refresh_credentials if credentials_expired?
|
||||
end
|
||||
|
@ -39,8 +40,8 @@ module Fog
|
|||
private
|
||||
|
||||
def credentials_expired?
|
||||
@use_iam_profile &&
|
||||
(!@aws_credentials_expire_at ||
|
||||
@use_iam_profile &&
|
||||
(!@aws_credentials_expire_at ||
|
||||
(@aws_credentials_expire_at && Fog::Time.now > @aws_credentials_expire_at - 15)) #new credentials become available from around 5 minutes before expiration time
|
||||
end
|
||||
|
||||
|
@ -61,4 +62,3 @@ module Fog
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -19,11 +19,9 @@ require 'fog/core/current_machine'
|
|||
require 'fog/core/deprecation'
|
||||
require 'fog/core/errors'
|
||||
require 'fog/core/hmac'
|
||||
require 'fog/core/json'
|
||||
require 'fog/core/logger'
|
||||
require 'fog/core/model'
|
||||
require 'fog/core/mock'
|
||||
require 'fog/core/parser' # FIXME: would be better to only load when nokogiri is required
|
||||
require 'fog/core/provider'
|
||||
require 'fog/core/service'
|
||||
require 'fog/core/ssh'
|
||||
|
@ -32,6 +30,11 @@ require 'fog/core/time'
|
|||
require 'fog/core/timeout'
|
||||
require 'fog/core/wait_for'
|
||||
|
||||
# data exchange specific (to be extracted and used on a per provider basis)
|
||||
require 'fog/xml'
|
||||
require 'fog/json'
|
||||
|
||||
|
||||
# service wrappers
|
||||
require 'fog/compute'
|
||||
require 'fog/identity'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'nokogiri'
|
||||
require "nokogiri"
|
||||
|
||||
module Fog
|
||||
module Parsers
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
require 'multi_json'
|
||||
require "multi_json"
|
||||
|
||||
module Fog
|
||||
|
||||
# @note Extracting JSON components out of core is a work in progress.
|
||||
#
|
||||
# The {JSON} module includes functionality that is common between APIs using
|
||||
# JSON to send and receive data.
|
||||
#
|
||||
# The intent is to provide common code for provider APIs using JSON but not
|
||||
# require it for those using XML.
|
||||
#
|
||||
# @todo Add +require "fog/json" and/or +include Fog::JSON+ to providers using
|
||||
# its services
|
||||
#
|
||||
module JSON
|
||||
|
||||
def self.sanitize(data)
|
||||
|
@ -28,6 +40,5 @@ module Fog
|
|||
def self.decode(obj)
|
||||
MultiJson.decode(obj)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
19
lib/fog/xml.rb
Normal file
19
lib/fog/xml.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
require "nokogiri"
|
||||
require "fog/core/parser"
|
||||
|
||||
module Fog
|
||||
|
||||
# @note Extracting XML components out of core is a work in progress.
|
||||
#
|
||||
# The {XML} module includes functionality that is common between APIs using
|
||||
# XML to send and receive data.
|
||||
#
|
||||
# The intent is to provide common code for provider APIs using XML but not
|
||||
# require it for those using JSON.
|
||||
#
|
||||
# @todo Add +require "fog/xml"+ and/or +include Fog::XML+ to providers using
|
||||
# its services
|
||||
#
|
||||
module XML
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue