deepsecurity 0.0.19 → 0.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,7 +17,7 @@ module DeepSecurity
17
17
  # @!group High-Level SOAP Wrapper
18
18
 
19
19
  # Return a new instance for events with the given event id.
20
- # @param [Integer] id
20
+ # @param id [Integer]
21
21
  # @return [IDFilter]
22
22
  def self.equals(id)
23
23
  instance = self.new()
@@ -27,7 +27,7 @@ module DeepSecurity
27
27
  end
28
28
 
29
29
  # Return a new instance for events with event ids less than the given event id.
30
- # @param [Integer] id
30
+ # @param id [Integer]
31
31
  # @return [IDFilter]
32
32
  def self.less_than(id)
33
33
  instance = self.new()
@@ -37,7 +37,7 @@ module DeepSecurity
37
37
  end
38
38
 
39
39
  # Return a new instance for events with event ids greater than the given event id.
40
- # @param [Integer] id
40
+ # @param id [Integer]
41
41
  # @return [IDFilter]
42
42
  def self.greater_than(id)
43
43
  instance = self.new()
@@ -36,7 +36,7 @@ module DeepSecurity
36
36
  :includeNonHostEvents => includeNonHostEvents ? "true" : "false"})[:system_events]
37
37
  return [] if events.nil?
38
38
  events[:item].map do |each|
39
- SystemEvent.from_savon_data(each)
39
+ SystemEvent.convert_from_savon(each)
40
40
  end
41
41
  end
42
42
 
@@ -45,7 +45,7 @@ module DeepSecurity
45
45
  end
46
46
 
47
47
  # Return a new instance for the given datetime range.
48
- # @param [Range] datetime_range A range of two datetimes
48
+ # @param datetime_range [Range] A range of two datetimes
49
49
  # @return [TimeFilter]
50
50
  def self.custom_range(datetime_range)
51
51
  instance = self.new()
@@ -56,7 +56,7 @@ module DeepSecurity
56
56
  end
57
57
 
58
58
  # Return a new instance for the given datetime.
59
- # @param [DateTime] datetime
59
+ # @param datetime [DateTime]
60
60
  # @return [TimeFilter]
61
61
  def self.specificTime(datetime)
62
62
  instance = self.new()
@@ -1,3 +1,3 @@
1
1
  module DeepSecurity
2
- VERSION = "0.0.19"
2
+ VERSION = "0.0.20"
3
3
  end
@@ -1,12 +1,20 @@
1
+ # @author Udo Schneider <Udo.Schneider@homeaddress.de>
2
+
1
3
  module Dsc
2
4
 
5
+ # This class defines the arguments, options and implementation for the `anti_malware_event` command/subcommand.
3
6
  class AntiMalwareEventCommand < Command
4
7
 
5
-
8
+ # DeepSecurity object covered by this class.
9
+ # @return [DeepSecurity::AntiMalwareEvent]
6
10
  def self.transport_class
7
11
  DeepSecurity::AntiMalwareEvent
8
12
  end
9
13
 
14
+ # @!group Fields flag
15
+
16
+ # Default fields if no argument is given
17
+ # @return [Array<String>] Default fields if no argument is given
10
18
  def self.default_fields
11
19
  [
12
20
  # DNS name of system
@@ -52,17 +60,56 @@ module Dsc
52
60
  ]
53
61
  end
54
62
 
55
- def list(options, args)
63
+ # @!endgroup
64
+
65
+ # @!group Command definitions
66
+
67
+ # Define all commands for this available for this (sub) command_context
68
+ # @param command_context [CLI::App] The current context of the command.
69
+ # @return [void]
70
+ def self.define_commands(command_context)
71
+ command_context.desc "Access #{transport_class_string}s"
72
+ command_context.command command_symbol do |anti_malware_event_command|
73
+ define_list_command(anti_malware_event_command)
74
+ define_schema_command(anti_malware_event_command)
75
+ end
76
+ end
77
+
78
+ # Define `list` command_context
79
+ # @param command_context [CLI::App] The current context of the command.
80
+ # @yieldparam list_command [GLI::Command] The just defined list command_context
81
+ # @yield [list_command] Gives the list command_context to the block
82
+ # @return [void]
83
+ def self.define_list_command(command_context)
84
+ super(command_context) do |list|
85
+ define_time_filter_flag(list)
86
+ define_time_format_flag(list)
87
+ end
88
+ end
89
+
90
+ # @!endgroup
91
+
92
+ # @!group Command Implementations
93
+
94
+ # `list` Implementation.
95
+ # List all entries of the `transport_class` type according to given filter parameters.
96
+ # @param options [Hash<Symbol => Object>] Merged global/local options from GLI
97
+ # @option options [String] :fields The fields to display.
98
+ # @option options [String] :time_filter Timeframe to request.
99
+ # @param args [Array<String>] Arguments from GLI
100
+ # @return [void]
101
+ def list_command(options, args)
56
102
  fields = parse_fields(options[:fields])
57
103
  time_filter = parse_time_filter(options[:time_filter])
104
+ parse_time_format(options[:time_format])
58
105
  output do |output|
59
- authenticate do |dsm|
106
+ authenticate do |manager|
60
107
  progressBar = ProgressBar.new("anti_malware_event", 100) if @show_progress_bar
61
- DeepSecurity::Host.all # Make sure that hosts are cached
108
+ manager.hosts() # Make sure that hosts are cached
62
109
  progressBar.set(10) if @show_progress_bar
63
110
  hostFilter = DeepSecurity::HostFilter.all_hosts
64
111
  eventIdFilter = DeepSecurity::IDFilter.greater_than(0)
65
- anti_malware_events = DeepSecurity::AntiMalwareEvent.find_all(time_filter, hostFilter, eventIdFilter)
112
+ anti_malware_events = manager.anti_malware_events_by_time_host_event(time_filter, hostFilter, eventIdFilter)
66
113
  progressBar.set(25) if @show_progress_bar
67
114
  csv = CSV.new(output)
68
115
  csv << fields
@@ -70,7 +117,7 @@ module Dsc
70
117
  progressBar.inc(75/anti_malware_events.size) if @show_progress_bar
71
118
  csv << fields.map do |attribute|
72
119
  begin
73
- anti_malware_event.instance_eval(attribute)
120
+ to_display_string(anti_malware_event.instance_eval(attribute))
74
121
  rescue => e
75
122
  "ERROR (#{e.message}"
76
123
  end
@@ -81,11 +128,7 @@ module Dsc
81
128
  end
82
129
  end
83
130
 
84
- def self.define_list_command(c)
85
- super(c) do |list|
86
- define_time_filter_argument(list)
87
- end
88
- end
131
+ # @!endgroup
89
132
 
90
133
  end
91
134
 
data/lib/dsc/command.rb CHANGED
@@ -1,72 +1,298 @@
1
+ # @author Udo Schneider <Udo.Schneider@homeaddress.de>
1
2
  require "progressbar"
2
3
  require "csv"
3
4
 
4
5
  module Dsc
5
6
 
7
+ # This class defines an superclass for all `dsc` commands. It defines several helper methods which either define
8
+ # flags, options and commands or helpers to define them.
9
+ # @abstract
6
10
  class Command
7
11
 
12
+ # @abstract DeepSecurity object covered by this class.
13
+ # @return [DeepSecurity::TransportObject]
8
14
  def self.transport_class
9
15
  nil
10
16
  end
11
17
 
18
+ # @!group Helper methods
19
+
20
+ # Transport class name without namespace
21
+ # @return [String] Transport class name without namespace
12
22
  def self.transport_class_name
13
- class_name = transport_class.name.split('::').last || ''
23
+ transport_class.name_without_namespace
14
24
  end
15
25
 
26
+ # Human readable transport class name without namespace
27
+ # @return [String] Human readable transport class name without namespace
16
28
  def self.transport_class_string
17
29
  transport_class_name.split(/(?=[A-Z])/).join(" ")
18
30
  end
19
31
 
32
+ # Class name without namespace as command_context symbol
33
+ # @return [Symbol] Class name without namespace as command_context symbol
20
34
  def self.command_symbol
21
35
  transport_class_name.split(/(?=[A-Z])/).join("_").downcase.to_sym
22
36
  end
23
37
 
38
+ # The schema of the transport class
39
+ # @return [Hash<Symbol => SavonHelper::TypeMapping]
24
40
  def self.schema
25
- transport_class.mappings
41
+ transport_class.all_type_mappings
26
42
  end
27
43
 
44
+ # @!endgroup
45
+
46
+ # @param global_options [Hash] Global options passed to the `dsc` command_context.
47
+ # @option global_options [String] :manager The hostname of the DeepSecurity Manager.
48
+ # @option global_options [String] :port The TCP port to use.
49
+ # @option global_options [String, nil] :tenant The tenant name or nil.
50
+ # @option global_options [String] :username The username.
51
+ # @option global_options [String] :password The password.
52
+ # @option global_options [Boolean] :P Show progessbar?
53
+ # @option global_options [String, nil] :debug The debug level.
54
+ # @option global_options [String] :outfile The outfile.
28
55
  def initialize(global_options)
29
- @hostname = global_options[:m]
56
+ @hostname = global_options[:manager]
30
57
  @port = global_options[:port].to_i
31
- @tenant = global_options[:t]
32
- @username =global_options[:u]
33
- @password = global_options[:p]
58
+ @tenant = global_options[:tenant]
59
+ @username = global_options[:username]
60
+ @password = global_options[:password]
34
61
  @show_progress_bar = global_options[:P]
35
- @debug_level = debug_level_from_option(global_options[:d])
36
- @output = global_options[:o]
62
+ @debug_level = parse_debug_level(global_options[:debug])
63
+ @output = global_options[:outfile]
64
+ end
65
+
66
+ # @!group Helper methods
67
+
68
+ # Provide an open output while executing the block.
69
+ # @yieldparam output [IO] Opened IO
70
+ # @yield [output] Gives the output to the block
71
+ # @return [void]
72
+ def output
73
+ unless @output == '--'
74
+ output = File.open(option, 'w')
75
+ else
76
+ output = STDOUT
77
+ end
78
+ yield output
79
+ output.close() unless @output == '--'
80
+ end
81
+
82
+ # Provides a connection to the DeepSecurity Manager while executing the block.
83
+ # @yieldparam manager [DeepSecurity::Manager] DeepSecurity Manager
84
+ # @yield [manager] Gives the manager to the block
85
+ # @return [void]
86
+ def connect
87
+ manager = DeepSecurity::Manager.server(@hostname, @port, @debug_level)
88
+ yield manager
89
+ end
90
+
91
+ # Provides an authenticated connection to the DeepSecurity Manager while executing the block.
92
+ # @yieldparam manager [DeepSecurity::Manager] DeepSecurity Manager
93
+ # @yield [manager] Gives the manager to the block
94
+ # @return [void]
95
+ def authenticate
96
+ connect do |manager|
97
+ begin
98
+ manager.connect(@tenant, @username, @password)
99
+ yield manager
100
+ rescue DeepSecurity::AuthenticationFailedException => e
101
+ puts "Authentication failed! #{e.message}"
102
+ ensure
103
+ manager.disconnect()
104
+ end
105
+ end
106
+ end
107
+
108
+ def to_display_string(value)
109
+ return "" if value.blank?
110
+ return value.strftime($time_format) if (value.is_a?(DateTime) && !$time_format.nil?)
111
+ value.to_s
112
+ end
113
+
114
+ # @!endgroup
115
+
116
+ # @!group Misc global flags/options definitions
117
+
118
+ # Define flags
119
+ # @return [void]
120
+ def self.define_global_flags(command_context)
121
+ define_debug_flag(command_context)
122
+ define_manager_flag(command_context)
123
+ define_port_flag(command_context)
124
+ define_tenant_flag(command_context)
125
+ define_username_flag(command_context)
126
+ define_password_flag(command_context)
127
+ define_outfile_flag(command_context)
128
+ define_progress_bar_option(command_context)
37
129
  end
38
130
 
131
+ # Define manager hostname flag
132
+ # @param command_context [CLI::App] The current context of the command.
133
+ # @return [void]
134
+ def self.define_manager_flag(command_context)
135
+ command_context.flag [:m, :manager],
136
+ :desc => 'Deep Security Manager Host',
137
+ :arg_name => 'hostname'
138
+ end
139
+
140
+ # Define manager TCP Port flag
141
+ # @param command_context [CLI::App] The current context of the command.
142
+ # @return [void]
143
+ def self.define_port_flag(command_context)
144
+ command_context.flag [:port],
145
+ :desc => 'Webservice Port',
146
+ :arg_name => 'port',
147
+ :default_value => '4119'
148
+ end
149
+
150
+ # Define tenant flag
151
+ # @param command_context [CLI::App] The current context of the command.
152
+ # @return [void]
153
+ def self.define_tenant_flag(command_context)
154
+ command_context.flag [:t, :tenant],
155
+ :desc => 'Tenat Name',
156
+ :arg_name => 'tenat',
157
+ :default_value => ''
158
+ end
159
+
160
+ # Define username flag
161
+ # @param command_context [CLI::App] The current context of the command.
162
+ # @return [void]
163
+ def self.define_username_flag(command_context)
164
+ command_context.flag [:u, :username],
165
+ :desc => 'Username',
166
+ :arg_name => 'username',
167
+ :default_value => 'MasterAdmin'
168
+ end
169
+
170
+ # Define password flag
171
+ # @param command_context [CLI::App] The current context of the command.
172
+ # @return [void]
173
+ def self.define_password_flag(command_context)
174
+ command_context.flag [:p, :password],
175
+ :desc => 'Password',
176
+ :arg_name => 'password'
177
+ end
178
+
179
+ # Define outfile flag
180
+ # @param command_context [CLI::App] The current context of the command.
181
+ # @return [void]
182
+ def self.define_outfile_flag(command_context)
183
+ command_context.flag [:o, :outfile],
184
+ :desc => 'Output filename',
185
+ :default_value => '--'
186
+ end
187
+
188
+ # Define outfile flag
189
+ # @param command_context [CLI::App] The current context of the command.
190
+ # @return [void]
191
+ def self.define_outfile_flag(command_context)
192
+ command_context.flag [:o, :outfile],
193
+ :desc => 'Output filename',
194
+ :default_value => '--'
195
+ end
196
+
197
+ # Define progress_bar option
198
+ # @param command_context [CLI::App] The current context of the command.
199
+ # @return [void]
200
+ def self.define_progress_bar_option(command_context)
201
+ command_context.switch [:P, :'progress_bar'],
202
+ :desc => 'Show progressbar',
203
+ :default_value => false
204
+ end
205
+
206
+ # @!endgroup
207
+
208
+ # @!group Debug Level flag
209
+
210
+ # Valid debug levels
211
+ # @return [Array<String>] Valid debug levels
39
212
  def self.valid_debug_levels
40
213
  DeepSecurity::LOG_MAPPING.keys
41
214
  end
42
215
 
216
+ # String of debug levels for help string
217
+ # @return [String] String of debug levels for help string
43
218
  def self.valid_debug_levels_string
44
219
  valid_debug_levels.join(", ")
45
220
  end
46
221
 
222
+ # Parse debug level argument
223
+ # @return [nil, DeepSecurity::LOG_MAPPING] Return parsed debug level
224
+ def parse_debug_level(argument)
225
+ return nil if argument.blank?
226
+ return argument.to_sym if (DeepSecurity::LOG_MAPPING.keys.include?(argument.to_sym))
227
+ :debug
228
+ end
229
+
230
+ # Define debug level flag
231
+ # @return [void]
232
+ def self.define_debug_flag(command_context)
233
+ command_context.flag [:d, :debug],
234
+ :desc => "Enable client debug output. (One of #{Dsc::Command.valid_debug_levels_string})",
235
+ :arg_name => 'debug_level'
236
+ end
237
+
238
+ # @!endgroup
239
+
240
+ # @!group Fields flag
241
+
242
+ # Default fields if no argument is given
243
+ # @note Needs to be overridden by subclass
244
+ # @return [Array<String>] Default fields if no argument is given
47
245
  def self.default_fields
48
246
  []
49
247
  end
50
248
 
249
+ # String of default fields for help string
250
+ # @return [String] String of default fields for help string
51
251
  def self.default_fields_string
52
252
  default_fields.join(",")
53
253
  end
54
254
 
255
+ # Sorted list of available fields
256
+ # @return [Array<String>] Sorted list of available fields
55
257
  def self.valid_fields
56
258
  transport_class.defined_attributes.sort
57
259
  end
58
260
 
261
+ # String of available fields for help string
262
+ # @return [String] String of available fields for help string
59
263
  def self.valid_fields_string
60
264
  valid_fields.join(", ")
61
265
  end
62
266
 
63
- def parse_fields(string)
64
- fields = string.split(",").map(&:strip)
267
+ # Parse fields argument. Either split the string or read from file
268
+ # @return [Array<String>] parse fields
269
+ def parse_fields(fields_string_or_filename_argument)
270
+ filename = File.absolute_path(fields_string_or_filename_argument)
271
+ if File.exists?(filename)
272
+ fields_string = File.read(filename)
273
+ else
274
+ fields_string = fields_string_or_filename_argument
275
+ end
276
+ fields = fields_string.split(",").map(&:strip)
65
277
  unknown_fields = fields.reject { |each| self.class.transport_class.has_attribute_chain(each) }
66
- raise "Unknown field found (#{unknown_fields.join(', ')}) - known fields are: #{self.class.valid_fields.join(', ')}" unless unknown_fields.empty?
278
+ raise "Unknown filename or field found (#{unknown_fields.join(', ')}) - known fields are: #{self.class.valid_fields.join(', ')}" unless unknown_fields.empty?
67
279
  fields
68
280
  end
69
281
 
282
+ # Define fields flag
283
+ # @return [void]
284
+ def self.define_fields_flag(command_context)
285
+ command_context.flag [:fields],
286
+ :desc => "A comma separated list of fields to display or a file containing those fields. (Available fields: #{self.valid_fields_string})",
287
+ :default_value => self.default_fields_string
288
+ end
289
+
290
+ # @!endgroup
291
+
292
+ # @!group Time filter flag
293
+
294
+ # Valid timefilter mapping (symbol to instance)
295
+ # @return [Hash<Symbol => DeepSecurity::TimeFilter>] Valid timefilter mapping
70
296
  def self.valid_time_filters
71
297
  {
72
298
  :last_hour => DeepSecurity::TimeFilter.last_hour,
@@ -76,109 +302,199 @@ module Dsc
76
302
  }
77
303
  end
78
304
 
305
+ # Valid time filter string for help string
306
+ # @return[String] Valid time filters
79
307
  def self.valid_time_filters_string
80
308
  valid_time_filters.keys.join(', ')
81
309
  end
82
310
 
83
- def parse_time_filter(string)
84
- filter = self.class.valid_time_filters[string.to_sym]
311
+ # Parse time_filter argument
312
+ # @return [DeepSecurity::TimeFilter] Time filter
313
+ def parse_time_filter(argument)
314
+ filter = self.class.valid_time_filters[argument.to_sym]
85
315
  raise "Unknown time filter" if filter.nil?
86
316
  filter
87
317
  end
88
318
 
319
+ # Define time_filter flag
320
+ # @return [void]
321
+ def self.define_time_filter_flag(command_context)
322
+ command_context.flag [:time_filter],
323
+ :desc => "A filter specifying the time interval to query (One of #{self.valid_time_filters_string})",
324
+ :default_value => "last_day"
325
+ end
89
326
 
90
- def debug_level_from_option(option)
91
- return nil if option.blank?
92
- return option.to_sym if (DeepSecurity::LOG_MAPPING.keys.include?(option.to_sym))
93
- :debug
327
+ # @!endgroup
328
+
329
+ # @!group Detail level flag
330
+
331
+ # Valid detail levels
332
+ # @return [Array<String>] Valid detail levels
333
+ def self.valid_detail_levels
334
+ DeepSecurity::EnumHostDetailLevel.keys()
94
335
  end
95
336
 
96
- def output
97
- unless @output == '--'
98
- output = File.open(option, 'w')
99
- else
100
- output = STDOUT
101
- end
102
- yield output
103
- output.close() unless @output == '--'
337
+ # Valid detail levels for help string
338
+ # @return [String] Valid detail levels for help string
339
+ def self.valid_detail_levels_string
340
+ valid_detail_levels.map(&:downcase).join(", ")
104
341
  end
105
342
 
106
- def connect
107
- yield DeepSecurity::Manager.server(@hostname, @port, @debug_level)
343
+ # Parse detail_level argument
344
+ # @return [EnumHostDetailLevel] Detail level
345
+ def parse_detail_level(argument)
346
+ detail_level = DeepSecurity::EnumHostDetailLevel[argument.upcase.strip]
347
+ raise "Unknown detail level filter" if detail_level.nil?
348
+ detail_level
108
349
  end
109
350
 
110
- def authenticate
111
- connect do |dsm|
112
- begin
113
- dsm.connect(@tenant, @username, @password)
114
- yield dsm
115
- rescue DeepSecurity::AuthenticationFailedException => e
116
- puts "Authentication failed! #{e.message}"
117
- ensure
118
- dsm.disconnect()
119
- end
120
- end
351
+ # Define detail_level flag
352
+ # @return [void]
353
+ def self.define_detail_level_flag(command_context)
354
+ command_context.flag [:detail_level],
355
+ :desc => "A detail level specifiying the extent of data returned. (Available values: #{self.valid_detail_levels_string})",
356
+ :default_value => "low"
121
357
  end
122
358
 
359
+ # @!endgroup
123
360
 
124
- def print_api_version(options, args)
125
- output do |output|
126
- authenticate do |dsm|
127
- output.puts dsm.api_version()
361
+ # @!group Time format flag
362
+
363
+ # Parse detail_level argument
364
+ # @return [EnumHostDetailLevel] Detail level
365
+ def parse_time_format(argument)
366
+ $time_format = argument.nil? ? "" : argument
367
+ end
368
+
369
+ # Define detail_level flag
370
+ # @return [void]
371
+ def self.define_time_format_flag(command_context)
372
+ command_context.flag [:time_format],
373
+ :desc => "An strftime() compatible string to use for outputting date/time."
374
+ end
375
+
376
+ # @!endgroup
377
+
378
+ # @!group Command definitions
379
+
380
+ # @abstract Define all commands for this available for this (sub) command_context
381
+ # @param command_context [CLI::App] The current context of the command.
382
+ # @return [void]
383
+ def self.define_commands(command_context)
384
+ end
385
+
386
+ # Define some simple commands.
387
+ # @param command_context [CLI::App] The current context of the command.
388
+ # @return [void]
389
+ def self.define_misc_commands(command_context)
390
+ self.define_api_version_command(command_context)
391
+ self.define_manager_time_command(command_context)
392
+ end
393
+
394
+ # Define `api_version` command_context
395
+ # @param command_context [CLI::App] The current context of the command.
396
+ # @return [void]
397
+ def self.define_api_version_command(command_context)
398
+ command_context.desc 'Display API Version'
399
+ command_context.command :api_version do |api_version_command|
400
+ api_version_command.action do |global_options, options, args|
401
+ self.new(global_options).api_version_command(options, args)
128
402
  end
129
403
  end
130
404
  end
131
405
 
132
- def print_manager_time(options, args)
133
- output do |output|
134
- authenticate do |dsm|
135
- output.puts dsm.manager_time()
406
+ # Define `manager_time` command_context
407
+ # @param command_context [CLI::App] The current context of the command.
408
+ # @return [void]
409
+ def self.define_manager_time_command(command_context)
410
+ command_context.desc 'Display Manager time'
411
+ command_context.command :manager_time do |manager_time_command|
412
+ manager_time_command.action do |global_options, options, args|
413
+ self.new(global_options).manager_time_command(options, args)
136
414
  end
137
415
  end
138
416
  end
139
417
 
140
- def print_schema(options, args)
141
- output do |output|
142
- schema = self.class.schema()
143
- schema.keys.sort.each do |key|
144
- output.puts "#{key} (#{schema[key].type_string}): #{schema[key].description}"
418
+ # Define `list` command_context
419
+ # @param command_context [CLI::App] The current context of the command.
420
+ # @yieldparam list_command [GLI::Command] The just defined list command_context
421
+ # @yield [list_command] Gives the list command_context to the block
422
+ # @return [void]
423
+ def self.define_list_command(command_context)
424
+ command_context.desc "List #{self.transport_class_string}s"
425
+ command_context.command :list do |list_command|
426
+ define_fields_flag(list_command)
427
+ yield list_command if block_given?
428
+ list_command.action do |global_options, options, args|
429
+ self.new(global_options).list_command(options, args)
145
430
  end
146
431
  end
147
432
  end
148
433
 
149
- def self.define_list_command(command)
150
- command.desc "List #{self.transport_class_string}s"
151
- command.command :list do |list|
152
- define_fields_argument(list)
153
- yield list if block_given?
154
- list.action do |global_options, options, args|
155
- self.new(global_options).list(options, args)
434
+ # Define `schema` command_context
435
+ # @param command_context [CLI::App] The current context of the command.
436
+ # @yieldparam schema_command [GLI::Command] The just defined schema command_context
437
+ # @yield [schema_command] Gives the schema command_context to the block
438
+ # @return [void]
439
+ def self.define_schema_command(command_context)
440
+ command_context.desc "Show #{self.transport_class_string} schema"
441
+ command_context.command :schema do |schema_command|
442
+ yield schema_command if block_given?
443
+ schema_command.action do |global_options, options, args|
444
+ self.new(global_options).schema_command(options, args)
156
445
  end
157
446
  end
158
447
  end
159
448
 
160
- def self.define_schema_command(command)
161
- command.desc "Show #{self.transport_class_string} schema"
162
- command.command :schema do |schema|
163
- yield schema if block_given?
164
- schema.action do |global_options, options, args|
165
- self.new(global_options).print_schema(options, args)
449
+ # @!endgroup
450
+
451
+ # @!group Command Implementations
452
+
453
+ # `api_version` Implementation.
454
+ # Display the API version in use by the DeepSecurity Manager.
455
+ # @note Does not require authentication
456
+ # @param options [Hash<Symbol => Object>] Merged global/local options from GLI
457
+ # @param args [Array<String>] Arguments from GLI
458
+ # @return [void]
459
+ def api_version_command(options, args)
460
+ output do |output|
461
+ connect do |manager|
462
+ output.puts manager.api_version()
166
463
  end
167
464
  end
168
465
  end
169
466
 
170
- def self.define_time_filter_argument(command)
171
- command.desc "A filter specifying the time interval to query (One of #{self.valid_time_filters_string})"
172
- command.default_value "last_day"
173
- command.flag [:time_filter]
467
+ # `manager_time` Implementation.
468
+ # Display the local time of the DeepSecurity Manager.
469
+ # @note Does not require authentication
470
+ # @param options [Hash<Symbol => Object>] Merged global/local options from GLI
471
+ # @param args [Array<String>] Arguments from GLI
472
+ # @return [void]
473
+ def manager_time_command(options, args)
474
+ output do |output|
475
+ connect do |manager|
476
+ output.puts manager.manager_time()
477
+ end
478
+ end
174
479
  end
175
480
 
176
- def self.define_fields_argument(command)
177
- command.desc "A comma separated list of fields to display. (Available fields: #{self.valid_fields_string})"
178
- command.default_value self.default_fields_string
179
- command.flag [:fields]
481
+ # `schema` Implementation.
482
+ # Display schema of the current datatype (defined by `transport_class`).
483
+ # @note Does not require authentication
484
+ # @param options [Hash<Symbol => Object>] Merged global/local options from GLI
485
+ # @param args [Array<String>] Arguments from GLI
486
+ # @return [void]
487
+ def schema_command(options, args)
488
+ output do |output|
489
+ schema = self.class.schema()
490
+ schema.keys.sort.each do |key|
491
+ output.puts "#{key} (#{schema[key].type_string}): #{schema[key].description}"
492
+ end
493
+ end
180
494
  end
181
495
 
496
+ # @!endgroup
497
+
182
498
  end
183
499
 
184
500
  end