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 a new ProtoMessageConverter provider interface to convert entities to typed protobuf messages #4469

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

jhrozek
Copy link
Contributor

@jhrozek jhrozek commented Sep 12, 2024

Summary

This will help us get rid of database and/or property calls in the
webhook handler.

Related: #4327

Change Type

  • 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

make test

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.

…s to typed protobuf messages

This will help us get rid of database and/or property calls in the
webhook handler.

Related: mindersec#4327
if err != nil {
return nil, fmt.Errorf("error converting artifact to protobuf: %w", err)
}

pbArtifact, ok := pbMsg.(*pb.Artifact)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this typing is a bit awkward, but as a follow-up (that I already have in another branch), I wanted to add a more generic WithEntityID that would replace WithRepositoryID and WithEntity that would replace WithRepository etc.

@@ -55,6 +56,10 @@ const (

// PropertiesService is the interface for the properties service
type PropertiesService interface {
// EntityWithPropertiesAsProto calls the provider to convert the entity with properties to the appropriate proto message
EntityWithPropertiesAsProto(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

At first I wanted to add this as a function to models instead of the service, but having it as a method makes testing easier as we generate mocks for the PropertiesService interface


// EntityWithPropertiesAsProto converts the entity with properties to a protobuf message
func (_ *propertiesService) EntityWithPropertiesAsProto(
ctx context.Context, ewp *models.EntityWithProperties, provMgr manager.ProviderManager,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could make the method more generic and instead of requiring EntityWithProperties let he caller just pass the provider ID and entity type

@jhrozek jhrozek merged commit ac41850 into mindersec:main Sep 12, 2024
22 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.

2 participants