-
Notifications
You must be signed in to change notification settings - Fork 196
internal: Add support for 'sensitive' JSON tag for bundle config fields #5896
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
Open
andrewnester
wants to merge
9
commits into
main
Choose a base branch
from
feat/sensitive-fields
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0cce77e
internal: Add support for 'sensitive' JSON tag for bundle config fields
andrewnester 0eefe27
Merge branch 'main' into feat/sensitive-fields
andrewnester 7abdf8a
no masking in plan
andrewnester f930a69
fix lint
andrewnester 687b636
fixed missed cache call
andrewnester f8ff27e
addressed feedback
andrewnester b5da9aa
fix lint
andrewnester 2e0b5c7
add new dyn type
andrewnester f52fb6a
fix fmt
andrewnester File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,10 @@ type structInfo struct { | |
| // Maps JSON-name of the field to Golang struct name | ||
| GolangNames map[string]string | ||
|
|
||
| // Sensitive tracks fields tagged `bundle:"sensitive"` by their JSON name. | ||
| // Values for these fields should be masked in display output. | ||
| Sensitive map[string]bool | ||
|
andrewnester marked this conversation as resolved.
|
||
|
|
||
| // ForceSendFieldsIndex maps the JSON-name of the field to the index path (for | ||
| // use with [reflect.Value.FieldByIndex]) of the ForceSendFields slice that | ||
| // governs it: the one declared by the struct that also declares the field. | ||
|
|
@@ -68,6 +72,7 @@ func buildStructInfo(typ reflect.Type) structInfo { | |
| ForceEmpty: make(map[string]bool), | ||
| GolangNames: make(map[string]string), | ||
| ForceSendFieldsIndex: make(map[string][]int), | ||
| Sensitive: make(map[string]bool), | ||
| } | ||
|
|
||
| // Queue holds the indexes of the structs to visit. | ||
|
|
@@ -134,6 +139,11 @@ func buildStructInfo(typ reflect.Type) structInfo { | |
| } | ||
| out.GolangNames[name] = sf.Name | ||
|
|
||
| btag := structtag.BundleTag(sf.Tag.Get("bundle")) | ||
| if btag.Sensitive() { | ||
| out.Sensitive[name] = true | ||
| } | ||
|
|
||
| // The field is declared directly in this struct, so it is governed by | ||
| // this struct's ForceSendFields (if it has one). | ||
| if forceSendFieldsIndex != nil { | ||
|
|
@@ -176,6 +186,25 @@ func (s *structInfo) FieldValues(v reflect.Value) []FieldValue { | |
| return out | ||
| } | ||
|
|
||
| // SensitiveFieldNames returns the JSON field names of typ that carry the | ||
| // `bundle:"sensitive"` tag. A pointer type is dereferenced before inspection. | ||
| // Returns nil for non-struct types. Callers use this to identify fields that | ||
| // must be masked in display output (validate -o json, plan -o json) without | ||
| // touching the typed values used by the actual deployment pipeline. | ||
| func SensitiveFieldNames(typ reflect.Type) map[string]bool { | ||
| for typ.Kind() == reflect.Pointer { | ||
| typ = typ.Elem() | ||
| } | ||
| if typ.Kind() != reflect.Struct { | ||
| return nil | ||
| } | ||
| si := getStructInfo(typ) | ||
| if len(si.Sensitive) == 0 { | ||
| return nil | ||
| } | ||
| return si.Sensitive | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a few unit tests here in dyn/convert that demonstrates that this works in cases with embedded structs, anonymous structs, etc. Would also be good to include a user of these fields in the same package. |
||
| // isForceSend reports whether the field named k is listed in the ForceSendFields | ||
| // that governs it (see structInfo.ForceSendFieldsIndex). | ||
| func (s *structInfo) isForceSend(v reflect.Value, k string) bool { | ||
|
|
||
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
The "normalize" function doesn't retain the flag.