-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(CI): add KasperskyScanEngine and fix some vulnerabilities
- Loading branch information
ruakbp4
authored and
ruakbp4
committed
Apr 23, 2024
1 parent
69f940f
commit b0084a0
Showing
63 changed files
with
2,162 additions
and
75 deletions.
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
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
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
56 changes: 56 additions & 0 deletions
56
...iennaNET.KasperskyScanEngine.Client/DependencyInjection/KseServiceCollectionExtensions.cs
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,56 @@ | ||
using System.Net.Http.Headers; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using ViennaNET.Extensions.Http.DependencyInjection; | ||
|
||
namespace ViennaNET.KasperskyScanEngine.Client.DependencyInjection; | ||
|
||
/// <summary> | ||
/// Предоставляет методы расширения для регистрации HTTP клиента. | ||
/// </summary> | ||
public static class HttpClientServiceCollectionExtensions | ||
{ | ||
/// <summary> | ||
/// Добавляет HTTP-клиент службы Kaspersky Scan Engine в колекцию служб. | ||
/// </summary> | ||
/// <param name="services">Ссылка на <see cref="IServiceCollection" />.</param> | ||
/// <param name="configuration">Ссылка на <see cref="IConfiguration"/>.</param> | ||
/// <param name="configure"> | ||
/// Делегат, осуществляющий настройку параметров клиента, если <see langword="null" />, | ||
/// по умолчанию будет осущесвляться привязка к секции конфигурации | ||
/// <see cref="KseClientOption"/>.<see cref="KseClientOption.SectionName" />. | ||
/// </param> | ||
/// <returns>Ссылка на <see cref="IHttpClientBuilder" />.</returns> | ||
public static IHttpClientBuilder AddKasperskyScanEngineApi( | ||
this IServiceCollection services, | ||
IConfiguration configuration, | ||
Action<KseClientOption>? configure = null) | ||
{ | ||
var configAction = configure ?? (option => configuration.GetSection(KseClientOption.SectionName).Bind(option)); | ||
|
||
var builder = services | ||
.Configure<JsonSerializerOptions>(IKasperskyScanEngineApi.JsonSerializerOptionsName, options => | ||
{ | ||
options.Converters.Add(new JsonValueConverterBooleanString()); | ||
options.WriteIndented = false; | ||
options.AllowTrailingCommas = false; | ||
options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; | ||
options.TypeInfoResolver = KseClientSerializerContext.Default; | ||
}) | ||
.AddHttpClient<IKasperskyScanEngineApi, KseApi, KseClientOption>(configAction) | ||
.ConfigureHttpClient((provider, client) => | ||
{ | ||
var opt = provider.GetRequiredService<IOptionsMonitor<KseClientOption>>().CurrentValue; | ||
if (opt.AuthorizationToken is { } token) | ||
{ | ||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); | ||
} | ||
}); | ||
|
||
return builder; | ||
} | ||
} |
Oops, something went wrong.