Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Henrik Lindberg updated an issue Puppet / PUP-7822 Add a get() function that supports dot syntax to "dig" into hash/array Change By: Henrik Lindberg Release Notes Summary: It is now possible to use the same "dot notation" to dig out a value from a structure like in hiera/lookup and elsewhere in puppet. To support this, the {{getvar()}} function has moved from stdlib to puppet, and we have added a new function {{get()}}. You can now for example use {{getvar('facts.os.family')}} starting with the variable name. The {{get}} function is the general function which takes a value and a dot-notation string. Release Notes: New Feature Add Comment This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Thomas Hallgren assigned an issue to Unassigned Puppet / PUP-7822 Add a get() function that supports dot syntax to "dig" into hash/array Change By: Thomas Hallgren Assignee: Thomas Hallgren Add Comment This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Thomas Hallgren commented on PUP-7822 Re: Add a get() function that supports dot syntax to "dig" into hash/array Merged to master at 7a5db8d. Add Comment This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Henrik Lindberg assigned an issue to Thomas Hallgren Puppet / PUP-7822 Add a get() function that supports dot syntax to "dig" into hash/array Change By: Henrik Lindberg Assignee: Thomas Hallgren Add Comment This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Henrik Lindberg commented on PUP-7822 Re: Add a get() function that supports dot syntax to "dig" into hash/array Agree - the get('$var...') is not needed. Will make those changes on the PR... (hold by beer...) Add Comment This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Reid Vandewiele commented on PUP-7822 Re: Add a get() function that supports dot syntax to "dig" into hash/array I agree that get() and getvar() would group nicely. I like getvar() better than var(). Is this what you're suggesting? $facts.get('os.family') get('$facts.os.family') getvar('facts.os.family') If we included getvar()... seems like we don't actually need the get('$facts.os.family') style, yes? These two would be enough: $facts.get('os.family') getvar('facts.os.family') One function for each use case / invocation. I would be fully to that. Add Comment
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Henrik Lindberg commented on PUP-7822 Re: Add a get() function that supports dot syntax to "dig" into hash/array Reid Vandewiele Note that you can write: '$facts.os.family'.get() Does change anything for you? If you want a separate function for variable access; there is already getvar() in stdlib. With that you could just do this: getvar('facts').get('os.family') (The getvar() function does not use a leading $ since it is not needed and an unnecessary potential gotcha when users have it in double quotes). What I like with a separate getvar() is that it is possible to handle that a variable does not exists differently from navigation not succeeding. I can imagine moving getvar() to puppet, and either just give it the ability to have a default value, or make it so it has the API of the get() with "$var" case (without a leading $). I am less keen on using the word var since we in the future may want to use that as a keyword to declare a local variable that can be reassigned. I also think that get() and getvar() would make them nicely grouped. Add Comment
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Reid Vandewiele commented on PUP-7822 Re: Add a get() function that supports dot syntax to "dig" into hash/array Henrik Lindberg For invocation #1, $facts.get('os.family'), I like it! For invocation #2, I like the $-prefixed string, e.g. '$facts.os.family'. I think that adds clarity to what's going on, and helps unify (as much as we can) the dot-notation with Puppet's existing variable syntax. If I got to choose, I'd make one last change, and then ship it. I want both of these functions. But seeing it all written out, the invocations are sufficiently different that for UX purposes, I think I'd prefer that they be different functions, rather than multiple invocations. PR as written $facts.get('os.family') $trusted.get('extensions.pp_role') get('$facts.os.family') get('$trusted.extensions.pp_role') Suggested separation into separate functions $facts.get('os.family') $trusted.get('extensions.pp_role') var('$facts.os.family')
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Henrik Lindberg commented on PUP-7822 Re: Add a get() function that supports dot syntax to "dig" into hash/array Reid Vandewiele - see if the PR I just put up suits your needs Add Comment This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Henrik Lindberg updated an issue Puppet / PUP-7822 Add a get() function that supports dot syntax to "dig" into hash/array Change By: Henrik Lindberg Fix Version/s: PUP 6.0.0 Add Comment This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Henrik Lindberg commented on PUP-7822 Re: Add a get() function that supports dot syntax to "dig" into hash/array The reason I am not keen on that solution is that get('varname') is a dynamic way to access a variable akin to Scope#get_var in Ruby. In Ruby that is needed since puppet variables simply has to be fetched using a method as they are not "ruby variables". Using indirection like that has been frowned upon in the past and thus the reason why the puppet language does not have a way to get a variable value given a string variable name. OTOH - we now have a call() function that can call a named function. This means you could write a function each for each variable you want to access (function only returns that variable) and then you select the function to call in place of directly selecting a variable name. Not saying that is a solution here, just pointing out that it is possible to do this now in puppet language alone in a very cumbersome way. (You could naturally write your own "getvar" in Ruby to return any variable). So, while I am not "keen", I am also not absolutely opposed to the idea. Here are some of the questions the idea raises: Would get('varname') behave the same as just $varname - i.e. it would error/warn if the variable does not exist as controlled by strict_variables setting? Or, should it behave more in the style of "dot-notation" and return undef if variable does not exist? (with or without warning, controlled by strict_variables or not?). Can it be used with fully qualified names like get('mymodule::mything::innerthing')? Does get('varname') work from topscope only - i.e. get('::varname') is implied? Or should it support resolution of variable name against local scope and users must use leading :: to indicate topscope to avoid picking variable in local scope? The rest of the "dot-notation" string is what it already is - nothing special there. Add Comment
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Reid Vandewiele commented on PUP-7822 Re: Add a get() function that supports dot syntax to "dig" into hash/array I'm not married to that idea specifically. I'd still like to find a way of supporting what users intuit should work based on their experiences elsewhere in the product. As an example, I was working with Andy Rajagopalan today on a project that required accessing structured facts and this is what he was intuitively trying to do ([source| https://github.com/raj-andy1/control-repo/commit/f89e925d7ee4b8cb65f99424d850b84de3666f11]): class araws::dnsprov { route53_a_record {"{$trusted.extensions.pp_hostname}.": ensure => present, The thing that springs out at me in this example is that we're training users in other areas of the product to use the top-level object/element as part of their dot-notation _expression_ about what variable they want. That is, trusted.subkey. The root goal of this ticket is to unify as much as we can how data is referenced in Puppet code, in the PE console, in PQL, and elsewhere. What I like about get() at this point is that it is used the same way for multiple root objects we care about, specifically $facts and $trusted. What I don't like about it is that in the invocation, it gets inserted into the middle of the "train of thought" people have about what data they're referencing. $trusted.get('extensions.pp_hostname'). I'm trying to see if there's a way to take this approach all the way to the end string people like Andy guess at, or intuit, might work. get('trusted.extensions.pp_hostname'). This isn't what Andy intuited, but it's closer. Professional services wants the string "facts" to be part of the call to bring more attention to the source of the information. All of the ideas solve for that. Is there a different function call or name that would make more sense when invoked stand-alone? e.g. get('trusted.extensions.pp_hostname') # meh scope('trusted.extensions.pp_hostname') # problem: conflicts with Ruby API function; is jargon-y
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Henrik Lindberg commented on PUP-7822 Re: Add a get() function that supports dot syntax to "dig" into hash/array I am not too keen on that last idea. Add Comment This message was sent by Atlassian JIRA (v7.5.1#75006-sha1:7df2574) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Reid Vandewiele commented on PUP-7822 Re: Add a get() function that supports dot syntax to "dig" into hash/array Working with a customer installation and Hiera this morning made me start thinking that it might be nice to provide a single-argument signature for the proposed function as well, such that it could be invoked the same way Hiera's subkey syntax works today. The whole objective after all is trying to unify the UX of this stuff. https://puppet.com/docs/puppet/4.9/hiera_subkey.html#keysubkey-syntax Assuming the same name "get", a single-argument signature taking no object, and only a string. E.g. dispatch :object_subkey do param 'Hash', :object param 'String[1]', :subkey end dispatch :key_subkey do param 'String[1]', :key_subkey end Invocations then might look like: $facts.get('osfamily') $trusted.get('extensions.pp_role')
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Henrik Lindberg assigned an issue to Unassigned Puppet / PUP-7822 Add a get() function that supports dot syntax to "dig" into hash/array Change By: Henrik Lindberg Assignee: Eric Sorenson Add Comment This message was sent by Atlassian JIRA (v7.0.2#70111-sha1:88534db) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Henrik Lindberg commented on PUP-7822 Re: Add a get() function that supports dot syntax to "dig" into hash/array In this ticket, or as a follow up ticket, it is also of value to add support for digging out a value from a pcore Object - a string segment is the name of an attribute. Add Comment This message was sent by Atlassian JIRA (v7.0.2#70111-sha1:88534db) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Henrik Lindberg commented on PUP-7822 Re: Add a get() function that supports dot syntax to "dig" into hash/array Ticket updated with a description for implementing get with support to provide default values, detection of undef vs. not found, and for custom error handling. Add Comment This message was sent by Atlassian JIRA (v7.0.2#70111-sha1:88534db) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Henrik Lindberg updated an issue Puppet / PUP-7822 Add a get() function that supports dot syntax to "dig" into hash/array Change By: Henrik Lindberg Supporting the dot-notation for digging into structured values (arrays and hashes) is of value. The current available function {{dig()}} does not parse the dot notation (it takes an array of segments) and it cannot be changed as that would break compatibility, and it also does not support a default value.A new function {{get()}} that also takes an optional lambda that gets called if the result would be undef. If the lambda takes no arguments it is simply called. If it accepts one argument, that is a {{Struct\[segments => Array\[String], values => Array]}}, thus making it possible to figure out how far the "dig" got before giving up, and to use that in a custom warning or error message (or simply logging it when debugging). (The value array ends with the undef value that caused the dig to give up). The lambda is not called if the final segment results in a nil value being found in a hash, but is called if the last segment did not exist.Examples:{code:puppet}$facts.get('some. fact ')$facts.get ( 'some.fact' ) || { 'go fish' } # 'go fish' is the default$fact.get('some.facts.detail.0.x') |$resolution| { $size = $resolution['values'].size() # std lib function for now since size is not in core notice(@("MESSAGE"))Could not lookup all given segments: ${resolution['segments']}Got an undef value for the key: ${resolution['segments'][$size-1]}Values per segment are: ${resolution['values']}|- MESSAGE}{code}When implementing this, it is of value to write a helper function {{parse_dig(String)}} that returns an array of segments from the dot-notation string. The {{get}} function uses that if it gets a string, if it gets an array it is taken as already parsed segments. The {{dig}} function should be given the lambda support to process the walked path. Thus:* Add a {{parse_dig(String)}} function* Add a lambda for processing default to {{dig}}* Add {{get(Variant\[Array, String])}}, calling {{parse_dig}} for a String arg, and then calling {{dig}} to do the digging.* Add a default value parameter to {{get}} which is mutually exclusive with giving a lambda - the default value is returned if value is undef (irrespective of reason) - if there is the need to differentiate between actual undef value, and not found, a lambda must be used. ORIGINAL-The fact() function provides a way to use the dot syntax for indexing into structured in the DSL. This was recently merged into stdlib(PR: https://github.com/puppetlabs/puppetlabs-stdlib/pull/787 Docs: https://github.com/puppetlabs/puppetlabs-stdlib#fact). Ideally this would be part of core puppet instead of the stdlib module given it's the syntax used in facter and heira for structured facts.
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Henrik Lindberg updated an issue Puppet / PUP-7822 Add a get() function that supports dot syntax to "dig" into hash/array Change By: Henrik Lindberg Acceptance Criteria: The fact A get () function or some other way of making that supports the dot - syntax available is in core puppet without needing for digging into a value and that optionally handles returning a default value if the stdlib module result would otherwise be undef . Add Comment This message was sent by Atlassian JIRA (v7.0.2#70111-sha1:88534db) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-7822) Add a get() function that supports dot syntax to "dig" into hash/array
Title: Message Title Henrik Lindberg updated an issue Puppet / PUP-7822 Add a get() function that supports dot syntax to "dig" into hash/array Change By: Henrik Lindberg Summary: Make the fact Add a get () function from stdlib part of core puppet so that the supports dot syntax is available in the DSL by default to "dig" into hash/array Add Comment This message was sent by Atlassian JIRA (v7.0.2#70111-sha1:88534db) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.