Class: Anamo::Node::Thor
- Inherits:
-
Thor
- Object
- Thor
- Anamo::Node::Thor
- Defined in:
- lib/anamo/node/thor.rb
Instance Method Summary collapse
Instance Method Details
#configure ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/anamo/node/thor.rb', line 55 def configure configuration = {} say "The Anamo configuration setup tool will walk you through the process\nof defining your configuration for:\n\n", [:green, :bold] say " #{config_file_path}\n\n", :green configuration['api_key'] = '' until configuration['api_key'].strip.length > 0 do configuration['api_key'] = ask "What is your Anamo API key?\n", :bold end say "\nYour configuration file:\n\n", [:green, :bold] configuration_yaml = YAML.dump configuration say configuration_yaml if ['yes', 'y'].include? ask("\nWould you like to save this file now? (\"y\" to save)", :bold).downcase File.open(config_file_path, 'w') { |file| file.write configuration_yaml } File.chmod(0600, config_file_path) say "Configurated saved at: #{config_file_path}", [:cyan, :bold] else say 'Configuration not saved.', [:red, :bold] end end |
#exec ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/anamo/node/thor.rb', line 16 def exec data = inspect false response = ::Anamo::Api.new.post_node MultiJson.dump data response_data = MultiJson.load response.body if response_data.respond_to?(:has_key?) and response_data.has_key?('client_key') File.open(key_file, 'w') { |file| file.write response_data['client_key'] } File.chmod(0600, key_file) end end |
#inspect(output = true) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/anamo/node/thor.rb', line 33 def inspect output = true ret = {} config = YAML.load_file "/etc/anamo.conf.yml" ret['api_key'] = config['api_key'] ret['beacon_modules'] = config['modules'] ret['node'] = {} ret['node']['hostname'] = Socket.gethostname ret['node']['ips'] = Socket.ip_address_list.map(){ |entry| entry.ip_address }.uniq puts ret if output ret end |