Skip to content

Add password_hash parameter to PutUser #3723

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

Merged
merged 1 commit into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 10 additions & 8 deletions src/Nest/XPack/Security/User/PutUser/ElasticClient-PutUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,43 @@ namespace Nest
{
public partial interface IElasticClient
{
/// <inheritdoc />
/// <summary>
/// Adds and updates users in the native realm. These users are commonly referred to as native users.
/// </summary>
IPutUserResponse PutUser(Name username, Func<PutUserDescriptor, IPutUserRequest> selector = null);

/// <inheritdoc />
/// <inheritdoc cref="PutUser(Nest.Name,System.Func{Nest.PutUserDescriptor,Nest.IPutUserRequest})" />
IPutUserResponse PutUser(IPutUserRequest request);

/// <inheritdoc />
/// <inheritdoc cref="PutUser(Nest.Name,System.Func{Nest.PutUserDescriptor,Nest.IPutUserRequest})" />
Task<IPutUserResponse> PutUserAsync(Name username, Func<PutUserDescriptor, IPutUserRequest> selector = null,
CancellationToken cancellationToken = default(CancellationToken)
);

/// <inheritdoc />
/// <inheritdoc cref="PutUser(Nest.Name,System.Func{Nest.PutUserDescriptor,Nest.IPutUserRequest})" />
Task<IPutUserResponse> PutUserAsync(IPutUserRequest request, CancellationToken cancellationToken = default(CancellationToken));
}

public partial class ElasticClient
{
/// <inheritdoc />
/// <inheritdoc cref="PutUser(Nest.Name,System.Func{Nest.PutUserDescriptor,Nest.IPutUserRequest})" />
public IPutUserResponse PutUser(Name username, Func<PutUserDescriptor, IPutUserRequest> selector = null) =>
PutUser(selector.InvokeOrDefault(new PutUserDescriptor(username)));

/// <inheritdoc />
/// <inheritdoc cref="PutUser(Nest.Name,System.Func{Nest.PutUserDescriptor,Nest.IPutUserRequest})" />
public IPutUserResponse PutUser(IPutUserRequest request) =>
Dispatcher.Dispatch<IPutUserRequest, PutUserRequestParameters, PutUserResponse>(
request,
LowLevelDispatch.XpackSecurityPutUserDispatch<PutUserResponse>
);

/// <inheritdoc />
/// <inheritdoc cref="PutUser(Nest.Name,System.Func{Nest.PutUserDescriptor,Nest.IPutUserRequest})" />
public Task<IPutUserResponse> PutUserAsync(Name username, Func<PutUserDescriptor, IPutUserRequest> selector = null,
CancellationToken cancellationToken = default(CancellationToken)
) =>
PutUserAsync(selector.InvokeOrDefault(new PutUserDescriptor(username)), cancellationToken);

/// <inheritdoc />
/// <inheritdoc cref="PutUser(Nest.Name,System.Func{Nest.PutUserDescriptor,Nest.IPutUserRequest})" />
public Task<IPutUserResponse> PutUserAsync(IPutUserRequest request, CancellationToken cancellationToken = default(CancellationToken)) =>
Dispatcher.DispatchAsync<IPutUserRequest, PutUserRequestParameters, PutUserResponse, IPutUserResponse>(
request,
Expand Down
61 changes: 61 additions & 0 deletions src/Nest/XPack/Security/User/PutUser/PutUserRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,113 @@ namespace Nest
{
public partial interface IPutUserRequest
{
/// <summary>
/// The email of the user.
/// </summary>
[JsonProperty("email")]
string Email { get; set; }

/// <summary>
/// The full name of the user.
/// </summary>
[JsonProperty("full_name")]
string FullName { get; set; }

/// <summary>
/// Arbitrary metadata that you want to associate with the user.
/// </summary>
[JsonProperty("metadata")]
IDictionary<string, object> Metadata { get; set; }

/// <summary>
/// The user’s password. Passwords must be at least 6 characters long.
/// </summary>
/// <remarks>
/// When adding a user, one of <see cref="Password" /> or <see cref="PasswordHash" /> is required. When updating an existing user,
/// the password is optional, so that other fields on the user (such as their roles) may be updated without modifying the user’s password.
/// </remarks>
[JsonProperty("password")]
string Password { get; set; }

/// <summary>
/// A hash of the user’s password. This must be produced using the same hashing algorithm as has been configured for password storage.
/// Using this parameter allows the client to pre-hash the password for performance and/or confidentiality reasons.
/// The <see cref="Password" /> parameter and the <see cref="PasswordHash" /> parameter cannot be used in the same request.
/// </summary>
[JsonProperty("password_hash")]
string PasswordHash { get; set; }

/// <summary>
/// A set of roles the user has. The roles determine the user’s access permissions. To create a user without any roles, specify an empty list.
/// </summary>
[JsonProperty("roles")]
IEnumerable<string> Roles { get; set; }
}

public partial class PutUserRequest
{
/// <inheritdoc />
public string Email { get; set; }

/// <inheritdoc />
public string FullName { get; set; }

/// <inheritdoc />
public IDictionary<string, object> Metadata { get; set; }

/// <inheritdoc />
public string Password { get; set; }

/// <inheritdoc />
public string PasswordHash { get; set; }

/// <inheritdoc />
public IEnumerable<string> Roles { get; set; }
}

[DescriptorFor("XpackSecurityPutUser")]
public partial class PutUserDescriptor
{
/// <inheritdoc />
string IPutUserRequest.Email { get; set; }

/// <inheritdoc />
string IPutUserRequest.FullName { get; set; }

/// <inheritdoc />
IDictionary<string, object> IPutUserRequest.Metadata { get; set; }

/// <inheritdoc />
string IPutUserRequest.Password { get; set; }

/// <inheritdoc />
string IPutUserRequest.PasswordHash { get; set; }

/// <inheritdoc />
IEnumerable<string> IPutUserRequest.Roles { get; set; }

/// <inheritdoc cref="IPutUserRequest.Password" />
public PutUserDescriptor Password(string password) => Assign(password, (a, v) => a.Password = v);

/// <inheritdoc cref="IPutUserRequest.PasswordHash" />
public PutUserDescriptor PasswordHash(string passwordHash) => Assign(passwordHash, (a, v) => a.PasswordHash = v);

/// <inheritdoc cref="IPutUserRequest.Roles" />
public PutUserDescriptor Roles(IEnumerable<string> roles) => Assign(roles, (a, v) => a.Roles = v);

/// <inheritdoc cref="IPutUserRequest.Roles" />
public PutUserDescriptor Roles(params string[] roles) => Assign(roles, (a, v) => a.Roles = v);

/// <inheritdoc cref="IPutUserRequest.FullName" />
public PutUserDescriptor FullName(string fullName) => Assign(fullName, (a, v) => a.FullName = v);

/// <inheritdoc cref="IPutUserRequest.Email" />
public PutUserDescriptor Email(string email) => Assign(email, (a, v) => a.Email = v);

/// <inheritdoc cref="IPutUserRequest.Metadata" />
public PutUserDescriptor Metadata(IDictionary<string, object> metadata) => Assign(metadata, (a, v) => a.Metadata = v);

/// <inheritdoc cref="IPutUserRequest.Metadata" />
public PutUserDescriptor Metadata(Func<FluentDictionary<string, object>, IDictionary<string, object>> selector) =>
Assign(selector, (a, v) => a.Metadata = v?.Invoke(new FluentDictionary<string, object>()));
}
Expand Down