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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# 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
configuration['modules'] = {}
if ['y','yes'].include? ask("Would you like to configure send frequencies? (y/n)\n", :bold).downcase
freq = ask "How often should filesystem data be sent to server? (in seconds -- default: 240 seconds)\n", :bold
if freq.strip.length > 0
configuration['modules']['fstree'] = {
'frequency' => freq.to_i
}
end
freq = ask "How often should package data be sent to server? (in seconds -- default: 60 seconds)\n", :bold
if freq.strip.length > 0
configuration['modules']['pkgver'] = {
'frequency' => freq.to_i
}
end
freq = ask "How often should port data be sent to server? (in seconds -- default: 60 seconds)\n", :bold
if freq.strip.length > 0
configuration['modules']['ports'] = {
'frequency' => freq.to_i
}
end
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
|