Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"reihitsu.cli": {
"version": "1.5.0",
"version": "1.6.0",
"commands": [
"reihitsu-format"
],
Expand Down
7 changes: 6 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,13 @@ dotnet_diagnostic.CA2241.severity = warning
dotnet_diagnostic.CA2242.severity = warning

# Diagnostics: IDE
dotnet_diagnostic.IDE0001.severity = warning
dotnet_diagnostic.IDE0001.severity = error
dotnet_diagnostic.IDE0028.severity = error
dotnet_diagnostic.IDE0090.severity = error
dotnet_diagnostic.IDE0300.severity = error
dotnet_diagnostic.IDE0301.severity = error
dotnet_diagnostic.IDE0305.severity = error
dotnet_diagnostic.IDE0350.severity = error
dotnet_diagnostic.IDE1006.severity = error

# Diagnostics: MSTEST
Expand Down
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="AngleSharp" Version="1.11.0" />
<PackageVersion Include="AngleSharp" Version="1.10.5" />
<PackageVersion Include="bunit" Version="2.15.2" />
<PackageVersion Include="coverlet.collector" Version="10.1.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="11.0.0" />
Expand All @@ -25,7 +25,7 @@
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.21.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.21.0" />
<!-- Code analysis (every project); reihitsu.cli in .config/dotnet-tools.json stays at the analyzer's version -->
<PackageVersion Include="Reihitsu.Analyzer" Version="1.5.0" />
<PackageVersion Include="Reihitsu.Analyzer" Version="1.6.0" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="10.37.0.15768" />
<PackageVersion Include="SQLitePCLRaw.lib.e_sqlite3" Version="3.53.3" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions DockerUpdateGuard.slnx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Solution>
<Folder Name="/00 Solution items/">
<File Path=".config/dotnet-tools.json" />
<File Path=".dockerignore" />
<File Path=".editorconfig" />
<File Path=".gitignore" />
Expand Down
4 changes: 2 additions & 2 deletions SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ο»Ώusing System.Reflection;
using System.Reflection;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
Expand All @@ -10,4 +10,4 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

[assembly: AssemblyVersion("1.3.*")]
[assembly: AssemblyVersion("1.4.*")]
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static async Task<IReadOnlyList<CurrentContainerSnapshotData>> GetCurrent
var currentSnapshots = new List<CurrentContainerSnapshotData>();

await AddRuntimeScanSnapshotsAsync(dbContext, targetScanRunByInstance, currentSnapshots, cancellationToken).ConfigureAwait(false);
await AddFallbackSnapshotsAsync(dbContext, targetScanRunByInstance.Keys.ToList(), currentSnapshots, cancellationToken).ConfigureAwait(false);
await AddFallbackSnapshotsAsync(dbContext, [.. targetScanRunByInstance.Keys], currentSnapshots, cancellationToken).ConfigureAwait(false);

return currentSnapshots;
}
Expand Down
53 changes: 26 additions & 27 deletions src/DockerUpdateGuard.Data/Queries/SharedBaseImageQueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,21 @@ private static SharedBaseImageUsageData CreateUsageData(IGrouping<string, Shared
return new SharedBaseImageUsageData
{
BaseImageVersionId = first.BaseImageVersionId,
BaseImageVersionIds = group.Select(entity => entity.BaseImageVersionId)
.Distinct()
.ToList(),
BaseImageVersionIds = [.. group.Select(entity => entity.BaseImageVersionId).Distinct()],
Registry = first.Registry,
Repository = first.Repository,
Tag = first.Tag,
Digest = first.Digest,
SourceReferences = group.Select(entity => entity.SourceReference ?? string.Empty)
.Where(entity => string.IsNullOrWhiteSpace(entity) == false)
.Distinct(StringComparer.OrdinalIgnoreCase)
.OrderBy(entity => entity, StringComparer.OrdinalIgnoreCase)
.ToList(),
SourceReferences = [
.. group.Select(entity => entity.SourceReference ?? string.Empty)
.Where(entity => string.IsNullOrWhiteSpace(entity) == false)
.Distinct(StringComparer.OrdinalIgnoreCase)
.OrderBy(entity => entity, StringComparer.OrdinalIgnoreCase)
],
ObservedImageCount = group.Select(entity => entity.ObservedImageId)
.Distinct()
.Count(),
ConsumingImageVersionIds = group.Select(entity => entity.CurrentImageVersionId)
.Distinct()
.ToList(),
ConsumingImageVersionIds = [.. group.Select(entity => entity.CurrentImageVersionId).Distinct()],
};
}

