diff options
author | elijah <elijah@riseup.net> | 2017-06-28 13:24:39 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2017-07-04 11:32:51 -0700 |
commit | f365b914662491ab33e6af18e1b02046f6b99538 (patch) | |
tree | 10b86025a80dddbf84d0b95d809b92695205b0b5 /lib/leap_cli/cloud/dependencies.rb | |
parent | 0d304e582d643893f5e139eb5126c793bc82ae6d (diff) |
leap_cli - make fog gem optional
Diffstat (limited to 'lib/leap_cli/cloud/dependencies.rb')
-rw-r--r-- | lib/leap_cli/cloud/dependencies.rb | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/lib/leap_cli/cloud/dependencies.rb b/lib/leap_cli/cloud/dependencies.rb index fd690e59..670d6134 100644 --- a/lib/leap_cli/cloud/dependencies.rb +++ b/lib/leap_cli/cloud/dependencies.rb @@ -1,40 +1,37 @@ # -# I am not sure this is a good idea, but it might be. Tricky, so disabled for now +# Ensure that the needed fog gems are installed # - -=begin module LeapCli class Cloud - def self.check_required_gems - begin - require "fog" - rescue LoadError - bail! do - log :error, "The 'vm' command requires the gem 'fog-core'. Please run `gem install fog-core` and try again." - end - end + SUPPORTED = { + 'aws' => {require: 'fog/aws', gem: 'fog-aws'} + }.freeze - fog_gems = @cloud.required_gems - if !options[:mock] && fog_gems.empty? - bail! do - log :warning, "no vm providers are configured in cloud.json." - log "You must have credentials for one of: #{@cloud.possible_apis.join(', ')}." + def self.check_dependencies!(config) + required_gem = map_api_to_gem(config['api']) + if required_gem.nil? + Util.bail! do + Util.log :error, "The API '#{config['api']}' specified in cloud.json is not one that I know how to speak. Try one of #{supported_list}." end end - fog_gems.each do |name, gem_name| - begin - require gem_name.sub('-','/') - rescue LoadError - bail! do - log :error, "The 'vm' command requires the gem '#{gem_name}' (because of what is configured in cloud.json)." - log "Please run `sudo gem install #{gem_name}` and try again." - end + begin + require required_gem[:require] + rescue LoadError + Util.bail! do + Util.log :error, "The 'vm' command requires the gem '#{required_gem[:gem]}'. Please run `gem install #{required_gem[:gem]}` and try again." + Util.log "(make sure you install the gem in the ruby #{RUBY_VERSION} environment)" end end end + def self.supported_list + SUPPORTED.keys.join(', ') + end + + def self.map_api_to_gem(api) + SUPPORTED[api] + end end end -=end
\ No newline at end of file |