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
4 changes: 2 additions & 2 deletions src/Benchmarks/Benchmarks/SignerBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task SetupAsync()
};

var httpContent = new GetItemHttpContent(request, request.TableName, request.Key.PartitionKeyName!, request.Key.SortKeyName);
_httpRequest = new HttpRequestMessage(HttpMethod.Post, RegionEndpoint.USEast1.RequestUri)
_httpRequest = new HttpRequestMessage(HttpMethod.Post, RegionEndpoint.USEast1.BuildRequestUri(ServiceNames.DynamoDb))
{
Content = httpContent
};
Expand All @@ -52,7 +52,7 @@ public HttpRequestMessage SigningNative()
CleanupHeaders(_httpRequest);

var meta = new SigningMetadata(RegionEndpoint.USEast1, new AwsCredentials("accessKey", "secretKey"), DateTime.UtcNow,
_httpClient.DefaultRequestHeaders, null);
_httpClient.DefaultRequestHeaders, null, ServiceNames.DynamoDb);
AwsRequestSigner.Sign(_httpRequest, _contentStream, meta);

return _httpRequest;
Expand Down
40 changes: 25 additions & 15 deletions src/EfficientDynamoDb/Configs/RegionEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,46 @@ public class RegionEndpoint
private const string ChinaEndpointFormat = "https://{0}.{1}.amazonaws.com.cn"; // 0 - Service Name, 1 - Region
private const string RegularEndpointFormat = "https://{0}.{1}.amazonaws.com"; // 0 - Service Name, 1 - Region

internal const string ServiceName = "dynamodb";
// internal const string ServiceName = "dynamodb";

private readonly string? _requestUriOverride;

internal string RequestUri { get; private set; }

public string Region { get; }

public static RegionEndpoint Create(string region)
{
var format =
region.StartsWith("cn-", StringComparison.OrdinalIgnoreCase)
? ChinaEndpointFormat
: RegularEndpointFormat;

return new RegionEndpoint(region, format);
return new RegionEndpoint(region);
}

public static RegionEndpoint Create(string region, string requestUri)
{
return new RegionEndpoint(region, RegularEndpointFormat) { RequestUri = requestUri };
return new RegionEndpoint(region, requestUri);
}

public static RegionEndpoint Create(RegionEndpoint region, string requestUri)
{
return new RegionEndpoint(region.Region, RegularEndpointFormat) { RequestUri = requestUri };
return new RegionEndpoint(region.Region, requestUri);
}

private RegionEndpoint(string region, string uriFormat = RegularEndpointFormat)
private RegionEndpoint(string region)
{
Region = region;
RequestUri = string.Format(uriFormat, ServiceName, region);
}

private RegionEndpoint(string region, string requestUriOverride) : this(region)
{
_requestUriOverride = requestUriOverride;
}

internal string BuildRequestUri(string serviceName)
{
if (!string.IsNullOrEmpty(_requestUriOverride))
return _requestUriOverride;

var format = Region.StartsWith("cn-", StringComparison.OrdinalIgnoreCase)
? ChinaEndpointFormat
: RegularEndpointFormat;
return string.Format(format, serviceName, Region);
}

/// <summary>
Expand Down Expand Up @@ -147,12 +157,12 @@ private RegionEndpoint(string region, string uriFormat = RegularEndpointFormat)
/// <summary>
/// The China (Beijing) endpoint.
/// </summary>
public static RegionEndpoint CNNorth1 => new RegionEndpoint("cn-north-1", ChinaEndpointFormat);
public static RegionEndpoint CNNorth1 => new RegionEndpoint("cn-north-1");

/// <summary>
/// The China (Ningxia) endpoint.
/// </summary>
public static RegionEndpoint CNNorthWest1 => new RegionEndpoint("cn-northwest-1", ChinaEndpointFormat);
public static RegionEndpoint CNNorthWest1 => new RegionEndpoint("cn-northwest-1");

/// <summary>
/// The Europe (Frankfurt) endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal async Task<OpResult> BatchWriteItemAsync(BuilderNode node, Cancellation
{
using var httpContent = new BatchWriteItemHighLevelHttpContent(this, node, Config.TableNamePrefix);

var apiResult = await Api.SendSafeAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
var apiResult = await Api.SendSafeAsync(httpContent, cancellationToken).ConfigureAwait(false);
if (apiResult.Exception is not null)
return new(apiResult.Exception);

Expand All @@ -45,7 +45,7 @@ internal async Task<OpResult> BatchWriteItemAsync(BuilderNode node, Cancellation
await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
using var unprocessedHttpContent = new BatchWriteItemHttpContent(new BatchWriteItemRequest{RequestItems = unprocessedItems}, null);

var unprocessedApiResult = await Api.SendSafeAsync(Config, unprocessedHttpContent, cancellationToken).ConfigureAwait(false);
var unprocessedApiResult = await Api.SendSafeAsync(unprocessedHttpContent, cancellationToken).ConfigureAwait(false);
if (unprocessedApiResult.Exception is not null)
return new(unprocessedApiResult.Exception);

Expand All @@ -60,7 +60,7 @@ internal async Task<OpResult<BatchWriteItemResponse>> BatchWriteItemResponseAsyn
{
using var httpContent = new BatchWriteItemHighLevelHttpContent(this, node, Config.TableNamePrefix);

var apiResult = await Api.SendSafeAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
var apiResult = await Api.SendSafeAsync(httpContent, cancellationToken).ConfigureAwait(false);
if (apiResult.Exception is not null)
return new(apiResult.Exception);

Expand All @@ -82,7 +82,7 @@ internal async Task<OpResult<BatchWriteItemResponse>> BatchWriteItemResponseAsyn
await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
using var unprocessedHttpContent = new BatchWriteItemHttpContent(new BatchWriteItemRequest{RequestItems = unprocessedItems}, null);

var unprocessedApiResult = await Api.SendSafeAsync(Config, unprocessedHttpContent, cancellationToken).ConfigureAwait(false);
var unprocessedApiResult = await Api.SendSafeAsync(unprocessedHttpContent, cancellationToken).ConfigureAwait(false);
if (unprocessedApiResult.Exception is not null)
return new(unprocessedApiResult.Exception);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal async Task<OpResult<List<TEntity>>> BatchGetItemListAsync<TEntity>(Buil
{
using var httpContent = new BatchGetItemHighLevelHttpContent(this, node);

var apiResult = await Api.SendSafeAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
var apiResult = await Api.SendSafeAsync(httpContent, cancellationToken).ConfigureAwait(false);
if (apiResult.Exception is not null)
return new(apiResult.Exception);

Expand All @@ -42,7 +42,7 @@ internal async Task<OpResult<List<TEntity>>> BatchGetItemListAsync<TEntity>(Buil
await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
using var unprocessedHttpContent = new BatchGetItemHttpContent(new BatchGetItemRequest {RequestItems = result.UnprocessedKeys}, null);

var unprocessedApiResult = await Api.SendSafeAsync(Config, unprocessedHttpContent, cancellationToken).ConfigureAwait(false);
var unprocessedApiResult = await Api.SendSafeAsync(unprocessedHttpContent, cancellationToken).ConfigureAwait(false);
if (unprocessedApiResult.Exception is not null)
return new(unprocessedApiResult.Exception);

Expand All @@ -58,7 +58,7 @@ internal async Task<OpResult<List<TEntity>>> BatchGetItemListAsync<TEntity>(Buil
internal async Task<OpResult<BatchGetItemResponse<TEntity>>> BatchGetItemResponseAsync<TEntity>(BuilderNode node, CancellationToken cancellationToken = default) where TEntity : class
{
using var httpContent = new BatchGetItemHighLevelHttpContent(this, node);
var apiResult = await Api.SendSafeAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
var apiResult = await Api.SendSafeAsync(httpContent, cancellationToken).ConfigureAwait(false);
if (apiResult.Exception is not null)
return new(apiResult.Exception);

Expand All @@ -78,7 +78,7 @@ internal async Task<OpResult<BatchGetItemResponse<TEntity>>> BatchGetItemRespons
await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
using var unprocessedHttpContent = new BatchGetItemHttpContent(new BatchGetItemRequest {RequestItems = result.UnprocessedKeys}, null);

var unprocessedApiResult = await Api.SendSafeAsync(Config, unprocessedHttpContent, cancellationToken).ConfigureAwait(false);
var unprocessedApiResult = await Api.SendSafeAsync(unprocessedHttpContent, cancellationToken).ConfigureAwait(false);
if (unprocessedApiResult.Exception is not null)
return new(unprocessedApiResult.Exception);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task DeleteItemAsync<TEntity>(object partitionKey, CancellationToke
{
using var httpContent = new DeleteItemByPkObjectHttpContent<TEntity>(this, partitionKey);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);

await ReadAsync<object>(response, cancellationToken).ConfigureAwait(false);
}
Expand All @@ -51,7 +51,7 @@ public async Task DeleteItemAsync<TEntity>(object partitionKey, object sortKey,
{
using var httpContent = new DeleteItemByPkAndSkObjectHttpContent<TEntity>(this, partitionKey, sortKey);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);

await ReadAsync<object>(response, cancellationToken).ConfigureAwait(false);
}
Expand All @@ -61,7 +61,7 @@ internal async Task<OpResult<DeleteItemEntityResponse<TEntity>>> DeleteItemRespo
{
using var httpContent = new DeleteItemHighLevelHttpContent(this, classInfo, node);

var apiResult = await Api.SendSafeAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
var apiResult = await Api.SendSafeAsync(httpContent, cancellationToken).ConfigureAwait(false);
if (apiResult.Exception is not null)
return new(apiResult.Exception);

Expand All @@ -75,7 +75,7 @@ internal async Task<OpResult<DeleteItemEntityResponse<TEntity>>> DeleteItemRespo
{
using var httpContent = new DeleteItemHighLevelHttpContent(this, classInfo, node);

var apiResult = await Api.SendSafeAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
var apiResult = await Api.SendSafeAsync(httpContent, cancellationToken).ConfigureAwait(false);
if (apiResult.Exception is not null)
return new(apiResult.Exception);

Expand All @@ -88,7 +88,7 @@ internal async Task<OpResult> DeleteItemAsync(DdbClassInfo classInfo, BuilderNod
{
using var httpContent = new DeleteItemHighLevelHttpContent(this, classInfo, node);

var apiResult = await Api.SendSafeAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
var apiResult = await Api.SendSafeAsync(httpContent, cancellationToken).ConfigureAwait(false);
if (apiResult.Exception is not null)
return new(apiResult.Exception);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public partial class DynamoDbContext
{
using var httpContent = new GetItemByPkObjectHttpContent<TEntity>(this, partitionKey);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
var result = await ReadAsync<GetItemEntityProjection<TEntity>>(response, cancellationToken).ConfigureAwait(false);

return result.Item;
Expand All @@ -56,7 +56,7 @@ public partial class DynamoDbContext
{
using var httpContent = new GetItemByPkAndSkObjectHttpContent<TEntity>(this, partitionKey, sortKey);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
var result = await ReadAsync<GetItemEntityProjection<TEntity>>(response, cancellationToken).ConfigureAwait(false);

return result.Item;
Expand Down Expand Up @@ -107,7 +107,7 @@ public partial class DynamoDbContext
{
using var httpContent = new GetItemHighLevelHttpContent(this, classInfo, node);

var apiResult = await Api.SendSafeAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
var apiResult = await Api.SendSafeAsync(httpContent, cancellationToken).ConfigureAwait(false);
if (apiResult.Exception is not null)
return new(apiResult.Exception);

Expand All @@ -121,7 +121,7 @@ internal async Task<OpResult<GetItemEntityResponse<TEntity>>> GetItemResponseAsy
{
using var httpContent = new GetItemHighLevelHttpContent(this, classInfo, node);

var apiResult = await Api.SendSafeAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
var apiResult = await Api.SendSafeAsync(httpContent, cancellationToken).ConfigureAwait(false);
if (apiResult.Exception is not null)
return new(apiResult.Exception);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal async Task<OpResult<PutItemEntityResponse<TEntity>>> PutItemResponseAsy
{
using var httpContent = new PutItemHighLevelHttpContent(this, node);

var apiResult = await Api.SendSafeAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
var apiResult = await Api.SendSafeAsync(httpContent, cancellationToken).ConfigureAwait(false);
if (apiResult.Exception is not null)
return new(apiResult.Exception);

Expand All @@ -46,7 +46,7 @@ internal async Task<OpResult<PutItemEntityResponse<TEntity>>> PutItemResponseAsy
{
using var httpContent = new PutItemHighLevelHttpContent(this, node);

var apiResult = await Api.SendSafeAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
var apiResult = await Api.SendSafeAsync(httpContent, cancellationToken).ConfigureAwait(false);
if (apiResult.Exception is not null)
return new(apiResult.Exception);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal async Task<OpResult<IReadOnlyList<TEntity>>> QueryListAsync<TEntity>(st
var contentNode = isFirst ? node : new PaginationTokenNode(result?.PaginationToken, node);
using var httpContent = new QueryHighLevelHttpContent(this, tableName, contentNode);

var apiResult = await Api.SendSafeAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
var apiResult = await Api.SendSafeAsync(httpContent, cancellationToken).ConfigureAwait(false);
if (apiResult.Exception is not null)
return new(apiResult.Exception);

Expand All @@ -52,7 +52,7 @@ internal async Task<OpResult<PagedResult<TEntity>>> QueryPageAsync<TEntity>(stri
{
using var httpContent = new QueryHighLevelHttpContent(this, tableName, node);

var apiResult = await Api.SendSafeAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
var apiResult = await Api.SendSafeAsync(httpContent, cancellationToken).ConfigureAwait(false);
if (apiResult.Exception is not null)
return new(apiResult.Exception);

Expand All @@ -73,7 +73,7 @@ internal async IAsyncEnumerable<IReadOnlyList<TEntity>> QueryAsyncEnumerable<TEn
var contentNode = isFirst ? node : new PaginationTokenNode(result?.PaginationToken, node);
using var httpContent = new QueryHighLevelHttpContent(this, tableName, contentNode);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
result = await ReadAsync<QueryEntityResponseProjection<TEntity>>(response, cancellationToken).ConfigureAwait(false);

yield return result.Items;
Expand All @@ -87,7 +87,7 @@ internal async Task<OpResult<QueryEntityResponse<TEntity>>> QueryAsync<TEntity>(
{
using var httpContent = new QueryHighLevelHttpContent(this, tableName, node);

var apiResult = await Api.SendSafeAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
var apiResult = await Api.SendSafeAsync(httpContent, cancellationToken).ConfigureAwait(false);
if (apiResult.Exception is not null)
return new(apiResult.Exception);

Expand Down
6 changes: 3 additions & 3 deletions src/EfficientDynamoDb/DynamoDbContext/DynamoDbContext.Scan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal async Task<OpResult<PagedResult<TEntity>>> ScanPageAsync<TEntity>(strin
{
using var httpContent = new ScanHighLevelHttpContent(this, tableName, node);

var apiResult = await Api.SendSafeAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
var apiResult = await Api.SendSafeAsync(httpContent, cancellationToken).ConfigureAwait(false);
if (apiResult.Exception is not null)
return new(apiResult.Exception);

Expand All @@ -43,7 +43,7 @@ internal async IAsyncEnumerable<IReadOnlyList<TEntity>> ScanAsyncEnumerable<TEnt
var contentNode = isFirst ? node : new PaginationTokenNode(result?.PaginationToken, node);
using var httpContent = new ScanHighLevelHttpContent(this, tableName, contentNode);

using var response = await Api.SendAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
using var response = await Api.SendAsync(httpContent, cancellationToken).ConfigureAwait(false);
result = await ReadAsync<ScanEntityResponseProjection<TEntity>>(response, cancellationToken).ConfigureAwait(false);

yield return result.Items;
Expand All @@ -59,7 +59,7 @@ internal async Task<OpResult<ScanEntityResponse<TEntity>>> ScanAsync<TEntity>(st
{
using var httpContent = new ScanHighLevelHttpContent(this, tableName, node);

var apiResult = await Api.SendSafeAsync(Config, httpContent, cancellationToken).ConfigureAwait(false);
var apiResult = await Api.SendSafeAsync(httpContent, cancellationToken).ConfigureAwait(false);
if (apiResult.Exception is not null)
return new(apiResult.Exception);

Expand Down
Loading
Loading