Expand Down Expand Up @@ -154,18 +151,19 @@ public async Task<IReadOnlyList<SharedBaseImageUsageData>> GetBaseImagesAsync(Ca
{
var flatResults = await QueryBaseImageUsageRowsAsync(cancellationToken).ConfigureAwait(false);

return flatResults.GroupBy(entity => BuildGroupingKey(entity.Registry,
entity.Repository,
entity.Tag,
entity.Digest,
entity.SourceReference),
StringComparer.OrdinalIgnoreCase)
.Select(CreateUsageData)
.OrderByDescending(entity => entity.ObservedImageCount)
.ThenBy(entity => entity.Registry)
.ThenBy(entity => entity.Repository)
.ThenBy(entity => entity.Tag)
.ToList();
return [
.. flatResults.GroupBy(entity => BuildGroupingKey(entity.Registry,
entity.Repository,
entity.Tag,
entity.Digest,
entity.SourceReference),
StringComparer.OrdinalIgnoreCase)
.Select(CreateUsageData)
.OrderByDescending(entity => entity.ObservedImageCount)
.ThenBy(entity => entity.Registry)
.ThenBy(entity => entity.Repository)
.ThenBy(entity => entity.Tag)
];
}

/// <inheritdoc/>
Expand Down Expand Up @@ -214,10 +212,11 @@ public async Task<IReadOnlyList<ObservedImageReferenceData>> GetObservedImagesBy
.ToListAsync(cancellationToken)
.ConfigureAwait(false);

return flatResults.GroupBy(entity => entity.ObservedImageId)
.Select(group => group.First())
.OrderBy(entity => entity.ObservedImageName)
.ToList();
return [
.. flatResults.GroupBy(entity => entity.ObservedImageId)
.Select(group => group.First())
.OrderBy(entity => entity.ObservedImageName)
];
}

