-
Notifications
You must be signed in to change notification settings - Fork 113
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
Add a nil case to the expandWildcards function #627
Add a nil case to the expandWildcards function #627
Conversation
Signed-off-by: Sergen Yalçın <[email protected]>
pkg/fieldpath/paved.go
Outdated
@@ -204,6 +204,8 @@ func expandWildcards(data any, segments Segments) ([]Segments, error) { //nolint | |||
} | |||
res = append(res, r...) | |||
} | |||
case nil: | |||
return nil, errNotFound{errors.Errorf("%s: value of the field is nil", segments[:i])} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we differentiate between the cases where an unexpected type is encountered versus the specified path is not found and we hit the newly added case nil
here.
nit:
return nil, errNotFound{errors.Errorf("%s: value of the field is nil", segments[:i])} | |
return nil, errNotFound{errors.Errorf("wildcard field %q is not found in the path", segments[:i])} |
- Added a unit-test case Signed-off-by: Sergen Yalçın <[email protected]>
079e276
to
4e24aae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sergenyalcin, lgtm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sergenyalcin 🙌 Returning errNotFound
for that case makes sense to me.
Description of your changes
This PR adds a nil case to the
expandWildcards
function to handle the case that the value of the segment is nil.The issue was observed while testing the GCP
certificatemanager.Certificate
resource. While trying to get the connection details of this resource, we try to read theself_managed[*].certificate_pem
attribute of this resource. If theself_managed
object is nil, then we observe an error:cannot get connection details: cannot get connection details: cannot expand wildcards: cannot expand wildcards for segments: "self_managed[*].certificate_pem": "self_managed": unexpected wildcard usage'
If the value of this field is nil, then we do not want to return an error because there is nothing to read in the sensitive attribute. In this case, we want to handle this situation in Upjet as a specific case other than the different cases. So, by returning a specific error from the
nil
case, we can handle this in Upjet by ignoring this error type.I observed a specific error type,
errNotFound
and used this for thenil
case.I have:
make reviewable test
to ensure this PR is ready for review.How has this code been tested
This was tested in the Upjet-based GCP provider. Resource:
certificatemanager.Certificate