From 611e99fe0d43d1156697c743c5621e58fede48d5 Mon Sep 17 00:00:00 2001 From: Russ Cam Date: Thu, 9 May 2019 14:17:04 +1000 Subject: [PATCH] Fix ILM and ApiKey APIs Some small fixes to ILM and ApiKey APIs that were discovered whilst forward porting to 7.x --- src/Nest/XPack/Ilm/LifecycleActions.cs | 4 ++-- .../XPack/Ilm/MoveToStep/MoveToStepRequest.cs | 10 ++++++++++ src/Nest/XPack/Ilm/Phases.cs | 12 +++++------- src/Nest/XPack/Ilm/Policy.cs | 6 ++---- .../ApiKey/CreateApiKey/ApiKeyPrivileges.cs | 4 ++++ .../Security/ApiKey/CreateApiKey/ApiKeyRole.cs | 1 + .../ApiKey/CreateApiKey/CreateApiKeyRequest.cs | 3 +-- .../ApiKey/GetApiKey/GetApiKeyResponse.cs | 15 +++++++-------- 8 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/Nest/XPack/Ilm/LifecycleActions.cs b/src/Nest/XPack/Ilm/LifecycleActions.cs index 4cc29199428..2b519982579 100644 --- a/src/Nest/XPack/Ilm/LifecycleActions.cs +++ b/src/Nest/XPack/Ilm/LifecycleActions.cs @@ -23,7 +23,7 @@ public LifecycleActions(Dictionary container) public void Add(IFreezeLifecycleAction action) => BackingDictionary.Add("freeze", action); public void Add(IReadOnlyLifecycleAction action) => BackingDictionary.Add("readonly", action); public void Add(IRolloverLifecycleAction action) => BackingDictionary.Add("rollover", action); - public void Add(ISetPriorityLifecycleAction action) => BackingDictionary.Add("setpriority", action); + public void Add(ISetPriorityLifecycleAction action) => BackingDictionary.Add("set_priority", action); public void Add(IShrinkLifecycleAction action) => BackingDictionary.Add("shrink", action); public void Add(IUnfollowLifecycleAction action) => BackingDictionary.Add("unfollow", action); } @@ -122,7 +122,7 @@ public LifecycleActionsDescriptor Rollover(Func selector) => - Assign("setpriority", selector.InvokeOrDefault(new SetPriorityLifecycleActionDescriptor())); + Assign("set_priority", selector.InvokeOrDefault(new SetPriorityLifecycleActionDescriptor())); public LifecycleActionsDescriptor Shrink(Func selector) => Assign("shrink", selector.InvokeOrDefault(new ShrinkLifecycleActionDescriptor())); diff --git a/src/Nest/XPack/Ilm/MoveToStep/MoveToStepRequest.cs b/src/Nest/XPack/Ilm/MoveToStep/MoveToStepRequest.cs index f3b9eae907c..2b2d094d2f9 100644 --- a/src/Nest/XPack/Ilm/MoveToStep/MoveToStepRequest.cs +++ b/src/Nest/XPack/Ilm/MoveToStep/MoveToStepRequest.cs @@ -12,6 +12,7 @@ public partial interface IMoveToStepRequest IStepKey NextStep { get; set; } } + [JsonConverter(typeof(ReadAsTypeJsonConverter))] public interface IStepKey { [JsonProperty("phase")] @@ -24,6 +25,15 @@ public interface IStepKey string Name { get; set; } } + public class StepKey : IStepKey + { + public string Phase { get; set; } + + public string Action { get; set; } + + public string Name { get; set; } + } + public partial class MoveToStepRequest { public IStepKey CurrentStep { get; set; } diff --git a/src/Nest/XPack/Ilm/Phases.cs b/src/Nest/XPack/Ilm/Phases.cs index 85229abc465..4df2802059d 100644 --- a/src/Nest/XPack/Ilm/Phases.cs +++ b/src/Nest/XPack/Ilm/Phases.cs @@ -27,25 +27,23 @@ public class Phases : IPhases public IPhase Delete { get; set; } } - public class PhasesDescriptor : IDescriptor, IPhases + public class PhasesDescriptor : DescriptorBase, IPhases { IPhase IPhases.Warm { get; set; } IPhase IPhases.Hot { get; set; } IPhase IPhases.Cold { get; set; } IPhase IPhases.Delete { get; set; } - private PhasesDescriptor Assign(TValue value, Action assigner) => Fluent.Assign(this, value, assigner); - public PhasesDescriptor Warm(Func selector) => - Assign(selector, (a, v) => a.Warm = v?.InvokeOrDefault(new PhaseDescriptor())); + Assign(selector, (a, v) => a.Warm = v.InvokeOrDefault(new PhaseDescriptor())); public PhasesDescriptor Hot(Func selector) => - Assign(selector, (a, v) => a.Hot = v?.InvokeOrDefault(new PhaseDescriptor())); + Assign(selector, (a, v) => a.Hot = v.InvokeOrDefault(new PhaseDescriptor())); public PhasesDescriptor Cold(Func selector) => - Assign(selector, (a, v) => a.Cold = v?.InvokeOrDefault(new PhaseDescriptor())); + Assign(selector, (a, v) => a.Cold = v.InvokeOrDefault(new PhaseDescriptor())); public PhasesDescriptor Delete(Func selector) => - Assign(selector, (a, v) => a.Delete = v?.InvokeOrDefault(new PhaseDescriptor())); + Assign(selector, (a, v) => a.Delete = v.InvokeOrDefault(new PhaseDescriptor())); } } diff --git a/src/Nest/XPack/Ilm/Policy.cs b/src/Nest/XPack/Ilm/Policy.cs index e72c9cd7137..566eb7d1a62 100644 --- a/src/Nest/XPack/Ilm/Policy.cs +++ b/src/Nest/XPack/Ilm/Policy.cs @@ -15,13 +15,11 @@ public class Policy : IPolicy public IPhases Phases { get; set; } } - public class PolicyDescriptor : IDescriptor, IPolicy + public class PolicyDescriptor : DescriptorBase, IPolicy { IPhases IPolicy.Phases { get; set; } - private PolicyDescriptor Assign(TValue value, Action assigner) => Fluent.Assign(this, value, assigner); - public PolicyDescriptor Phases(Func selector) => - Assign(selector, (a, v) => a.Phases = v?.InvokeOrDefault(new PhasesDescriptor())); + Assign(selector, (a, v) => a.Phases = v.InvokeOrDefault(new PhasesDescriptor())); } } diff --git a/src/Nest/XPack/Security/ApiKey/CreateApiKey/ApiKeyPrivileges.cs b/src/Nest/XPack/Security/ApiKey/CreateApiKey/ApiKeyPrivileges.cs index 1b86ee74b09..fd714d8e7a1 100644 --- a/src/Nest/XPack/Security/ApiKey/CreateApiKey/ApiKeyPrivileges.cs +++ b/src/Nest/XPack/Security/ApiKey/CreateApiKey/ApiKeyPrivileges.cs @@ -1,18 +1,22 @@ using System; using System.Collections.Generic; +using Newtonsoft.Json; namespace Nest { + [JsonConverter(typeof(ReadAsTypeJsonConverter))] public interface IApiKeyPrivileges { /// /// A list of names. /// + [JsonProperty("names")] IEnumerable Names { get; set; } /// /// A list of privileges. /// + [JsonProperty("privileges")] IEnumerable Privileges { get; set; } } diff --git a/src/Nest/XPack/Security/ApiKey/CreateApiKey/ApiKeyRole.cs b/src/Nest/XPack/Security/ApiKey/CreateApiKey/ApiKeyRole.cs index c9abd4ebbf1..e2697037fd4 100644 --- a/src/Nest/XPack/Security/ApiKey/CreateApiKey/ApiKeyRole.cs +++ b/src/Nest/XPack/Security/ApiKey/CreateApiKey/ApiKeyRole.cs @@ -4,6 +4,7 @@ namespace Nest { + [JsonConverter(typeof(ReadAsTypeJsonConverter))] public interface IApiKeyRole { /// diff --git a/src/Nest/XPack/Security/ApiKey/CreateApiKey/CreateApiKeyRequest.cs b/src/Nest/XPack/Security/ApiKey/CreateApiKey/CreateApiKeyRequest.cs index 34812d5aac4..f2a5a6bd77b 100644 --- a/src/Nest/XPack/Security/ApiKey/CreateApiKey/CreateApiKeyRequest.cs +++ b/src/Nest/XPack/Security/ApiKey/CreateApiKey/CreateApiKeyRequest.cs @@ -57,7 +57,6 @@ public partial class CreateApiKeyDescriptor /// public CreateApiKeyDescriptor Roles(Func> selector) => - Assign(selector, - (a, v) => a.Roles = v?.Invoke(new ApiKeyRolesDescriptor())?.Value ?? new ApiKeyRoles()); // Ensure not null, as server expects {} + Assign(selector, (a, v) => a.Roles = v.InvokeOrDefault(new ApiKeyRolesDescriptor()).Value); } } diff --git a/src/Nest/XPack/Security/ApiKey/GetApiKey/GetApiKeyResponse.cs b/src/Nest/XPack/Security/ApiKey/GetApiKey/GetApiKeyResponse.cs index e221a92efaa..eae1d064c5f 100644 --- a/src/Nest/XPack/Security/ApiKey/GetApiKey/GetApiKeyResponse.cs +++ b/src/Nest/XPack/Security/ApiKey/GetApiKey/GetApiKeyResponse.cs @@ -25,44 +25,43 @@ public class ApiKeys /// Id for the API key /// [JsonProperty("id")] - public string Id { get; set; } + public string Id { get; internal set; } /// /// Name of the API key /// [JsonProperty("name")] - public string Name { get; set; } + public string Name { get; internal set; } /// /// Creation time for the API key /// [JsonProperty("creation")] [JsonConverter(typeof(EpochMillisecondsDateTimeJsonConverter))] - public DateTimeOffset Creation { get; set; } + public DateTimeOffset Creation { get; internal set; } /// /// Optional expiration time for the API key in milliseconds /// [JsonProperty("expiration")] [JsonConverter(typeof(EpochMillisecondsDateTimeJsonConverter))] - public DateTimeOffset? Expiration { get; set; } + public DateTimeOffset? Expiration { get; internal set; } /// /// Invalidation status for the API key. If the key has been invalidated, it has a value of true. Otherwise, it is false. /// [JsonProperty("invalidated")] - public bool Invalidated { get; set; } + public bool Invalidated { get; internal set; } /// /// Principal for which this API key was created /// [JsonProperty("username")] - public string Username { get; set; } - + public string Username { get; internal set; } /// /// Realm name of the principal for which this API key was created /// [JsonProperty("realm")] - public string Realm { get; set; } + public string Realm { get; internal set; } } }