From 1dbc7b47699e7392cbe198b8f06b714f7a30a5c3 Mon Sep 17 00:00:00 2001 From: Edward Muller Date: Fri, 8 Jun 2012 16:36:08 -0700 Subject: [PATCH] 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. --- lib/fog/aws/compute.rb | 2 ++ lib/fog/aws/storage.rb | 2 ++ lib/fog/core/service.rb | 17 +++++++++++++++++ lib/fog/hp/compute.rb | 2 ++ 4 files changed, 23 insertions(+) diff --git a/lib/fog/aws/compute.rb b/lib/fog/aws/compute.rb index c932012a1..51d5ce9ae 100644 --- a/lib/fog/aws/compute.rb +++ b/lib/fog/aws/compute.rb @@ -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 diff --git a/lib/fog/aws/storage.rb b/lib/fog/aws/storage.rb index 257d9eeb4..ec595bd55 100644 --- a/lib/fog/aws/storage.rb +++ b/lib/fog/aws/storage.rb @@ -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 diff --git a/lib/fog/core/service.rb b/lib/fog/core/service.rb index 3fb97b45a..7fc7138b3 100644 --- a/lib/fog/core/service.rb +++ b/lib/fog/core/service.rb @@ -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 diff --git a/lib/fog/hp/compute.rb b/lib/fog/hp/compute.rb index d55be8813..f0526be83 100644 --- a/lib/fog/hp/compute.rb +++ b/lib/fog/hp/compute.rb @@ -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