Skip to content
Merged

.NET 10 #3482

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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: [push, pull_request]
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_NOLOGO: true
DOTNET_SDK_VERSION: 9.0
DOTNET_SDK_VERSION: 10.0

permissions: {}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ env:
CONFIGURATION: Release
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_NOLOGO: true
DOTNET_SDK_VERSION: 9.0
DOTNET_SDK_VERSION: 10.0
NODE_JS_VERSION: 'lts/*'
PLUGINS_BUNDLED: ArchiSteamFarm.OfficialPlugins.ItemsMatcher ArchiSteamFarm.OfficialPlugins.MobileAuthenticator ArchiSteamFarm.OfficialPlugins.SteamTokenDumper
PLUGINS_INCLUDED: ArchiSteamFarm.OfficialPlugins.Monitoring # Apart from declaring them here, there is certain amount of hardcoding needed below for uploading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

<ItemGroup>
<PackageReference Include="JetBrains.Annotations.Sources" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" IncludeAssets="compile" />
<PackageReference Include="SteamKit2" IncludeAssets="compile" />
<PackageReference Include="System.Composition.AttributedModel" IncludeAssets="compile" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

<ItemGroup>
<PackageReference Include="JetBrains.Annotations.Sources" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" IncludeAssets="compile" />
<PackageReference Include="System.Composition.AttributedModel" IncludeAssets="compile" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ItemGroup>
<PackageReference Include="AngleSharp" IncludeAssets="compile" />
<PackageReference Include="JetBrains.Annotations.Sources" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" IncludeAssets="compile" />
<PackageReference Include="System.Composition.AttributedModel" IncludeAssets="compile" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

<ItemGroup>
<PackageReference Include="JetBrains.Annotations.Sources" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" IncludeAssets="compile" />
<PackageReference Include="Microsoft.CodeAnalysis.ResxSourceGenerator" PrivateAssets="all" />
<PackageReference Include="SteamKit2" IncludeAssets="compile" />
<PackageReference Include="System.Composition.AttributedModel" IncludeAssets="compile" />
<PackageReference Include="System.Linq.Async" IncludeAssets="compile" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

<ItemGroup>
<PackageReference Include="JetBrains.Annotations.Sources" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" IncludeAssets="compile" />
<PackageReference Include="Microsoft.CodeAnalysis.ResxSourceGenerator" PrivateAssets="all" />
<PackageReference Include="SteamKit2" IncludeAssets="compile" />
<PackageReference Include="System.Composition.AttributedModel" IncludeAssets="compile" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<ItemGroup>
<PackageReference Include="JetBrains.Annotations.Sources" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" IncludeAssets="compile" />
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

