Skip to content

⭐ Improve expanded labels#6651

Open
LittleSalkin1806 wants to merge 3 commits intomondoohq:mainfrom
LittleSalkin1806:change-expanded-labels
Open

⭐ Improve expanded labels#6651
LittleSalkin1806 wants to merge 3 commits intomondoohq:mainfrom
LittleSalkin1806:change-expanded-labels

Conversation

@LittleSalkin1806
Copy link
Copy Markdown
Contributor

@LittleSalkin1806 LittleSalkin1806 commented Feb 19, 2026

When querying resources with nested @defaults (e.g., gcp.project.pubsub.topic{*}), nested resource fields displayed as raw resource IDs instead of their declared default fields. For example, a topic's messageStoragePolicy would show its internal ID rather than expanding to show allowedPersistenceRegions as declared in the .lr definition.

In addition i changed the resource display and labels as they were for me personally quite clubbering some things up.
This is purely for user output. So please review if its up to the liking. Or if it takes some logic for the user.
We now trust more the named fields instead of the full path.

if messageStoragePolicy.allowedPersistenceRegions is used in defaults this is unchanged

After

image

Before

image

@tas50 tas50 changed the title Change expanded labels ⭐ Improve expanded labels Feb 22, 2026
@chris-rock
Copy link
Copy Markdown
Member

/review

Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct fix for nested @defaults expansion; one defensive gap in the printer

Comment on lines +668 to +671
hasEntrypoints := block != nil && len(block.Entrypoints) > 0
if !hasEntrypoints {
res.WriteString(name)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 warning — If hasEntrypoints is true but every entrypoint is skipped (no matching checksum data in m), the returned string will be empty — the resource name was suppressed and nothing took its place. Previously this path still produced the resource name.

Consider falling back to the resource name when nothing was printed:

hasEntrypoints := block != nil && len(block.Entrypoints) > 0
if !hasEntrypoints {
    res.WriteString(name)
}
// ... entrypoint loop ...
// after the loop:
if hasEntrypoints && first {
    // all entrypoints were skipped, fall back to resource name
    res.WriteString(name)
}

Comment on lines +111 to +112
if idx := strings.LastIndex(typeName, "."); idx >= 0 {
label = parentLabel + typeName[idx:]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 suggestion — Using LastIndex means that for a type like gcp.project.pubsubService.topic, only .topic is appended. This works well for deep hierarchies, but if two sibling resources happen to share the same final segment (e.g., both aws.ec2.securityGroup.rule and aws.vpc.securityGroup.rule exist), labels could collide under the same parent. The current naming conventions make this unlikely, but a comment noting the assumption would help future readers.

for i := range code.Blocks {
// Use index-based loop instead of range so that blocks appended by
// expandResourceFields (nested @defaults) are visited in the same pass.
for i := 0; i < len(code.Blocks); i++ {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 suggestion — Good fix — range captures slice length once, so blocks appended by expandResourceFields were silently skipped. The index-based loop is the right approach. Consider adding a guard against run-away expansion (e.g., a max-iteration cap) just in case future .lr changes introduce a cycle:

const maxBlocks = 10_000
for i := 0; i < len(code.Blocks) && i < maxBlocks; i++ {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does not adress the root problem and is a safeguard against a very low expansion loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants