-
Notifications
You must be signed in to change notification settings - Fork 126
Populate conda-lock md5 and sha256 in scan manifests #1802
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,7 +5,7 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent; | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| public class CondaComponent : TypedComponent | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| public CondaComponent(string name, string version, string build, string channel, string subdir, string @namespace, string url, string md5) | ||||||||||||||||||||||||||
| public CondaComponent(string name, string version, string build, string channel, string subdir, string @namespace, string url, string md5, string sha256 = null) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.Conda)); | ||||||||||||||||||||||||||
| this.Version = this.ValidateRequiredInput(version, nameof(this.Version), nameof(ComponentType.Conda)); | ||||||||||||||||||||||||||
|
|
@@ -15,6 +15,7 @@ public CondaComponent(string name, string version, string build, string channel, | |||||||||||||||||||||||||
| this.Namespace = @namespace; | ||||||||||||||||||||||||||
| this.Url = url; | ||||||||||||||||||||||||||
| this.MD5 = md5; | ||||||||||||||||||||||||||
| this.Sha256 = sha256; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| public CondaComponent() | ||||||||||||||||||||||||||
|
|
@@ -46,8 +47,12 @@ public CondaComponent() | |||||||||||||||||||||||||
| [JsonPropertyName("mD5")] | ||||||||||||||||||||||||||
| public string MD5 { get; set; } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||||||||||||||||||||||||||
| [JsonPropertyName("sha256")] | ||||||||||||||||||||||||||
| public string Sha256 { get; set; } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| [JsonIgnore] | ||||||||||||||||||||||||||
| public override ComponentType Type => ComponentType.Conda; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| protected override string ComputeBaseId() => $"{this.Name} {this.Version} {this.Build} {this.Channel} {this.Subdir} {this.Namespace} {this.Url} {this.MD5} - {this.Type}"; | ||||||||||||||||||||||||||
| protected override string ComputeBaseId() => $"{this.Name} {this.Version} {this.Build} {this.Channel} {this.Subdir} {this.Namespace} {this.Url} {this.MD5} {this.Sha256} - {this.Type}"; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| protected override string ComputeBaseId() => $"{this.Name} {this.Version} {this.Build} {this.Channel} {this.Subdir} {this.Namespace} {this.Url} {this.MD5} {this.Sha256} - {this.Type}"; | |
| protected override string ComputeBaseId() | |
| { | |
| var baseIdWithoutSha256 = $"{this.Name} {this.Version} {this.Build} {this.Channel} {this.Subdir} {this.Namespace} {this.Url} {this.MD5}"; | |
| if (string.IsNullOrEmpty(this.Sha256)) | |
| { | |
| return $"{baseIdWithoutSha256} - {this.Type}"; | |
| } | |
| return $"{baseIdWithoutSha256} {this.Sha256} - {this.Type}"; | |
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,6 +34,14 @@ public PipComponent(string name, string version, string author = null, string li | |||||||||||||||||||||||||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||||||||||||||||||||||||||
| [JsonPropertyName("license")] | ||||||||||||||||||||||||||
| public string? License { get; set; } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||||||||||||||||||||||||||
| [JsonPropertyName("mD5")] | ||||||||||||||||||||||||||
| public string? Md5 { get; set; } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||||||||||||||||||||||||||
| [JsonPropertyName("sha256")] | ||||||||||||||||||||||||||
| public string? Sha256 { get; set; } | ||||||||||||||||||||||||||
|
Comment on lines
+38
to
+44
|
||||||||||||||||||||||||||
| #nullable disable | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| [JsonIgnore] | ||||||||||||||||||||||||||
|
|
@@ -43,5 +51,18 @@ public PipComponent(string name, string version, string author = null, string li | |||||||||||||||||||||||||
| public override PackageURL PackageUrl => new PackageURL("pypi", null, this.Name, this.Version, null, null); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| [SuppressMessage("Usage", "CA1308:Normalize String to Uppercase", Justification = "Casing cannot be overwritten.")] | ||||||||||||||||||||||||||
| protected override string ComputeBaseId() => $"{this.Name} {this.Version} - {this.Type}".ToLowerInvariant(); | ||||||||||||||||||||||||||
| protected override string ComputeBaseId() | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| var digestSuffix = string.Empty; | ||||||||||||||||||||||||||
| if (!string.IsNullOrEmpty(this.Sha256)) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| digestSuffix = $" {this.Sha256}"; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| else if (!string.IsNullOrEmpty(this.Md5)) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| digestSuffix = $" {this.Md5}"; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return $"{this.Name} {this.Version}{digestSuffix} - {this.Type}".ToLowerInvariant(); | ||||||||||||||||||||||||||
|
Comment on lines
+56
to
+66
|
||||||||||||||||||||||||||
| var digestSuffix = string.Empty; | |
| if (!string.IsNullOrEmpty(this.Sha256)) | |
| { | |
| digestSuffix = $" {this.Sha256}"; | |
| } | |
| else if (!string.IsNullOrEmpty(this.Md5)) | |
| { | |
| digestSuffix = $" {this.Md5}"; | |
| } | |
| return $"{this.Name} {this.Version}{digestSuffix} - {this.Type}".ToLowerInvariant(); | |
| return $"{this.Name} {this.Version} - {this.Type}".ToLowerInvariant(); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -122,9 +122,47 @@ private static List<CondaPackage> GetPackages(CondaLock condaLock) | |||||
| /// <param name="package">The CondaPackage to convert.</param> | ||||||
| /// <returns>The TypedComponent.</returns> | ||||||
| private static TypedComponent CreateComponent(CondaPackage package) | ||||||
| => IsPythonPackage(package) | ||||||
| ? new PipComponent(package.Name, package.Version) | ||||||
| : new CondaComponent(package.Name, package.Version, null, package.Category, null, null, null, null); | ||||||
| { | ||||||
| var md5 = TryGetHash(package.Hash, "md5"); | ||||||
| var sha256 = TryGetHash(package.Hash, "sha256"); | ||||||
|
|
||||||
| if (IsPythonPackage(package)) | ||||||
| { | ||||||
| return new PipComponent(package.Name, package.Version) | ||||||
| { | ||||||
| Md5 = md5, | ||||||
| Sha256 = sha256, | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| return new CondaComponent(package.Name, package.Version, null, package.Category, null, null, null, md5, sha256); | ||||||
|
||||||
| return new CondaComponent(package.Name, package.Version, null, package.Category, null, null, null, md5, sha256); | |
| return new CondaComponent(package.Name, package.Version, null, package.Category, null, null, null, null, null); |
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.
Sha256is ignored when null, butMD5is still always serialized. IfMD5is missing for a package, this will emit"mD5": nullin scan manifests, which is inconsistent with the newsha256behavior and may create noisy diffs. Consider addingJsonIgnore(Condition = WhenWritingNull)toMD5as well (or otherwise aligning null-handling for both digest fields).