nicinfo 1.3.0.pre.alpha1 → 1.5.0

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.
@@ -0,0 +1,238 @@
1
+ ; all_parts strict_all.jcr
2
+ ;
3
+ ; Override rules for strict RDAP checking.
4
+ ;
5
+
6
+ ;
7
+ ; Object class response
8
+ ;
9
+
10
+ ; start_part strict_object_classes.jcr
11
+ @{root} $entity_response = {
12
+ $response_mixin,
13
+ $entity_mixin,
14
+ @{not} $error_mixin,
15
+ @{not} $search_results
16
+ }
17
+
18
+ @{root} $nameserver_response = {
19
+ $response_mixin,
20
+ $nameserver_mixin,
21
+ @{not} $error_mixin,
22
+ @{not} $search_results
23
+ }
24
+
25
+ @{root} $domain_response = {
26
+ $response_mixin,
27
+ $domain_mixin,
28
+ @{not} $error_mixin,
29
+ @{not} $search_results
30
+ }
31
+
32
+ @{root} $network_response = {
33
+ $response_mixin,
34
+ $network_mixin,
35
+ @{not} $error_mixin,
36
+ @{not} $search_results
37
+ }
38
+
39
+ @{root} $autnum_response = {
40
+ $response_mixin,
41
+ $autnum_mixin,
42
+ @{not} $error_mixin,
43
+ @{not} $search_results
44
+ }
45
+ ; end_part
46
+ ;
47
+ ; Help and error response
48
+ ;
49
+
50
+ ; start_part strict_help_and_error.jcr
51
+ @{root} $error_response = {
52
+ $response_mixin,
53
+ $error_mixin,
54
+ @{not} $object_class,
55
+ @{not} $search_results
56
+ }
57
+
58
+ @{root} $help_response = {
59
+ $response_mixin,
60
+ $lang ?,
61
+ @{not} $error_mixin,
62
+ @{not} $object_class,
63
+ @{not} $search_results
64
+ }
65
+ ; end_part
66
+ ;
67
+ ; Search responses
68
+ ;
69
+
70
+ ; start_part strict_search_responses.jcr
71
+ @{root} $domainSearch_response = {
72
+ $response_mixin,
73
+ $lang ?,
74
+ $domainSearchResult,
75
+ @{not} $error_mixin,
76
+ @{not} $object_class
77
+ }
78
+
79
+ @{root} $nameserverSearch_response = {
80
+ $response_mixin,
81
+ $lang ?,
82
+ $nameserverSearchResult,
83
+ @{not} $error_mixin,
84
+ @{not} $object_class
85
+ }
86
+
87
+ @{root} $entitySearch_response = {
88
+ $response_mixin,
89
+ $lang ?,
90
+ $entitySearchResult,
91
+ @{not} $error_mixin,
92
+ @{not} $object_class
93
+ }
94
+ ; end_part
95
+ ;
96
+ ; Object class mixins
97
+ ;
98
+
99
+ ; start_part strict_object_class_mixins.jcr
100
+ $object_class = (
101
+ $entity_mixin |
102
+ $nameserver_mixin |
103
+ $domain_mixin |
104
+ $network_mixin |
105
+ $autnum_mixin
106
+ )
107
+ ; end_part
108
+ ;
109
+ ; All search results
110
+ ;
111
+
112
+ ; start_part strict_searches.jcr
113
+ $search_results = (
114
+ $domainSearchResult |
115
+ $nameserverSearchResult |
116
+ $entitySearchResult
117
+ )
118
+ ; end_part
119
+ ;
120
+ ; IANA Status Values
121
+ ;
122
+
123
+ ; start_part strict_iana_status_values.jcr
124
+ $status = "status" : [ $status_values * ]
125
+
126
+ $status_values = (
127
+ "validated" |
128
+ "renew prohibited" |
129
+ "update prohibited" |
130
+ "transfer prohibited" |
131
+ "delete prohibited" |
132
+ "proxy" |
133
+ "private" |
134
+ "removed" |
135
+ "obscured" |
136
+ "associated" |
137
+ "active" |
138
+ "inactive" |
139
+ "locked" |
140
+ "pending create" |
141
+ "pending renew" |
142
+ "pending transfer" |
143
+ "pending update" |
144
+ "pending delete" |
145
+ "add period" |
146
+ "auto renew period" |
147
+ "client delete prohibited" |
148
+ "client hold" |
149
+ "client renew prohibited" |
150
+ "client transfer prohibited" |
151
+ "client update prohibited" |
152
+ "pending restore" |
153
+ "redemption period" |
154
+ "renew period" |
155
+ "server delete prohibited" |
156
+ "server renew prohibited" |
157
+ "server transfer prohibited" |
158
+ "server update prohibited" |
159
+ "server hold" |
160
+ "transfer period"
161
+ )
162
+ ; end_part
163
+ ;
164
+ ; IANA Notice and Remark Types
165
+ ;
166
+
167
+ ; start_part strict_iana_notice_remark_types.jcr
168
+ $noticeRemarkType = "type" : $noticeRemarkType_values
169
+
170
+ $noticeRemarkType_values = (
171
+ "result set truncated due to authorization" |
172
+ "result set truncated due to excessive load" |
173
+ "result set truncated due to unexplainable reasons" |
174
+ "object truncated due to authorization" |
175
+ "object truncated due to excessive load" |
176
+ "object truncated due to unexplainable reasons"
177
+ )
178
+ ; end_part
179
+ ;
180
+ ; IANA Roles
181
+ ;
182
+
183
+ ; start_part strict_iana_roles.jcr
184
+ $roles = "roles" : [ $role_values * ]
185
+
186
+ $role_values = (
187
+ "registrant" |
188
+ "technical" |
189
+ "administrative" |
190
+ "abuse" |
191
+ "billing" |
192
+ "registrar" |
193
+ "reseller" |
194
+ "sponsor" |
195
+ "proxy" |
196
+ "notifications" |
197
+ "noc"
198
+ )
199
+
200
+ ; end_part
201
+ ;
202
+ ; IANA Domain Variant Relations
203
+ ;
204
+
205
+ ; start_part strict_iana_domain_variant_relations.jcr
206
+ $variantRelation = "relation" : [ $variantRelation_values * ]
207
+
208
+ $variantRelation_values = (
209
+ "registered" |
210
+ "unregistered" |
211
+ "registration restricted" |
212
+ "open registration" |
213
+ "conjoined"
214
+ )
215
+ ; end_part
216
+ ;
217
+ ; IANA Event Actions
218
+ ;
219
+
220
+ ; start_part strict_iana_event_actions.jcr
221
+ $eventAction = "eventAction" : $eventAction_values
222
+
223
+ $eventAction_values = (
224
+ "registration" |
225
+ "reregistration" |
226
+ "last changed" |
227
+ "expiration" |
228
+ "deletion" |
229
+ "reinstantiation" |
230
+ "transfer" |
231
+ "locked" |
232
+ "unlocked" |
233
+ "last update of RDAP database" |
234
+ "registrar expiration" |
235
+ "enum validation expiration"
236
+ )
237
+ ; end_part
238
+
@@ -15,6 +15,7 @@
15
15
  # The run_pager code came from http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby
16
16
  # and is credited to Nathan Weizenbaum
17
17
 
18
+ require 'rainbow'
18
19
  require 'nicinfo/enum'
19
20
 
20
21
  module NicInfo
@@ -47,18 +48,44 @@ module NicInfo
47
48
 
48
49
  end
49
50
 
51
+ class AttentionType < NicInfo::Enum
52
+
53
+ AttentionType.add_item(:SUCCESS, "SUCCESS" )
54
+ AttentionType.add_item(:INFO, "INFO" )
55
+ AttentionType.add_item(:PRIMARY, "PRIMARY" )
56
+ AttentionType.add_item(:SECONDARY, "SECONDARY" )
57
+ AttentionType.add_item(:ERROR, "ERROR" )
58
+
59
+ end
60
+
61
+ class ColorScheme < NicInfo::Enum
62
+
63
+ # dark background
64
+ ColorScheme.add_item(:DARK, "DARK")
65
+
66
+ # light background
67
+ ColorScheme.add_item(:LIGHT, "LIGHT")
68
+
69
+ # none
70
+ ColorScheme.add_item(:NONE, "NONE")
71
+
72
+ end
73
+
50
74
  # A logger for this application.
51
75
  class Logger
52
76
 
53
77
  attr_accessor :message_level, :data_amount, :message_out, :data_out, :item_name_length, :item_name_rjust, :pager
54
78
  attr_accessor :auto_wrap, :detect_width, :default_width, :prose_name_rjust, :prose_name_length
79
+ attr_accessor :is_less_available, :color_scheme, :rainbow
55
80
 
56
81
  def initialize
57
82
 
58
83
  @message_level = MessageLevel::SOME_MESSAGES
59
84
  @data_amount = DataAmount::NORMAL_DATA
85
+ @color_scheme = ColorScheme::DARK
60
86
  @message_out = $stdout
61
87
  @data_out = $stdout
88
+ @rainbow = Rainbow.new
62
89
  @item_name_length = 25
63
90
  @item_name_rjust = true
64
91
  @prose_name_length = 10
@@ -67,7 +94,7 @@ module NicInfo
67
94
  @message_last_written_to = false
68
95
  @data_last_written_to = false
69
96
 
70
- return if RUBY_PLATFORM =~ /win32/
97
+ return if Gem.win_platform?
71
98
  #else
72
99
  @columns = get_terminal_columns( `stty -a`, @default_width )
73
100
  end
@@ -80,12 +107,17 @@ module NicInfo
80
107
 
81
108
  def validate_message_level
82
109
  raise ArgumentError, "Message log level not defined" if @message_level == nil
83
- raise ArgumentError, "Unknown message log level '" + @message_level.to_s + "'" if !MessageLevel.has_value?(@message_level.to_s)
110
+ raise ArgumentError, "Unknown message log level '" + @message_level.to_s + "'" unless MessageLevel.has_value?(@message_level.to_s)
84
111
  end
85
112
 
86
113
  def validate_data_amount
87
114
  raise ArgumentError, "Data log level not defined" if @data_amount == nil
88
- raise ArgumentError, "Unknown data log level '" + @data_amount.to_s + "'" if !DataAmount.has_value?(@data_amount.to_s)
115
+ raise ArgumentError, "Unknown data log level '" + @data_amount.to_s + "'" unless DataAmount.has_value?(@data_amount.to_s)
116
+ end
117
+
118
+ def validate_color_scheme
119
+ raise ArgumentError, "Color scheme not defined" if @color_scheme == nil
120
+ raise ArgumentError, "Unknown color scheme '" + @color_scheme.to_s + "'" unless ColorScheme.has_value?(@color_scheme.to_s)
89
121
  end
90
122
 
91
123
  def start_data_item
@@ -107,147 +139,167 @@ module NicInfo
107
139
  end
108
140
 
109
141
  # Outputs at the :SOME_MESSAGES level
110
- def mesg message
142
+ def mesg message, attention_type = nil
111
143
  validate_message_level()
112
144
  if (@message_level != MessageLevel::NO_MESSAGES)
113
- log_info("# " + message.to_s)
145
+ log_info("# " + message.to_s, attention_type )
114
146
  return true
115
147
  end
116
148
  return false
117
149
  end
118
150
 
119
151
  # Outputs at the :ALL_MESSAGES level
120
- def trace message
152
+ def trace message, attention_type = nil
121
153
  validate_message_level()
122
154
  if (@message_level != MessageLevel::NO_MESSAGES && @message_level != MessageLevel::SOME_MESSAGES)
123
- log_info("## " + message.to_s)
155
+ log_info("## " + message.to_s, attention_type )
124
156
  return true
125
157
  end
126
158
  return false
127
159
  end
128
160
 
129
161
  # Outputs a datum at :TERSE_DATA level
130
- def terse item_name, item_value
162
+ def terse item_name, item_value, attention_type = nil
131
163
  validate_data_amount()
132
- log_data(item_name, item_value)
164
+ log_data(item_name, item_value, attention_type )
133
165
  return true
134
166
  end
135
167
 
136
168
  # Outputs a data at :NORMAL_DATA level
137
- def datum item_name, item_value
169
+ def datum item_name, item_value, attention_type = nil
138
170
  validate_data_amount()
139
171
  if (@data_amount != DataAmount::TERSE_DATA)
140
- log_data(item_name, item_value)
172
+ log_data(item_name, item_value, attention_type )
141
173
  return true
142
174
  end
143
175
  return false
144
176
  end
145
177
 
146
- def extra item_name, item_value
178
+ def extra item_name, item_value, attention_type = nil
147
179
  validate_data_amount()
148
180
  if (@data_amount != DataAmount::TERSE_DATA && @data_amount != DataAmount::NORMAL_DATA)
149
- log_data(item_name, item_value)
181
+ log_data(item_name, item_value, attention_type )
150
182
  return true
151
183
  end
152
184
  return false
153
185
  end
154
186
 
155
- def data_title title
187
+ def data_title title, attention_type = nil
156
188
  validate_data_amount()
157
- log_just title, " ", @item_name_length, @item_name_rjust, ""
189
+ log_just title, " ", @item_name_length, @item_name_rjust, "", attention_type
158
190
  return true
159
191
  end
160
192
 
161
- def info data_amount, item_name, item_value
193
+ def info data_amount, item_name, item_value, attention_type = nil
162
194
  retval = false
163
195
  validate_data_amount()
164
196
  case data_amount
165
197
  when DataAmount::TERSE_DATA
166
- log_data(item_name, item_value)
198
+ log_data(item_name, item_value, attention_type )
167
199
  retval = true
168
200
  when DataAmount::NORMAL_DATA
169
201
  if (@data_amount != DataAmount::TERSE_DATA)
170
- log_data( item_name, item_value)
202
+ log_data( item_name, item_value, attention_type )
171
203
  retval = true
172
204
  end
173
205
  when DataAmount::EXTRA_DATA
174
206
  if (@data_amount != DataAmount::TERSE_DATA && @data_amount != DataAmount::NORMAL_DATA)
175
- log_data( item_name, item_value )
207
+ log_data( item_name, item_value, attention_type )
176
208
  retval = true
177
209
  end
178
210
  end
179
211
  return retval
180
212
  end
181
213
 
182
- def raw data_amount, raw_data, wrap = true
214
+ def raw data_amount, raw_data, wrap = true, attention_type = nil
183
215
  retval = false
184
216
  validate_data_amount()
185
217
  case data_amount
186
218
  when DataAmount::TERSE_DATA
187
- log_raw(raw_data, wrap)
219
+ log_raw(raw_data, wrap, attention_type )
188
220
  retval = true
189
221
  when DataAmount::NORMAL_DATA
190
222
  if (@data_amount != DataAmount::TERSE_DATA)
191
- log_raw(raw_data, wrap)
223
+ log_raw(raw_data, wrap, attention_type )
192
224
  retval = true
193
225
  end
194
226
  when DataAmount::EXTRA_DATA
195
227
  if (@data_amount != DataAmount::TERSE_DATA && @data_amount != DataAmount::NORMAL_DATA)
196
- log_raw(raw_data, wrap)
228
+ log_raw(raw_data, wrap, attention_type )
197
229
  retval = true
198
230
  end
199
231
  end
200
232
  return retval
201
233
  end
202
234
 
203
- def prose data_amount, prose_name, prose_value
235
+ def prose data_amount, prose_name, prose_value, attention_type = nil
204
236
  retval = false
205
237
  validate_data_amount()
206
238
  case data_amount
