From d81cc071d2f01a9e865a9f41e4fc50341be7e720 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Sat, 4 May 2013 19:15:02 -0400 Subject: [PATCH 1/2] Load google/api_client late to avoid dep. Updates the google/compute.rb module so that it requires the 'google/api_client' dependency late. This avoids having to require (and install) proprietary google client API code to use Fog for other providers. (previously, even when using AWS I'd still have to install google-client-api) --- I understand code reuse is important but I think the fact that we recently added google-api-client as a top level dependency sets a bad precedent and perhaps highlights the need to move further towards "fog modules" for each provider to avoid these types of situations. --- fog.gemspec | 1 - lib/fog/google/compute.rb | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/fog.gemspec b/fog.gemspec index eb773a754..22b402a8c 100644 --- a/fog.gemspec +++ b/fog.gemspec @@ -41,7 +41,6 @@ Gem::Specification.new do |s| ## List your runtime dependencies here. Runtime dependencies are those ## that are needed for an end user to actually USE your code. s.add_dependency('builder') - s.add_dependency('google-api-client', '~>0.6.2') s.add_dependency('excon', '~>0.20') s.add_dependency('formatador', '~>0.2.0') s.add_dependency('json', '~>1.7') diff --git a/lib/fog/google/compute.rb b/lib/fog/google/compute.rb index 5636f9042..7d0a65dc5 100644 --- a/lib/fog/google/compute.rb +++ b/lib/fog/google/compute.rb @@ -1,6 +1,5 @@ require 'fog/google' require 'fog/compute' -require 'google/api_client' module Fog module Compute @@ -67,6 +66,8 @@ module Fog attr_reader :project def initialize(options) + + base_url = 'https://www.googleapis.com/compute/' api_version = 'v1beta14' api_scope_url = 'https://www.googleapis.com/auth/compute' @@ -74,6 +75,8 @@ module Fog @project = options[:google_project] google_client_email = options[:google_client_email] @api_url = base_url + api_version + '/projects/' + #NOTE: loaded here to avoid requiring this as a core Fog dependency + require 'google/api_client' key = ::Google::APIClient::KeyUtils.load_from_pkcs12(File.expand_path(options[:google_key_location]), 'notasecret') @client = ::Google::APIClient.new({ From 1c96372672ddafdaf15e976466e53cc9450c591a Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Sat, 4 May 2013 19:26:24 -0400 Subject: [PATCH 2/2] Add a custom log warning on load error. --- lib/fog/google/compute.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/fog/google/compute.rb b/lib/fog/google/compute.rb index 7d0a65dc5..714e64602 100644 --- a/lib/fog/google/compute.rb +++ b/lib/fog/google/compute.rb @@ -76,7 +76,11 @@ module Fog google_client_email = options[:google_client_email] @api_url = base_url + api_version + '/projects/' #NOTE: loaded here to avoid requiring this as a core Fog dependency - require 'google/api_client' + begin + require 'google/api_client' + rescue LoadError + Fog::Logger.warning("Please install the google-api-client gem before using this provider.") + end key = ::Google::APIClient::KeyUtils.load_from_pkcs12(File.expand_path(options[:google_key_location]), 'notasecret') @client = ::Google::APIClient.new({