Skip to content

Commit e47d1d4

Browse files
authored
Add COSE paths to SbomConfig (#1152)
* Add COSE file paths on sbom config * Fix tests
1 parent 0a278ab commit e47d1d4

File tree

8 files changed

+54
-0
lines changed

8 files changed

+54
-0
lines changed

src/Microsoft.Sbom.Api/Manifest/BaseManifestConfigHandler.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ protected BaseManifestConfigHandler(
4646

4747
protected string BsiFilePath => fileSystemUtils.JoinPaths(SbomDirPath, Constants.BsiFileName);
4848

49+
protected string BsiCoseFilePath => fileSystemUtils.JoinPaths(SbomDirPath, Constants.BsiCoseFileName);
50+
51+
protected string ManifestCoseFilePath => fileSystemUtils.JoinPaths(SbomDirPath, Constants.ManifestCoseFileName);
52+
4953
protected IMetadataBuilder MetadataBuilder => metadataBuilderFactory.Get(ManifestInfo);
5054

5155
protected ISbomConfig CreateSbomConfig()
@@ -57,6 +61,8 @@ protected ISbomConfig CreateSbomConfig()
5761
ManifestJsonFilePath = SbomFilePath,
5862
CatalogFilePath = CatalogFilePath,
5963
BsiFilePath = BsiFilePath,
64+
BsiCoseFilePath = BsiCoseFilePath,
65+
ManifestCoseFilePath = ManifestCoseFilePath,
6066
ManifestJsonFileSha256FilePath = ManifestJsonSha256FilePath,
6167
MetadataBuilder = MetadataBuilder,
6268
Recorder = new SbomPackageDetailsRecorder()

src/Microsoft.Sbom.Api/Manifest/Configuration/SbomConfig.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ public SbomConfig(IFileSystemUtils fileSystemUtils)
5050
/// </summary>
5151
public string BsiFilePath { get; set; }
5252

53+
/// <summary>
54+
/// Gets or sets the absolute path of the build session information COSE file.
55+
/// </summary>
56+
public string BsiCoseFilePath { get; set; }
57+
58+
/// <summary>
59+
/// Gets or sets the absolute path of the manifest COSE file.
60+
/// </summary>
61+
public string ManifestCoseFilePath { get; set; }
62+
5363
/// <summary>
5464
/// Gets or sets derived manifestInfo or from configurations.
5565
/// </summary>

src/Microsoft.Sbom.Api/Manifest/Configuration/SbomConfigFactory.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public ISbomConfig Get(
2626
string manifestFileSha256HashPath,
2727
string catalogFilePath,
2828
string bsiFilePath,
29+
string bsiCoseFilePath,
30+
string manifestCoseFilePath,
2931
ISbomPackageDetailsRecorder recorder,
3032
IMetadataBuilder metadataBuilder)
3133
{
@@ -35,6 +37,8 @@ public ISbomConfig Get(
3537
ManifestJsonDirPath = manifestDirPath,
3638
ManifestJsonFilePath = manifestFilePath,
3739
BsiFilePath = bsiFilePath,
40+
BsiCoseFilePath = bsiCoseFilePath,
41+
ManifestCoseFilePath = manifestCoseFilePath,
3842
CatalogFilePath = catalogFilePath,
3943
ManifestJsonFileSha256FilePath = manifestFileSha256HashPath,
4044
MetadataBuilder = metadataBuilder,
@@ -52,6 +56,8 @@ public ISbomConfig Get(
5256
var shaFilePath = $"{sbomFilePath}.sha256";
5357
var catFilePath = fileSystemUtils.JoinPaths(sbomDirPath, Constants.CatalogFileName);
5458
var bsiFilePath = fileSystemUtils.JoinPaths(sbomDirPath, Constants.BsiFileName);
59+
var bsiCoseFilePath = fileSystemUtils.JoinPaths(sbomDirPath, Constants.BsiCoseFileName);
60+
var manifestCoseFilePath = fileSystemUtils.JoinPaths(sbomDirPath, Constants.ManifestCoseFileName);
5561
if (!fileSystemUtils.FileExists(shaFilePath) && !fileSystemUtils.FileExists(catFilePath) && !fileSystemUtils.FileExists(bsiFilePath))
5662
{
5763
// This is likely a CloudBuild SBOM, adjust paths accordingly
@@ -66,6 +72,8 @@ public ISbomConfig Get(
6672
shaFilePath,
6773
catFilePath,
6874
bsiFilePath,
75+
bsiCoseFilePath,
76+
manifestCoseFilePath,
6977
new SbomPackageDetailsRecorder(),
7078
metadataBuilderFactory.Get(manifestInfo));
7179
}

src/Microsoft.Sbom.Api/Utils/Constants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public static class Constants
7070
public const string DefaultRootElement = "SPDXRef-Document";
7171
public const string CatalogFileName = "manifest.cat";
7272
public const string BsiFileName = "bsi.json";
73+
public const string BsiCoseFileName = "bsi.cose";
74+
public const string ManifestCoseFileName = "manifest.spdx.cose";
7375
public const string DeleteManifestDirBoolVariableName = "DeleteManifestDirIfPresent";
7476
public const string RootPackageIdValue = "SPDXRef-RootPackage";
7577

src/Microsoft.Sbom.Common/ISbomConfigFactory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public ISbomConfig Get(
2121
string manifestFileSha256HashPath,
2222
string catalogFilePath,
2323
string bsiFilePath,
24+
string bsiCoseFilePath,
25+
string manifestCoseFilePath,
2426
ISbomPackageDetailsRecorder recorder,
2527
IMetadataBuilder metadataBuilder);
2628

src/Microsoft.Sbom.Extensions/ISbomConfig.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ public interface ISbomConfig : IDisposable, IAsyncDisposable
3737
/// </summary>
3838
public string BsiFilePath { get; set; }
3939

40+
/// <summary>
41+
/// Gets or sets the absolute path of the build session information COSE file.
42+
/// </summary>
43+
public string BsiCoseFilePath { get; set; }
44+
45+
/// <summary>
46+
/// Gets or sets the absolute path of the manifest COSE file.
47+
/// </summary>
48+
public string ManifestCoseFilePath { get; set; }
49+
4050
/// <summary>
4151
/// Gets or sets derived manifestInfo or from configurations.
4252
/// </summary>

test/Microsoft.Sbom.Api.Tests/Manifest/Configuration/SbomConfigFactoryTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class SbomConfigFactoryTests
2424
private string cbCatFilePathStub = "cloud-build-cat-file-path";
2525
private string bsiFilePathStub = "bsi-file-path";
2626
private string cbBsiFilePathStub = "cloud-build-bsi-file-path";
27+
private string bsiCoseFilePathStub = "bsi-cose-file-path";
28+
private string manifestCoseFilePathStub = "manifest-cose-file-path";
2729
private ManifestInfo manifestInfoStub = Api.Utils.Constants.SPDX30ManifestInfo;
2830
private string manifestInfoStringStub = "spdx_3.0";
2931
private string manifestFileNameStub = "manifest.spdx.json";
@@ -85,6 +87,12 @@ public void Get_ReturnsCorrectConfig_AdoStyleSbom()
8587
fileSystemUtilsMock
8688
.Setup(m => m.JoinPaths(spdxDirPathStub, Api.Utils.Constants.BsiFileName))
8789
.Returns(bsiFilePathStub);
90+
fileSystemUtilsMock
91+
.Setup(m => m.JoinPaths(spdxDirPathStub, Api.Utils.Constants.BsiCoseFileName))
92+
.Returns(bsiCoseFilePathStub);
93+
fileSystemUtilsMock
94+
.Setup(m => m.JoinPaths(spdxDirPathStub, Api.Utils.Constants.ManifestCoseFileName))
95+
.Returns(manifestCoseFilePathStub);
8896
fileSystemUtilsMock
8997
.Setup(m => m.FileExists($"{sbomFilePathStub}.sha256"))
9098
.Returns(true);
@@ -114,6 +122,12 @@ public void Get_ReturnsCorrectConfig_CloudBuildStyleSbom()
114122
fileSystemUtilsMock
115123
.Setup(m => m.JoinPaths(spdxDirPathStub, Api.Utils.Constants.BsiFileName))
116124
.Returns(bsiFilePathStub);
125+
fileSystemUtilsMock
126+
.Setup(m => m.JoinPaths(spdxDirPathStub, Api.Utils.Constants.BsiCoseFileName))
127+
.Returns(bsiCoseFilePathStub);
128+
fileSystemUtilsMock
129+
.Setup(m => m.JoinPaths(spdxDirPathStub, Api.Utils.Constants.ManifestCoseFileName))
130+
.Returns(manifestCoseFilePathStub);
117131
fileSystemUtilsMock
118132
.Setup(m => m.FileExists($"{sbomFilePathStub}.sha256"))
119133
.Returns(false);

test/Microsoft.Sbom.Api.Tests/VersionSpecificPins/Version_4_0/InterfaceConcretionTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ private class PinnedISbomConfig : ISbomConfig
220220
public string ManifestJsonFileSha256FilePath { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
221221
public string CatalogFilePath { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
222222
public string BsiFilePath { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
223+
public string BsiCoseFilePath { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
224+
public string ManifestCoseFilePath { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
223225
public ManifestInfo ManifestInfo { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
224226
public IMetadataBuilder MetadataBuilder { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
225227

0 commit comments

Comments
 (0)