Skip to content

Commit b56f677

Browse files
authored
Fix ILM and ApiKey APIs (#3735)
Some small fixes to ILM and ApiKey APIs that were discovered whilst forward porting to 7.x
1 parent 00a6a5b commit b56f677

File tree

8 files changed

+32
-23
lines changed

8 files changed

+32
-23
lines changed

src/Nest/XPack/Ilm/LifecycleActions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public LifecycleActions(Dictionary<string, ILifecycleAction> container)
2323
public void Add(IFreezeLifecycleAction action) => BackingDictionary.Add("freeze", action);
2424
public void Add(IReadOnlyLifecycleAction action) => BackingDictionary.Add("readonly", action);
2525
public void Add(IRolloverLifecycleAction action) => BackingDictionary.Add("rollover", action);
26-
public void Add(ISetPriorityLifecycleAction action) => BackingDictionary.Add("setpriority", action);
26+
public void Add(ISetPriorityLifecycleAction action) => BackingDictionary.Add("set_priority", action);
2727
public void Add(IShrinkLifecycleAction action) => BackingDictionary.Add("shrink", action);
2828
public void Add(IUnfollowLifecycleAction action) => BackingDictionary.Add("unfollow", action);
2929
}
@@ -122,7 +122,7 @@ public LifecycleActionsDescriptor Rollover(Func<RolloverLifecycleActionDescripto
122122
Assign("rollover", selector.InvokeOrDefault(new RolloverLifecycleActionDescriptor()));
123123

124124
public LifecycleActionsDescriptor SetPriority(Func<SetPriorityLifecycleActionDescriptor, ISetPriorityLifecycleAction> selector) =>
125-
Assign("setpriority", selector.InvokeOrDefault(new SetPriorityLifecycleActionDescriptor()));
125+
Assign("set_priority", selector.InvokeOrDefault(new SetPriorityLifecycleActionDescriptor()));
126126

127127
public LifecycleActionsDescriptor Shrink(Func<ShrinkLifecycleActionDescriptor, IShrinkLifecycleAction> selector) =>
128128
Assign("shrink", selector.InvokeOrDefault(new ShrinkLifecycleActionDescriptor()));

src/Nest/XPack/Ilm/MoveToStep/MoveToStepRequest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public partial interface IMoveToStepRequest
1212
IStepKey NextStep { get; set; }
1313
}
1414

15+
[JsonConverter(typeof(ReadAsTypeJsonConverter<StepKey>))]
1516
public interface IStepKey
1617
{
1718
[JsonProperty("phase")]
@@ -24,6 +25,15 @@ public interface IStepKey
2425
string Name { get; set; }
2526
}
2627

28+
public class StepKey : IStepKey
29+
{
30+
public string Phase { get; set; }
31+
32+
public string Action { get; set; }
33+
34+
public string Name { get; set; }
35+
}
36+
2737
public partial class MoveToStepRequest
2838
{
2939
public IStepKey CurrentStep { get; set; }

src/Nest/XPack/Ilm/Phases.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,23 @@ public class Phases : IPhases
2727
public IPhase Delete { get; set; }
2828
}
2929

30-
public class PhasesDescriptor : IDescriptor, IPhases
30+
public class PhasesDescriptor : DescriptorBase<PhasesDescriptor, IPhases>, IPhases
3131
{
3232
IPhase IPhases.Warm { get; set; }
3333
IPhase IPhases.Hot { get; set; }
3434
IPhase IPhases.Cold { get; set; }
3535
IPhase IPhases.Delete { get; set; }
3636

37-
private PhasesDescriptor Assign<TValue>(TValue value, Action<IPhases, TValue> assigner) => Fluent.Assign(this, value, assigner);
38-
3937
public PhasesDescriptor Warm(Func<PhaseDescriptor, IPhase> selector) =>
40-
Assign(selector, (a, v) => a.Warm = v?.InvokeOrDefault(new PhaseDescriptor()));
38+
Assign(selector, (a, v) => a.Warm = v.InvokeOrDefault(new PhaseDescriptor()));
4139

4240
public PhasesDescriptor Hot(Func<PhaseDescriptor, IPhase> selector) =>
43-
Assign(selector, (a, v) => a.Hot = v?.InvokeOrDefault(new PhaseDescriptor()));
41+
Assign(selector, (a, v) => a.Hot = v.InvokeOrDefault(new PhaseDescriptor()));
4442

4543
public PhasesDescriptor Cold(Func<PhaseDescriptor, IPhase> selector) =>
46-
Assign(selector, (a, v) => a.Cold = v?.InvokeOrDefault(new PhaseDescriptor()));
44+
Assign(selector, (a, v) => a.Cold = v.InvokeOrDefault(new PhaseDescriptor()));
4745

4846
public PhasesDescriptor Delete(Func<PhaseDescriptor, IPhase> selector) =>
49-
Assign(selector, (a, v) => a.Delete = v?.InvokeOrDefault(new PhaseDescriptor()));
47+
Assign(selector, (a, v) => a.Delete = v.InvokeOrDefault(new PhaseDescriptor()));
5048
}
5149
}

