Skip to content
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

Add alias to data source reference #5292

Merged
merged 1 commit into from
Jan 13, 2025

Conversation

eleftherias
Copy link
Contributor

Summary

Add an alias to a data source reference in the rule type, so the data source can be referenced in the Rego code with an alias different than its name.

If we include data sources in a bundle, then the name will be namespaced, e.g "custom/my-data-source". This syntax is not easy to refer to in rego code, so instead we can use an alias.

Example:

  eval:
    type: rego
    data_sources:
      - name: osv
        alias: vulnerability-db

Change Type

Mark the type of change your PR introduces:

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

@eleftherias eleftherias requested a review from a team as a code owner January 13, 2025 10:41
@coveralls
Copy link

coveralls commented Jan 13, 2025

Coverage Status

coverage: 56.617% (+0.01%) from 56.606%
when pulling f57860e on eleftherias:data-source-name-alias
into 2caea05 on mindersec:main.

Copy link
Member

@rdimitrov rdimitrov left a comment

Choose a reason for hiding this comment

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

What would happen in case there's 2 data sources with the same alias? I suppose one way is to make ensure they're unique and validate this upon data source creation.

@eleftherias
Copy link
Contributor Author

What would happen in case there's 2 data sources with the same alias? I suppose one way is to make ensure they're unique and validate this upon data source creation.

Thanks for catching that. Right now it will error on evaluation, but you're right it would be much better to error on creation. I'll update the PR.

@eleftherias eleftherias force-pushed the data-source-name-alias branch from 6ee9dcf to f57860e Compare January 13, 2025 13:29
@eleftherias eleftherias requested a review from rdimitrov January 13, 2025 13:41
Copy link
Member

@rdimitrov rdimitrov left a comment

Choose a reason for hiding this comment

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

🚀

@eleftherias eleftherias merged commit 9b2ecaa into mindersec:main Jan 13, 2025
27 checks passed
@eleftherias eleftherias deleted the data-source-name-alias branch January 13, 2025 13:53
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.

3 participants