Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0b041c0
feat: introduce `Namespace`
winstxnhdw Jul 31, 2023
4cc0f50
Merge branch 'master' into namespace
winstxnhdw Jul 31, 2023
1447adc
chore: add notice for enterprise-only features
winstxnhdw Aug 2, 2023
85d3d03
Merge branch 'master' into namespace
marcin-krystianc Aug 2, 2023
9bf414e
Merge branch 'master' into namespace
winstxnhdw Aug 9, 2023
351b98d
feat: add `Namespace` controller
winstxnhdw Aug 9, 2023
2f8186f
Merge branch 'master' into namespace
winstxnhdw Aug 9, 2023
0c32831
fix: intialise `Namespace` correctly
winstxnhdw Aug 9, 2023
79ec6a4
fix: use correct env variable for default namespace
winstxnhdw Aug 10, 2023
9bf6e5b
feat: add overload to use default Query/WriteOptions
winstxnhdw Aug 16, 2023
103cf5b
feat: add test for Namespaces API
winstxnhdw Aug 21, 2023
acc987f
chore: remove unused `using`
winstxnhdw Aug 21, 2023
cd4fbb7
fix: assign `_namespaces`
winstxnhdw Aug 21, 2023
0cf301e
fix: skip namespace test if not supported
winstxnhdw Aug 23, 2023
b0d882d
fix: remove `Partition` field
winstxnhdw Aug 23, 2023
b8f4d30
chore: sort usings
winstxnhdw Aug 23, 2023
9e18df6
Merge branch 'master' into namespace
winstxnhdw Aug 24, 2023
207d2a6
fix: use `DateTime` instead of `TimeSpan`
winstxnhdw Aug 27, 2023
a32d82b
fix: deleted namespaces are not immediately deleted
winstxnhdw Aug 27, 2023
6274a47
fix: `ToHashSet` is not supported in net461
winstxnhdw Aug 27, 2023
b2e85a7
fix: `Put` request must specify incoming response
winstxnhdw Aug 28, 2023
2231c57
refactor: `DeletedAt` should be in main `Namespace` class
winstxnhdw Aug 28, 2023
d6931cd
fix: use `EnterpriseOnlyFact` attribute instead
winstxnhdw Aug 28, 2023
3a689cb
refactor: expose correct response
winstxnhdw Aug 28, 2023
6a66429
chore: try skipping without a skippable attribute
winstxnhdw Aug 29, 2023
a0812b1
feat: make `EnterpriseOnlyFact` skippable
winstxnhdw Aug 29, 2023
b783ee9
chore: fix name when skipping test
winstxnhdw Aug 29, 2023
476dadf
docs: add documentation for Namespaces
winstxnhdw Aug 29, 2023
9064700
refactor: verify if created namespaces exist
winstxnhdw Aug 30, 2023
0c47061
feat: add Namespace test with KV
winstxnhdw Aug 30, 2023
f50a2ac
chore: fix comment indentation
winstxnhdw Aug 30, 2023
6f0f8a1
fix: apply dotnet format
winstxnhdw Aug 31, 2023
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
25 changes: 20 additions & 5 deletions Consul/Client_DeleteRequests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public DeleteReturnRequest(ConsulClient client, string url, WriteOptions options
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentException(nameof(url));
throw new ArgumentException(null, nameof(url));
}
Options = options ?? WriteOptions.Default;
}
Expand Down Expand Up @@ -93,6 +93,11 @@ protected override void ApplyOptions(ConsulClientConfiguration clientConfig)
return;
}

if (!string.IsNullOrEmpty(Options.Namespace))
{
Params["ns"] = Options.Namespace;
}

if (!string.IsNullOrEmpty(Options.Datacenter))
{
Params["dc"] = Options.Datacenter;
Expand All @@ -119,7 +124,7 @@ public DeleteRequest(ConsulClient client, string url, WriteOptions options = nul
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentException(nameof(url));
throw new ArgumentException(null, nameof(url));
}
Options = options ?? WriteOptions.Default;
}
Expand Down Expand Up @@ -168,6 +173,11 @@ protected override void ApplyOptions(ConsulClientConfiguration clientConfig)
return;
}

if (!string.IsNullOrEmpty(Options.Namespace))
{
Params["ns"] = Options.Namespace;
}

if (!string.IsNullOrEmpty(Options.Datacenter))
{
Params["dc"] = Options.Datacenter;
Expand All @@ -190,13 +200,13 @@ protected override void ApplyHeaders(HttpRequestMessage message, ConsulClientCon
public class DeleteAcceptingRequest<TIn> : ConsulRequest
{
public WriteOptions Options { get; set; }
private TIn _body;
private readonly TIn _body;

public DeleteAcceptingRequest(ConsulClient client, string url, TIn body, WriteOptions options = null) : base(client, url, HttpMethod.Delete)
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentException(nameof(url));
throw new ArgumentException(null, nameof(url));
}
_body = body;
Options = options ?? WriteOptions.Default;
Expand All @@ -217,7 +227,7 @@ public async Task<WriteResult> Execute(CancellationToken ct)

if (typeof(TIn) == typeof(byte[]))
{
content = new ByteArrayContent((_body as byte[]) ?? new byte[0]);
content = new ByteArrayContent((_body as byte[]) ?? Array.Empty<byte>());
}
else if (typeof(TIn) == typeof(Stream))
{
Expand Down Expand Up @@ -263,6 +273,11 @@ protected override void ApplyOptions(ConsulClientConfiguration clientConfig)
return;
}

if (!string.IsNullOrEmpty(Options.Namespace))
{
Params["ns"] = Options.Namespace;
}

if (!string.IsNullOrEmpty(Options.Datacenter))
{
Params["dc"] = Options.Datacenter;
Expand Down
10 changes: 10 additions & 0 deletions Consul/Client_GetRequests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ protected override void ApplyOptions(ConsulClientConfiguration clientConfig)
return;
}

if (!string.IsNullOrEmpty(Options.Namespace))
{
Params["ns"] = Options.Namespace;
}

if (!string.IsNullOrEmpty(Options.Datacenter))
{
Params["dc"] = Options.Datacenter;
Expand Down Expand Up @@ -302,6 +307,11 @@ protected override void ApplyOptions(ConsulClientConfiguration clientConfig)
return;
}

if (!string.IsNullOrEmpty(Options.Namespace))
{
Params["ns"] = Options.Namespace;
}

if (!string.IsNullOrEmpty(Options.Datacenter))
{
Params["dc"] = Options.Datacenter;
Expand Down
17 changes: 14 additions & 3 deletions Consul/Client_Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,29 @@ public class QueryOptions
public static readonly QueryOptions Default = new QueryOptions()
{
Consistency = ConsistencyMode.Default,
Namespace = Environment.GetEnvironmentVariable("HTTPNamespaceEnvName"),
Datacenter = string.Empty,
Token = string.Empty,
WaitIndex = 0
};

/// <summary>
/// Providing a datacenter overwrites the DC provided by the Config
/// Namespace is the name of the namespace to send along for the request when no other Namespace is present in the QueryOptions.
/// </summary>
public string Namespace { get; set; }

/// <summary>
/// Providing a datacenter overwrites the DC provided by the Config.
/// </summary>
public string Datacenter { get; set; }

/// <summary>
/// The consistency level required for the operation
/// The consistency level required for the operation.
/// </summary>
public ConsistencyMode Consistency { get; set; }

/// <summary>
/// WaitIndex is used to enable a blocking query. Waits until the timeout or the next index is reached
/// WaitIndex is used to enable a blocking query. Waits until the timeout or the next index is reached.
/// </summary>
public ulong WaitIndex { get; set; }

Expand Down Expand Up @@ -82,6 +88,11 @@ public class WriteOptions
Token = string.Empty
};

/// <summary>
/// Namespace is the name of the namespace to send along for the request when no other Namespace is present in the QueryOptions
/// </summary>
public string Namespace { get; set; }

/// <summary>
/// Providing a datacenter overwrites the DC provided by the Config
/// </summary>
Expand Down
38 changes: 28 additions & 10 deletions Consul/Client_PostRequests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public PostReturningRequest(ConsulClient client, string url, WriteOptions option
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentException(nameof(url));
throw new ArgumentException(null, nameof(url));
}

Options = options ?? WriteOptions.Default;
Expand Down Expand Up @@ -97,6 +97,11 @@ protected override void ApplyOptions(ConsulClientConfiguration clientConfig)
return;
}

if (!string.IsNullOrEmpty(Options.Namespace))
{
Params["ns"] = Options.Namespace;
}

if (!string.IsNullOrEmpty(Options.Datacenter))
{
Params["dc"] = Options.Datacenter;
Expand All @@ -119,13 +124,13 @@ protected override void ApplyHeaders(HttpRequestMessage message, ConsulClientCon
public class PostRequest<TIn> : ConsulRequest
{
public WriteOptions Options { get; set; }
private TIn _body;
private readonly TIn _body;

public PostRequest(ConsulClient client, string url, TIn body, WriteOptions options = null) : base(client, url, HttpMethod.Post)
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentException(nameof(url));
throw new ArgumentException(null, nameof(url));
}
_body = body;
Options = options ?? WriteOptions.Default;
Expand Down Expand Up @@ -192,6 +197,11 @@ protected override void ApplyOptions(ConsulClientConfiguration clientConfig)
return;
}

if (!string.IsNullOrEmpty(Options.Namespace))
{
Params["ns"] = Options.Namespace;
}

if (!string.IsNullOrEmpty(Options.Datacenter))
{
Params["dc"] = Options.Datacenter;
Expand All @@ -215,13 +225,13 @@ protected override void ApplyHeaders(HttpRequestMessage message, ConsulClientCon
public class PostRequest<TIn, TOut> : ConsulRequest
{
public WriteOptions Options { get; set; }
private TIn _body;
private readonly TIn _body;

public PostRequest(ConsulClient client, string url, TIn body, WriteOptions options = null) : base(client, url, HttpMethod.Post)
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentException(nameof(url));
throw new ArgumentException(null, nameof(url));
}
_body = body;
Options = options ?? WriteOptions.Default;
Expand Down Expand Up @@ -293,6 +303,11 @@ protected override void ApplyOptions(ConsulClientConfiguration clientConfig)
return;
}

if (!string.IsNullOrEmpty(Options.Namespace))
{
Params["ns"] = Options.Namespace;
}

if (!string.IsNullOrEmpty(Options.Datacenter))
{
Params["dc"] = Options.Datacenter;
Expand All @@ -314,13 +329,13 @@ protected override void ApplyHeaders(HttpRequestMessage message, ConsulClientCon
public class PostRequest : ConsulRequest
{
public WriteOptions Options { get; set; }
private string _body;
private readonly string _body;

public PostRequest(ConsulClient client, string url, string body, WriteOptions options = null) : base(client, url, HttpMethod.Post)
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentException(nameof(url));
throw new ArgumentException(null, nameof(url));
}
_body = body;
Options = options ?? WriteOptions.Default;
Expand All @@ -336,10 +351,8 @@ public async Task<WriteResult<string>> Execute(CancellationToken ct)
Client.CheckDisposed();
var timer = Stopwatch.StartNew();
var result = new WriteResult<string>();

HttpContent content = null;
var bodyBytes = Encoding.UTF8.GetBytes(_body);
content = new ByteArrayContent(bodyBytes);
HttpContent content = new ByteArrayContent(bodyBytes);

var message = new HttpRequestMessage(HttpMethod.Post, BuildConsulUri(Endpoint, Params));
ApplyHeaders(message, Client.Config);
Expand Down Expand Up @@ -383,6 +396,11 @@ protected override void ApplyOptions(ConsulClientConfiguration clientConfig)
return;
}

if (!string.IsNullOrEmpty(Options.Namespace))
{
Params["ns"] = Options.Namespace;
}

if (!string.IsNullOrEmpty(Options.Datacenter))
{
Params["dc"] = Options.Datacenter;
Expand Down
36 changes: 28 additions & 8 deletions Consul/Client_PutRequests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public PutReturningRequest(ConsulClient client, string url, WriteOptions options
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentException(nameof(url));
throw new ArgumentException(null, nameof(url));
}
Options = options ?? WriteOptions.Default;
}
Expand Down Expand Up @@ -92,6 +92,11 @@ protected override void ApplyOptions(ConsulClientConfiguration clientConfig)
return;
}

if (!string.IsNullOrEmpty(Options.Namespace))
{
Params["ns"] = Options.Namespace;
}

if (!string.IsNullOrEmpty(Options.Datacenter))
{
Params["dc"] = Options.Datacenter;
Expand All @@ -118,7 +123,7 @@ public PutNothingRequest(ConsulClient client, string url, WriteOptions options =
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentException(nameof(url));
throw new ArgumentException(null, nameof(url));
}
Options = options ?? WriteOptions.Default;
}
Expand Down Expand Up @@ -167,6 +172,11 @@ protected override void ApplyOptions(ConsulClientConfiguration clientConfig)
return;
}

if (!string.IsNullOrEmpty(Options.Namespace))
{
Params["ns"] = Options.Namespace;
}

if (!string.IsNullOrEmpty(Options.Datacenter))
{
Params["dc"] = Options.Datacenter;
Expand All @@ -189,13 +199,13 @@ protected override void ApplyHeaders(HttpRequestMessage message, ConsulClientCon
public class PutRequest<TIn> : ConsulRequest
{
public WriteOptions Options { get; set; }
private TIn _body;
private readonly TIn _body;

public PutRequest(ConsulClient client, string url, TIn body, WriteOptions options = null) : base(client, url, HttpMethod.Put)
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentException(nameof(url));
throw new ArgumentException(null, nameof(url));
}
_body = body;
Options = options ?? WriteOptions.Default;
Expand All @@ -216,7 +226,7 @@ public async Task<WriteResult> Execute(CancellationToken ct)

if (typeof(TIn) == typeof(byte[]))
{
content = new ByteArrayContent((_body as byte[]) ?? new byte[0]);
content = new ByteArrayContent((_body as byte[]) ?? Array.Empty<byte>());
}
else if (typeof(TIn) == typeof(Stream))
{
Expand Down Expand Up @@ -262,6 +272,11 @@ protected override void ApplyOptions(ConsulClientConfiguration clientConfig)
return;
}

if (!string.IsNullOrEmpty(Options.Namespace))
{
Params["ns"] = Options.Namespace;
}

if (!string.IsNullOrEmpty(Options.Datacenter))
{
Params["dc"] = Options.Datacenter;
Expand All @@ -285,13 +300,13 @@ protected override void ApplyHeaders(HttpRequestMessage message, ConsulClientCon
public class PutRequest<TIn, TOut> : ConsulRequest
{
public WriteOptions Options { get; set; }
private TIn _body;
private readonly TIn _body;

public PutRequest(ConsulClient client, string url, TIn body, WriteOptions options = null) : base(client, url, HttpMethod.Put)
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentException(nameof(url));
throw new ArgumentException(null, nameof(url));
}
_body = body;
Options = options ?? WriteOptions.Default;
Expand All @@ -312,7 +327,7 @@ public async Task<WriteResult<TOut>> Execute(CancellationToken ct)

if (typeof(TIn) == typeof(byte[]))
{
var bodyBytes = (_body as byte[]);
var bodyBytes = _body as byte[];
if (bodyBytes != null)
{
content = new ByteArrayContent(bodyBytes);
Expand Down Expand Up @@ -367,6 +382,11 @@ protected override void ApplyOptions(ConsulClientConfiguration clientConfig)
return;
}

if (!string.IsNullOrEmpty(Options.Namespace))
{
Params["ns"] = Options.Namespace;
}

if (!string.IsNullOrEmpty(Options.Datacenter))
{
Params["dc"] = Options.Datacenter;
Expand Down