From 6e5289b7df7ff2f1320ba139303018d260c9b9cf Mon Sep 17 00:00:00 2001 From: elijah Date: Fri, 8 Feb 2013 21:47:45 -0800 Subject: leap inspect now works with all .json files --- lib/leap_cli/commands/inspect.rb | 62 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 5 deletions(-) (limited to 'lib/leap_cli') diff --git a/lib/leap_cli/commands/inspect.rb b/lib/leap_cli/commands/inspect.rb index 1856ad6..97d0b20 100644 --- a/lib/leap_cli/commands/inspect.rb +++ b/lib/leap_cli/commands/inspect.rb @@ -30,16 +30,39 @@ module LeapCli; module Commands log 2, "file is of type '#{ftype}'" if FTYPE_MAP[ftype] FTYPE_MAP[ftype] - elsif ftype == "ASCII text" - nil + elsif File.extname(object) == ".json" + full_path = File.expand_path(object, Dir.pwd) + if path_match?(:node_config, full_path) + :inspect_node + elsif path_match?(:service_config, full_path) + :inspect_service + elsif path_match?(:tag_config, full_path) + :inspect_tag + elsif path_match?(:provider_config, full_path) + :inspect_provider + elsif path_match?(:common_config, full_path) + :inspect_common + end end elsif manager.nodes[object] :inspect_node + elsif manager.services[object] + :inspect_service + elsif manager.tags[object] + :inspect_tag + elsif object == "common" + :inspect_common + elsif object == "provider" + :inspect_provider else nil end end + # + # inspectors + # + def inspect_x509_key(file_path, options) assert_bin! 'openssl' puts assert_run! 'openssl rsa -in %s -text -check' % file_path @@ -59,9 +82,38 @@ module LeapCli; module Commands #def inspect_ssh_pub_key(file_path) #end - def inspect_node(node_name, options) - node = manager.nodes[node_name] - puts node.dump_json + def inspect_node(arg, options) + inspect_json(arg, options) {|name| manager.nodes[name] } + end + + def inspect_service(arg, options) + inspect_json(arg, options) {|name| manager.services[name] } + end + + def inspect_tag(arg, options) + inspect_json(arg, options) {|name| manager.tags[name] } + end + + def inspect_provider(arg, options) + inspect_json(arg, options) {|name| manager.provider } + end + + def inspect_common(arg, options) + inspect_json(arg, options) {|name| manager.common } + end + + # + # helpers + # + + def inspect_json(arg, options) + name = File.basename(arg).sub(/\.json$/, '') + config = yield name + puts config.dump_json + end + + def path_match?(path_symbol, path) + Dir.glob(Path.named_path([path_symbol, '*'])).include?(path) end end; end -- cgit v1.2.3