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

[feature] Query for package URL (purl) #1538

Closed
ridhoq opened this issue Nov 29, 2023 · 1 comment · Fixed by #1611
Closed

[feature] Query for package URL (purl) #1538

ridhoq opened this issue Nov 29, 2023 · 1 comment · Fixed by #1611
Labels
enhancement New feature or request

Comments

@ridhoq
Copy link
Contributor

ridhoq commented Nov 29, 2023

Is your feature request related to a problem? Please describe.
A subset of the guacone tooling is centered around using purl. For example:

  • guacone patch command uses start-purl and stop-purl
  • guacone query vuln uses purl as an argument

However, when querying for packages using the GraphQL API, there is no way to actually get the purl of a package without constructing it manually yourself like this:

cat results.json | jq '.data.findSoftware[] | "pkg:" + .type + "/" + .namespaces[0].namespace + "/" + .namespaces[0].names[0].name'

It's fairly trivial to do so, but it adds friction.

Describe the solution you'd like
We could use a custom GraphQL schema directive. In our case, we could use a schema directive on the id field on PackageVersion to return a purl.

directive @packageURL(packageVersionID: String) on FIELD_DEFINITION

gqlgen does support schema directives but we would have to do further investigation if this particular use case is supported.

Describe alternatives you've considered
Alternatively, we could implement a findSoftwarePurl query similar to findSoftware. However, it would require maintaining another GraphQL query for all backends. It would also potentially require a user to make two queries to get the purl for a package.

Additional context
Inspired by some schema directive examples from here, specifically, the date formatting one

@kanchan-dhamane
Copy link
Contributor

Hi @ridhoq , adding GraphQL custom directive on id field of PackageVersion module might not work. In custom directive function, we can only access a id value not the Package object.
Tried adding the custom resolver for namespaces field in Package object, it populates the purl in PackageVersion object. Created a PR.

@kodiakhq kodiakhq bot closed this as completed in #1611 Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants