Skip to content

Commit f156a9e

Browse files
committed
update to net6.0, package upgrades, etc
1 parent fe1d382 commit f156a9e

File tree

10 files changed

+45
-35
lines changed

10 files changed

+45
-35
lines changed

src/Scopely.ElasticsearchPipeline/AWS4RequestSigner.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class AWS4RequestSigner
1616
{
1717
private readonly string _access_key;
1818
private readonly string _secret_key;
19-
private readonly string _token;
19+
private readonly string? _token;
2020
private const string algorithm = "AWS4-HMAC-SHA256";
2121

22-
public AWS4RequestSigner(string accessKey, string secretKey, string token = null)
22+
public AWS4RequestSigner(string accessKey, string secretKey, string? token = null)
2323
{
2424

2525
if (string.IsNullOrEmpty(accessKey))
@@ -108,9 +108,11 @@ public async Task<HttpRequestMessage> Sign(HttpRequestMessage request, string se
108108
throw new ArgumentNullException(nameof(request));
109109
}
110110

111+
var uri = request.RequestUri ?? throw new ArgumentException("requst.RequestUri can't be null", nameof(request));
112+
111113
if (request.Headers.Host == null)
112114
{
113-
request.Headers.Host = request.RequestUri.Host;
115+
request.Headers.Host = uri.Host;
114116
}
115117

116118
var t = DateTimeOffset.UtcNow;
@@ -120,7 +122,7 @@ public async Task<HttpRequestMessage> Sign(HttpRequestMessage request, string se
120122

121123
var canonical_request = new StringBuilder();
122124
canonical_request.Append(request.Method + "\n");
123-
var canonical_uri = GetPath(request.RequestUri);
125+
var canonical_uri = GetPath(uri);
124126
canonical_request.Append(canonical_uri);
125127
canonical_request.Append("\n");
126128

@@ -172,7 +174,8 @@ public async Task<HttpRequestMessage> Sign(HttpRequestMessage request, string se
172174

173175
private static string GetCanonicalQueryParams(HttpRequestMessage request)
174176
{
175-
var querystring = HttpUtility.ParseQueryString(request.RequestUri.Query);
177+
var uri = request.RequestUri ?? throw new ArgumentException(nameof(request));
178+
var querystring = HttpUtility.ParseQueryString(uri.Query);
176179
var keys = querystring.AllKeys.OrderBy(a => a).ToArray();
177180
var queryParams = keys.Select(key => $"{key}={querystring[key]}");
178181
var canonicalQueryParams = string.Join("&", queryParams);

src/Scopely.ElasticsearchPipeline/BulkOperations.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ namespace Scopely.Elasticsearch
77
{
88
public abstract class BulkOperation
99
{
10-
public string Index { get; set; }
10+
public string? Index { get; set; }
1111

12-
public string Type { get; set; }
12+
public string? Type { get; set; }
1313

14-
public string Id { get; set; }
14+
public string? Id { get; set; }
1515

1616
public abstract void Write(BulkWriter writer);
1717

1818
protected internal class Header
1919
{
20-
public string _index;
21-
public string _type;
22-
public string _id;
20+
public string? _index;
21+
public string? _type;
22+
public string? _id;
2323

2424
public Header(BulkOperation op)
2525
{
@@ -32,7 +32,8 @@ public Header(BulkOperation op)
3232

3333
public abstract class BulkDocumentOperation : BulkOperation
3434
{
35-
public object Doc { get; set; }
35+
private static readonly object _defaultDoc = new();
36+
public object Doc { get; set; } = _defaultDoc;
3637
}
3738

3839
public sealed class BulkUpdateOperation : BulkDocumentOperation

src/Scopely.ElasticsearchPipeline/Cache.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ static class Cache
99
{
1010
private class CachedItem<T>
1111
{
12+
public CachedItem(T value)
13+
{
14+
Value = value;
15+
Watch = Stopwatch.StartNew();
16+
}
17+
1218
public Stopwatch Watch;
1319
public T Value;
1420
}
@@ -28,11 +34,7 @@ public static Func<T> Wrap<T>(TimeSpan maxAge, Func<T> inner)
2834
{
2935
if (i == null || i.Watch.Elapsed > maxAge)
3036
{
31-
i = item = new CachedItem<T>
32-
{
33-
Value = inner(),
34-
Watch = Stopwatch.StartNew(),
35-
};
37+
i = item = new CachedItem<T>(inner());
3638
}
3739
}
3840
}

src/Scopely.ElasticsearchPipeline/ElasticsearchPipeline.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ private static ITargetBlock<byte[]> CreateBulkWriterBlock(string url, Elasticsea
8585
logger?.LogError(await response.GetDumpAsync());
8686
throw new Exception($"Got {response.StatusCode} but it wasn't JSON.");
8787
}
88-
var responseBody = await response.Content.ReadAsStringAsync();
89-
var bulkResponse = JsonConvert.DeserializeObject<BulkResponse>(responseBody);
88+
var responseBody = await (response.Content ?? throw new Exception($"Empty response from {postUrl}")).ReadAsStringAsync();
89+
var bulkResponse = JsonConvert.DeserializeObject<BulkResponse>(responseBody)
90+
?? throw new Exception($"Empty respnose from {postUrl}");
9091
if (bulkResponse.Errors)
9192
{
9293
logger?.LogError($"Bulk response from {postUrl} had errors:\n" + responseBody);
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.Extensions.Logging;
2+
using Microsoft.Extensions.Logging.Abstractions;
23
using System;
34
using System.Net.Http;
45

@@ -7,12 +8,12 @@ namespace Scopely.Elasticsearch
78
public class ElasticsearchPipelineOptions
89
{
910
public int TargetBulkSizeInBytes { get; set; } = 1 << 20;
10-
public ILogger Logger { get; set; }
11+
public ILogger Logger { get; set; } = NullLogger.Instance;
1112
/// <summary>
1213
/// False by default. True to omit _type in the bulk api.
1314
/// Note that _type is deprected in newer versions of elasticsearch.
1415
/// </summary>
1516
public bool OmitTypeHeaders { get; set; }
16-
public Func<HttpClient> HttpClientFactory { get; set; }
17+
public Func<HttpClient>? HttpClientFactory { get; set; }
1718
}
1819
}

src/Scopely.ElasticsearchPipeline/ElasticsearchSigner.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public static class ElasticsearchSigner
2525

2626
public static Task<HttpRequestMessage> SignAsync(HttpRequestMessage request)
2727
{
28-
var match = _hostRegex.Match(request.RequestUri.Host);
28+
var uri = request.RequestUri ?? throw new ArgumentException("request.RequestUri null", nameof(request));
29+
var match = _hostRegex.Match(uri.Host);
2930
if (!match.Success) return Task.FromResult(request);
3031
var region = match.Groups[1].Value;
3132
return Signer.Sign(request, "es", region);

src/Scopely.ElasticsearchPipeline/ElasticsearchUrl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public ElasticsearchUrl(string url)
2121
}
2222
}
2323

24-
public string AwsRegion { get; private set; }
24+
public string? AwsRegion { get; private set; }
2525

2626
public override string ToString() => _url;
2727
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
<RootNamespace>Scopely.Elasticsearch</RootNamespace>
66
<Company>Scopely</Company>
77
<Authors>bcuff</Authors>
@@ -11,15 +11,16 @@
1111
<RepositoryUrl>https://github.com/scopely/elasticsearch-pipeline</RepositoryUrl>
1212
<RepositoryType>git</RepositoryType>
1313
<PackageTags>elasticsearch</PackageTags>
14-
<Version>1.1.0</Version>
15-
<WarningsAsErrors />
14+
<Version>1.2.0</Version>
15+
<Nullable>enable</Nullable>
16+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1617
</PropertyGroup>
1718

1819
<ItemGroup>
1920
<PackageReference Include="AWSSDK.Core" Version="3.7.*" />
20-
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
21-
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.9.0" />
22-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.0.1" />
21+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
22+
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="7.0.0" />
23+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
2324
</ItemGroup>
2425

2526
</Project>

src/Scopely.ElasticsearchPipeline/TargetBlockWithCompletion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public TargetBlockWithCompletion(ITargetBlock<T> target, Task completion)
2020

2121
public void Fault(Exception exception) => _target.Fault(exception);
2222

23-
public DataflowMessageStatus OfferMessage(DataflowMessageHeader messageHeader, T messageValue, ISourceBlock<T> source, bool consumeToAccept)
23+
public DataflowMessageStatus OfferMessage(DataflowMessageHeader messageHeader, T messageValue, ISourceBlock<T>? source, bool consumeToAccept)
2424
=> _target.OfferMessage(messageHeader, messageValue, source, consumeToAccept);
2525
}
2626
}

tests/Scopely.ElasticsearchPipeline.Tests/Scopely.ElasticsearchPipeline.Tests.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55

66
<IsPackable>false</IsPackable>
77

88
<RootNamespace>Scopely.Elasticsearch.Tests</RootNamespace>
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="nunit" Version="3.10.1" />
13-
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
15-
<PackageReference Include="FakeItEasy" Version="4.7.1" />
12+
<PackageReference Include="nunit" Version="3.13.3" />
13+
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
15+
<PackageReference Include="FakeItEasy" Version="7.4.0" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

0 commit comments

Comments
 (0)