From effe065ad6d810431c61f02330011c7443967bc4 Mon Sep 17 00:00:00 2001 From: elijah Date: Thu, 5 Feb 2015 23:23:33 -0800 Subject: minor - fix indentation --- lib/leap_cli/config/secrets.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/leap_cli/config') diff --git a/lib/leap_cli/config/secrets.rb b/lib/leap_cli/config/secrets.rb index 366ffd3..e0f3080 100644 --- a/lib/leap_cli/config/secrets.rb +++ b/lib/leap_cli/config/secrets.rb @@ -13,10 +13,10 @@ module LeapCli; module Config @discovered_keys = {} end - # we can't use fetch() or get(), since those already have special meanings - def retrieve(key, environment=nil) - self.fetch(environment||'default', {})[key.to_s] - end + # we can't use fetch() or get(), since those already have special meanings + def retrieve(key, environment=nil) + self.fetch(environment||'default', {})[key.to_s] + end def set(key, value, environment=nil) environment ||= 'default' -- cgit v1.2.3 From 80f28c3862da72172a55d3e0218faad5cdd46b4b Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 5 May 2015 14:57:27 -0700 Subject: properly bind 'global.services' and 'global.tags' in the right environment in the macros. --- lib/leap_cli/config/manager.rb | 9 +++++--- lib/leap_cli/config/object.rb | 43 ++++++++++++++++++++++++++++++++++++-- lib/leap_cli/config/object_list.rb | 2 +- 3 files changed, 48 insertions(+), 6 deletions(-) (limited to 'lib/leap_cli/config') diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb index be95831..33b7f05 100644 --- a/lib/leap_cli/config/manager.rb +++ b/lib/leap_cli/config/manager.rb @@ -133,9 +133,9 @@ module LeapCli next unless ename log 3, :loading, '%s environment...' % ename env(ename) do |e| - e.services = load_all_json(Path.named_path([:service_env_config, '*', ename], @provider_dir), Config::Tag) - e.tags = load_all_json(Path.named_path([:tag_env_config, '*', ename], @provider_dir), Config::Tag) - e.provider = load_json( Path.named_path([:provider_env_config, ename], @provider_dir), Config::Provider) + e.services = load_all_json(Path.named_path([:service_env_config, '*', ename], @provider_dir), Config::Tag, :env => ename) + e.tags = load_all_json(Path.named_path([:tag_env_config, '*', ename], @provider_dir), Config::Tag, :env => ename) + e.provider = load_json( Path.named_path([:provider_env_config, ename], @provider_dir), Config::Provider, :env => ename) e.services.inherit_from! env('default').services e.tags.inherit_from! env('default').tags e.provider.inherit_from! env('default').provider @@ -315,6 +315,9 @@ module LeapCli if obj name = File.basename(filename).force_encoding('utf-8').sub(/^([^\.]+).*\.json$/,'\1') obj['name'] ||= name + if options[:env] + obj.environment = options[:env] + end results[name] = obj end end diff --git a/lib/leap_cli/config/object.rb b/lib/leap_cli/config/object.rb index a0d402b..6f71a08 100644 --- a/lib/leap_cli/config/object.rb +++ b/lib/leap_cli/config/object.rb @@ -10,6 +10,34 @@ require 'ya2yaml' # pure ruby yaml module LeapCli module Config + + # + # A proxy for Manager that binds to a particular object + # (so that we can bind to a particular environment) + # + class ManagerBinding + def initialize(manager, object) + @manager = manager + @object = object + end + + def services + @manager.env(@object.environment).services + end + + def tags + @manager.env(@object.environment).tags + end + + def provider + @manager.env(@object.environment).provider + end + + def method_missing(*args) + @manager.send(*args) + end + end + # # This class represents the configuration for a single node, service, or tag. # Also, all the nested hashes are also of this type. @@ -19,8 +47,6 @@ module LeapCli class Object < Hash attr_reader :node - attr_reader :manager - alias :global :manager def initialize(manager=nil, node=nil) # keep a global pointer around to the config manager. used a lot in the eval strings and templates @@ -31,6 +57,19 @@ module LeapCli @node = node || self end + def manager + ManagerBinding.new(@manager, self) + end + alias :global :manager + + def environment=(e) + self.store('environment', e) + end + + def environment + self['environment'] + end + # # export YAML # diff --git a/lib/leap_cli/config/object_list.rb b/lib/leap_cli/config/object_list.rb index 33ca4dd..afcc6a6 100644 --- a/lib/leap_cli/config/object_list.rb +++ b/lib/leap_cli/config/object_list.rb @@ -174,7 +174,7 @@ module LeapCli if self[name] self[name].inherit_from!(object) else - self[name] = object.dup + self[name] = object.deep_dup end end end -- cgit v1.2.3 From 3c1cc376787a7866d929205959e42be403a2c2ce Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 5 May 2015 15:21:14 -0700 Subject: added support for secrets.set() with value passed as a block, so that secrets don't get needlessly generated --- lib/leap_cli/config/secrets.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'lib/leap_cli/config') diff --git a/lib/leap_cli/config/secrets.rb b/lib/leap_cli/config/secrets.rb index e0f3080..184d11d 100644 --- a/lib/leap_cli/config/secrets.rb +++ b/lib/leap_cli/config/secrets.rb @@ -14,17 +14,28 @@ module LeapCli; module Config end # we can't use fetch() or get(), since those already have special meanings - def retrieve(key, environment=nil) - self.fetch(environment||'default', {})[key.to_s] + def retrieve(key, environment) + self.fetch(environment, {})[key.to_s] end - def set(key, value, environment=nil) - environment ||= 'default' + def set(*args, &block) + if block_given? + set_with_block(*args, &block) + else + set_without_block(*args) + end + end + + def set_without_block(key, value, environment) + set_with_block(key, environment) {value} + end + + def set_with_block(key, environment, &block) key = key.to_s @discovered_keys[environment] ||= {} @discovered_keys[environment][key] = true self[environment] ||= {} - self[environment][key] ||= value + self[environment][key] ||= yield end # -- cgit v1.2.3