Skip to content

fix: update dir.go to deny walkthrough non supported file types - #1069

Merged
ritzorama merged 2 commits into
meshery:masterfrom
YASHMAHAKAL:rego-errors
Jul 24, 2026
Merged

ritzorama merged 2 commits into
meshery:masterfrom
YASHMAHAKAL:rego-errors

Conversation

@YASHMAHAKAL

@YASHMAHAKAL YASHMAHAKAL commented Jul 22, 2026

Copy link
Copy Markdown

Notes for Reviewers

Description

Model directory registration (registration.NewDir(...).Register(...)) walks every file in a model package and tries to parse it as an entity definition. Non-JSON/YAML files like OPA .rego policy scripts (e.g. under meshery-core/policies/) were being sniffed as YAML (since .rego is plain text), then failing JSON parsing — surfacing misleading unsupported extension for operation 'import' errors during registration.

Fix

Skip known non-entity file extensions (.rego, .template, .svg, .png, .md) early in processDir (models/registration/dir.go), before any content parsing is attempted. Genuinely malformed entity files (bad .json/.yaml) still surface as errors — only known non-model assets are ignored.

Testing

  • go build ./... — clean
  • go test ./models/registration/... — pass
  • Built Meshery server against this branch via local replace in meshery/go.mod — clean
  • Confirmed .rego files no longer appear as invalid definitions in ~/.meshery/logs/registery/registry-errors.logs

Signed commits

  • Yes, I signed my commits.

Summary by CodeRabbit

  • Bug Fixes
    • Improved registration scanning by ignoring non-model files, such as assets, documentation, policies, templates, and other unsupported content types.
    • Prevents unsupported files from being read and processed during directory scans.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2f788a73-6b63-4159-8cec-aa9287e032b9

📥 Commits

Reviewing files that changed from the base of the PR and between d6af8ab and a8e3a88.

📒 Files selected for processing (1)
  • models/registration/dir.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • models/registration/dir.go

📝 Walkthrough

Walkthrough

processDir filters non-model file extensions during directory traversal, skipping policies, assets, documentation, and templates before reading or parsing them.

Changes

Model registration

Layer / File(s) Summary
Skip non-model extensions
models/registration/dir.go
processDir normalizes file extensions and returns early for extensions such as .rego, .template, .svg, .png, and .md before reading or parsing file contents.

Estimated code review effort: 2 (Simple) | ~5 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the dir.go change to skip unsupported file types.
Linked Issues check ✅ Passed The change skips .rego and other non-entity files before parsing, matching the issue's goal to stop invalid definitions.
Out of Scope Changes check ✅ Passed The added file-type filtering stays within the parser guard and does not introduce unrelated changes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

Signed-off-by: YASHMAHAKAL <yvsst01@gmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@models/registration/dir.go`:
- Around line 84-95: Normalize the extension returned in the file-filtering
logic before checking nonEntityExtensions, so uppercase variants such as .MD,
.REGO, and .SVG match the existing lowercase entries. Update the extension
handling near filepath.Ext(path) without changing the skip behavior for
supported or already-lowercase extensions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 163c6c44-166a-40c3-93da-71774e072967

📥 Commits

Reviewing files that changed from the base of the PR and between 78679d1 and 783d705.

📒 Files selected for processing (1)
  • models/registration/dir.go

Comment thread models/registration/dir.go
Signed-off-by: YASHMAHAKAL <yvsst01@gmail.com>
@ritzorama
ritzorama merged commit ba4967a into meshery:master Jul 24, 2026
5 checks passed
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.

[Models] "meshery-core" contains invalid relationship definitions

2 participants