-
Notifications
You must be signed in to change notification settings - Fork 187
Defining and generating spdx 3.0 json elements #830
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
Conversation
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Entities/AnyLicenseInfo.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Entities/Enums/RelationshipType.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Entities/Spdx30Relationship.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Entities/Spdx30Relationship.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Utils/ElementSerializer.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Utils/InternalMetadataProviderIdentityExtensions.cs
Show resolved
Hide resolved
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Utils/InternalMetadataProviderIdentityExtensions.cs
Show resolved
Hide resolved
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Utils/SPDXExtensions.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.Sbom.Parsers.Spdx30SbomParser.Tests/Parser/GeneratorTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.Sbom.Parsers.Spdx30SbomParser.Tests/Parser/GeneratorTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.Sbom.Parsers.Spdx30SbomParser.Tests/Parser/GeneratorTests.cs
Outdated
Show resolved
Hide resolved
...crosoft.Sbom.Parsers.Spdx30SbomParser.Tests/Parser/JsonStrings/SbomDocCreationJsonStrings.cs
Show resolved
Hide resolved
test/Microsoft.Sbom.Parsers.Spdx30SbomParser.Tests/Utils/SPDXExtensionsTest.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Utils/ElementSerializer.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Utils/InternalMetadataProviderIdentityExtensions.cs
Show resolved
Hide resolved
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Entities/Element.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Entities/AnyLicenseInfo.cs
Outdated
Show resolved
Hide resolved
|
[heart] Alison Lomaka reacted to your message:
________________________________
From: Dave Tryon ***@***.***>
Sent: Thursday, December 12, 2024 1:21:51 AM
To: microsoft/sbom-tool ***@***.***>
Cc: Alison Lomaka ***@***.***>; Comment ***@***.***>
Subject: Re: [microsoft/sbom-tool] Defining and generating spdx 3.0 json elements (PR #830)
@DaveTryon commented on this pull request.
________________________________
In src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Entities/AnyLicenseInfo.cs<#830 (comment)>:
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System.Collections.Generic;
+using System.Text.Json.Serialization;
+
+namespace Microsoft.Sbom.Parsers.Spdx30SbomParser.Entities;
+
+/// <summary>
+/// Class defintion is based on: https://spdx.github.io/spdx-spec/v3.0.1/model/SimpleLicensing/Classes/AnyLicenseInfo/
+/// </summary>
+public class AnyLicenseInfo : Element
+{
+ public AnyLicenseInfo()
+ {
+ Type = nameof(AnyLicenseInfo);
This is way better than hardcoded strings, but we might be able to do even better. Since all of the types derive from Element, you could centralize the code that sets the Type property in the constructor of the Element class:
Type = GetType().Name;
For derived classes, this will provide the name of the derived class, not the base class.
Looking at the code, I think the NoneElement is the only class that sets its type to a value that doesn't match the class. In that case. you can continue to set it in the constructor for NoneElement, since the base class constructor is called before the derived class constructor and the property will just get overwritten
—
Reply to this email directly, view it on GitHub<#830 (review)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AXRTARW7PUYC3YIPLAZ45TL2FDQK7AVCNFSM6AAAAABTOEMERKVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDIOJXGM2TKOJSGA>.
You are receiving this because you commented.Message ID: ***@***.***>
|
|
[like] Alison Lomaka reacted to your message:
________________________________
From: Dave Tryon ***@***.***>
Sent: Thursday, December 12, 2024 1:18:34 AM
To: microsoft/sbom-tool ***@***.***>
Cc: Alison Lomaka ***@***.***>; Comment ***@***.***>
Subject: Re: [microsoft/sbom-tool] Defining and generating spdx 3.0 json elements (PR #830)
@DaveTryon commented on this pull request.
________________________________
In src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Entities/Element.cs<#830 (comment)>:
@@ -0,0 +1,70 @@
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System.Collections;
+using System.Collections.Generic;
+using System.Text.Json.Serialization;
+
+namespace Microsoft.Sbom.Parsers.Spdx30SbomParser.Entities;
+
+/// <summary>
+/// Base domain class from which all other SPDX-3.0 domain classes derive.
+/// https://spdx.github.io/spdx-spec/v3.0.1/model/Core/Classes/Element/
+/// </summary>
+public class Element
Should this be abstract? I'm not sure if we ever have just an Element that isn't a derived object.
—
Reply to this email directly, view it on GitHub<#830 (review)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AXRTARUK2UXZIHBKI5VOOLD2FDP6VAVCNFSM6AAAAABTOEMERKVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDIOJXGM2TGMJTGY>.
You are receiving this because you commented.Message ID: ***@***.***>
|
|
[like] Alison Lomaka reacted to your message:
________________________________
From: Pragnya ***@***.***>
Sent: Wednesday, December 11, 2024 9:59:13 PM
To: microsoft/sbom-tool ***@***.***>
Cc: Alison Lomaka ***@***.***>; Comment ***@***.***>
Subject: Re: [microsoft/sbom-tool] Defining and generating spdx 3.0 json elements (PR #830)
@pragnya17 commented on this pull request.
________________________________
In src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Generator.cs<#830 (comment)>:
+ {
+ Name = orgName,
+ };
+
+ var spdxTool = new Tool
+ {
+ Name = toolName,
+ };
+
+ spdxOrganization.AddSpdxId();
+ spdxTool.AddSpdxId();
+
+ var spdxCreationInfo = new CreationInfo
+ {
+ Id = "_:creationinfo",
+ SpecVersion = Constants.SPDXVersion,
In the 2.2 Generator it is also defined as just major.minor - https://github.com/microsoft/sbom-tool/blob/main/src/Microsoft.Sbom.Parsers.Spdx22SbomParser/Constants.cs. So I think this should be fine here as well
—
Reply to this email directly, view it on GitHub<#830 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AXRTARWUGUXB53OEDYV7UF32FCYTDAVCNFSM6AAAAABTOEMERKVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDIOJXGEYDCNZQG4>.
You are receiving this because you commented.Message ID: ***@***.***>
|
|
[like] Alison Lomaka reacted to your message:
________________________________
From: Pragnya ***@***.***>
Sent: Wednesday, December 11, 2024 9:35:03 PM
To: microsoft/sbom-tool ***@***.***>
Cc: Alison Lomaka ***@***.***>; Comment ***@***.***>
Subject: Re: [microsoft/sbom-tool] Defining and generating spdx 3.0 json elements (PR #830)
@pragnya17 commented on this pull request.
________________________________
In src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Generator.cs<#830 (comment)>:
+/// </summary>
+public class Generator : IManifestGenerator
+{
+ private static readonly Dictionary<AlgorithmName, HashAlgorithm> AlgorithmMap = new()
+ {
+ { AlgorithmName.SHA1, HashAlgorithm.sha1 },
+ { AlgorithmName.SHA256, HashAlgorithm.sha256 },
+ { AlgorithmName.SHA512, HashAlgorithm.sha512 },
+ { AlgorithmName.MD5, HashAlgorithm.md5 }
+ };
+
+ public AlgorithmName[] RequiredHashAlgorithms => new[] { AlgorithmName.SHA256, AlgorithmName.SHA1 };
+
+ public string Version { get; set; } = string.Join("-", Constants.SPDXName, Constants.SPDXVersion);
+
+ string IManifestGenerator.FilesArrayHeaderName => throw new NotImplementedException();
Yes that makes more sense, I wasn't aware of that before. Ideally, we wouldn't have these at all:
string IManifestGenerator.FilesArrayHeaderName => throw new NotSupportedException();
string IManifestGenerator.PackagesArrayHeaderName => throw new NotSupportedException();
string IManifestGenerator.RelationshipsArrayHeaderName => throw new NotSupportedException();
string IManifestGenerator.ExternalDocumentRefArrayHeaderName => throw new NotSupportedException();
But they are required since this class should inherit from the IManifestGenerator - similar to what is done in the 2.2 generator.
—
Reply to this email directly, view it on GitHub<#830 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AXRTARW3JKIBRNORA2RYEPL2FCVYPAVCNFSM6AAAAABTOEMERKVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDIOJXGA2TQOBVHE>.
You are receiving this because you commented.Message ID: ***@***.***>
|
src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Entities/ContentIdentifier.cs
Outdated
Show resolved
Hide resolved
DaveTryon
left a comment
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.
LGTM
|
[like] Alison Lomaka reacted to your message:
________________________________
From: Pragnya ***@***.***>
Sent: Monday, December 16, 2024 6:45:53 PM
To: microsoft/sbom-tool ***@***.***>
Cc: Alison Lomaka ***@***.***>; Comment ***@***.***>
Subject: Re: [microsoft/sbom-tool] Defining and generating spdx 3.0 json elements (PR #830)
@pragnya17 commented on this pull request.
________________________________
In src/Microsoft.Sbom.Parsers.Spdx30SbomParser/Generator.cs<#830 (comment)>:
+ /// <exception cref="MissingHashValueException"></exception>
+ public GenerationResult GenerateJsonDocument(ExternalDocumentReferenceInfo externalDocumentReferenceInfo)
+ {
+ if (externalDocumentReferenceInfo is null)
+ {
+ throw new ArgumentNullException(nameof(externalDocumentReferenceInfo));
+ }
+
+ if (externalDocumentReferenceInfo.Checksum is null)
+ {
+ throw new ArgumentNullException(nameof(externalDocumentReferenceInfo.Checksum));
+ }
+
+ var sha1Hash = externalDocumentReferenceInfo.Checksum.FirstOrDefault(h => h.Algorithm == AlgorithmName.SHA1) ??
+ throw new MissingHashValueException(
+ $"The hash value for algorithm {AlgorithmName.SHA1} is missing from {nameof(externalDocumentReferenceInfo)}");
Talked to Rob and he confirmed that SHA1 was required. Will check with Adrian in the new year to get more context and document why it is required.
—
Reply to this email directly, view it on GitHub<#830 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AXRTARX4YBFUK3YE7UOXUUD2F4NWDAVCNFSM6AAAAABTOEMERKVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDKMBWHE4TSOJRGY>.
You are receiving this because you commented.Message ID: ***@***.***>
|
c772392 to
7447224
Compare
@microsoft-github-policy-service agree [company="{Microsoft}"] |
|
@microsoft-github-policy-service agree company="Microsoft" |
|
[heart] Alison Lomaka reacted to your message:
…________________________________
From: Pragnya ***@***.***>
Sent: Monday, December 16, 2024 10:38:37 PM
To: microsoft/sbom-tool ***@***.***>
Cc: Alison Lomaka ***@***.***>; Comment ***@***.***>
Subject: Re: [microsoft/sbom-tool] Defining and generating spdx 3.0 json elements (PR #830)
Merged #830<#830> into main.
—
Reply to this email directly, view it on GitHub<#830 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AXRTART2DERVIPXJY672PDL2F5I63AVCNFSM6AAAAABTOEMERKVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJVGY3TOMZWGQ4TSNY>.
You are receiving this because you commented.Message ID: ***@***.***>
|
With the completion of this feature, we will be able to generate spdx 3.0 json elements which make up an SBOM document.
The goal is to generate spdx 3.0 elements in the format that is specified by the 3.0 spec - SPDX Specification 3.0.1
Specifically these are the changes that are introduced in this PR: