Class: Conjur::Policy::YAML::Handler
- Inherits:
-
Psych::Handler
- Object
- Psych::Handler
- Conjur::Policy::YAML::Handler
show all
- Includes:
- Logger
- Defined in:
- lib/conjur/policy/yaml/handler.rb
Defined Under Namespace
Classes: Base, MapEntry, Mapping, Root, Sequence
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Logger
included
Constructor Details
Returns a new instance of Handler.
308
309
310
311
312
313
|
# File 'lib/conjur/policy/yaml/handler.rb', line 308
def initialize
@root = Root.new self
@handlers = [ @root ]
@anchors = {}
@filename = "<no-filename>"
end
|
Instance Attribute Details
Returns the value of attribute filename.
7
8
9
|
# File 'lib/conjur/policy/yaml/handler.rb', line 7
def filename
@filename
end
|
Returns the value of attribute parser.
7
8
9
|
# File 'lib/conjur/policy/yaml/handler.rb', line 7
def parser
@parser
end
|
Returns the value of attribute result.
7
8
9
|
# File 'lib/conjur/policy/yaml/handler.rb', line 7
def result
@result
end
|
Instance Method Details
#alias(key) ⇒ Object
345
346
347
348
|
# File 'lib/conjur/policy/yaml/handler.rb', line 345
def alias key
log {"#{indent}anchor '#{key}'=#{anchor(key)}"}
handler.alias key
end
|
#anchor(*args) ⇒ Object
Get or set an anchor. Invoke with just the anchor name to get the value. Invoke with the anchor name and value to set the value.
327
328
329
330
331
332
333
334
335
336
337
338
339
|
# File 'lib/conjur/policy/yaml/handler.rb', line 327
def anchor *args
key, value, _ = args
if _
raise ArgumentError, "Expecting 1 or 2 arguments, got #{args.length}"
elsif key && value
raise "Duplicate anchor #{key}" if @anchors[key]
@anchors[key] = value
elsif key
@anchors[key]
else
nil
end
end
|
#end_mapping ⇒ Object
370
371
372
373
|
# File 'lib/conjur/policy/yaml/handler.rb', line 370
def end_mapping
log {"#{indent}end mapping"}
handler.end_mapping
end
|
#end_sequence ⇒ Object
365
366
367
368
|
# File 'lib/conjur/policy/yaml/handler.rb', line 365
def end_sequence
log {"#{indent}end sequence"}
handler.end_sequence
end
|
343
|
# File 'lib/conjur/policy/yaml/handler.rb', line 343
def handler; @handlers.last; end
|
389
390
391
|
# File 'lib/conjur/policy/yaml/handler.rb', line 389
def indent
" " * [ @handlers.length - 1, 0 ].max
end
|
#log(&block) ⇒ Object
383
384
385
386
387
|
# File 'lib/conjur/policy/yaml/handler.rb', line 383
def log &block
logger.debug('conjur/policy/handler') {
yield
}
end
|
#pop_handler ⇒ Object
320
321
322
323
|
# File 'lib/conjur/policy/yaml/handler.rb', line 320
def pop_handler
@handlers.pop
log {"#{indent}popped to handler #{handler.class}"}
end
|
#push_handler(handler) ⇒ Object
315
316
317
318
|
# File 'lib/conjur/policy/yaml/handler.rb', line 315
def push_handler handler
log {"#{indent}pushing handler #{handler.class}"}
@handlers.push handler
end
|
#scalar(*args) ⇒ Object
375
376
377
378
379
380
381
|
# File 'lib/conjur/policy/yaml/handler.rb', line 375
def scalar *args
value, anchor, tag, _, quoted = args
log {"#{indent}got scalar #{tag ? tag + '=' : ''}#{value}#{anchor ? '#' + anchor : ''}"}
value = handler.scalar value, tag, quoted
anchor anchor, value
end
|
#start_mapping(*args) ⇒ Object
350
351
352
353
354
355
356
|
# File 'lib/conjur/policy/yaml/handler.rb', line 350
def start_mapping *args
log {"#{indent}start mapping #{args}"}
anchor, tag, _ = args
tag = "!automatic-role" if %w(!managed-role !managed_role).include?(tag)
value = handler.start_mapping tag
anchor anchor, value
end
|
#start_sequence(*args) ⇒ Object
358
359
360
361
362
363
|
# File 'lib/conjur/policy/yaml/handler.rb', line 358
def start_sequence *args
log {"#{indent}start sequence : #{args}"}
anchor, _ = args
value = handler.start_sequence
anchor anchor, value
end
|