summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormokha <mokha@cisco.com>2018-03-19 16:05:24 -0600
committermokha <mokha@cisco.com>2018-03-19 16:05:24 -0600
commitd5824b750c802e0e07de5ada85bd037b8bffdc05 (patch)
tree1612cb6d6d588ddf8e21ece92a68bdbc4c14d55b
parent8ea3d5a9fe06531c29a764ff462220dfa53c2bbe (diff)
move setup to a separate command.
-rw-r--r--lib/ats/cli.rb40
-rw-r--r--lib/ats/cli/setup.rb49
2 files changed, 53 insertions, 36 deletions
diff --git a/lib/ats/cli.rb b/lib/ats/cli.rb
index cb58954..cd400fc 100644
--- a/lib/ats/cli.rb
+++ b/lib/ats/cli.rb
@@ -1,6 +1,7 @@
require 'ats'
require 'thor'
require 'ats/cli/command'
+require 'ats/cli/setup'
require 'ats/cli/threat_grid/organizations'
require 'ats/cli/threat_grid/samples'
require 'ats/cli/threat_grid/search'
@@ -24,46 +25,13 @@ module ATS
desc 'amp4e SUBCOMMAND ...ARGS', 'interact with the AMP for Endpoints API'
subcommand 'amp4e', AMP4E::Application
+ desc 'setup', 'setup'
+ subcommand :setup, ATS::CLI::Setup
+
desc 'version', 'Display the current version'
def version
say ATS::VERSION
end
-
- desc 'setup', 'Initialize the .atsrc file.'
- def setup(configuration = ATS.configuration)
- say "Current Configuration:", :green
- say JSON.pretty_generate(configuration.to_h), :green
-
- configuration.config_files.each do |file|
- if File.exist?(file)
- say "Found #{file}. Nothing to do. Good bye!", :green
- exit 0
- end
- end
-
- say "Configuration file not found."
- new_file = configuration.config_files.first
- say "New file created at #{new_file}."
- yaml = YAML.dump({
- default: {
- amp4e: {
- client_id: '',
- client_secret: '',
- host: 'api.amp.cisco.com',
- port: 443,
- scheme: 'https',
- },
- threatgrid: {
- api_key: '',
- host: 'panacea.threatgrid.com',
- port: 443,
- scheme: 'https',
- },
- }
- })
- say yaml, :yellow
- IO.write(new_file, yaml)
- end
end
end
end
diff --git a/lib/ats/cli/setup.rb b/lib/ats/cli/setup.rb
new file mode 100644
index 0000000..b8539f5
--- /dev/null
+++ b/lib/ats/cli/setup.rb
@@ -0,0 +1,49 @@
+module ATS
+ module CLI
+ class Setup < Command
+ default_command :setup
+
+ desc 'setup', 'Initialize the .atsrc file.'
+ def setup
+ say "Current Configuration:", :green
+ say JSON.pretty_generate(configuration.to_h), :green
+
+ configuration.config_files.each do |file|
+ if File.exist?(file)
+ say "Found #{file}. Nothing to do. Good bye!", :green
+ exit 0
+ end
+ end
+
+ say "Configuration file not found."
+ new_file = configuration.config_files.first
+ say "New file created at #{new_file}."
+ yaml = YAML.dump(default_settings)
+ say yaml, :yellow
+ IO.write(new_file, yaml)
+ end
+
+ private
+
+ def default_settings
+ {
+ default: {
+ amp4e: {
+ client_id: '',
+ client_secret: '',
+ host: 'api.amp.cisco.com',
+ port: 443,
+ scheme: 'https',
+ },
+ threatgrid: {
+ api_key: '',
+ host: 'panacea.threatgrid.com',
+ port: 443,
+ scheme: 'https',
+ },
+ }
+ }
+ end
+ end
+ end
+end