summaryrefslogtreecommitdiff
path: root/lib/leap_cli/cloud/dependencies.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/leap_cli/cloud/dependencies.rb')
-rw-r--r--lib/leap_cli/cloud/dependencies.rb47
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