aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2014-03-14 17:45:32 -0700
committerelijah <elijah@riseup.net>2014-03-14 17:45:32 -0700
commitae2936655c50e369c0150ff4c049cdcf696848a7 (patch)
tree20d341abf719333b52b9c65db4fae25684fb9c14
parent2c2125b372bcfc69764f8f2a2ec6a1410f2e0669 (diff)
downloadleap_cli-ae2936655c50e369c0150ff4c049cdcf696848a7.tar.gz
leap_cli-ae2936655c50e369c0150ff4c049cdcf696848a7.tar.bz2
added ability to define environment specific provider.json (e.g. provider.production.json)
-rw-r--r--lib/leap_cli.rb1
-rw-r--r--lib/leap_cli/commands/inspect.rb8
-rw-r--r--lib/leap_cli/config/macros.rb7
-rw-r--r--lib/leap_cli/config/manager.rb18
-rw-r--r--lib/leap_cli/config/provider.rb11
-rw-r--r--lib/leap_cli/path.rb4
-rw-r--r--lib/leap_cli/version.rb2
7 files changed, 44 insertions, 7 deletions
diff --git a/lib/leap_cli.rb b/lib/leap_cli.rb
index 2f9ffec..ed5932a 100644
--- a/lib/leap_cli.rb
+++ b/lib/leap_cli.rb
@@ -27,6 +27,7 @@ require 'leap_cli/ssh_key'
require 'leap_cli/config/object'
require 'leap_cli/config/node'
require 'leap_cli/config/tag'
+require 'leap_cli/config/provider'
require 'leap_cli/config/secrets'
require 'leap_cli/config/object_list'
require 'leap_cli/config/manager'
diff --git a/lib/leap_cli/commands/inspect.rb b/lib/leap_cli/commands/inspect.rb
index 23c75bb..746a80c 100644
--- a/lib/leap_cli/commands/inspect.rb
+++ b/lib/leap_cli/commands/inspect.rb
@@ -39,7 +39,7 @@ module LeapCli; module Commands
:inspect_service
elsif path_match?(:tag_config, full_path)
:inspect_tag
- elsif path_match?(:provider_config, full_path)
+ elsif path_match?(:provider_config, full_path) || path_match?(:provider_env_config, full_path)
:inspect_provider
elsif path_match?(:common_config, full_path)
:inspect_common
@@ -108,6 +108,8 @@ module LeapCli; module Commands
def inspect_provider(arg, options)
if options[:base]
inspect_json manager.base_provider
+ elsif arg =~ /provider\.(.*)\.json/
+ inspect_json manager.providers[$1]
else
inspect_json manager.provider
end
@@ -130,7 +132,9 @@ module LeapCli; module Commands
end
def inspect_json(config)
- puts JSON.sorted_generate(config)
+ if config
+ puts JSON.sorted_generate(config)
+ end
end
def path_match?(path_symbol, path)
diff --git a/lib/leap_cli/config/macros.rb b/lib/leap_cli/config/macros.rb
index 79f3972..69b3a22 100644
--- a/lib/leap_cli/config/macros.rb
+++ b/lib/leap_cli/config/macros.rb
@@ -19,6 +19,13 @@ module LeapCli; module Config
end
#
+ # grab an environment appropriate provider
+ #
+ def provider
+ global.providers[@node.environment] || global.provider
+ end
+
+ #
# returns a list of nodes that match the same environment
#
# if @node.environment is not set, we return other nodes
diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb
index d6cb89e..46d7686 100644
--- a/lib/leap_cli/config/manager.rb
+++ b/lib/leap_cli/config/manager.rb
@@ -16,7 +16,7 @@ module LeapCli
## ATTRIBUTES
##
- attr_reader :services, :tags, :nodes, :provider, :common, :secrets
+ attr_reader :services, :tags, :nodes, :provider, :providers, :common, :secrets
attr_reader :base_services, :base_tags, :base_provider, :base_common
#
@@ -48,7 +48,7 @@ module LeapCli
@base_services = load_all_json(Path.named_path([:service_config, '*'], Path.provider_base), Config::Tag)
@base_tags = load_all_json(Path.named_path([:tag_config, '*'], Path.provider_base), Config::Tag)
@base_common = load_json(Path.named_path(:common_config, Path.provider_base), Config::Object)
- @base_provider = load_json(Path.named_path(:provider_config, Path.provider_base), Config::Object)
+ @base_provider = load_json(Path.named_path(:provider_config, Path.provider_base), Config::Provider)
# load provider
provider_path = Path.named_path(:provider_config, @provider_dir)
@@ -58,7 +58,7 @@ module LeapCli
@tags = load_all_json(Path.named_path([:tag_config, '*'], @provider_dir), Config::Tag)
@nodes = load_all_json(Path.named_path([:node_config, '*'], @provider_dir), Config::Node)
@common = load_json(common_path, Config::Object)
- @provider = load_json(provider_path, Config::Object)
+ @provider = load_json(provider_path, Config::Provider)
@secrets = load_json(Path.named_path(:secrets_config, @provider_dir), Config::Secrets)
### BEGIN HACK
@@ -83,8 +83,18 @@ module LeapCli
remove_disabled_nodes
end
- # validate
+ # load optional environment specific providers
validate_provider(@provider)
+ @providers = {}
+ environments.each do |env|
+ if Path.defined?(:provider_env_config)
+ provider_path = Path.named_path([:provider_env_config, env], @provider_dir)
+ providers[env] = load_json(provider_path, Config::Provider)
+ providers[env].inherit_from! @provider
+ validate_provider(providers[env])
+ end
+ end
+
end
#
diff --git a/lib/leap_cli/config/provider.rb b/lib/leap_cli/config/provider.rb
new file mode 100644
index 0000000..224e57b
--- /dev/null
+++ b/lib/leap_cli/config/provider.rb
@@ -0,0 +1,11 @@
+#
+# Configuration class for provider.json
+#
+
+module LeapCli; module Config
+ class Provider < Object
+ def provider
+ self
+ end
+ end
+end; end
diff --git a/lib/leap_cli/path.rb b/lib/leap_cli/path.rb
index b705788..cd0e169 100644
--- a/lib/leap_cli/path.rb
+++ b/lib/leap_cli/path.rb
@@ -72,6 +72,10 @@ module LeapCli; module Path
File.exists?(named_path(name, provider_dir))
end
+ def self.defined?(name)
+ Leap::Platform.paths[name]
+ end
+
def self.relative_path(path, provider_dir=Path.provider)
if provider_dir
path = named_path(path, provider_dir)
diff --git a/lib/leap_cli/version.rb b/lib/leap_cli/version.rb
index 926929a..83b1c39 100644
--- a/lib/leap_cli/version.rb
+++ b/lib/leap_cli/version.rb
@@ -1,6 +1,6 @@
module LeapCli
unless defined?(LeapCli::VERSION)
- VERSION = '1.4.0'
+ VERSION = '1.5.0'
COMPATIBLE_PLATFORM_VERSION = '0.3.0'..'1.99'
SUMMARY = 'Command line interface to the LEAP platform'
DESCRIPTION = 'The command "leap" can be used to manage a bevy of servers running the LEAP platform from the comfort of your own home.'