[FEATURE] Update ACL Token List endpoint#592
[FEATURE] Update ACL Token List endpoint#592marcin-krystianc merged 35 commits intoG-Research:masterfrom
List endpoint#592Conversation
…te-acl-token-list-endpoint
…te-acl-token-list-endpoint
…te-acl-token-list-endpoint
7e56c96 to
ce9d08c
Compare
Consul.Test/TokenTest.cs
Outdated
| { | ||
| Skip.If(string.IsNullOrEmpty(TestHelper.MasterToken)); | ||
| var cutOffVersion = SemanticVersion.Parse("1.7.14"); | ||
| Skip.If(AgentVersion == cutOffVersion, $"Node Identity is not supported in {AgentVersion}"); |
There was a problem hiding this comment.
Generally, it is not a good idea to change (or remove) existing tests when implementing new features. It is easier to reason about backwards compatibility if we do not touch exisiting test code.
Consul/Token.cs
Outdated
| public TokenEntry() | ||
| : this(string.Empty, string.Empty, Array.Empty<PolicyLink>(), Array.Empty<RoleLink>(), Array.Empty<ServiceIdentity>()) | ||
| : this(string.Empty, string.Empty, Array.Empty<PolicyLink>(), Array.Empty<RoleLink>(), Array.Empty<ServiceIdentity>(), false, Array.Empty<TemplatedPolicy>(), Array.Empty<NodeIdentity>(), null, null) | ||
| { | ||
| } | ||
|
|
||
| public TokenEntry(string description, PolicyLink[] policies) | ||
| : this(string.Empty, description, policies, Array.Empty<RoleLink>(), Array.Empty<ServiceIdentity>()) | ||
| : this(string.Empty, description, policies, Array.Empty<RoleLink>(), Array.Empty<ServiceIdentity>(), false, Array.Empty<TemplatedPolicy>(), Array.Empty<NodeIdentity>(), null, null) | ||
| { | ||
| } | ||
|
|
||
| public TokenEntry(string description, RoleLink[] roles) | ||
| : this(string.Empty, description, Array.Empty<PolicyLink>(), roles, Array.Empty<ServiceIdentity>()) | ||
| : this(string.Empty, description, Array.Empty<PolicyLink>(), roles, Array.Empty<ServiceIdentity>(), false, Array.Empty<TemplatedPolicy>(), Array.Empty<NodeIdentity>(), null, null) | ||
| { | ||
| } | ||
|
|
||
| public TokenEntry(string description, ServiceIdentity[] serviceIdentities) | ||
| : this(string.Empty, description, Array.Empty<PolicyLink>(), Array.Empty<RoleLink>(), serviceIdentities) | ||
| : this(string.Empty, description, Array.Empty<PolicyLink>(), Array.Empty<RoleLink>(), serviceIdentities, false, Array.Empty<TemplatedPolicy>(), Array.Empty<NodeIdentity>(), null, null) | ||
| { | ||
| } | ||
|
|
||
| public TokenEntry(string accessorId, string description) | ||
| : this(accessorId, description, Array.Empty<PolicyLink>(), Array.Empty<RoleLink>(), Array.Empty<ServiceIdentity>()) | ||
| : this(accessorId, description, Array.Empty<PolicyLink>(), Array.Empty<RoleLink>(), Array.Empty<ServiceIdentity>(), false, Array.Empty<TemplatedPolicy>(), Array.Empty<NodeIdentity>(), null, null) | ||
| { | ||
| } | ||
|
|
||
| public TokenEntry(string accessorId, string description, PolicyLink[] policies, RoleLink[] roles, ServiceIdentity[] serviceIdentities) | ||
| public TokenEntry(string accessorId, string description, PolicyLink[] policies, RoleLink[] roles, ServiceIdentity[] serviceIdentities, bool local, TemplatedPolicy[] templatedPolicies, NodeIdentity[] nodeIdentities, DateTime? expirationTime, TimeSpan? expirationTTL) |
There was a problem hiding this comment.
I don't think there's any need to update the constructors here. Ideally, we would remove them entirely, but that should be done in another PR, if at all.
Consul/Interfaces/ITokenEndpoint.cs
Outdated
| Task<QueryResult<TokenEntry[]>> List(string policy, string role, string serviceName, string authMethod, CancellationToken ct); | ||
| Task<QueryResult<TokenEntry[]>> List(string policy, string role, string serviceName, string authMethod); | ||
| Task<QueryResult<TokenEntry[]>> List(string policy, string role, string serviceName, string authMethod, QueryOptions q, CancellationToken ct = default); |
There was a problem hiding this comment.
I think a single overload would do:
| Task<QueryResult<TokenEntry[]>> List(string policy, string role, string serviceName, string authMethod, CancellationToken ct); | |
| Task<QueryResult<TokenEntry[]>> List(string policy, string role, string serviceName, string authMethod); | |
| Task<QueryResult<TokenEntry[]>> List(string policy, string role, string serviceName, string authMethod, QueryOptions q, CancellationToken ct = default); | |
| Task<QueryResult<TokenEntry[]>> List(string policy, string role, string serviceName, string authMethod, QueryOptions q = QueryOptions.Default, CancellationToken ct = default); |
Consul/TemplatedPolicy.cs
Outdated
| { | ||
| public class TemplatedPolicy | ||
| { | ||
| [JsonProperty("TemplateName")] |
There was a problem hiding this comment.
I don't think that this adds any value:
| [JsonProperty("TemplateName")] |
Consul/TemplatedPolicy.cs
Outdated
| [JsonProperty("TemplateName")] | ||
| public string TemplateName { get; set; } | ||
|
|
||
| [JsonProperty("TemplateVariables")] |
There was a problem hiding this comment.
I don't think that this adds any value:
| [JsonProperty("TemplateVariables")] |
0a31b2a to
44a10c2
Compare
b03daab to
03cd119
Compare
Consul.Test/TokenTest.cs
Outdated
| if (matchingToken.Response != null) | ||
| await _client.Token.Delete(matchingToken.Response.AccessorID); | ||
| if (nonMatchingToken.Response != null) | ||
| await _client.Token.Delete(nonMatchingToken.Response.AccessorID); |
There was a problem hiding this comment.
If matchingToken or nonMatchingToken would be null, it would throw NRE. Thus, the if conditions don't make much sense here.
Let's just get rid of try/finally and complicated cleanup logic.
Consul/TemplatedPolicy.cs
Outdated
| // <copyright file="TemplatedPolicy.cs" company="PlayFab Inc"> | ||
| // Copyright 2015 PlayFab Inc. |
There was a problem hiding this comment.
| // <copyright file="TemplatedPolicy.cs" company="PlayFab Inc"> | |
| // Copyright 2015 PlayFab Inc. | |
| // <copyright file="TemplatedPolicy.cs" company="G-Research Limited"> | |
| // Copyright 2020 G-Research Limited | |
Consul/Token.cs
Outdated
| public bool ShouldSerializeTemplatedPolicies() | ||
| { | ||
| return TemplatedPolicies != null && TemplatedPolicies.Length > 0; | ||
| } | ||
|
|
||
| public bool ShouldSerializeNodeIdentities() | ||
| { | ||
| return NodeIdentities != null && NodeIdentities.Length > 0; | ||
| } | ||
|
|
There was a problem hiding this comment.
I don't think this methods are needed at all, please remove them:
| public bool ShouldSerializeTemplatedPolicies() | |
| { | |
| return TemplatedPolicies != null && TemplatedPolicies.Length > 0; | |
| } | |
| public bool ShouldSerializeNodeIdentities() | |
| { | |
| return NodeIdentities != null && NodeIdentities.Length > 0; | |
| } |
Consul.Test/TokenTest.cs
Outdated
| Assert.NotEmpty(nonMatchingToken.Response.Description); | ||
|
|
||
| // List tokens filtering by the specific Policy ID | ||
| var filteredList = await _client.Token.List(policy.Response.ID, null, null, null); |
There was a problem hiding this comment.
Only policyId is tested here, but other filters need to be tested as well.
81c540d to
28b79a2
Compare
28b79a2 to
c936662
Compare
19a276f to
526fe66
Compare
Ah, I realised that I pointed you to a broken test example. I've opened a PR to fix it #614. Please try using the code from that PR. |
…te-acl-token-list-endpoint
b6fe02e to
ed927a8
Compare
I tried to fix it following your approach, and it worked well for creating a new what does this message mean? |
Looking at the docs, it is not possible to set the |
|
I realised that we need to create the token with AuthMethod.Login(), but that one is implemented but not working properly (#615). |
|
Yes, that is what I realized too. I tried to use it but it didn't work, throws: |
Yes, the #615 needs to be done first. I've pushed commit that kind of does this (just an attempt with an agentic tool). Feel free, use it as a starting point and open a PR to fix it properly. |
…te-acl-token-list-endpoint
|
There is a small nit in the previous PR, inside So do you recommend to fix it here or open a separate PR for it? |
Feel, free to open a PR with a fix for that. |
Consul.Test/TokenTest.cs
Outdated
| Assert.NotEmpty(token3.Response.AccessorID); | ||
| Assert.NotEmpty(token3.Response.SecretID); | ||
| Assert.Equal(authMethodEntry.Name, token3.Response.AuthMethod); | ||
| #endif |
There was a problem hiding this comment.
Can you group all the code into a single conditional compilation block? it will make it more readable.
96754bb to
8c4f4e0
Compare
…te-acl-token-list-endpoint
d504119 to
7c3c29d
Compare
Co-authored-by: Marcin Krystianc <marcin.krystianc@gmail.com>
Description
[FEATURE] Update ACL Token
ListendpointRelated Issues
#531
Additional Context
Checklist
Please make sure to check the following before submitting your pull request: