Skip to content

Commit 0dcb5e8

Browse files
Add more Security APIs (#6351) (#6352)
Co-authored-by: Steve Gordon <sgordon@hotmail.co.uk>
1 parent 056a860 commit 0dcb5e8

File tree

66 files changed

+4697
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+4697
-12
lines changed

src/Elastic.Clients.Elasticsearch/Common/Infer/Name/Name.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,44 @@ public override int GetHashCode()
4848
}
4949
}
5050
}
51+
52+
[DebuggerDisplay("{DebugDisplay,nq}")]
53+
[JsonConverter(typeof(StringAliasConverter<Username>))]
54+
public class Username : IEquatable<Username>, IUrlParameter
55+
{
56+
public Username(string name) => Value = name?.Trim();
57+
58+
internal string Value { get; }
59+
60+
private string DebugDisplay => Value;
61+
62+
private static int TypeHashCode { get; } = typeof(Username).GetHashCode();
63+
64+
public bool Equals(Username other) => EqualsString(other?.Value);
65+
66+
string IUrlParameter.GetString(ITransportConfiguration settings) => Value;
67+
68+
public override string ToString() => DebugDisplay;
69+
70+
public static implicit operator Username(string name) => name.IsNullOrEmpty() ? null : new Username(name);
71+
72+
public static bool operator ==(Username left, Username right) => Equals(left, right);
73+
74+
public static bool operator !=(Username left, Username right) => !Equals(left, right);
75+
76+
public override bool Equals(object obj) =>
77+
obj is string s ? EqualsString(s) : obj is Username i && EqualsString(i.Value);
78+
79+
private bool EqualsString(string other) => !other.IsNullOrEmpty() && other.Trim() == Value;
80+
81+
public override int GetHashCode()
82+
{
83+
unchecked
84+
{
85+
var result = TypeHashCode;
86+
result = (result * 397) ^ (Value?.GetHashCode() ?? 0);
87+
return result;
88+
}
89+
}
90+
}
5191
}

src/Elastic.Clients.Elasticsearch/_Generated/Api/ApiUrlsLookup.g.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,37 @@ internal static class ApiUrlsLookups
242242
internal static ApiUrls SearchableSnapshotsStats = new ApiUrls(new[] { "/_searchable_snapshots/stats", "/{index}/_searchable_snapshots/stats" });
243243
internal static ApiUrls NoNamespaceSearch = new ApiUrls(new[] { "/_search", "/{index}/_search" });
244244
internal static ApiUrls NoNamespaceSearchShards = new ApiUrls(new[] { "/_search_shards", "/{index}/_search_shards" });
245+
internal static ApiUrls SecurityAuthenticate = new ApiUrls(new[] { "/_security/_authenticate" });
246+
internal static ApiUrls SecurityChangePassword = new ApiUrls(new[] { "/_security/user/{username}/_password", "/_security/user/_password" });
245247
internal static ApiUrls SecurityClearApiKeyCache = new ApiUrls(new[] { "/_security/api_key/{ids}/_clear_cache" });
248+
internal static ApiUrls SecurityClearCachedPrivileges = new ApiUrls(new[] { "/_security/privilege/{application}/_clear_cache" });
249+
internal static ApiUrls SecurityClearCachedRealms = new ApiUrls(new[] { "/_security/realm/{realms}/_clear_cache" });
250+
internal static ApiUrls SecurityClearCachedRoles = new ApiUrls(new[] { "/_security/role/{name}/_clear_cache" });
246251
internal static ApiUrls SecurityCreateApiKey = new ApiUrls(new[] { "/_security/api_key" });
252+
internal static ApiUrls SecurityDeletePrivileges = new ApiUrls(new[] { "/_security/privilege/{application}/{name}" });
253+
internal static ApiUrls SecurityDeleteRoleMapping = new ApiUrls(new[] { "/_security/role_mapping/{name}" });
254+
internal static ApiUrls SecurityDeleteRole = new ApiUrls(new[] { "/_security/role/{name}" });
255+
internal static ApiUrls SecurityDeleteUser = new ApiUrls(new[] { "/_security/user/{username}" });
256+
internal static ApiUrls SecurityDisableUser = new ApiUrls(new[] { "/_security/user/{username}/_disable" });
257+
internal static ApiUrls SecurityEnableUser = new ApiUrls(new[] { "/_security/user/{username}/_enable" });
247258
internal static ApiUrls SecurityGetApiKey = new ApiUrls(new[] { "/_security/api_key" });
259+
internal static ApiUrls SecurityGetBuiltinPrivileges = new ApiUrls(new[] { "/_security/privilege/_builtin" });
260+
internal static ApiUrls SecurityGetPrivileges = new ApiUrls(new[] { "/_security/privilege", "/_security/privilege/{application}", "/_security/privilege/{application}/{name}" });
261+
internal static ApiUrls SecurityGetRoleMapping = new ApiUrls(new[] { "/_security/role_mapping/{name}", "/_security/role_mapping" });
262+
internal static ApiUrls SecurityGetRole = new ApiUrls(new[] { "/_security/role/{name}", "/_security/role" });
263+
internal static ApiUrls SecurityGetToken = new ApiUrls(new[] { "/_security/oauth2/token" });
248264
internal static ApiUrls SecurityGrantApiKey = new ApiUrls(new[] { "/_security/api_key/grant" });
265+
internal static ApiUrls SecurityHasPrivileges = new ApiUrls(new[] { "/_security/user/_has_privileges", "/_security/user/{user}/_has_privileges" });
249266
internal static ApiUrls SecurityInvalidateApiKey = new ApiUrls(new[] { "/_security/api_key" });
267+
internal static ApiUrls SecurityInvalidateToken = new ApiUrls(new[] { "/_security/oauth2/token" });
268+
internal static ApiUrls SecurityPutUser = new ApiUrls(new[] { "/_security/user/{username}" });
250269
internal static ApiUrls SecurityQueryApiKeys = new ApiUrls(new[] { "/_security/_query/api_key" });
270+
internal static ApiUrls SecuritySamlAuthenticate = new ApiUrls(new[] { "/_security/saml/authenticate" });
271+
internal static ApiUrls SecuritySamlCompleteLogout = new ApiUrls(new[] { "/_security/saml/complete_logout" });
272+
internal static ApiUrls SecuritySamlInvalidate = new ApiUrls(new[] { "/_security/saml/invalidate" });
273+
internal static ApiUrls SecuritySamlLogout = new ApiUrls(new[] { "/_security/saml/logout" });
274+
internal static ApiUrls SecuritySamlPrepareAuthentication = new ApiUrls(new[] { "/_security/saml/prepare" });
275+
internal static ApiUrls SecuritySamlServiceProviderMetadata = new ApiUrls(new[] { "/_security/saml/metadata/{realm_name}" });
251276
internal static ApiUrls SnapshotLifecycleManagementDeleteLifecycle = new ApiUrls(new[] { "/_slm/policy/{policy_id}" });
252277
internal static ApiUrls SnapshotLifecycleManagementExecuteLifecycle = new ApiUrls(new[] { "/_slm/policy/{policy_id}/_execute" });
253278
internal static ApiUrls SnapshotLifecycleManagementExecuteRetention = new ApiUrls(new[] { "/_slm/_execute_retention" });
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
//
5+
// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
6+
// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
7+
// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗
8+
// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝
9+
// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗
10+
// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
11+
// ------------------------------------------------
12+
//
13+
// This file is automatically generated.
14+
// Please do not edit these files manually.
15+
//
16+
// ------------------------------------------------
17+
18+
using Elastic.Transport;
19+
using System;
20+
using System.Collections.Generic;
21+
using System.Linq.Expressions;
22+
using System.Text.Json;
23+
using System.Text.Json.Serialization;
24+
25+
#nullable restore
26+
namespace Elastic.Clients.Elasticsearch.Security
27+
{
28+
public class SecurityAuthenticateRequestParameters : RequestParameters<SecurityAuthenticateRequestParameters>
29+
{
30+
}
31+
32+
public partial class SecurityAuthenticateRequest : PlainRequestBase<SecurityAuthenticateRequestParameters>
33+
{
34+
internal override ApiUrls ApiUrls => ApiUrlsLookups.SecurityAuthenticate;
35+
protected override HttpMethod HttpMethod => HttpMethod.GET;
36+
protected override bool SupportsBody => false;
37+
}
38+
39+
public sealed partial class SecurityAuthenticateRequestDescriptor : RequestDescriptorBase<SecurityAuthenticateRequestDescriptor, SecurityAuthenticateRequestParameters>
40+
{
41+
internal SecurityAuthenticateRequestDescriptor(Action<SecurityAuthenticateRequestDescriptor> configure) => configure.Invoke(this);
42+
public SecurityAuthenticateRequestDescriptor()
43+
{
44+
}
45+
46+
internal override ApiUrls ApiUrls => ApiUrlsLookups.SecurityAuthenticate;
47+
protected override HttpMethod HttpMethod => HttpMethod.GET;
48+
protected override bool SupportsBody => false;
49+
protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
50+
{
51+
}
52+
}
53+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
//
5+
// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
6+
// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
7+
// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗
8+
// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝
9+
// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗
10+
// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
11+
// ------------------------------------------------
12+
//
13+
// This file is automatically generated.
14+
// Please do not edit these files manually.
15+
//
16+
// ------------------------------------------------
17+
18+
using Elastic.Transport.Products.Elasticsearch;
19+
using System.Collections.Generic;
20+
using System.Text.Json.Serialization;
21+
22+
#nullable restore
23+
namespace Elastic.Clients.Elasticsearch.Security
24+
{
25+
public partial class SecurityAuthenticateResponse : ElasticsearchResponseBase
26+
{
27+
[JsonInclude]
28+
[JsonPropertyName("api_key")]
29+
public Elastic.Clients.Elasticsearch.Security.ApiKey? ApiKey { get; init; }
30+
31+
[JsonInclude]
32+
[JsonPropertyName("authentication_realm")]
33+
public Elastic.Clients.Elasticsearch.Security.RealmInfo AuthenticationRealm { get; init; }
34+
35+
[JsonInclude]
36+
[JsonPropertyName("authentication_type")]
37+
public string AuthenticationType { get; init; }
38+
39+
[JsonInclude]
40+
[JsonPropertyName("email")]
41+
public string? Email { get; init; }
42+
43+
[JsonInclude]
44+
[JsonPropertyName("enabled")]
45+
public bool Enabled { get; init; }
46+
47+
[JsonInclude]
48+
[JsonPropertyName("full_name")]
49+
public string? FullName { get; init; }
50+
51+
[JsonInclude]
52+
[JsonPropertyName("lookup_realm")]
53+
public Elastic.Clients.Elasticsearch.Security.RealmInfo LookupRealm { get; init; }
54+
55+
[JsonInclude]
56+
[JsonPropertyName("metadata")]
57+
public Dictionary<string, object> Metadata { get; init; }
58+
59+
[JsonInclude]
60+
[JsonPropertyName("roles")]
61+
public IReadOnlyCollection<string> Roles { get; init; }
62+
63+
[JsonInclude]
64+
[JsonPropertyName("token")]
65+
public Elastic.Clients.Elasticsearch.Security.Token? Token { get; init; }
66+
67+
[JsonInclude]
68+
[JsonPropertyName("username")]
69+
public string Username { get; init; }
70+
}
71+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
//
5+
// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
6+
// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
7+
// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗
8+
// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝
9+
// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗
10+
// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
11+
// ------------------------------------------------
12+
//
13+
// This file is automatically generated.
14+
// Please do not edit these files manually.
15+
//
16+
// ------------------------------------------------
17+
18+
using Elastic.Transport;
19+
using System;
20+
using System.Collections.Generic;
21+
using System.Linq.Expressions;
22+
using System.Text.Json;
23+
using System.Text.Json.Serialization;
24+
25+
#nullable restore
26+
namespace Elastic.Clients.Elasticsearch.Security
27+
{
28+
public class SecurityChangePasswordRequestParameters : RequestParameters<SecurityChangePasswordRequestParameters>
29+
{
30+
[JsonIgnore]
31+
public Elastic.Clients.Elasticsearch.Refresh? Refresh { get => Q<Elastic.Clients.Elasticsearch.Refresh?>("refresh"); set => Q("refresh", value); }
32+
}
33+
34+
public partial class SecurityChangePasswordRequest : PlainRequestBase<SecurityChangePasswordRequestParameters>
35+
{
36+
public SecurityChangePasswordRequest()
37+
{
38+
}
39+
40+
public SecurityChangePasswordRequest(Elastic.Clients.Elasticsearch.Username? username) : base(r => r.Optional("username", username))
41+
{
42+
}
43+
44+
internal override ApiUrls ApiUrls => ApiUrlsLookups.SecurityChangePassword;
45+
protected override HttpMethod HttpMethod => HttpMethod.PUT;
46+
protected override bool SupportsBody => true;
47+
[JsonIgnore]
48+
public Elastic.Clients.Elasticsearch.Refresh? Refresh { get => Q<Elastic.Clients.Elasticsearch.Refresh?>("refresh"); set => Q("refresh", value); }
49+
50+
[JsonInclude]
51+
[JsonPropertyName("password")]
52+
public string? Password { get; set; }
53+
54+
[JsonInclude]
55+
[JsonPropertyName("password_hash")]
56+
public string? PasswordHash { get; set; }
57+
}
58+
59+
public sealed partial class SecurityChangePasswordRequestDescriptor : RequestDescriptorBase<SecurityChangePasswordRequestDescriptor, SecurityChangePasswordRequestParameters>
60+
{
61+
internal SecurityChangePasswordRequestDescriptor(Action<SecurityChangePasswordRequestDescriptor> configure) => configure.Invoke(this);
62+
public SecurityChangePasswordRequestDescriptor()
63+
{
64+
}
65+
66+
internal override ApiUrls ApiUrls => ApiUrlsLookups.SecurityChangePassword;
67+
protected override HttpMethod HttpMethod => HttpMethod.PUT;
68+
protected override bool SupportsBody => true;
69+
public SecurityChangePasswordRequestDescriptor Refresh(Elastic.Clients.Elasticsearch.Refresh? refresh) => Qs("refresh", refresh);
70+
public SecurityChangePasswordRequestDescriptor Username(Elastic.Clients.Elasticsearch.Username? username)
71+
{
72+
RouteValues.Optional("username", username);
73+
return Self;
74+
}
75+
76+
private string? PasswordValue { get; set; }
77+
78+
private string? PasswordHashValue { get; set; }
79+
80+
public SecurityChangePasswordRequestDescriptor Password(string? password)
81+
{
82+
PasswordValue = password;
83+
return Self;
84+
}
85+
86+
public SecurityChangePasswordRequestDescriptor PasswordHash(string? passwordHash)
87+
{
88+
PasswordHashValue = passwordHash;
89+
return Self;
90+
}
91+
92+
protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
93+
{
94+
writer.WriteStartObject();
95+
if (PasswordValue is not null)
96+
{
97+
writer.WritePropertyName("password");
98+
JsonSerializer.Serialize(writer, PasswordValue, options);
99+
}
100+
101+
if (!string.IsNullOrEmpty(PasswordHashValue))
102+
{
103+
writer.WritePropertyName("password_hash");
104+
writer.WriteStringValue(PasswordHashValue);
105+
}
106+
107+
writer.WriteEndObject();
108+
}
109+
}
110+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information.
4+
//
5+
// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
6+
// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
7+
// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗
8+
// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝
9+
// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗
10+
// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
11+
// ------------------------------------------------
12+
//
13+
// This file is automatically generated.
14+
// Please do not edit these files manually.
15+
//
16+
// ------------------------------------------------
17+
18+
using Elastic.Transport.Products.Elasticsearch;
19+
using System.Collections.Generic;
20+
using System.Text.Json.Serialization;
21+
22+
#nullable restore
23+
namespace Elastic.Clients.Elasticsearch.Security
24+
{
25+
public partial class SecurityChangePasswordResponse : ElasticsearchResponseBase
26+
{
27+
}
28+
}

0 commit comments

Comments
 (0)