expression type | example output |
---|---|
literal undef | nil |
literal default | "default" |
literal integer | 1 |
literal float | 3.14 |
literal false | false |
literal true | true |
literal string | "hello" |
literal regexp | "/this|that.*/" |
string with single quote | "ta'phoenix" |
string with double quote | "he said \"hi\"" |
user defined Object | "Car({'regnbr' => 'abc123'})" |
deferred | "Deferred({'name' => 'func', 'arguments' => [1, 2, 3]})" |
sensitive | "#<Sensitive [value redacted]:70229233735920>" |
Timestamp 'now' | "2018-09-01T15:56:53.993630000 UTC" |
array | [1, 2, 3] |
array with sensitive | ["#<Sensitive [value redacted]:70229233766180>"] |
hash with sensitive | {"x"=>"#<Sensitive [value redacted]:70229233764800>"} |
hash | {"a"=>10, "b"=>20} |
hash non Data key | {"[\"funky\", \"key\"]"=>10} |
hash Sensitive key | {"#<Sensitive [value redacted]:70229233763220>"=>42} |
hash __ptype key | {"__ptype"=>10} |
binary | "aGVsbG8=" |
ascii-8bit string | "AgMEaGVsbG8=" |
runtime 'alien' object | "#Alien:0x007fbf0534a7f8" |
runtime symbol | "symbolic" |
runtime 'alien' fact | "#Alien:0x007fbf0534a7f8" |
a type | "Integer[0, 100]" |
a user defined type | "Car" |
a self referencing type | "Tree = Array[Variant[String, Tree]]" |
Stringified output
require 'puppet_pal' | |
Puppet.initialize_settings | |
binary_string = "\x02\x03\x04hello".force_encoding('ascii-8bit') | |
class Alien | |
end | |
alien_fact = Alien.new | |
vars = { | |
'binary_val' => binary_string, | |
'alien_val' => [] | |
} | |
facts = { | |
'alien_fact' => alien_fact | |
} | |
result = Puppet::Pal.in_tmp_environment('pal_env', modulepath: [], facts: facts, variables: vars) do |pal| | |
pal.with_catalog_compiler {|c| | |
vars['alien_val'][0] = alien_fact # punch a runtime value into the mutable array | |
vars['alien_val'][1] = :symbolic # punch a symbol value | |
source = <<-'SOURCE' | |
type Car = Object[attributes => {regnbr => String}]; | |
type Tree = Array[Variant[String, Tree]] | |
$x = { | |
"literal undef" => undef, | |
"literal default" => default, | |
"literal integer" => 1, | |
"literal float" => 3.14, | |
"literal false" => false, | |
"literal true" => true, | |
"literal string" => "hello", | |
"literal regexp" => /this|that.*/, | |
"string with single quote" => "ta'phoenix", | |
"string with double quote" => "he said \"hi\"", | |
"user defined Object" => Car(abc123), | |
"deferred" => Deferred(func,[1,2,3]), | |
"sensitive" => Sensitive(hush), | |
"Timestamp 'now'" => Timestamp(), | |
"array" => [1,2,3], | |
"array with sensitive" => [Sensitive(hush)], | |
"hash with sensitive" => {x => Sensitive(hush)}, | |
"hash" => { a=> 10, b=> 20}, | |
"hash non Data key" => {[funky, key] => 10}, | |
"hash Sensitive key" => {Sensitive(hush) => 42 }, | |
"hash __ptype key" => {__ptype => 10}, | |
"binary" => Binary("hello", "%s"), | |
"ascii-8bit string" => $binary_val, | |
"runtime 'alien' object" => $alien_val[0], | |
"runtime symbol" => $alien_val[1], | |
"runtime 'alien' fact" => $facts['alien_fact'], | |
"a type" => Integer[0,100], | |
"a user defined type" => Car, | |
"a self referencing type" => Tree, | |
} | |
$x | |
SOURCE | |
require 'byebug'; debugger | |
val = c.evaluate_string(source) | |
Puppet::Pops::Serialization::ToStringifiedConverter.convert(val, | |
:message_prefix => "The data given to sconv.rb" | |
) | |
} | |
end | |
puts "| expression type | example output |" | |
puts "| --- | --- |" | |
result.each_pair do |k,v| | |
puts "| #{k} | #{v.inspect} |" | |
end |
This comment has been minimized.
This comment has been minimized.
"funky hash" could also be shown as |
This comment has been minimized.
This comment has been minimized.
ascii-8bit changed to output base64 (actually all non UTF-8) |
This comment has been minimized.
This comment has been minimized.
Gist is updated with more variants. Some notable changes:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
The "funky key" needs work - right now it turns the funky key into a string. It could use the alternative form
"Hash([["funky key"], 10])"