Conversation
Signed-off-by: Johannes Özkan Preisinger <johannes.preisinger@dynatrace.com>
0acdceb to
5dcf14e
Compare
|
@Shnatsel, what do you think? |
|
|
Heya, sorry this slipped through the cracks. Could you explain the motivation behind this change? What does this accomplish? |
@Shnatsel attempts to add the repo url as a VCS ExternalReference, to enrich the component information and link it to an origin repository |
|
According to https://doc.rust-lang.org/cargo/commands/cargo-metadata.html#json-format this field is meant to be opaque and its content is not stable between versions and does not conform to any particular format:
I'm not sure it's a good idea to rely on parsing an explicitly opaque value. |
Thats why we don't extract the repository url if the field does not exist |
|
@Shnatsel what do you think? |
|
Could this instead be accomplished by parsing the |
|
This field is already (not quite correctly) used: |
|
I'm going over the outstanding PRs and this is the last one standing. Could you please elaborate on two things:
|
|
I'm watching this PR already for some time and can share our primary use-case:
There is also a motivation from a CycloneDX BOM perspective:
Regarding the pkgid-spec question, I think you're right. Not sure if the original author wants to follow-up on this but I'd aim for something like the following: let id_str = package.id.to_string();
if id_str.starts_with("git+") {
let vcs_url = id_str
.split_once('#')
.map_or(id_str.as_str(), |(url, _)| url);
match Uri::try_from(vcs_url.to_string()) {
Ok(uri) => references.push(ExternalReference::new(ExternalReferenceType::Vcs, uri)),
Err(e) => log::warn!(
"Package {} has an invalid repository URI (from id: {}): {} ",
package.name,
package.id,
e
),
}
}I guess this should also be adjusted for the PURL identifier to address #799. |
|
@beer4code thanks for the info! Let's not wait on the original author. Would you go ahead and open a new PR with your version? |
|
Thanks for the fast response. Yes, can do. I'll take care of it in the next few days 👍 |
|
There's also a big open question about qualifiers. If we include the qualifier, it's also not clear in what format it should appear. The PURL spec says that for I also can't find any guidance on whether we should include |
|
I looked up the ECMA spec since it's more complete than the earlier iterations, but it only says:
I guess we'll need to look at what existing tools write and what they do with it. |
|
Thanks for the additional research!
You're correct, I've indeed missed that.
I'm afraid every vague specification leaves room for interpretation and variation. |
Replace the use of package.source (opaque/unstable) with package.id (stable pkgid spec) for extracting VCS URLs from git dependencies. - Add extract_git_url_from_id helper in purl.rs that strips the #name@version fragment and ?branch=/?tag=/?rev= query params from the pkgid, returning a clean git+proto://host/path URL - Use the helper in get_purl for the PURL vcs_url qualifier, replacing the previous source_to_vcs_url function - Use the helper in get_external_references as a fallback when package.repository is absent on git dependencies - Update git_package.json fixture to use the new pkgid format package.source is explicitly documented as opaque and unstable by the cargo_metadata crate. package.id (the pkgid spec) is the stable alternative. On Rust 1.77+ the pkgid format for git deps is: git+proto://host/path[?query]#name@version. The fragment contains name@version (not a commit hash like package.source does), so the output no longer includes commit hashes. This was recommended by the maintainer in PR CycloneDX#777.
Replace the use of package.source (opaque/unstable) with package.id (stable pkgid spec) for extracting VCS URLs from git dependencies. - Add extract_git_url_from_id helper in purl.rs that strips the #name@version fragment and ?branch=/?tag=/?rev= query params from the pkgid, returning a clean git+proto://host/path URL - Use the helper in get_purl for the PURL vcs_url qualifier, replacing the previous source_to_vcs_url function - Use the helper in get_external_references as a fallback when package.repository is absent on git dependencies - Update git_package.json fixture to use the new pkgid format package.source is explicitly documented as opaque and unstable by the cargo_metadata crate. package.id (the pkgid spec) is the stable alternative. On Rust 1.77+ the pkgid format for git deps is: git+proto://host/path[?query]#name@version. The fragment contains name@version (not a commit hash like package.source does), so the output no longer includes commit hashes. This was recommended by the maintainer in PR CycloneDX#777. Signed-off-by: Johannes Feichtner <johannes@web-wack.at> Signed-off-by: beer4code <102912454+beer4code@users.noreply.github.com>
Replace the use of package.source (opaque/unstable) with package.id (stable pkgid spec) for extracting VCS URLs from git dependencies. - Add extract_git_url_from_id helper in purl.rs that strips the #name@version fragment and ?branch=/?tag=/?rev= query params from the pkgid, returning a clean git+proto://host/path URL - Use the helper in get_purl for the PURL vcs_url qualifier, replacing the previous source_to_vcs_url function - Use the helper in get_external_references as a fallback when package.repository is absent on git dependencies - Update git_package.json fixture to use the new pkgid format package.source is explicitly documented as opaque and unstable by the cargo_metadata crate. package.id (the pkgid spec) is the stable alternative. On Rust 1.77+ the pkgid format for git deps is: git+proto://host/path[?query]#name@version. The fragment contains name@version (not a commit hash like package.source does), so the output no longer includes commit hashes. This was recommended by the maintainer in PR CycloneDX#777. Signed-off-by: beer4code <102912454+beer4code@users.noreply.github.com>
No description provided.