-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSonarClient.cs
46 lines (38 loc) · 1.42 KB
/
SonarClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using Cms.BatCave.Sonar.Agent.Configuration;
using Cms.BatCave.Sonar.Json;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
namespace Cms.BatCave.Sonar.Agent;
public partial class SonarClient {
private readonly String _apiKeyValue;
public SonarClient(IOptions<ApiConfiguration> apiConfig, HttpClient client) : this(apiConfig.Value.BaseUrl, client) {
var apiKeyValue = apiConfig.Value.ApiKey;
if (apiConfig.Value.ApiKeyId.HasValue) {
apiKeyValue = apiConfig.Value.ApiKeyId + ":" + apiConfig.Value.ApiKey;
}
if (apiKeyValue != null) {
this._apiKeyValue = apiKeyValue;
}
}
partial void UpdateJsonSerializerSettings(JsonSerializerOptions settings) {
settings.PropertyNameCaseInsensitive = true;
settings.Converters.Add(new JsonStringEnumConverter());
settings.Converters.Add(new ArrayTupleConverterFactory());
}
partial void PrepareRequest(HttpClient client, HttpRequestMessage request, string url) {
if (!request.Headers.Contains("ApiKey")) {
request.Headers.Add("ApiKey", this._apiKeyValue);
}
}
partial void PrepareRequest(HttpClient client, HttpRequestMessage request, StringBuilder urlBuilder) {
if (!request.Headers.Contains("ApiKey")) {
request.Headers.Add("ApiKey", this._apiKeyValue);
}
}
}