<ItemGroup>
<PackageReference Include="JetBrains.Annotations.Sources" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" IncludeAssets="compile" />
<PackageReference Include="Microsoft.CodeAnalysis.ResxSourceGenerator" PrivateAssets="all" />
<PackageReference Include="SteamKit2" IncludeAssets="compile" />
<PackageReference Include="System.Composition.AttributedModel" IncludeAssets="compile" />
Expand Down
1 change: 0 additions & 1 deletion ArchiSteamFarm/ArchiSteamFarm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<PackageReference Include="Scalar.AspNetCore" />
<PackageReference Include="SteamKit2" />
<PackageReference Include="System.Composition" />
<PackageReference Include="System.Linq.Async" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion ArchiSteamFarm/Core/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ internal static async Task<bool> UpdateFromArchive(ZipArchive zipArchive, string
// Now extract the zip file to entirely new location, this decreases chance of corruptions if user kills the process during this stage
string updateDirectory = Path.Combine(targetDirectory, SharedInfo.UpdateDirectoryNew);

zipArchive.ExtractToDirectory(updateDirectory, true);
await zipArchive.ExtractToDirectoryAsync(updateDirectory, true).ConfigureAwait(false);

// Now, critical section begins, we're going to move all files from target directory to a backup directory
string backupDirectory = Path.Combine(targetDirectory, SharedInfo.UpdateDirectoryOld);
Expand Down
4 changes: 2 additions & 2 deletions ArchiSteamFarm/IPC/ArchiKestrel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
using Microsoft.Net.Http.Headers;
using NLog.Web;
using Scalar.AspNetCore;
using IPNetwork = Microsoft.AspNetCore.HttpOverrides.IPNetwork;
using IPNetwork = System.Net.IPNetwork;

namespace ArchiSteamFarm.IPC;

Expand Down Expand Up @@ -323,7 +323,7 @@ private static void ConfigureServices([SuppressMessage("ReSharper", "SuggestBase

if (knownNetworks != null) {
foreach (IPNetwork knownNetwork in knownNetworks) {
options.KnownNetworks.Add(knownNetwork);
options.KnownIPNetworks.Add(knownNetwork);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions ArchiSteamFarm/IPC/Integration/ApiAuthenticationMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,19 @@ internal static bool UnbanIP(IPAddress ipAddress) {
return (HttpStatusCode.OK, true);
}

if (ForwardedHeadersOptions.KnownNetworks.Count == 0) {
if (ForwardedHeadersOptions.KnownIPNetworks.Count == 0) {
return (HttpStatusCode.Forbidden, true);
}

if (clientIP.IsIPv4MappedToIPv6) {
IPAddress mappedClientIP = clientIP.MapToIPv4();

if (ForwardedHeadersOptions.KnownNetworks.Any(network => network.Contains(mappedClientIP))) {
if (ForwardedHeadersOptions.KnownIPNetworks.Any(network => network.Contains(mappedClientIP))) {
return (HttpStatusCode.OK, true);
}
}

return (ForwardedHeadersOptions.KnownNetworks.Any(network => network.Contains(clientIP)) ? HttpStatusCode.OK : HttpStatusCode.Forbidden, true);
return (ForwardedHeadersOptions.KnownIPNetworks.Any(network => network.Contains(clientIP)) ? HttpStatusCode.OK : HttpStatusCode.Forbidden, true);
}

if (!context.Request.Headers.TryGetValue(HeadersField, out StringValues passwords) && !context.Request.Query.TryGetValue("password", out passwords)) {
Expand Down
2 changes: 1 addition & 1 deletion ArchiSteamFarm/IPC/Integration/CustomSwaggerAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

using System;
using JetBrains.Annotations;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

namespace ArchiSteamFarm.IPC.Integration;

Expand Down
9 changes: 5 additions & 4 deletions ArchiSteamFarm/IPC/Integration/SwaggerItemsMinMaxAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
// limitations under the License.

using System;
using System.Globalization;
using JetBrains.Annotations;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

namespace ArchiSteamFarm.IPC.Integration;

Expand All @@ -45,16 +46,16 @@ public uint MinimumUint {
public override void Apply(OpenApiSchema schema) {
ArgumentNullException.ThrowIfNull(schema);

if (schema.Items == null) {
if (schema.Items is not OpenApiSchema items) {
throw new InvalidOperationException(nameof(schema.Items));
}

if (BackingMinimum.HasValue) {
schema.Items.Minimum = BackingMinimum.Value;
items.Minimum = BackingMinimum.Value.ToString(CultureInfo.InvariantCulture);
}

if (BackingMaximum.HasValue) {
schema.Items.Maximum = BackingMaximum.Value;
items.Maximum = BackingMaximum.Value.ToString(CultureInfo.InvariantCulture);
}
}
}
23 changes: 16 additions & 7 deletions ArchiSteamFarm/IPC/Integration/SwaggerSecurityCriticalAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
// limitations under the License.

using System;
using System.Text.Json.Nodes;
using JetBrains.Annotations;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

namespace ArchiSteamFarm.IPC.Integration;

Expand All @@ -36,10 +35,20 @@ public sealed class SwaggerSecurityCriticalAttribute : CustomSwaggerAttribute {
public override void Apply(OpenApiSchema schema) {
ArgumentNullException.ThrowIfNull(schema);

if (schema.Items is { Reference: null }) {
schema.Items.AddExtension(ExtensionName, new OpenApiBoolean(true));
} else {
schema.AddExtension(ExtensionName, new OpenApiBoolean(true));
JsonValue value = JsonValue.Create(true);

if (schema.Items != null) {
if (schema.Items is OpenApiSchema items) {
items.AddExtension(ExtensionName, new JsonNodeExtension(value));
} else if (schema.Items.Extensions != null) {
schema.Items.Extensions[ExtensionName] = new JsonNodeExtension(value);
} else {
throw new InvalidOperationException(nameof(schema.Items));
}

return;
}

schema.AddExtension(ExtensionName, new JsonNodeExtension(value));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
// limitations under the License.

using System;
using System.Globalization;
using JetBrains.Annotations;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;
using SteamKit2;

namespace ArchiSteamFarm.IPC.Integration;
Expand All @@ -38,7 +39,7 @@ public sealed class SwaggerSteamIdentifierAttribute : CustomSwaggerAttribute {
public override void Apply(OpenApiSchema schema) {
ArgumentNullException.ThrowIfNull(schema);

schema.Minimum = new SteamID(MinimumAccountID, Universe, AccountType);
schema.Maximum = new SteamID(MaximumAccountID, Universe, AccountType);
schema.Minimum = new SteamID(MinimumAccountID, Universe, AccountType).ConvertToUInt64().ToString(CultureInfo.InvariantCulture);
schema.Maximum = new SteamID(MaximumAccountID, Universe, AccountType).ConvertToUInt64().ToString(CultureInfo.InvariantCulture);
}
}
36 changes: 25 additions & 11 deletions ArchiSteamFarm/IPC/Integration/SwaggerValidValuesAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,50 @@
// limitations under the License.

using System;
using System.Linq;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Nodes;
using JetBrains.Annotations;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

namespace ArchiSteamFarm.IPC.Integration;

[PublicAPI]
public sealed class SwaggerValidValuesAttribute : CustomSwaggerAttribute {
private const string ExtensionName = "x-valid-values";

public int[]? ValidIntValues { get; init; }
public string[]? ValidStringValues { get; init; }

[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "We're not creating json values with non-primitive types")]
public override void Apply(OpenApiSchema schema) {
ArgumentNullException.ThrowIfNull(schema);

OpenApiArray validValues = [];
JsonArray validValues = [];

if (ValidIntValues != null) {
validValues.AddRange(ValidIntValues.Select(static type => new OpenApiInteger(type)));
foreach (int value in ValidIntValues) {
validValues.Add(JsonValue.Create(value));
}
}

if (ValidStringValues != null) {
validValues.AddRange(ValidStringValues.Select(static type => new OpenApiString(type)));
foreach (string value in ValidStringValues) {
validValues.Add(JsonValue.Create(value));
}
}

if (schema.Items is { Reference: null }) {
schema.Items.AddExtension("x-valid-values", validValues);
} else {
schema.AddExtension("x-valid-values", validValues);
if (schema.Items != null) {
if (schema.Items is OpenApiSchema items) {
items.AddExtension(ExtensionName, new JsonNodeExtension(validValues));
} else if (schema.Items.Extensions != null) {
schema.Items.Extensions[ExtensionName] = new JsonNodeExtension(validValues);
} else {
throw new InvalidOperationException(nameof(schema.Items));
}

return;
}

schema.AddExtension(ExtensionName, new JsonNodeExtension(validValues));
}
}
5 changes: 2 additions & 3 deletions ArchiSteamFarm/IPC/OpenApi/DocumentTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
using ArchiSteamFarm.Storage;
using JetBrains.Annotations;
using Microsoft.AspNetCore.OpenApi;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

namespace ArchiSteamFarm.IPC.OpenApi;

Expand All @@ -40,7 +40,6 @@ public Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransformerC
ArgumentNullException.ThrowIfNull(document);
ArgumentNullException.ThrowIfNull(context);

document.Info ??= new OpenApiInfo();
document.Info.Title = $"{SharedInfo.AssemblyName} API";
document.Info.Version = SharedInfo.Version.ToString();

Expand All @@ -53,7 +52,7 @@ public Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransformerC
document.Info.License.Url = new Uri(SharedInfo.LicenseURL);

document.Components ??= new OpenApiComponents();
document.Components.SecuritySchemes ??= new Dictionary<string, OpenApiSecurityScheme>(1);
document.Components.SecuritySchemes ??= new Dictionary<string, IOpenApiSecurityScheme>(1);

document.Components.SecuritySchemes.Add(
nameof(GlobalConfig.IPCPassword), new OpenApiSecurityScheme {
Expand Down
10 changes: 2 additions & 8 deletions ArchiSteamFarm/IPC/OpenApi/OperationTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
using ArchiSteamFarm.Storage;
using JetBrains.Annotations;
using Microsoft.AspNetCore.OpenApi;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi;

namespace ArchiSteamFarm.IPC.OpenApi;

Expand All @@ -45,13 +45,7 @@ public Task TransformAsync(OpenApiOperation operation, OpenApiOperationTransform
operation.Security.Add(
new OpenApiSecurityRequirement {
{
new OpenApiSecurityScheme {
Reference = new OpenApiReference {
Id = nameof(GlobalConfig.IPCPassword),
Type = ReferenceType.SecurityScheme
}
},

new OpenApiSecuritySchemeReference(nameof(GlobalConfig.IPCPassword), context.Document),
[]
}
}
Expand Down
Loading