aboutsummaryrefslogtreecommitdiff
path: root/lib/leap_cli/config/manager.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2012-11-04 11:30:16 -0800
committerelijah <elijah@riseup.net>2012-11-04 11:30:16 -0800
commit08b03669c262fd7ea67c7e2e5e5448a98db4ceef (patch)
tree6d08a0ae0fe6e7f8baf49fa58c52e7c0a23911cd /lib/leap_cli/config/manager.rb
parentb561a3eadd43218a59650b6255f8d12266b38884 (diff)
downloadleap_cli-08b03669c262fd7ea67c7e2e5e5448a98db4ceef.tar.gz
leap_cli-08b03669c262fd7ea67c7e2e5e5448a98db4ceef.tar.bz2
added automatic secret generation in secrets.json
Diffstat (limited to 'lib/leap_cli/config/manager.rb')
-rw-r--r--lib/leap_cli/config/manager.rb18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb
index 2eda7a4..8a4a617 100644
--- a/lib/leap_cli/config/manager.rb
+++ b/lib/leap_cli/config/manager.rb
@@ -8,7 +8,7 @@ module LeapCli
#
class Manager
- attr_reader :services, :tags, :nodes, :provider, :common
+ attr_reader :services, :tags, :nodes, :provider, :common, :secrets
##
## IMPORT EXPORT
@@ -18,11 +18,13 @@ module LeapCli
# load .json configuration files
#
def load(provider_dir=Path.provider)
+ @provider_dir = provider_dir
@services = load_all_json(Path.named_path([:service_config, '*'], provider_dir))
@tags = load_all_json(Path.named_path([:tag_config, '*'], provider_dir))
@nodes = load_all_json(Path.named_path([:node_config, '*'], provider_dir))
@common = load_json(Path.named_path(:common_config, provider_dir))
@provider = load_json(Path.named_path(:provider_config, provider_dir))
+ @secrets = load_json(Path.named_path(:secrets_config, provider_dir))
Util::assert!(@provider, "Failed to load provider.json")
Util::assert!(@common, "Failed to load common.json")
@@ -35,7 +37,8 @@ module LeapCli
#
# save compiled hiera .yaml files
#
- def export(dir=Path.named_path(:hiera_dir))
+ def export_nodes(destination_directory = nil)
+ dir = destination_directory || Path.named_path(:hiera_dir, @provider_dir)
existing_files = Dir.glob(dir + '/*.yaml')
updated_files = []
@nodes.each do |name, node|
@@ -48,6 +51,13 @@ module LeapCli
end
end
+ def export_secrets(destination_file = nil)
+ if @secrets.any?
+ file_path = destination_file || Path.named_path(:secrets_config, @provider_dir)
+ Util.write_file!(file_path, @secrets.dump_json + "\n")
+ end
+ end
+
##
## FILTERING
##
@@ -119,6 +129,10 @@ module LeapCli
end
def load_json(filename)
+ if !File.exists?(filename)
+ return Config::Object.new(self)
+ end
+
#
# read file, strip out comments
# (File.read(filename) would be faster, but we like ability to have comments)