src/Nest/XPack/Ilm/Policy.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ public class Policy : IPolicy
1515
public IPhases Phases { get; set; }
1616
}
1717

18-
public class PolicyDescriptor : IDescriptor, IPolicy
18+
public class PolicyDescriptor : DescriptorBase<PolicyDescriptor, IPolicy>, IPolicy
1919
{
2020
IPhases IPolicy.Phases { get; set; }
2121

22-
private PolicyDescriptor Assign<TValue>(TValue value, Action<IPolicy, TValue> assigner) => Fluent.Assign(this, value, assigner);
23-
2422
public PolicyDescriptor Phases(Func<PhasesDescriptor, IPhases> selector) =>
25-
Assign(selector, (a, v) => a.Phases = v?.InvokeOrDefault(new PhasesDescriptor()));
23+
Assign(selector, (a, v) => a.Phases = v.InvokeOrDefault(new PhasesDescriptor()));
2624
}
2725
}

src/Nest/XPack/Security/ApiKey/CreateApiKey/ApiKeyPrivileges.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
using System;
22
using System.Collections.Generic;
3+
using Newtonsoft.Json;
34

45
namespace Nest
56
{
7+
[JsonConverter(typeof(ReadAsTypeJsonConverter<ApiKeyPrivileges>))]
68
public interface IApiKeyPrivileges
79
{
810
/// <summary>
911
/// A list of names.
1012
/// </summary>
13+
[JsonProperty("names")]
1114
IEnumerable<string> Names { get; set; }
1215

1316
/// <summary>
1417
/// A list of privileges.
1518
/// </summary>
19+
[JsonProperty("privileges")]
1620
IEnumerable<string> Privileges { get; set; }
1721
}
1822

src/Nest/XPack/Security/ApiKey/CreateApiKey/ApiKeyRole.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Nest
66
{
7+
[JsonConverter(typeof(ReadAsTypeJsonConverter<ApiKeyRole>))]
78
public interface IApiKeyRole
89
{
910
/// <summary>

src/Nest/XPack/Security/ApiKey/CreateApiKey/CreateApiKeyRequest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public partial class CreateApiKeyDescriptor
5757

5858
/// <inheritdoc cref="ICreateApiKeyRequest.Roles" />
5959
public CreateApiKeyDescriptor Roles(Func<ApiKeyRolesDescriptor, IPromise<IApiKeyRoles>> selector) =>
60-
Assign(selector,
61-
(a, v) => a.Roles = v?.Invoke(new ApiKeyRolesDescriptor())?.Value ?? new ApiKeyRoles()); // Ensure not null, as server expects {}
60+
Assign(selector, (a, v) => a.Roles = v.InvokeOrDefault(new ApiKeyRolesDescriptor()).Value);
6261
}
6362
}

src/Nest/XPack/Security/ApiKey/GetApiKey/GetApiKeyResponse.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,44 +25,43 @@ public class ApiKeys
2525
/// Id for the API key
2626
/// </summary>
2727
[JsonProperty("id")]
28-
public string Id { get; set; }
28+
public string Id { get; internal set; }
2929

3030
/// <summary>
3131
/// Name of the API key
3232
/// </summary>
3333
[JsonProperty("name")]
34-
public string Name { get; set; }
34+
public string Name { get; internal set; }
3535

3636
/// <summary>
3737
/// Creation time for the API key
3838
/// </summary>
3939
[JsonProperty("creation")]
4040
[JsonConverter(typeof(EpochMillisecondsDateTimeJsonConverter))]
41-
public DateTimeOffset Creation { get; set; }
41+
public DateTimeOffset Creation { get; internal set; }
4242

4343
/// <summary>
4444
/// Optional expiration time for the API key in milliseconds
4545
/// </summary>
4646
[JsonProperty("expiration")]
4747
[JsonConverter(typeof(EpochMillisecondsDateTimeJsonConverter))]
48-
public DateTimeOffset? Expiration { get; set; }
48+
public DateTimeOffset? Expiration { get; internal set; }
4949

5050
/// <summary>
5151
/// Invalidation status for the API key. If the key has been invalidated, it has a value of true. Otherwise, it is false.
5252
/// </summary>
5353
[JsonProperty("invalidated")]
54-
public bool Invalidated { get; set; }
54+
public bool Invalidated { get; internal set; }
5555

5656
/// <summary>
5757
/// Principal for which this API key was created
5858
/// </summary>
5959
[JsonProperty("username")]
60-
public string Username { get; set; }
61-
60+
public string Username { get; internal set; }
6261
/// <summary>
6362
/// Realm name of the principal for which this API key was created
6463
/// </summary>
6564
[JsonProperty("realm")]
66-
public string Realm { get; set; }
65+
public string Realm { get; internal set; }
6766
}
6867
}

0 commit comments

Comments
 (0)