Skip to content
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

API BREAKING CHANGE: Remove back-compat interface shims #952

Merged
merged 4 commits into from
Mar 3, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions src/Microsoft.Sbom.Api/Config/ConfigSanitizer.cs
Original file line number Diff line number Diff line change
@@ -78,32 +78,28 @@ public IConfiguration SanitizeConfig(IConfiguration configuration)
// Set default package supplier if not provided in configuration.
configuration.PackageSupplier = GetPackageSupplierFromAssembly(configuration, logger);

var configuration2 = configuration as IConfiguration2;
if (configuration2 is not null)
// Prevent null value for LicenseInformationTimeoutInSeconds.
// Values of (0, Constants.MaxLicenseFetchTimeoutInSeconds] are allowed. Negative values are replaced with the default, and
// the higher values are truncated to the maximum of Common.Constants.MaxLicenseFetchTimeoutInSeconds
if (configuration.LicenseInformationTimeoutInSeconds is null)
{
// Prevent null value for LicenseInformationTimeoutInSeconds.
// Values of (0, Constants.MaxLicenseFetchTimeoutInSeconds] are allowed. Negative values are replaced with the default, and
// the higher values are truncated to the maximum of Common.Constants.MaxLicenseFetchTimeoutInSeconds
if (configuration2.LicenseInformationTimeoutInSeconds is null)
{
configuration2.LicenseInformationTimeoutInSeconds = new(Common.Constants.DefaultLicenseFetchTimeoutInSeconds, SettingSource.Default);
}
else if (configuration2.LicenseInformationTimeoutInSeconds.Value <= 0)
{
logger.Warning($"Negative and Zero Values not allowed for timeout. Using the default {Common.Constants.DefaultLicenseFetchTimeoutInSeconds} seconds instead.");
configuration2.LicenseInformationTimeoutInSeconds.Value = Common.Constants.DefaultLicenseFetchTimeoutInSeconds;
}
else if (configuration2.LicenseInformationTimeoutInSeconds.Value > Common.Constants.MaxLicenseFetchTimeoutInSeconds)
{
logger.Warning($"Specified timeout exceeds maximum allowed. Truncating the timeout to {Common.Constants.MaxLicenseFetchTimeoutInSeconds} seconds.");
configuration2.LicenseInformationTimeoutInSeconds.Value = Common.Constants.MaxLicenseFetchTimeoutInSeconds;
}
configuration.LicenseInformationTimeoutInSeconds = new(Common.Constants.DefaultLicenseFetchTimeoutInSeconds, SettingSource.Default);
}
else if (configuration.LicenseInformationTimeoutInSeconds.Value <= 0)
{
logger.Warning($"Negative and Zero Values not allowed for timeout. Using the default {Common.Constants.DefaultLicenseFetchTimeoutInSeconds} seconds instead.");
configuration.LicenseInformationTimeoutInSeconds.Value = Common.Constants.DefaultLicenseFetchTimeoutInSeconds;
}
else if (configuration.LicenseInformationTimeoutInSeconds.Value > Common.Constants.MaxLicenseFetchTimeoutInSeconds)
{
logger.Warning($"Specified timeout exceeds maximum allowed. Truncating the timeout to {Common.Constants.MaxLicenseFetchTimeoutInSeconds} seconds.");
configuration.LicenseInformationTimeoutInSeconds.Value = Common.Constants.MaxLicenseFetchTimeoutInSeconds;
}

// Check if arg -lto is specified but -li is not
if (configuration.FetchLicenseInformation?.Value != true && !configuration2.LicenseInformationTimeoutInSeconds.IsDefaultSource)
{
logger.Warning("A license fetching timeout is specified (argument -lto), but this has no effect when FetchLicenseInfo is unspecified or false (argument -li)");
}
// Check if arg -lto is specified but -li is not
if (configuration.FetchLicenseInformation?.Value != true && !configuration.LicenseInformationTimeoutInSeconds.IsDefaultSource)
{
logger.Warning("A license fetching timeout is specified (argument -lto), but this has no effect when FetchLicenseInfo is unspecified or false (argument -li)");
}

// Replace backslashes in directory paths with the OS-sepcific directory separator character.
Original file line number Diff line number Diff line change
@@ -144,21 +144,20 @@ async Task Scan(string path)
licenseInformationRetrieved = true;

List<string> apiResponses;
var licenseInformationFetcher2 = licenseInformationFetcher as ILicenseInformationFetcher2;
var licenseInformationTimeoutInSecondsConfigSetting = GetLicenseInformationTimeoutInSecondsSetting(configuration);
var licenseInformationTimeoutInSecondsConfigSetting = configuration.LicenseInformationTimeoutInSeconds;

if (licenseInformationFetcher2 is null && (bool)!licenseInformationTimeoutInSecondsConfigSetting?.IsDefaultSource)
if (licenseInformationFetcher is null && (bool)!licenseInformationTimeoutInSecondsConfigSetting?.IsDefaultSource)
{
log.Warning("Timeout value is specified, but ILicenseInformationFetcher2 is not implemented for the licenseInformationFetcher");
}

if (licenseInformationFetcher2 is null || licenseInformationTimeoutInSecondsConfigSetting is null)
if (licenseInformationFetcher is null || licenseInformationTimeoutInSecondsConfigSetting is null)
{
apiResponses = await licenseInformationFetcher.FetchLicenseInformationAsync(listOfComponentsForApi);
}
else
{
apiResponses = await licenseInformationFetcher2.FetchLicenseInformationAsync(listOfComponentsForApi, licenseInformationTimeoutInSecondsConfigSetting.Value);
apiResponses = await licenseInformationFetcher.FetchLicenseInformationAsync(listOfComponentsForApi, licenseInformationTimeoutInSecondsConfigSetting.Value);
}

foreach (var response in apiResponses)
@@ -233,15 +232,4 @@ async Task Scan(string path)
}

protected abstract IEnumerable<ScannedComponent> FilterScannedComponents(ScanResult result);

private ConfigurationSetting<int>? GetLicenseInformationTimeoutInSecondsSetting(IConfiguration configuration)
{
var configuration2 = configuration as IConfiguration2;
if (configuration2 is not null)
{
return configuration2.LicenseInformationTimeoutInSeconds;
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -50,4 +50,12 @@ public interface ILicenseInformationFetcher
/// <param name="key">The "name@version" of a component.</param>
/// <returns></returns>
public string GetFromLicenseDictionary(string key);

/// <summary>
/// Calls the ClearlyDefined API to get the license information for the list of components.
/// </summary>
/// <param name="listOfComponentsForApi"> A list of strings formatted into a list of strings that can be used to call the batch ClearlyDefined API.</param>
/// <param name="timeoutInSeconds">Timeout in seconds to use when making web requests</param>
/// <returns></returns>
Task<List<string>> FetchLicenseInformationAsync(List<string> listOfComponentsForApi, int timeoutInSeconds);
}
18 changes: 0 additions & 18 deletions src/Microsoft.Sbom.Api/Executors/ILicenseInformationFetcher2.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@

namespace Microsoft.Sbom.Api.Executors;

public class LicenseInformationFetcher : ILicenseInformationFetcher2
public class LicenseInformationFetcher : ILicenseInformationFetcher
{
private readonly ILogger log;
private readonly IRecorder recorder;
2 changes: 1 addition & 1 deletion src/Microsoft.Sbom.Common/Config/Configuration.cs
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ namespace Microsoft.Sbom.Common.Config;

[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1311:Static readonly fields should begin with upper-case letter", Justification = "Private fields with the same name as public properties.")]
[SuppressMessage("Naming", "CA1724:Type names should not match namespaces", Justification = "This is the configuration class")]
public class Configuration : IConfiguration2
public class Configuration : IConfiguration
{
private static readonly AsyncLocal<ConfigurationSetting<string>> buildDropPath = new();
private static readonly AsyncLocal<ConfigurationSetting<string>> buildComponentPath = new();
6 changes: 6 additions & 0 deletions src/Microsoft.Sbom.Common/Config/IConfiguration.cs
Original file line number Diff line number Diff line change
@@ -212,4 +212,10 @@ public interface IConfiguration
/// The compliance standard to validate against.
/// </summary>
ConfigurationSetting<string> ComplianceStandard { get; set; }

/// Specifies the timeout in seconds for fetching the license information. Defaults to <see cref="Constants.DefaultLicenseFetchTimeoutInSeconds"/>.
/// Has no effect if FetchLicenseInformation (li) argument is false or not provided. Negative values are set to the default and values exceeding the
/// maximum are truncated to <see cref="Constants.MaxLicenseFetchTimeoutInSeconds"/>
/// </summary>
ConfigurationSetting<int> LicenseInformationTimeoutInSeconds { get; set; }
}
19 changes: 0 additions & 19 deletions src/Microsoft.Sbom.Common/Config/IConfiguration2.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Microsoft.Sbom.Common/Config/InputConfiguration.cs
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
namespace Microsoft.Sbom.Common.Config;

[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1311:Static readonly fields should begin with upper-case letter", Justification = "Private fields with the same name as public properties.")]
public class InputConfiguration : IConfiguration2
public class InputConfiguration : IConfiguration
{
/// <inheritdoc cref="IConfiguration.BuildDropPath" />
[DirectoryExists]
Original file line number Diff line number Diff line change
@@ -76,6 +76,7 @@ private class PinnedILicenseInformationFetcher : ILicenseInformationFetcher
public Dictionary<string, string> ConvertClearlyDefinedApiResponseToList(string httpResponseContent) => throw new NotImplementedException();
public List<string> ConvertComponentsToListForApi(IEnumerable<ScannedComponent> scannedComponents) => throw new NotImplementedException();
public Task<List<string>> FetchLicenseInformationAsync(List<string> listOfComponentsForApi) => throw new NotImplementedException();
public Task<List<string>> FetchLicenseInformationAsync(List<string> listOfComponentsForApi, int timeoutInSeconds) => throw new NotImplementedException();
public string GetFromLicenseDictionary(string key) => throw new NotImplementedException();
public ConcurrentDictionary<string, string> GetLicenseDictionary() => throw new NotImplementedException();
}
@@ -330,6 +331,7 @@ private class PinnedIConfiguration : IConfiguration
public ConfigurationSetting<string> SbomPath { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public ConfigurationSetting<string> SbomDir { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public ConfigurationSetting<string> ComplianceStandard { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public ConfigurationSetting<int> LicenseInformationTimeoutInSeconds { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
}

private class PinnedISettingSourceable : ISettingSourceable