#endregion // ISharedBaseImageQueryService
Expand Down
3 changes: 2 additions & 1 deletion src/DockerUpdateGuard/ApplicationInitializationExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DockerUpdateGuard.Configuration;
using DockerUpdateGuard.Data;
using DockerUpdateGuard.Images;
using DockerUpdateGuard.Images.Interfaces;
using DockerUpdateGuard.Portainer;
Expand Down Expand Up @@ -31,7 +32,7 @@ public static async Task InitializeDockerUpdateGuardAsync(this WebApplication ap

await using (scope.ConfigureAwait(false))
{
var dbContext = scope.ServiceProvider.GetRequiredService<DockerUpdateGuard.Data.DockerUpdateGuardDbContext>();
var dbContext = scope.ServiceProvider.GetRequiredService<DockerUpdateGuardDbContext>();
var instanceDiscoveryService = scope.ServiceProvider.GetRequiredService<IInstanceDiscoveryService>();
var applicationTelemetry = scope.ServiceProvider.GetRequiredService<ApplicationTelemetry>();
var applicationOptions = scope.ServiceProvider.GetRequiredService<IOptions<DockerUpdateGuardOptions>>().Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private List<VulnerabilityFindingViewData> GetFilteredFindings()
findings = findings.Where(MatchesSearchText);
}

return findings.ToList();
return [.. findings];
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ private static List<ResourceUsagePointViewData> GetChronologicalHistory(IReadOnl
{
ArgumentNullException.ThrowIfNull(history);

return history.OrderBy(point => point.RecordedAtUtc)
.ToList();
return [.. history.OrderBy(point => point.RecordedAtUtc)];
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private List<VulnerabilityOverviewItemData> GetFilteredItems()
items = items.Where(MatchesSearchText);
}

return items.ToList();
return [.. items];
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/DockerUpdateGuard/Docker/DockerInstanceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public sealed class DockerInstanceClient : IDockerInstanceClient, IDisposable
/// <summary>
/// Image reference parser
/// </summary>
private static readonly ImageReferenceParser _imageReferenceParser = new ImageReferenceParser();
private static readonly ImageReferenceParser _imageReferenceParser = new();

/// <summary>
/// Tracks Docker instance names for which the disabled-certificate-validation warning has already been emitted
Expand All @@ -49,7 +49,7 @@ public sealed class DockerInstanceClient : IDockerInstanceClient, IDisposable
/// <summary>
/// Client certificate loader
/// </summary>
private static readonly ClientCertificateLoader _clientCertificateLoader = new ClientCertificateLoader();
private static readonly ClientCertificateLoader _clientCertificateLoader = new();

/// <summary>
/// Pooled HTTP clients keyed by their connection-relevant configuration to avoid the new-client-per-request anti-pattern
Expand Down Expand Up @@ -869,7 +869,7 @@ private static async Task<ExternalOperationResult<DockerImageInspectData>> ReadI
using var jsonDocument = await RemoteJsonDocument.ParseObjectAsync(responseStream, requestTimeoutSource.Token)
.ConfigureAwait(false);

return ExternalOperationResult.Succeeded<DockerImageInspectData>(ParseImageInspect(jsonDocument.RootElement));
return ExternalOperationResult.Succeeded(ParseImageInspect(jsonDocument.RootElement));
}
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
Expand Down Expand Up @@ -1423,7 +1423,7 @@ public async Task<ExternalOperationResult<long>> GetHostMemoryTotalAsync(DockerI
using var jsonDocument = await RemoteJsonDocument.ParseAsync(responseStream, requestTimeoutSource.Token)
.ConfigureAwait(false);

return ExternalOperationResult.Succeeded<long>(TryGetInt64(jsonDocument.RootElement, "MemTotal"));
return ExternalOperationResult.Succeeded(TryGetInt64(jsonDocument.RootElement, "MemTotal"));
}
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
Expand Down
4 changes: 2 additions & 2 deletions src/DockerUpdateGuard/DockerHub/DockerHubAccessTokenCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public async Task<ExternalOperationResult<string>> GetOrRequestAsync(Uri loginUr

if (TryGetValidToken(loginKey, trimmedUserName, fingerprint, out var cachedToken))
{
return ExternalOperationResult.Succeeded<string>(cachedToken);
return ExternalOperationResult.Succeeded(cachedToken);
}

await _loginLock.WaitAsync(cancellationToken)
Expand All @@ -152,7 +152,7 @@ await _loginLock.WaitAsync(cancellationToken)
{
if (TryGetValidToken(loginKey, trimmedUserName, fingerprint, out cachedToken))
{
return ExternalOperationResult.Succeeded<string>(cachedToken);
return ExternalOperationResult.Succeeded(cachedToken);
}

using var timeoutSource = new CancellationTokenSource(loginTimeout, _timeProvider);
Expand Down
20 changes: 10 additions & 10 deletions src/DockerUpdateGuard/DockerHub/DockerHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ private async Task<ExternalOperationResult<bool>> ApplyAuthenticationAsync(HttpR

if (string.IsNullOrWhiteSpace(options.Pat))
{
return ExternalOperationResult.Succeeded<bool>(true);
return ExternalOperationResult.Succeeded(true);
}

if (string.IsNullOrWhiteSpace(options.UserName))
Expand All @@ -929,7 +929,7 @@ private async Task<ExternalOperationResult<bool>> ApplyAuthenticationAsync(HttpR

request.Headers.Authorization = new AuthenticationHeaderValue(BearerScheme, accessTokenResult.Data);

return ExternalOperationResult.Succeeded<bool>(true);
return ExternalOperationResult.Succeeded(true);
}

/// <summary>
Expand Down Expand Up @@ -1027,7 +1027,7 @@ private async Task<ExternalOperationResult<string>> RequestAccessTokenAsync(stri

return string.IsNullOrWhiteSpace(token)
? ExternalOperationResult.Failed<string>("Docker Hub authentication token response did not contain a token")
: ExternalOperationResult.Succeeded<string>(token);
: ExternalOperationResult.Succeeded(token);
}
}

Expand Down Expand Up @@ -1273,10 +1273,10 @@ public async Task<ExternalOperationResult<DockerHubAuthenticatedUserData>> GetCu

_logger.DockerHubAuthenticatedAccountResolved(userName);

return ExternalOperationResult.Succeeded<DockerHubAuthenticatedUserData>(new DockerHubAuthenticatedUserData
{
UserName = userName,
});
return ExternalOperationResult.Succeeded(new DockerHubAuthenticatedUserData
{
UserName = userName,
});
}
},
cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -1364,7 +1364,7 @@ public async Task<ExternalOperationResult<DockerHubRepositoryData>> GetRepositor
LastUpdatedAtUtc = TryGetDateTimeOffset(root, "last_updated"),
};

