Skip to content

Commit e4045f6

Browse files
committed
Added Metadata for Roles (#2450)
* Added Metadata for Roles * Added Metadata to Put Role Request
1 parent d9d9acc commit e4045f6

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/Nest/XPack/Security/Role/GetRole/Role.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ public class XPackRole
1515
[JsonProperty("indices")]
1616
public IReadOnlyCollection<IIndicesPrivileges> Indices { get; private set; } = EmptyReadOnly<IIndicesPrivileges>.Collection;
1717

18+
[JsonProperty("metadata")]
19+
public IReadOnlyDictionary<string, object> Metadata { get; internal set; } = EmptyReadOnly<string, object>.Dictionary;
1820
}
1921
}

src/Nest/XPack/Security/Role/PutRole/PutRoleRequest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public partial interface IPutRoleRequest
1515
[JsonProperty("indices")]
1616
IEnumerable<IIndicesPrivileges> Indices { get; set; }
1717

18+
[JsonProperty("metadata")]
19+
IDictionary<string, object> Metadata { get; set; }
20+
1821
}
1922

2023
public partial class PutRoleRequest
@@ -24,6 +27,8 @@ public partial class PutRoleRequest
2427
public IEnumerable<string> RunAs { get; set; }
2528

2629
public IEnumerable<IIndicesPrivileges> Indices { get; set; }
30+
31+
public IDictionary<string, object> Metadata { get; set; }
2732
}
2833

2934
[DescriptorFor("XpackSecurityPutRole")]
@@ -32,6 +37,7 @@ public partial class PutRoleDescriptor
3237
IEnumerable<string> IPutRoleRequest.Cluster { get; set; }
3338
IEnumerable<string> IPutRoleRequest.RunAs { get; set; }
3439
IEnumerable<IIndicesPrivileges> IPutRoleRequest.Indices { get; set; }
40+
IDictionary<string, object> IPutRoleRequest.Metadata { get; set; }
3541

3642
public PutRoleDescriptor Cluster(IEnumerable<string> clusters) => Assign(a => a.Cluster = clusters);
3743
public PutRoleDescriptor Cluster(params string[] clusters) => Assign(a => a.Cluster = clusters);
@@ -45,5 +51,10 @@ public partial class PutRoleDescriptor
4551
public PutRoleDescriptor Indices(Func<IndicesPrivilegesDescriptor, IPromise<IList<IIndicesPrivileges>>> selector) =>
4652
Assign(a => a.Indices = selector?.Invoke(new IndicesPrivilegesDescriptor())?.Value);
4753

54+
55+
public PutRoleDescriptor Metadata(IDictionary<string, object> metadata) => Assign(a => a.Metadata = metadata);
56+
public PutRoleDescriptor Metadata(Func<FluentDictionary<string, object>, IDictionary<string, object>> selector) =>
57+
Assign(a => a.Metadata = selector?.Invoke(new FluentDictionary<string, object>()));
58+
4859
}
4960
}

src/Tests/XPack/Security/Role/PutRole/PutRoleApiTests.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ protected override LazyResponses ClientUsage() => Calls(
4545
field_security = new { grant = new [] { "name", "description" } },
4646
query = new { match_all = new {} }
4747
}
48+
},
49+
metadata = new []
50+
{
51+
new
52+
{
53+
_internal = true
54+
}
4855
}
4956
};
5057

@@ -64,6 +71,10 @@ protected override LazyResponses ClientUsage() => Calls(
6471
Privileges = new [] { "all" },
6572
Query = new MatchAllQuery()
6673
}
74+
},
75+
Metadata = new Dictionary<string, object>()
76+
{
77+
{ "_internal", true }
6778
}
6879
};
6980

@@ -84,7 +95,8 @@ protected override LazyResponses ClientUsage() => Calls(
8495
.Privileges("all")
8596
.Query(q => q.MatchAll())
8697
)
87-
);
98+
)
99+
.Metadata( m => m.Add("_internal", true));
88100

89101
protected override void ExpectResponse(IPutRoleResponse response)
90102
{

0 commit comments

Comments
 (0)