-
Notifications
You must be signed in to change notification settings - Fork 90
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
Fix slice type sensitive fieldpath generation #355
Fix slice type sensitive fieldpath generation #355
Conversation
Signed-off-by: Sergen Yalçın <[email protected]>
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.
Thank you @sergenyalcin, left a comment regarding the situation with the maps.
pkg/types/field.go
Outdated
switch f.FieldType.String() { | ||
case "string", "*string", "map[string]string", "map[string]*string": | ||
cfg.Sensitive.AddFieldPath(fieldPathWithWildcard(f.TerraformPaths), "spec.forProvider."+fieldPathWithWildcard(f.CRDPaths)+sfx) | ||
case "[]string", "[]*string": | ||
f.CRDPaths[len(f.CRDPaths)-2] = f.CRDPaths[len(f.CRDPaths)-2] + sfx | ||
cfg.Sensitive.AddFieldPath(fieldPathWithWildcard(f.TerraformPaths), "spec.forProvider."+fieldPathWithWildcard(f.CRDPaths)) | ||
} |
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.
Because we already have a validation enumeration under this switch block, how about getting rid of the enumeration here?
switch f.FieldType.String() { | |
case "string", "*string", "map[string]string", "map[string]*string": | |
cfg.Sensitive.AddFieldPath(fieldPathWithWildcard(f.TerraformPaths), "spec.forProvider."+fieldPathWithWildcard(f.CRDPaths)+sfx) | |
case "[]string", "[]*string": | |
f.CRDPaths[len(f.CRDPaths)-2] = f.CRDPaths[len(f.CRDPaths)-2] + sfx | |
cfg.Sensitive.AddFieldPath(fieldPathWithWildcard(f.TerraformPaths), "spec.forProvider."+fieldPathWithWildcard(f.CRDPaths)) | |
} | |
switch f.FieldType.(type) { | |
case *types.Slice: | |
f.CRDPaths[len(f.CRDPaths)-2] = f.CRDPaths[len(f.CRDPaths)-2] + sfx | |
cfg.Sensitive.AddFieldPath(fieldPathWithWildcard(f.TerraformPaths), "spec.forProvider."+fieldPathWithWildcard(f.CRDPaths)) | |
default: | |
cfg.Sensitive.AddFieldPath(fieldPathWithWildcard(f.TerraformPaths), "spec.forProvider."+fieldPathWithWildcard(f.CRDPaths)+sfx) | |
} |
Also, do we need to handle the maps in a similar manner?
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.
Thank you @ulucinar for that comment. It will be valuable to record an essential piece of information.
When I started to prepare this change, I first evaluated the map type together with the slice type and, put it in the same case, and tried generation. However, I got an index out of range
error in this case. Then, in the debugging session I did, I saw that the fieldpath
we generate for the fields of the map type does not contain the [*]
expression at the end, similar to slices, but only the name of the field, like the string type. Therefore, I put the maps in the same case as the strings.
Calculated fieldpath examples
String: x.y.z
Map: x.y.z
Slice: x.y.z[*]
In short, we do not need to handle the map type here. It seems that the paved library can handle an expression without a wildcard correctly for maps but requires a wildcard for slices. At this point, we need a branch.
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.
Signed-off-by: Sergen Yalçın <[email protected]>
Successfully created backport PR #366 for |
Successfully created backport PR #367 for |
Description of your changes
This PR fixes sensitive fieldpath generation for slices. In the current behavior, we do not have any handling mechanism for slices while calculating the fieldpath. With this PR we will have this.
I have:
make reviewable
to ensure this PR is ready for review.backport release-x.y
labels to auto-backport this PR if necessary.How has this code been tested
Tested on this PR. And observed two diffs in generated fieldpaths:
Diffs respectively: