feat: order YAML output fields for Profile, RuleType, DataSource#6432
Open
maryam22001 wants to merge 2 commits into
Open
feat: order YAML output fields for Profile, RuleType, DataSource#6432maryam22001 wants to merge 2 commits into
maryam22001 wants to merge 2 commits into
Conversation
f7d864b to
228ec38
Compare
Member
evankanderson
left a comment
There was a problem hiding this comment.
How will this scale as we add new fields to protocol buffers? I'm concerned that we'll end up forgetting to adjust the helpers, and end up omitting new fields in input and output.
Thinking out loud, it almost feels like we want to have a known set of document nodes which we serialize first, then serialize everything else alphabetically.
Looking at e.g. https://github.com/mindersec/minder-rules-and-profiles/blob/main/rule-types/github/branch_protection_lock_branch.yaml, it also seems like we serialize consistently within the def of the RuleType; ingest comes before eval comes before remediate comes before alert (which is the order that evaluation happens in).
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.
Summary
When printing YAML output for profiles, rule types, and data sources, fields were ordered by protobuf field number rather than the canonical order defined in the project conventions. This PR adds a
GetOrderedYamlFromProtohelper ininternal/util/that marshals fields in the standard order (version → type → name → context → ...) for Profile, RuleType, and DataSource resources. Non-resource protos fall back to alphabetical order to avoid regressions.Fixes #6428
Changes
GetOrderedYamlFromProtohelper ininternal/util/yaml_order.gocmd/cli/app/profile/get.go,ruletype/get.go, anddatasource/get.goto use the new helperinternal/util/yaml_order_test.goTesting
Unit tests
New tests added in
internal/util/yaml_order_test.go:TestGetOrderedYamlFromProto_Profileversion → type → nameare fields 1–3TestGetOrderedYamlFromProto_RuleTypeversion → type → nameare fields 1–3TestGetOrderedYamlFromProto_DataSourceversion → type → nameare fields 1–3TestGetOrderedYamlFromProto_ContextComesAfterNamecontextis field 4 when presentTestGetOrderedYamlFromProto_NonResourceFallsBackToAlphaTestGetOrderedYamlFromProto_NilReturnsEmptyObjectnilinput returns{}\nwith no errorAll 6 pass
Existing CLI golden file tests
Golden files updated to reflect the new field order:
go test ./cmd/cli/app/profile/... ./cmd/cli/app/ruletype/... ./cmd/cli/app/datasource/...Updated files:
list_profiles.yaml.golden,status_get.yaml.golden,status_list.yaml.golden,get_by_name.yaml.golden,list_populated.yaml.goldenSmoke test
Expected — every resource starts with
version → type → name → context:Configuration
1.26.2