Skip to content

Commit

Permalink
Move SBOM Tool to OSS
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Sigmund committed Jun 22, 2022
1 parent 1157f24 commit a92935c
Show file tree
Hide file tree
Showing 26 changed files with 359 additions and 250 deletions.
6 changes: 6 additions & 0 deletions Microsoft.Sbom.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Sbom.Api", "src\M
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Sbom.Api.Tests", "test\Microsoft.Sbom.Api.Tests\Microsoft.Sbom.Api.Tests.csproj", "{4F94EA4F-CC6B-4FA0-8A7E-654EAA26B625}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Sbom.Tool", "src\Microsoft.Sbom.Tool\Microsoft.Sbom.Tool.csproj", "{3B51DBCC-7305-42B9-8CBB-422F4291AF8E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -65,6 +67,10 @@ Global
{4F94EA4F-CC6B-4FA0-8A7E-654EAA26B625}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F94EA4F-CC6B-4FA0-8A7E-654EAA26B625}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F94EA4F-CC6B-4FA0-8A7E-654EAA26B625}.Release|Any CPU.Build.0 = Release|Any CPU
{3B51DBCC-7305-42B9-8CBB-422F4291AF8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3B51DBCC-7305-42B9-8CBB-422F4291AF8E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3B51DBCC-7305-42B9-8CBB-422F4291AF8E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3B51DBCC-7305-42B9-8CBB-422F4291AF8E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Binary file not shown.
30 changes: 30 additions & 0 deletions src/Microsoft.Sbom.Tool/Microsoft.Sbom.Tool.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PackAsTool>true</PackAsTool>
<ToolCommandName>manifesttool</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
<AssemblyName>Microsoft.Sbom.Tool</AssemblyName>
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>
<SignAssembly>true</SignAssembly>
<IsPublishable>true</IsPublishable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.Sbom.Api\Microsoft.Sbom.Api.csproj" />
<ProjectReference Include="..\Microsoft.Sbom.Common\Microsoft.Sbom.Common.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="signtool.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Update="MS.ThirdPartyMarketplaceRoot.cer">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
45 changes: 45 additions & 0 deletions src/Microsoft.Sbom.Tool/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using PowerArgs;
using Serilog;
using System;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.Sbom.Api;
//using Microsoft.Sbom.Common.Config;
using Microsoft.Sbom.Api.Config;

namespace Microsoft.Sbom.Tool
{
internal class Program
{
internal static string Name => NameValue.Value;

internal static string Version => VersionValue.Value;

private static readonly Lazy<string> NameValue = new Lazy<string>(() =>
{
return typeof(Program).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyProductAttribute>()?.Product ?? "DropValidator";
});

private static readonly Lazy<string> VersionValue = new Lazy<string>(() =>
{
return typeof(Program).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? string.Empty;
});

public static async Task<int> Main(string[] args)
{
var result = await Args.InvokeActionAsync<ManifestToolCmdRunner>(args);
Log.CloseAndFlush();
if (result.Cancelled || result.HandledException != null || result.Args.IsFailed)
{
if (result.Args != null && result.Args.IsAccessError)
{
return (int)ExitCode.WriteAccessError;
}

return (int)ExitCode.GeneralError;
}

return (int)ExitCode.Success;
}
}
}
Binary file added src/Microsoft.Sbom.Tool/signtool.exe
Binary file not shown.
45 changes: 23 additions & 22 deletions test/Microsoft.Sbom.Api.Tests/ApiConfigurationBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,36 @@
namespace Microsoft.Sbom.Api.Tests
{
/// <summary>
/// Responsible for testing <see cref="ApiConfigurationBuilder"/>
/// Responsible for testing <see cref="ApiConfigurationBuilder"/>.
/// </summary>
[TestClass]
public class ApiConfigurationBuilderTests
{
private const string rootPath = @"D:\TMP";
private const string RootPath = @"D:\TMP";
private const int MinParallelism = 2;
private const int DefaultParallelism = 8;
private const int MaxParallelism = 48;
private const string packageName = "packageName";
private const string packageVersion = "packageVersion";

ApiConfigurationBuilder builder = new ApiConfigurationBuilder();
SBOMMetadata metadata = new SBOMMetadata()
private const string PackageName = "packageName";
private const string PackageVersion = "packageVersion";
private readonly ApiConfigurationBuilder builder = new ApiConfigurationBuilder();
private readonly SBOMMetadata metadata = new SBOMMetadata()
{
PackageName = packageName,
PackageVersion = packageVersion,
PackageName = PackageName,
PackageVersion = PackageVersion,
};
RuntimeConfiguration runtime = new RuntimeConfiguration()

private readonly RuntimeConfiguration runtime = new RuntimeConfiguration()
{
Verbosity = EventLevel.Verbose,
WorkflowParallelism = DefaultParallelism,
DeleteManifestDirectoryIfPresent = true
};
string manifestDirPath = "manifestDirPath";
List<SBOMFile> files = new List<SBOMFile>();
List<SBOMPackage> packages = new List<SBOMPackage>();
string externalDocumentRefListFile = "externalDocRef";
string componentPath = @"D:\COMPONENT";

private readonly string manifestDirPath = "manifestDirPath";
private readonly List<SBOMFile> files = new List<SBOMFile>();
private readonly List<SBOMPackage> packages = new List<SBOMPackage>();
private readonly string externalDocumentRefListFile = "externalDocRef";
private readonly string componentPath = @"D:\COMPONENT";

[TestMethod]
public void GetConfiguration_PopulateAll()
Expand All @@ -57,14 +58,14 @@ public void GetConfiguration_PopulateAll()
Version = "2.2"
};

var config = builder.GetConfiguration(rootPath, manifestDirPath, files, packages, metadata, specs, runtime, externalDocumentRefListFile, componentPath);
var config = builder.GetConfiguration(RootPath, manifestDirPath, files, packages, metadata, specs, runtime, externalDocumentRefListFile, componentPath);

Assert.AreEqual(rootPath, config.BuildDropPath.Value);
Assert.AreEqual(RootPath, config.BuildDropPath.Value);
Assert.AreEqual(componentPath, config.BuildComponentPath.Value);
Assert.AreEqual(manifestDirPath, config.ManifestDirPath.Value);
Assert.AreEqual(ManifestToolActions.Generate, config.ManifestToolAction);
Assert.AreEqual(packageName, config.PackageName.Value);
Assert.AreEqual(packageVersion, config.PackageVersion.Value);
Assert.AreEqual(PackageName, config.PackageName.Value);
Assert.AreEqual(PackageVersion, config.PackageVersion.Value);
Assert.AreEqual(DefaultParallelism, config.Parallelism.Value);
Assert.AreEqual(LogEventLevel.Verbose, config.Verbosity.Value);
Assert.AreEqual(0, config.PackagesList.Value.ToList().Count);
Expand All @@ -89,7 +90,7 @@ public void GetConfiguration_PopulateAll()
[TestMethod]
public void GetConfiguration_NullProperties()
{
var config = builder.GetConfiguration(rootPath, manifestDirPath, null, null, metadata, null, runtime, null, componentPath);
var config = builder.GetConfiguration(RootPath, manifestDirPath, null, null, metadata, null, runtime, null, componentPath);

Assert.IsNull(config.PackagesList);
Assert.IsNull(config.FilesList);
Expand All @@ -102,7 +103,7 @@ public void GetConfiguration_NullProperties()
[DataRow(" ")]
public void GetConfiguration_NullComponentPath(string componentPath)
{
var config = builder.GetConfiguration(rootPath, manifestDirPath, null, null, metadata, null, runtime, null, componentPath);
var config = builder.GetConfiguration(RootPath, manifestDirPath, null, null, metadata, null, runtime, null, componentPath);

Assert.IsNull(config.BuildComponentPath);
}
Expand All @@ -123,7 +124,7 @@ public void GetConfiguration_ShouldMapVerbosity(EventLevel input, LogEventLevel
};

IConfiguration config = builder.GetConfiguration(
rootPath, string.Empty, null, null,
RootPath, string.Empty, null, null,
metadata, null, runtime);

Assert.AreEqual(output, config.Verbosity.Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ private Configuration GetConfigurationBaseObject()
};
}


[TestMethod]
public void SetValueForManifestInfoForValidation_Succeeds()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected void Init()
hashAlgorithmProvider.Init();

var configSanitizer = new ConfigSanitizer(hashAlgorithmProvider, fileSystemUtilsMock.Object, mockAssemblyConfig.Object);
object ctor(Type type)
object Ctor(Type type)
{
if (type == typeof(ConfigPostProcessor))
{
Expand All @@ -61,7 +61,7 @@ object ctor(Type type)

var mapperConfiguration = new MapperConfiguration(cfg =>
{
cfg.ConstructServicesUsing(ctor);
cfg.ConstructServicesUsing(Ctor);
cfg.AddProfile<ConfigurationProfile>();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public async Task ConfigurationBuilderTest_CombinesConfigs_NegativeParallism_Thr
var configuration = await cb.GetConfiguration(args);
}


[TestMethod]
public async Task ConfigurationBuilderTest_Validation_DefaultManifestDirPath_AddsManifestDir()
{
Expand Down
9 changes: 5 additions & 4 deletions test/Microsoft.Sbom.Api.Tests/Config/SBOMConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ public void SBOMConfig_NoBuildEnvironmentName_DefaultMetadataProvider_Returned()
}

private ISbomConfigProvider CreateSbomConfigs(IMetadataProvider[] metadataProviders) =>
new SbomConfigProvider(manifestConfigHandlers: new IManifestConfigHandler[] { configHandler.Object },
metadataProviders: metadataProviders,
logger: logger.Object,
recorder: recorder.Object);
new SbomConfigProvider(
manifestConfigHandlers: new IManifestConfigHandler[] { configHandler.Object },
metadataProviders: metadataProviders,
logger: logger.Object,
recorder: recorder.Object);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public async Task ConvertTestAsync()
{
var scannedComponents = new List<ScannedComponent>()
{
new ScannedComponent
new ScannedComponent
{
LocationsFoundAt = "test".Split(),
Component = new NuGetComponent("nugetpackage", "1.0.0")
},
new ScannedComponent
new ScannedComponent
{
LocationsFoundAt = "test".Split(),
Component = new NuGetComponent("nugetpackage2", "1.0.0")
Expand Down Expand Up @@ -161,11 +161,11 @@ public async Task ConvertWorksWithBuildComponentPathNull()
{
Component = new NuGetComponent("nugetpackage", "1.0.0")
},
new ScannedComponent
new ScannedComponent
{
Component = new NuGetComponent("nugetpackage2", "1.0.0")
},
new ScannedComponent
new ScannedComponent
{
Component = new GitComponent(new Uri("http://test.uri"), "hash")
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ namespace Microsoft.Sbom.Api.Tests.Executors
[TestClass]
public class ExternalDocumentReferenceWriterTest
{
private Mock<ILogger> mockLogger = new Mock<ILogger>();
private Mock<IRecorder> recorderMock = new Mock<IRecorder>();
private Mock<IFileSystemUtils> fileSystemUtilsMock = new Mock<IFileSystemUtils>();

private readonly Mock<ILogger> mockLogger = new Mock<ILogger>();
private readonly Mock<IRecorder> recorderMock = new Mock<IRecorder>();
private readonly Mock<IFileSystemUtils> fileSystemUtilsMock = new Mock<IFileSystemUtils>();

[TestMethod]
public async Task PassExternalDocumentReferenceInfosChannel_ReturnsJsonDocWithSerializer()
Expand Down
Loading

0 comments on commit a92935c

Please sign in to comment.