-
Notifications
You must be signed in to change notification settings - Fork 94
Added GET GatewayService endpoint, tests for it #347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
afd02b7
8d8b471
b50c8b9
e70153c
c9305bd
954dbf7
fa04eef
a80f67f
1161a9e
7705e0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -317,5 +317,102 @@ public async Task Catalog_ServicesForNodes() | |||||
| Assert.Contains(services.Response.Services, n => n.ID == svcID); | ||||||
| Assert.DoesNotContain(services.Response.Services, n => n.ID == svcID2); | ||||||
| } | ||||||
|
|
||||||
| [Fact] | ||||||
| public async Task Catalog_GatewayServices() | ||||||
| { | ||||||
| using (IConsulClient client = new ConsulClient(c => | ||||||
| { | ||||||
| c.Token = TestHelper.MasterToken; | ||||||
| c.Address = TestHelper.HttpUri; | ||||||
| })) | ||||||
| { | ||||||
| var terminatingGatewayName = "terminating-gateway"; | ||||||
|
||||||
| var terminatingGatewayName = "terminating-gateway"; | |
| var terminatingGatewayName = "my-terminating-gateway"; |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use a non-standard name, e.g.:
| var ingressGatewayName = "ingress-gateway"; | |
| var ingressGatewayName = "my-ingress-gateway"; |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would also be good to check if other fields in the response are non-null, hence we know that the struct is correctly defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's a good idea, let me do that real quick
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would also be good to check if other fields in the response are non-null, hence we know that the struct is correctly defined.
Just added the checks, you can see that we can't check all fields, cause some fields are just not present in the response for both gateways, and some just for ingress one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add checks for port and protocol for the ingress one. Apart from that, it looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcin-krystianc
Sorry, just saw your message, added the assertions, tests went good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Thanks for help with the PRs!
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,6 +118,62 @@ public class ServiceAddress | |
| public int Port { get; set; } | ||
| } | ||
|
|
||
| public class CompoundServiceName | ||
| { | ||
| public string Namespace { get; set; } | ||
| public string Partition { get; set; } | ||
| public string Name { get; set; } | ||
| } | ||
|
|
||
| public class GatewayService | ||
| { | ||
| public CompoundServiceName Gateway { get; set; } | ||
| public CompoundServiceName Service { get; set; } | ||
| public ServiceKind GatewayKind { get; set; } | ||
| public int Port { get; set; } | ||
| public string Protocol { get; set; } | ||
| public List<string> Hosts { get; set; } | ||
| public string CAFile { get; set; } | ||
| public string CertFile { get; set; } | ||
| public string KeyFile { get; set; } | ||
| public string SNI { get; set; } | ||
| public bool FromWildcard { get; set; } | ||
| } | ||
|
|
||
| public class TerminatingGatewayConfigEntry : IConfigurationEntry | ||
|
||
| { | ||
| public string Kind { get; set; } | ||
| public string Name { get; set; } | ||
| public List<LinkedServiceGateway> Services { get; set; } | ||
| } | ||
|
|
||
| public class LinkedServiceGateway | ||
| { | ||
| public string Name { get; set; } | ||
| public string CAFile { get; set; } | ||
| public string CertFile { get; set; } | ||
| public string KeyFile { get; set; } | ||
| public string SNI { get; set; } | ||
| } | ||
|
|
||
| public class IngressGatewayConfigEntry : IConfigurationEntry | ||
| { | ||
| public string Kind { get; set; } | ||
| public string Name { get; set; } | ||
| public List<IngressListener> Listeners { get; set; } | ||
| } | ||
|
|
||
| public class IngressListener | ||
| { | ||
| public int Port { get; set; } | ||
| public List<IngressService> Services { get; set; } | ||
| } | ||
|
|
||
| public class IngressService | ||
| { | ||
| public string Name { get; set; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Catalog can be used to query the Catalog endpoints | ||
| /// </summary> | ||
|
|
@@ -352,6 +408,30 @@ public Task<QueryResult<NodeService>> ServicesForNode(string node, QueryOptions | |
| { | ||
| return _client.Get<NodeService>(string.Format("/v1/catalog/node-services/{0}", node), q).Execute(ct); | ||
| } | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// GatewayServices is used to query for the services associated with an ingress gateway or terminating gateway | ||
| /// </summary> | ||
| /// <param name="gateway">Gateway name</param> | ||
| /// <param name="q">Query Parameters</param> | ||
| /// <param name="ct">Cancellation Token</param> | ||
| /// <returns>Gateway services</returns> | ||
| public Task<QueryResult<GatewayService[]>> GatewayService(string gateway, QueryOptions q, CancellationToken ct = default) | ||
| { | ||
| return _client.Get<GatewayService[]>($"/v1/catalog/gateway-services/{gateway}", q).Execute(ct); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// GatewayServices is used to query for the services associated with an ingress gateway or terminating gateway | ||
| /// </summary> | ||
| /// <param name="gateway">Gateway name</param> | ||
| /// <param name="ct">Cancellation Token</param> | ||
| /// <returns>Gateway services</returns> | ||
| public Task<QueryResult<GatewayService[]>> GatewayService(string gateway, CancellationToken ct = default) | ||
| { | ||
| return GatewayService(gateway, QueryOptions.Default, ct); | ||
| } | ||
| } | ||
|
|
||
| public partial class ConsulClient : IConsulClient | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That test fails for consul 1.6 and 1.7, you can skip running it for these consul versions: see
consuldotnet/Consul.Test/AgentTest.cs
Lines 542 to 546 in 18a429e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okey, let me fix that!