-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add security.clear_cached_privileges API
Relates: elastic/elasticsearch#55836 Derive ClearCachedRealmsResponse from NodesResponseBase to expose NodeStatistics.
- Loading branch information
Showing
11 changed files
with
196 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/Nest/XPack/Security/ClearCachedPrivileges/ClearCachedPrivilegesRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
namespace Nest | ||
{ | ||
[MapsApi("security.clear_cached_privileges.json")] | ||
public partial interface IClearCachedPrivilegesRequest { } | ||
|
||
public partial class ClearCachedPrivilegesRequest { } | ||
|
||
public partial class ClearCachedPrivilegesDescriptor { } | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Nest/XPack/Security/ClearCachedPrivileges/ClearCachedPrivilegesResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System.Collections.Generic; | ||
using System.Runtime.Serialization; | ||
using Elasticsearch.Net; | ||
|
||
namespace Nest | ||
{ | ||
public class ClearCachedPrivilegesResponse : NodesResponseBase | ||
{ | ||
[DataMember(Name ="cluster_name")] | ||
public string ClusterName { get; internal set; } | ||
|
||
[DataMember(Name ="nodes")] | ||
public IReadOnlyDictionary<string, SecurityNode> Nodes { get; internal set; } = EmptyReadOnly<string, SecurityNode>.Dictionary; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
tests/Tests/XPack/Security/ClearCachedPrivileges/ClearCachedPrivilegesApiTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System; | ||
using System.Linq; | ||
using Elastic.Elasticsearch.Ephemeral; | ||
using Elastic.Elasticsearch.Xunit.XunitPlumbing; | ||
using Elasticsearch.Net; | ||
using FluentAssertions; | ||
using Nest; | ||
using Tests.Core.Extensions; | ||
using Tests.Core.ManagedElasticsearch.Clusters; | ||
using Tests.Framework.EndpointTests; | ||
using Tests.Framework.EndpointTests.TestState; | ||
|
||
namespace Tests.XPack.Security.ClearCachedPrivileges | ||
{ | ||
[SkipVersion("<7.9.0", "Introduced in 7.9.0")] | ||
public class ClearCachedPrivilegesApiTests | ||
: ApiIntegrationTestBase<XPackCluster, ClearCachedPrivilegesResponse, IClearCachedPrivilegesRequest, ClearCachedPrivilegesDescriptor, | ||
ClearCachedPrivilegesRequest> | ||
{ | ||
public ClearCachedPrivilegesApiTests(XPackCluster cluster, EndpointUsage usage) : base(cluster, usage) { } | ||
|
||
protected override bool ExpectIsValid => true; | ||
protected override int ExpectStatusCode => 200; | ||
|
||
protected override Func<ClearCachedPrivilegesDescriptor, IClearCachedPrivilegesRequest> Fluent => d => d; | ||
protected override HttpMethod HttpMethod => HttpMethod.POST; | ||
|
||
protected override ClearCachedPrivilegesRequest Initializer => new ClearCachedPrivilegesRequest(Application); | ||
|
||
protected override bool SupportsDeserialization => false; | ||
|
||
protected override string UrlPath => $"/_security/privilege/{U(Application)}/_clear_cache"; | ||
|
||
private string Application => "myapp"; | ||
|
||
protected override LazyResponses ClientUsage() => Calls( | ||
(client, f) => client.Security.ClearCachedPrivileges(Application, f), | ||
(client, f) => client.Security.ClearCachedPrivilegesAsync(Application, f), | ||
(client, r) => client.Security.ClearCachedPrivileges(r), | ||
(client, r) => client.Security.ClearCachedPrivilegesAsync(r) | ||
); | ||
|
||
protected override ClearCachedPrivilegesDescriptor NewDescriptor() => new ClearCachedPrivilegesDescriptor(Application); | ||
|
||
protected override void ExpectResponse(ClearCachedPrivilegesResponse response) | ||
{ | ||
response.ClusterName.Should().NotBeNullOrWhiteSpace(); | ||
response.Nodes.Should().NotBeEmpty().And.HaveCount(1); | ||
response.NodeStatistics.Should().NotBeNull(); | ||
var node = response.Nodes.First().Value; | ||
node.Should().NotBeNull(); | ||
node.Name.Should().NotBeNullOrEmpty(); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/Tests/XPack/Security/ClearCachedPrivileges/ClearCachedPrivilegesUrlTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System.Threading.Tasks; | ||
using Elastic.Elasticsearch.Xunit.XunitPlumbing; | ||
using Nest; | ||
using Tests.Framework.EndpointTests; | ||
using static Tests.Framework.EndpointTests.UrlTester; | ||
|
||
namespace Tests.XPack.Security.ClearCachedPrivileges | ||
{ | ||
public class ClearCachedPrivilegesUrlTests : UrlTestsBase | ||
{ | ||
[U] public override async Task Urls() => | ||
await POST("/_security/privilege/myapp/_clear_cache") | ||
.Fluent(c => c.Security.ClearCachedPrivileges("myapp")) | ||
.Request(c => c.Security.ClearCachedPrivileges(new ClearCachedPrivilegesRequest("myapp"))) | ||
.FluentAsync(c => c.Security.ClearCachedPrivilegesAsync("myapp")) | ||
.RequestAsync(c => c.Security.ClearCachedPrivilegesAsync(new ClearCachedPrivilegesRequest("myapp"))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters