1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Generalize NoLeak Inspector for Fog::Service

Fog::Services can use the 'secrets' class method to list the symbols of
the instance variables not to display via #inspect.
This commit is contained in:
Edward Muller 2012-06-08 16:36:08 -07:00
parent bed38882f8
commit 1dbc7b4769
4 changed files with 23 additions and 0 deletions

View file

@ -9,6 +9,8 @@ module Fog
requires :aws_access_key_id, :aws_secret_access_key
recognizes :endpoint, :region, :host, :path, :port, :scheme, :persistent, :aws_session_token, :use_iam_profile, :aws_credentials_expire_at
secrets :aws_secret_access_key, :hmac, :aws_session_token
model_path 'fog/aws/models/compute'
model :address
collection :addresses

View file

@ -9,6 +9,8 @@ module Fog
requires :aws_access_key_id, :aws_secret_access_key
recognizes :endpoint, :region, :host, :path, :port, :scheme, :persistent, :use_iam_profile, :aws_session_token, :aws_credentials_expire_at
secrets :aws_secret_access_key, :hmac
model_path 'fog/aws/models/storage'
collection :directories
model :directory

View file

@ -9,6 +9,12 @@ module Fog
class Error < Fog::Errors::Error; end
class NotFound < Fog::Errors::NotFound; end
module NoLeakInspector
def inspect
"#<#{self.class}:#{self.object_id} #{(self.instance_variables - service.secrets).map {|iv| [iv, self.instance_variable_get(iv).inspect].join('=')}.join(' ')}>"
end
end
module Collections
def collections
@ -58,6 +64,7 @@ module Fog
service::Mock.new(options)
else
service::Real.send(:include, service::Collections)
service::Real.send(:include, service::NoLeakInspector)
service::Real.new(options)
end
end
@ -163,6 +170,16 @@ module Fog
@requests ||= []
end
def secrets(*args)
if args.empty?
@secrets ||= []
else
args.inject(secrets) do |secrets, secret|
secrets << "@#{secret}".to_sym
end
end
end
def requires(*args)
requirements.concat(args)
end

View file

@ -8,6 +8,8 @@ module Fog
requires :hp_secret_key, :hp_account_id, :hp_tenant_id
recognizes :hp_auth_uri, :hp_servicenet, :persistent, :connection_options, :hp_use_upass_auth_style, :hp_auth_version, :hp_avl_zone
secrets :hp_secret_key
model_path 'fog/hp/models/compute'
model :address
collection :addresses