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
Prev Previous commit
Next Next commit
Remove v2 interfaces, code cleanup
  • Loading branch information
DaveTryon committed Mar 3, 2025
commit bd00099a284c851e300c31ad2f3887fda2119deb
Original file line number Diff line number Diff line change
@@ -144,21 +144,8 @@ async Task Scan(string path)
licenseInformationRetrieved = true;

List<string> apiResponses;
var licenseInformationTimeoutInSecondsConfigSetting = configuration.LicenseInformationTimeoutInSeconds;

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

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

foreach (var response in apiResponses)
{
Original file line number Diff line number Diff line change
@@ -17,13 +17,6 @@ public interface ILicenseInformationFetcher
/// <returns></returns>
List<string> ConvertComponentsToListForApi(IEnumerable<ScannedComponent> scannedComponents);

/// <summary>
/// Calls the ClearlyDefined API to get the license information for the list of components. Uses a default timeout specified in implementation
/// </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>
/// <returns></returns>
Task<List<string>> FetchLicenseInformationAsync(List<string> listOfComponentsForApi);

/// <summary>
/// Gets the dictionary of licenses that were fetched from the ClearlyDefined API.
/// </summary>
@@ -55,7 +48,7 @@ public interface ILicenseInformationFetcher
/// 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>
/// <param name="timeoutInSeconds">Timeout in seconds to use when making web requests. Caller owns sanitizing this value</param>
/// <returns></returns>
Task<List<string>> FetchLicenseInformationAsync(List<string> listOfComponentsForApi, int timeoutInSeconds);
}
Original file line number Diff line number Diff line change
@@ -8,5 +8,5 @@ namespace Microsoft.Sbom.Api.Executors;

public interface ILicenseInformationService
{
public Task<List<string>> FetchLicenseInformationFromAPI(List<string> listOfComponentsForApi);
public Task<List<string>> FetchLicenseInformationFromAPI(List<string> listOfComponentsForApi, int timeoutInSeconds);
}
12 changes: 0 additions & 12 deletions src/Microsoft.Sbom.Api/Executors/ILicenseInformationService2.cs

This file was deleted.

16 changes: 1 addition & 15 deletions src/Microsoft.Sbom.Api/Executors/LicenseInformationFetcher.cs
Original file line number Diff line number Diff line change
@@ -82,23 +82,9 @@ public List<string> ConvertComponentsToListForApi(IEnumerable<ScannedComponent>
return listOfComponentsForApi;
}

public async Task<List<string>> FetchLicenseInformationAsync(List<string> listOfComponentsForApi)
{
return await licenseInformationService.FetchLicenseInformationFromAPI(listOfComponentsForApi);
}

public async Task<List<string>> FetchLicenseInformationAsync(List<string> listOfComponentsForApi, int timeoutInSeconds)
{
var licenseInformationService2 = licenseInformationService as ILicenseInformationService2;
if (licenseInformationService2 is null)
{
log.Warning("Timeout is specified in License Fetcher, but licenseInformationService does not implement ILicenseInformationService2");
return await licenseInformationService.FetchLicenseInformationFromAPI(listOfComponentsForApi);
}
else
{
return await licenseInformationService2.FetchLicenseInformationFromAPI(listOfComponentsForApi, timeoutInSeconds);
}
return await licenseInformationService.FetchLicenseInformationFromAPI(listOfComponentsForApi, timeoutInSeconds);
}

// Will attempt to extract license information from a clearlyDefined batch API response. Will always return a dictionary which may be empty depending on the response.
12 changes: 2 additions & 10 deletions src/Microsoft.Sbom.Api/Executors/LicenseInformationService.cs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@

namespace Microsoft.Sbom.Api.Executors;

