-
Notifications
You must be signed in to change notification settings - Fork 138
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
Users/ksigmund/sbom api oss #12
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7d32d23
Move Sbom.Api to OSS repo
7ca8733
Version cleanup
881aab8
Add Sbom.Api.Tests
ba99e97
Fix StyleCop issues
9208df2
Add copyright headers to tests
86fbef0
More StyleCop fixes
3536acf
Uncomment Sha1HashAlgorithm
9894b3f
Addressing PR comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,247 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using AutoMapper; | ||
using Microsoft.Sbom.Extensions; | ||
using Microsoft.Sbom.Extensions.Entities; | ||
using Microsoft.Sbom.Api.Converters; | ||
using Microsoft.Sbom.Api.Convertors; | ||
using Microsoft.Sbom.Api.Entities.Output; | ||
using Microsoft.Sbom.Api.Executors; | ||
using Microsoft.Sbom.Api.Filters; | ||
using Microsoft.Sbom.Api.Hashing; | ||
using Microsoft.Sbom.Api.Logging; | ||
using Microsoft.Sbom.Api.Manifest; | ||
using Microsoft.Sbom.Api.Manifest.Configuration; | ||
using Microsoft.Sbom.Api.Output; | ||
using Microsoft.Sbom.Api.Output.Telemetry; | ||
using Microsoft.Sbom.Api.Providers; | ||
using Microsoft.Sbom.Api.SignValidator; | ||
using Microsoft.Sbom.Api.Utils; | ||
using Microsoft.Sbom.Api.Workflows; | ||
using Microsoft.Sbom.Api.Workflows.Helpers; | ||
using Microsoft.Sbom.Common; | ||
using Microsoft.Sbom.Contracts.Interfaces; | ||
using Ninject; | ||
using Ninject.Extensions.Conventions; | ||
using Ninject.Modules; | ||
using Serilog; | ||
using Microsoft.Sbom.Api.Config; | ||
using Microsoft.Sbom.Common.Config.Validators; | ||
using Microsoft.Sbom.Common.Extensions; | ||
|
||
namespace Microsoft.Sbom.Api | ||
{ | ||
/// <summary> | ||
/// Creates the Ninject bindings for the whole project. | ||
/// </summary> | ||
/// <remarks> | ||
/// Microsoft.ManifestTool.Api.dll is the assembly name of the SBOM API project. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ManifestTool is an old name |
||
/// Using pattern matching until all bindings are in the same assembly. | ||
/// </remarks> | ||
public class Bindings : NinjectModule | ||
{ | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1123:Do not place regions within elements", Justification = "Enable documentation of code")] | ||
public override void Load() | ||
{ | ||
Bind<IFileSystemUtils>().ToProvider<FileSystemUtilsProvider>().InSingletonScope(); | ||
|
||
Bind<ValidationResultGenerator>().ToSelf(); | ||
Bind<IOutputWriter>().To<FileOutputWriter>(); | ||
Bind<IOSUtils>().To<OSUtils>().InSingletonScope(); | ||
Bind<IEnvironmentWrapper>().To<EnvironmentWrapper>().InSingletonScope(); | ||
Bind<ConfigFileParser>().ToSelf(); | ||
Bind<IJsonArrayGenerator>().To<FileArrayGenerator>().Named(nameof(FileArrayGenerator)); | ||
Bind<IJsonArrayGenerator>().To<PackageArrayGenerator>().Named(nameof(PackageArrayGenerator)); | ||
Bind<IJsonArrayGenerator>().To<RelationshipsArrayGenerator>().Named(nameof(RelationshipsArrayGenerator)); | ||
Bind<IJsonArrayGenerator>().To<ExternalDocumentReferenceGenerator>().Named(nameof(ExternalDocumentReferenceGenerator)); | ||
Bind<ComponentDetector>().ToSelf(); | ||
Bind<IAssemblyConfig>().To<AssemblyConfig>().InSingletonScope(); | ||
|
||
Bind<IFilter>().To<DownloadedRootPathFilter>().Named(nameof(DownloadedRootPathFilter)).OnActivation(f => f.Init()); | ||
Bind<IFilter>().To<ManifestFolderFilter>().Named(nameof(ManifestFolderFilter)).OnActivation(f => f.Init()); | ||
|
||
Bind<ILogger>().ToProvider<LoggerProvider>(); | ||
|
||
#region Bind all manifest parsers | ||
|
||
// Search external assemblies | ||
Kernel.Bind(scan => scan | ||
.FromAssembliesMatching("*Parsers*") | ||
.SelectAllClasses() | ||
.InheritedFrom<IManifestInterface>() | ||
.BindAllInterfaces()); | ||
|
||
// Search this assembly in case --self-contained is used with dotnet publish | ||
Kernel.Bind(scan => scan | ||
.FromThisAssembly() | ||
.SelectAllClasses() | ||
.InheritedFrom<IManifestInterface>() | ||
.BindAllInterfaces()); | ||
|
||
Bind<ManifestData>().ToProvider<ManifestDataProvider>().InSingletonScope(); | ||
Bind<ManifestParserProvider>().ToSelf().InSingletonScope().OnActivation<ManifestParserProvider>(m => m.Init()); | ||
|
||
#endregion | ||
|
||
#region Bind all manifest generators | ||
|
||
// Search external assemblies | ||
Kernel.Bind(scan => scan | ||
.FromAssembliesMatching("*Parsers*") | ||
.SelectAllClasses() | ||
.InheritedFrom<IManifestGenerator>() | ||
.BindAllInterfaces()); | ||
|
||
// Search this assembly in case --self-contained is used with dotnet publish | ||
Kernel.Bind(scan => scan | ||
.FromThisAssembly() | ||
.SelectAllClasses() | ||
.InheritedFrom<IManifestGenerator>() | ||
.BindAllInterfaces()); | ||
|
||
Bind<ManifestGeneratorProvider>().ToSelf().InSingletonScope().OnActivation<ManifestGeneratorProvider>(mg => mg.Init()); | ||
|
||
#endregion | ||
|
||
#region Bind all signature validators | ||
Kernel.Bind(scan => scan | ||
.FromAssembliesMatching("*Parsers*") | ||
.SelectAllClasses() | ||
.InheritedFrom<ISignValidator>() | ||
.BindAllInterfaces()); | ||
|
||
Kernel.Bind(scan => scan | ||
.FromThisAssembly() | ||
.SelectAllClasses() | ||
.InheritedFrom<ISignValidator>() | ||
.BindAllInterfaces()); | ||
|
||
Bind<SignValidationProvider>().ToSelf().InSingletonScope().OnActivation<SignValidationProvider>(s => s.Init()); | ||
|
||
#endregion | ||
|
||
#region Manifest Config | ||
|
||
Kernel.Bind(scan => scan | ||
.FromAssembliesMatching("*Parsers*") | ||
.SelectAllClasses() | ||
.InheritedFrom<IManifestConfigHandler>() | ||
.BindAllInterfaces()); | ||
|
||
Kernel.Bind(scan => scan | ||
.FromThisAssembly() | ||
.SelectAllClasses() | ||
.InheritedFrom<IManifestConfigHandler>() | ||
.BindAllInterfaces()); | ||
|
||
Bind<ISbomConfigProvider>().To<SbomConfigProvider>().InSingletonScope(); | ||
Bind<ISbomConfigFactory>().To<SbomConfigFactory>(); | ||
|
||
#endregion | ||
|
||
#region QuickBuild Manifest workflow bindings | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think QB is internal |
||
Bind<IHashCodeGenerator>().To<HashCodeGenerator>(); | ||
Bind<IManifestPathConverter>().To<DropValidatorManifestPathConverter>(); | ||
#endregion | ||
|
||
#region AutoMapper bindings | ||
var mapperConfiguration = new MapperConfiguration(cfg => cfg.AddProfile<ConfigurationProfile>()); | ||
mapperConfiguration.AssertConfigurationIsValid(); | ||
Bind<MapperConfiguration>().ToConstant(mapperConfiguration).InSingletonScope(); | ||
Bind<IMapper>().ToMethod(ctx => | ||
new Mapper(mapperConfiguration, type => ctx.Kernel.Get(type))); | ||
|
||
#endregion | ||
|
||
#region Workflows | ||
|
||
Bind<IWorkflow>().To<DropValidatorWorkflow>().Named(nameof(DropValidatorWorkflow)); | ||
Bind<IWorkflow>().To<SBOMGenerationWorkflow>().Named(nameof(SBOMGenerationWorkflow)); | ||
|
||
#endregion | ||
|
||
Kernel.Bind(scan => scan | ||
.FromThisAssembly() | ||
.SelectAllClasses() | ||
.InheritedFrom<ConfigValidator>() | ||
.BindAllBaseClasses()); | ||
|
||
#region Bind metadata providers | ||
|
||
Kernel.Bind(scan => scan | ||
.FromAssembliesInPath(new AssemblyConfig().AssemblyDirectory) | ||
.SelectAllClasses() | ||
.InheritedFrom<IMetadataProvider>() | ||
.BindAllInterfaces()); | ||
|
||
Bind<IMetadataBuilderFactory>().To<MetadataBuilderFactory>(); | ||
|
||
#endregion | ||
|
||
#region Bind all sources providers. | ||
Kernel.Bind(scan => scan | ||
.FromThisAssembly() | ||
.SelectAllClasses() | ||
.InheritedFrom<ISourcesProvider>() | ||
.BindAllInterfaces()); | ||
#endregion | ||
|
||
#region Converters | ||
|
||
Bind<ComponentToExternalReferenceInfoConverter>().ToSelf().InThreadScope(); | ||
Bind<ExternalReferenceInfoToPathConverter>().ToSelf().InThreadScope(); | ||
|
||
#endregion | ||
|
||
#region Executors | ||
|
||
Bind<ChannelUtils>().ToSelf().InThreadScope(); | ||
Bind<FileHasher>().ToSelf().InThreadScope(); | ||
Bind<HashValidator>().ToSelf().InThreadScope(); | ||
Bind<DirectoryWalker>().ToSelf().InThreadScope(); | ||
Bind<FileListEnumerator>().ToSelf().InThreadScope(); | ||
Bind<ManifestFileFilterer>().ToSelf().InThreadScope(); | ||
Bind<ManifestFolderFilterer>().ToSelf().InThreadScope(); | ||
Bind<PackagesWalker>().ToSelf().InThreadScope(); | ||
Bind<SBOMComponentsWalker>().ToSelf().InThreadScope(); | ||
Bind<ComponentToPackageInfoConverter>().ToSelf().InThreadScope(); | ||
Bind<RelationshipGenerator>().ToSelf().InThreadScope(); | ||
Bind<SBOMFileToFileInfoConverter>().ToSelf().InThreadScope(); | ||
Bind<SBOMPackageToPackageInfoConverter>().ToSelf().InThreadScope(); | ||
Bind<ExternalDocumentReferenceWriter>().ToSelf().InThreadScope(); | ||
Bind<ISBOMReaderForExternalDocumentReference>().To<SPDXSBOMReaderForExternalDocumentReference>().InThreadScope(); | ||
|
||
#endregion | ||
|
||
#region Bind all hash algorithm providers | ||
|
||
// TODO: Put all dependent assemblies in the plugins folder and search using | ||
// that path here. | ||
Kernel.Bind(scan => scan | ||
.FromAssembliesMatching("*Parsers*", "*Contract*") | ||
.SelectAllClasses() | ||
.InheritedFrom<IAlgorithmNames>() | ||
.BindAllInterfaces()); | ||
|
||
// We should move all algorithm implementations into their own lib, so that | ||
// we can remove this additional scan. | ||
Kernel.Bind(scan => scan. | ||
FromThisAssembly() | ||
.SelectAllClasses() | ||
.InheritedFrom<IAlgorithmNames>() | ||
.BindAllInterfaces()); | ||
|
||
Bind<IHashAlgorithmProvider>().To<HashAlgorithmProvider>().InSingletonScope(); | ||
|
||
#endregion | ||
|
||
Bind<IRecorder>().To<TelemetryRecorder>().InSingletonScope(); | ||
Bind<ComponentDetectorCachedExecutor>().ToSelf().InSingletonScope(); | ||
Bind<ExternalReferenceDeduplicator>().ToSelf().InSingletonScope(); | ||
Bind<InternalSBOMFileInfoDeduplicator>().ToSelf().InSingletonScope(); | ||
Bind<IFileTypeUtils>().To<FileTypeUtils>().InSingletonScope(); | ||
Bind<IFileSystemUtilsExtension>().To<FileSystemUtilsExtension>().InSingletonScope(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this a fix for the issue you mentioned today?