207
239
  when DataAmount::TERSE_DATA
208
- log_prose prose_name, prose_value
240
+ log_prose prose_name, prose_value, attention_type
209
241
  retval = true
210
242
  when DataAmount::NORMAL_DATA
211
243
  if (@data_amount != DataAmount::TERSE_DATA)
212
- log_prose prose_name, prose_value
244
+ log_prose prose_name, prose_value, attention_type
213
245
  retval = true
214
246
  end
215
247
  when DataAmount::EXTRA_DATA
216
248
  if (@data_amount != DataAmount::TERSE_DATA && @data_amount != DataAmount::NORMAL_DATA)
217
- log_prose prose_name, prose_value
249
+ log_prose prose_name, prose_value, attention_type
218
250
  retval = true
219
251
  end
220
252
  end
221
253
  return retval
222
254
  end
223
255
 
224
- def log_tree_item data_amount, tree_item
256
+ def log_tree_item data_amount, tree_item, attention_type = nil
225
257
  retval = false
226
258
  validate_data_amount()
227
259
  case data_amount
228
260
  when DataAmount::TERSE_DATA
229
- log_raw(tree_item, true)
261
+ log_raw(tree_item, true, attention_type )
230
262
  retval = true
231
263
  when DataAmount::NORMAL_DATA
232
264
  if (@data_amount != DataAmount::TERSE_DATA)
233
- log_raw(tree_item, true)
265
+ log_raw(tree_item, true, attention_type )
234
266
  retval = true
235
267
  end
236
268
  when DataAmount::EXTRA_DATA
237
269
  if (@data_amount != DataAmount::TERSE_DATA && @data_amount != DataAmount::NORMAL_DATA)
238
- log_raw(tree_item, true)
270
+ log_raw(tree_item, true, attention_type )
239
271
  retval = true
240
272
  end
241
273
  end
242
274
  return retval
243
275
  end
244
276
 
277
+ def is_less_available?
278
+ if @is_less_available == nil
279
+ avail = ENV['PATH'].split(File::PATH_SEPARATOR).any? do |dir|
280
+ File.executable?(File.join(dir, "less"))
281
+ end
282
+ if avail
283
+ @is_less_available = "less"
284
+ else
285
+ @is_less_available = false
286
+ end
287
+ end
288
+ return @is_less_available
289
+ end
290
+
291
+ def get_pager
292
+ ENV['PAGER'] || is_less_available? || 'more'
293
+ end
294
+
245
295
  # This code came from http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby
246
296
  def run_pager
247
297
  return unless @pager
248
- return if RUBY_PLATFORM =~ /win32/
298
+ return if Gem.win_platform?
249
299
  return unless STDOUT.tty?
250
300
 
301
+ @color_scheme = ColorScheme::NONE unless get_pager == "less"
302
+
251
303
  read, write = IO.pipe
252
304
 
253
305
  unless Kernel.fork # Child process
@@ -266,7 +318,7 @@ module NicInfo
266
318
  ENV['LESS'] = 'FSRX' # Don't page if the input is short enough
267
319
 
268
320
  Kernel.select [STDIN] # Wait until we have input before we start the pager
269
- pager = ENV['PAGER'] || 'more'
321
+ pager = get_pager
270
322
  exec pager rescue exec "/bin/sh", "-c", pager
271
323
  end
272
324
 
@@ -310,24 +362,24 @@ module NicInfo
310
362
 
311
363
  private
312
364
 
313
- def log_info message
365
+ def log_info message, attention_type
314
366
  if @data_last_written_to && @message_out == @data_out
315
367
  @data_out.puts
316
368
  end
317
- @message_out.puts(message)
369
+ puts_color( @message_out, message, attention_type)
318
370
  @message_last_written_to = true
319
371
  @data_last_written_to = false
320
372
  end
321
373
 
322
- def log_data item_name, item_value
323
- log_just item_name, item_value, @item_name_length, @item_name_rjust, ": "
374
+ def log_data item_name, item_value, attention_type
375
+ log_just item_name, item_value, @item_name_length, @item_name_rjust, ": ", attention_type
324
376
  end
325
377
 
326
- def log_prose item_name, item_value
327
- log_just item_name, item_value, @prose_name_length, @prose_name_rjust, " "
378
+ def log_prose item_name, item_value, attention_type
379
+ log_just item_name, item_value, @prose_name_length, @prose_name_rjust, " ", attention_type
328
380
  end
329
381
 
330
- def log_just item_name, item_value, name_length, name_rjust, separator
382
+ def log_just item_name, item_value, name_length, name_rjust, separator, attention_type
331
383
  if (item_value != nil && !item_value.to_s.empty?)
332
384
  format_string = "%" + name_length.to_s + "s%s%s"
333
385
  if (!name_rjust)
@@ -338,33 +390,80 @@ module NicInfo
338
390
  i = 0
339
391
  lines.each do |line|
340
392
  if i == 0
341
- @data_out.puts(format(format_string, item_name, separator, line))
393
+ puts_color( @data_out, format(format_string, item_name, separator, line), attention_type )
342
394
  else
343
- @data_out.puts(format(format_string, " ", separator, line))
395
+ puts_color( @data_out, format(format_string, " ", separator, line), attention_type )
344
396
  end
345
397
  i = i + 1
346
398
  end
347
399
  else
348
- @data_out.puts(format(format_string, item_name, separator, item_value))
400
+ puts_color( @data_out, format(format_string, item_name, separator, item_value), attention_type )
349
401
  end
350
402
  @data_last_written_to = true
351
403
  @message_last_written_to = false
352
404
  end
353
405
  end
354
406
 
355
- def log_raw item_value, wrap
407
+ def log_raw item_value, wrap, attention_type
356
408
  if @auto_wrap and wrap
357
409
  lines = break_up_line item_value, get_width
358
410
  lines.each do |line|
359
- @data_out.puts(line)
411
+ puts_color( @data_out, line, attention_type )
360
412
  end
361
413
  else
362
- @data_out.puts(item_value)
414
+ puts_color( @data_out, item_value, attention_type )
363
415
  end
364
416
  @data_last_written_to = true
365
417
  @message_last_written_to = false
366
418
  end
367
419
 
420
+ def puts_color out, string, attention_type
421
+ if !attention_type || @color_scheme == ColorScheme::NONE || attention_type == AttentionType::PRIMARY
422
+ out.puts string
423
+ else
424
+ case attention_type
425
+ when AttentionType::SUCCESS
426
+ case @color_scheme
427
+ when ColorScheme::DARK
428
+ out.puts @rainbow.wrap(string).aqua
429
+ when ColorScheme::LIGHT
430
+ out.puts @rainbow.wrap(string).blue
431
+ else
432
+ out.puts string
433
+ end
434
+ when AttentionType::SECONDARY
435
+ case @color_scheme
436
+ when ColorScheme::DARK
437
+ out.puts @rainbow.wrap(string).green
438
+ when ColorScheme::LIGHT
439
+ out.puts @rainbow.wrap(string).green
440
+ else
441
+ out.puts string
442
+ end
443
+ when AttentionType::INFO
444
+ case @color_scheme
445
+ when ColorScheme::DARK
446
+ out.puts @rainbow.wrap(string).yellow.bright
447
+ when ColorScheme::LIGHT
448
+ out.puts @rainbow.wrap(string).blue.bright
449
+ else
450
+ out.puts string
451
+ end
452
+ when AttentionType::ERROR
453
+ case @color_scheme
454
+ when ColorScheme::DARK
455
+ out.puts @rainbow.wrap(string).red.bright
456
+ when ColorScheme::LIGHT
457
+ out.puts @rainbow.wrap(string).red
458
+ else
459
+ out.puts string
460
+ end
461
+ else
462
+ out.puts string
463
+ end
464
+ end
465
+ end
466
+
368
467
  end
369
468
 
370
469
  end