return ExternalOperationResult.Succeeded<DockerHubRepositoryData>(repositoryData);
return ExternalOperationResult.Succeeded(repositoryData);
}
},
cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -1436,7 +1436,7 @@ public async Task<ExternalOperationResult<DockerHubTagData>> GetTagAsync(ImageRe

tagData.PlatformDigests = ReadPlatformDigests(jsonDocument.RootElement);

return ExternalOperationResult.Succeeded<DockerHubTagData>(tagData);
return ExternalOperationResult.Succeeded(tagData);
}
},
cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -1526,7 +1526,7 @@ public async Task<ExternalOperationResult<RegistryImageConfigurationData>> GetIm

return imageConfiguration is null
? ExternalOperationResult.Failed<RegistryImageConfigurationData>($"Image configuration blob could not be read for '{imageReference.FullReference}'")
: ExternalOperationResult.Succeeded<RegistryImageConfigurationData>(imageConfiguration);
: ExternalOperationResult.Succeeded(imageConfiguration);
},
cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ private static bool MatchesRepository(ObservedImage observedImage,
/// <returns>Latest repository per path</returns>
private static List<DockerHubRepositoryData> SelectLatestRepositories(IEnumerable<DockerHubRepositoryData> repositories)
{
return repositories.Where(entity => string.IsNullOrWhiteSpace(entity.Repository) == false)
.GroupBy(entity => entity.Repository, StringComparer.OrdinalIgnoreCase)
.Select(group => group.OrderByDescending(entity => entity.LastUpdatedAtUtc)
.First())
.ToList();
return [
.. repositories.Where(entity => string.IsNullOrWhiteSpace(entity.Repository) == false)
.GroupBy(entity => entity.Repository, StringComparer.OrdinalIgnoreCase)
.Select(group => group.OrderByDescending(entity => entity.LastUpdatedAtUtc)
.First())
];
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/DockerUpdateGuard/Images/DotNetReleaseMetadataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private async Task<ExternalOperationResult<bool>> LoadIndexAsync(CancellationTok
{
if (_indexLoaded)
{
return ExternalOperationResult.Succeeded<bool>(true);
return ExternalOperationResult.Succeeded(true);
}

try
Expand Down Expand Up @@ -193,7 +193,7 @@ private async Task<ExternalOperationResult<bool>> LoadIndexAsync(CancellationTok

_indexLoaded = true;

return ExternalOperationResult.Succeeded<bool>(true);
return ExternalOperationResult.Succeeded(true);
}
catch (Exception exception)
{
Expand All @@ -214,7 +214,7 @@ public async Task<ExternalOperationResult<DotNetChannelReleaseData>> GetChannelR

if (_channelCache.TryGetValue(channelVersion, out var cachedChannelData))
{
return ExternalOperationResult.Succeeded<DotNetChannelReleaseData>(cachedChannelData);
return ExternalOperationResult.Succeeded(cachedChannelData);
}

var indexResult = await LoadIndexAsync(cancellationToken).ConfigureAwait(false);
Expand All @@ -225,7 +225,7 @@ public async Task<ExternalOperationResult<DotNetChannelReleaseData>> GetChannelR
}

return _channelCache.TryGetValue(channelVersion, out var channelData)
? ExternalOperationResult.Succeeded<DotNetChannelReleaseData>(channelData)
? ExternalOperationResult.Succeeded(channelData)
: ExternalOperationResult.NotFound<DotNetChannelReleaseData>($"No .NET release metadata is available for channel '{channelVersion}'");
}

Expand Down
Loading