summaryrefslogtreecommitdiff
path: root/lib/leap_cli/config
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 /lib/leap_cli/config
parent2c2125b372bcfc69764f8f2a2ec6a1410f2e0669 (diff)
added ability to define environment specific provider.json (e.g. provider.production.json)
Diffstat (limited to 'lib/leap_cli/config')
-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
3 files changed, 32 insertions, 4 deletions
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