-
Notifications
You must be signed in to change notification settings - Fork 6
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
Implement Backend interface for ent #4
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this, some initial comments
5bffbca
to
74e5efc
Compare
@puerco (and anyone else who might be interested) I'd like to leverage generic types for the Interface exampletype (
ProtobomType interface {
sbom.Document | sbom.DocumentType | sbom.Edge | sbom.ExternalReference |
sbom.Metadata | sbom.Node | sbom.NodeList | sbom.Person | sbom.Purpose | sbom.Tool |
map[sbom.HashAlgorithm]string | map[sbom.SoftwareIdentifierType]string
}
StoreRetriever[T ProtobomType] interface {
Store(*T, *options.StoreOptions) error
Retrieve(string, *options.RetrieveOptions) (*T, error)
}
) This would add some flexibility by allowing ent and other backend types to implement a backend for any of the protobom types instead of just Sample implementationtype ToolBackend Backend
var _ StoreRetriever[sbom.Tool] = (*ToolBackend)(nil)
func (backend *ToolBackend) Store(tool *sbom.Tool, opts *options.StoreOptions) error {
// store logic
return nil
}
func (backend *ToolBackend) Retrieve(id string, opts *options.RetrieveOptions) (*sbom.Tool, error) {
// retrieve logic
return nil, nil
} So, a few questions:
EDIT: for context, the reason for this is because the logic for inserting into the database using the ent API follows a very similar pattern for each protobom type, including Document. To me it seems like the perfect use case for reusing the interface for different protobom types. Also, it would enable useful functionality for projects like |
For retrieve, the
|
@jhoward-lm I haven't used ent before but I am going to assume the files with the spdx license header are auto generated? Is there a way to edit the header template to include a note about which files are generated and not to be edited manually (or do you edit them with ent)? I like how this is very explicit with protos. |
@eddiezane this is already done with a go template (example), which has the nice side effect of being automatically ignored by golangci-lint. So if that first line isn’t present, it isn’t auto generated. The template is in Inside
|
Updating this for those not present at the community meeting: we fixed the generation of the document IDs when reading data from SPDX. Answering @jhoward-lm 's question above: Yes, the idea is that storage backends retrieve the IDs using the document identifier. The doc identifier is supposed to be globally unique (when used properly). At some point we can think of another way to key them. We may develop a serialization method and content-address them in the database, but for now I expect the protobom structures to be still in flux so it could be hard to keep up to do it now. |
@puerco can you cut a new protobom release with the document ID fix? |
chore: - Update protobom dependency to v0.4.2 Signed-off-by: Jonathan Howard <jonathan.w.howard@lmco.com>
f5dd611
to
1c92c10
Compare
Signed-off-by: Jonathan Howard <jonathan.w.howard@lmco.com>
Signed-off-by: Jonathan Howard <jonathan.w.howard@lmco.com>
Signed-off-by: Jonathan Howard <jonathan.w.howard@lmco.com>
@puerco @eddiezane @houdini91 ready for review Do we want |
Moved back to draft while addressing a unique constraint issue with node edge types. |
Signed-off-by: Jonathan Howard <jonathan.w.howard@lmco.com>
@puerco @eddiezane @houdini91 Created a separate PR #9 containing schema updates and generated ent code to minimize the number of changes in this PR. The other PR should be merged before this one. Also added a godoc example in |
Need to address a small issue with retrieving node list edges |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking really good, but I have a few of comments on some patterns in the code
chore: - address PR comments Signed-off-by: Jonathan Howard <jonathan.w.howard@lmco.com>
Signed-off-by: Jonathan Howard <jonathan.w.howard@lmco.com>
@puerco summary of changes from most recent commit:
edit: I wanted to just initialize the client within |
Signed-off-by: Jonathan Howard <jonathan.w.howard@lmco.com>
Signed-off-by: Jonathan Howard <jonathan.w.howard@lmco.com>
Signed-off-by: Jonathan Howard <jonathan.w.howard@lmco.com>
Signed-off-by: Jonathan Howard <jonathan.w.howard@lmco.com>
Signed-off-by: Jonathan Howard <jonathan.w.howard@lmco.com>
Nice, LGTM. Let's merge it. Two thoughts:
Returning an error in the constructor doesn't feel strange to me, but I get it :) If you want to keep the same signature, defer the error by storing it as a property (eg
OK, it is concerning because this will fail once we have conformance tests. But TBH, it feels that a document that has two edges of the same type, eg: graph LR;
SRC-->DEPENDS_ON;
DEPENDS_ON-->NODE1;
SRC-->D2[DEPENDS_ON];
D2-->NODE2;
... should be equivalent to another one that has just one edge pointing to the same two destinations graph LR;
SRC-->DEPENDS_ON;
DEPENDS_ON-->NODE1;
DEPENDS_ON-->NODE2;
I think we don't have support to compare these two as equivalents, do you want to open an issue on protobom/protobom? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Add the
Store
andRetrieve
methods in order to implement theBackend
interface.