Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] (PUP-11981) Syntactically incorrect types cause nil types in Puppet::InfoService::ClassInformationService #9215

Merged
merged 1 commit into from
Jan 22, 2024

Conversation

AriaXLi
Copy link
Contributor

@AriaXLi AriaXLi commented Jan 22, 2024

Backport of #9190 and #9210 to 7.x

@AriaXLi AriaXLi requested a review from a team as a code owner January 22, 2024 19:56
@mhashizume mhashizume added the bug Something isn't working label Jan 22, 2024
This commit adds logic to validate class parameters are literal and provides a
descriptive warning if parameter(s) are not literal, adds QualifiedReference
and AccessExpression as a valid literal values & updates spec tests to check
for more cases of invalid class parameters and any that broke as a result of
the changes.

The logic to validate class parameters is done in
internal_check_parameter_type_literal method where the appropriate literal
method is called on each parameter. There are different literal methods for
each literal object/type [1]. For example if the parameter is String type, then
literal_LiteralString is called. If a parameter is found to be not literal,
then a :not_literal will be thrown & warning message with the invalid class
parameter and its type will be printed.

QualifiedReference is considered literal since it is a literal reference,
however, there is a possibility it could be a faulty dangling reference that
doesn't reference anything. AccessExpresions are anything with the Access
Operator ([ ]) such as Optional[String] or Variant[Boolean, Float] [2]. Since
these are valid class parameters, AccessExpressions are also considered
literal.

The logic to add QualifiedReference & AccessExpression as valid
literal values is done in the literal_QualifiedReference &
literal_AccessExpression methods. The literal_AccessExpression works by
validating each key in the expression is literal. The
literal_QualifiedReference method looks at o.value, similar to other existing
literal methods like literal_LiteralString.

[1] http://puppet-on-the-edge.blogspot.com/2014/02/puppet-internals-polymorphic-dispatch.html
[2] https://github.com/puppetlabs/puppet-specifications/blob/master/language/expressions.md#assignment-operator

For more information on this issue, see puppetlabs#9140

(cherry picked from commit adbb02c)

(PUP-11981) Add test for non-literal class params in ClassInfoService spec

(cherry picked from commit 8992763)
@AriaXLi AriaXLi merged commit a799b82 into puppetlabs:7.x Jan 22, 2024
12 checks passed
@AriaXLi AriaXLi deleted the PUP-11981_7.x branch January 22, 2024 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants