Add a nil case to the expandWildcards function#627
Merged
turkenh merged 2 commits intocrossplane:masterfrom Dec 13, 2023
Merged
Add a nil case to the expandWildcards function#627turkenh merged 2 commits intocrossplane:masterfrom
turkenh merged 2 commits intocrossplane:masterfrom
Conversation
Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
3 tasks
ulucinar
reviewed
Dec 12, 2023
pkg/fieldpath/paved.go
Outdated
| res = append(res, r...) | ||
| } | ||
| case nil: | ||
| return nil, errNotFound{errors.Errorf("%s: value of the field is nil", segments[:i])} |
Contributor
There was a problem hiding this comment.
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:
Suggested change
| 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 <yalcinsergen97@gmail.com>
079e276 to
4e24aae
Compare
ulucinar
approved these changes
Dec 12, 2023
Contributor
ulucinar
left a comment
There was a problem hiding this comment.
Thanks @sergenyalcin, lgtm.
turkenh
approved these changes
Dec 13, 2023
Member
turkenh
left a comment
There was a problem hiding this comment.
Thanks @sergenyalcin 🙌 Returning errNotFound for that case makes sense to me.
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of your changes
This PR adds a nil case to the
expandWildcardsfunction to handle the case that the value of the segment is nil.The issue was observed while testing the GCP
certificatemanager.Certificateresource. While trying to get the connection details of this resource, we try to read theself_managed[*].certificate_pemattribute of this resource. If theself_managedobject 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
nilcase, we can handle this in Upjet by ignoring this error type.I observed a specific error type,
errNotFoundand used this for thenilcase.I have:
make reviewable testto 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