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.
305
306
307
308
309
310
|
# File 'lib/conjur/policy/yaml/handler.rb', line 305
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
344
345
346
347
348
|
# File 'lib/conjur/policy/yaml/handler.rb', line 344
def alias key
log {"#{indent}WARNING: anchor '#{key}' is not defined"} unless anchor(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.
328
329
330
331
332
333
334
335
336
337
338
339
340
|
# File 'lib/conjur/policy/yaml/handler.rb', line 328
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
368
369
370
371
|
# File 'lib/conjur/policy/yaml/handler.rb', line 368
def end_mapping
log {"#{indent}end mapping"}
handler.end_mapping
end
|
#end_sequence ⇒ Object
363
364
365
366
|
# File 'lib/conjur/policy/yaml/handler.rb', line 363
def end_sequence
log {"#{indent}end sequence"}
handler.end_sequence
end
|
342
|
# File 'lib/conjur/policy/yaml/handler.rb', line 342
def handler; @handlers.last; end
|
386
387
388
|
# File 'lib/conjur/policy/yaml/handler.rb', line 386
def indent
" " * [ @handlers.length - 1, 0 ].max
end
|
#log(&block) ⇒ Object
380
381
382
383
384
|
# File 'lib/conjur/policy/yaml/handler.rb', line 380
def log &block
logger.debug('conjur/policy/handler') {
yield
}
end
|
#pop_handler ⇒ Object
321
322
323
324
|
# File 'lib/conjur/policy/yaml/handler.rb', line 321
def pop_handler
@handlers.pop
log {"#{indent}popped to handler #{handler.class}"}
end
|
#push_handler(handler) ⇒ Object
316
317
318
319
|
# File 'lib/conjur/policy/yaml/handler.rb', line 316
def push_handler handler
@handlers.push handler
log {"#{indent}pushed handler #{handler.class}"}
end
|
#scalar(*args) ⇒ Object
373
374
375
376
377
378
|
# File 'lib/conjur/policy/yaml/handler.rb', line 373
def scalar *args
value, anchor, tag, _, quoted = args
log {"#{indent}got scalar #{tag ? tag + '=' : ''}#{value}#{anchor ? '#' + anchor : ''}"}
handler.scalar value, tag, quoted, anchor
end
|
#start_mapping(*args) ⇒ Object
350
351
352
353
354
355
|
# 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)
handler.start_mapping tag, anchor
end
|
#start_sequence(*args) ⇒ Object
357
358
359
360
361
|
# File 'lib/conjur/policy/yaml/handler.rb', line 357
def start_sequence *args
log {"#{indent}start sequence : #{args}"}
anchor, _ = args
handler.start_sequence anchor
end
|