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

Refactor engine code to use specific provider traits in more places #3262

Merged
merged 3 commits into from
May 7, 2024

Conversation

dmjb
Copy link
Contributor

@dmjb dmjb commented May 7, 2024

Relates to #2845

When evaluating a policy, we instantiate a ProviderBuilder and then pass it around to various parts of the code. Once the specific trait is known, we get the specific trait we need from the ProviderBuilder.

While replacing the ProviderBuilder, I notice that there are many parts of the code where we continue to pass around the ProviderBuilder even though we know the specific provider trait which will be needed. I changed various code to explicitly require the provider trait it needs instead of taking the ProviderBuilder and getting an instance of the desired type. As a result of this change, test setup is simplified, and this will make my PR to replace the ProviderBuilder smaller.

Summary

Provide a brief overview of the changes and the issue being addressed.
Explain the rationale and any background necessary for understanding the changes.
List dependencies required by this change, if any.

Fixes #(related issue)

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.

@dmjb dmjb requested a review from a team as a code owner May 7, 2024 11:13
@@ -43,7 +43,11 @@ func NewRuleAlert(rt *pb.RuleType, pbuild *providers.ProviderBuilder) (engif.Act
if alertCfg.GetSecurityAdvisory() == nil {
return nil, fmt.Errorf("alert engine missing security-advisory configuration")
}
return security_advisory.NewSecurityAdvisoryAlert(ActionType, rt.GetSeverity(), alertCfg.GetSecurityAdvisory(), pbuild)
client, err := pbuild.GetGitHub()
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we first check if the provider implements github and skip if it doesn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I agree with this suggestion:

  1. The code copies the existing behaviour: https://github.com/stacklok/minder/blob/main/internal/engine/actions/alert/security_advisory/security_advisory.go#L161
  2. If other aspects of the configuration are incorrect, we also return an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note in my next PR, I will change the behaviour to print an explicit error if the provider is not Github

Copy link
Contributor

Choose a reason for hiding this comment

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

There is an explicit "error" that gets the engine to mark something as skipped. Anyway, it's fine to do it in a separate PR.

@coveralls
Copy link

coveralls commented May 7, 2024

Coverage Status

coverage: 50.178% (-0.01%) from 50.191%
when pulling 54c65c6 on engine-provider-traits
into 82dd48b on main.

dmjb added 2 commits May 7, 2024 14:03
Relates to #2845

When evaluating a policy, we instantiate a ProviderBuilder and then pass
it around to various parts of the code. Once the specific trait is
known, we get the specific trait we need from the ProviderBuilder.

While replacing the ProviderBuilder, I notice that there are many parts
of the code where we continue to pass around the ProviderBuilder even
though we know the specific provider trait which will be needed.
I changed various code to explicitly require the provider trait it needs
instead of taking the ProviderBuilder and getting an instance of the
desired type. As a result of this change, test setup is simplified, and
this will make my PR to replace the ProviderBuilder smaller.
@dmjb dmjb merged commit e2414bc into main May 7, 2024
24 checks passed
@dmjb dmjb deleted the engine-provider-traits branch May 7, 2024 13:28
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