public class LicenseInformationService : ILicenseInformationService2
public class LicenseInformationService : ILicenseInformationService
{
private readonly ILogger log;
private readonly IRecorder recorder;
@@ -28,11 +28,6 @@ public LicenseInformationService(ILogger log, IRecorder recorder, HttpClient htt
this.httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
}

public async Task<List<string>> FetchLicenseInformationFromAPI(List<string> listOfComponentsForApi)
{
return await FetchLicenseInformationFromAPI(listOfComponentsForApi, Common.Constants.MaxLicenseFetchTimeoutInSeconds);
}

public async Task<List<string>> FetchLicenseInformationFromAPI(List<string> listOfComponentsForApi, int timeoutInSeconds)
{
var batchSize = 500;
@@ -42,10 +37,7 @@ public async Task<List<string>> FetchLicenseInformationFromAPI(List<string> list
var uri = new Uri("https://api.clearlydefined.io/definitions?expand=-files");

httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
if (timeoutInSeconds > 0)
{
httpClient.Timeout = TimeSpan.FromSeconds(timeoutInSeconds);
} // The else cases should be sanitized in Config Sanitizer, and even if not, it'll just use httpClient's default timeout
httpClient.Timeout = TimeSpan.FromSeconds(timeoutInSeconds);

for (var i = 0; i < listOfComponentsForApi.Count; i += batchSize)
{
4 changes: 2 additions & 2 deletions src/Microsoft.Sbom.Common/Config/Configuration.cs
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ public class Configuration : IConfiguration
private static readonly AsyncLocal<ConfigurationSetting<string>> generationTimestamp = new();
private static readonly AsyncLocal<ConfigurationSetting<bool>> followSymlinks = new();
private static readonly AsyncLocal<ConfigurationSetting<bool>> fetchLicenseInformation = new();
private static readonly AsyncLocal<ConfigurationSetting<int>> licenseInformationTimeout = new(); // IConfiguration2
private static readonly AsyncLocal<ConfigurationSetting<int>> licenseInformationTimeout = new();
private static readonly AsyncLocal<ConfigurationSetting<bool>> enablePackageMetadataParsing = new();
private static readonly AsyncLocal<ConfigurationSetting<bool>> deleteManifestDirIfPresent = new();
private static readonly AsyncLocal<ConfigurationSetting<bool>> failIfNoPackages = new();
@@ -311,7 +311,7 @@ public ConfigurationSetting<bool> FetchLicenseInformation
set => fetchLicenseInformation.Value = value;
}

/// <inheritdoc cref="IConfiguration2.LicenseInformationTimeoutInSeconds" />
/// <inheritdoc cref="IConfiguration.LicenseInformationTimeoutInSeconds" />
[DefaultValue(Constants.DefaultLicenseFetchTimeoutInSeconds)]
public ConfigurationSetting<int> LicenseInformationTimeoutInSeconds
{
2 changes: 1 addition & 1 deletion src/Microsoft.Sbom.Common/Config/InputConfiguration.cs
Original file line number Diff line number Diff line change
@@ -141,7 +141,7 @@ public class InputConfiguration : IConfiguration
[DefaultValue(false)]
public ConfigurationSetting<bool> FetchLicenseInformation { get; set; }

/// <inheritdoc cref="IConfiguration2.LicenseInformationTimeoutInSeconds" />
/// <inheritdoc cref="IConfiguration.LicenseInformationTimeoutInSeconds" />
[DefaultValue(Constants.DefaultLicenseFetchTimeoutInSeconds)]
public ConfigurationSetting<int> LicenseInformationTimeoutInSeconds { get; set; }

Original file line number Diff line number Diff line change
@@ -75,15 +75,14 @@ private class PinnedILicenseInformationFetcher : ILicenseInformationFetcher
public void AppendLicensesToDictionary(Dictionary<string, string> partialLicenseDictionary) => throw new NotImplementedException();
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();
}

private class PinnedILicenstInformationSErvice : ILicenseInformationService
private class PinnedILicenstInformationService : ILicenseInformationService
{
public Task<List<string>> FetchLicenseInformationFromAPI(List<string> listOfComponentsForApi) => throw new NotImplementedException();
public Task<List<string>> FetchLicenseInformationFromAPI(List<string> listOfComponentsForApi, int timeoutInSeconds) => throw new NotImplementedException();
}

private class Pinned_SBOMReaderForExternalDocumentReference : ISbomReaderForExternalDocumentReference