4
4
5
5
namespace Elasticsearch . Net
6
6
{
7
- public interface IRequestConfiguration
7
+ public interface IRequestConfiguration
8
8
{
9
9
/// <summary>
10
10
/// The timeout for this specific request, takes precedence over the global timeout settings
@@ -20,7 +20,7 @@ public interface IRequestConfiguration
20
20
/// Force a difference content type header on the request
21
21
/// </summary>
22
22
string ContentType { get ; set ; }
23
-
23
+
24
24
/// <summary>
25
25
/// This will override whatever is set on the connection configuration or whatever default the connectionpool has.
26
26
/// </summary>
@@ -32,13 +32,13 @@ public interface IRequestConfiguration
32
32
Uri ForceNode { get ; set ; }
33
33
34
34
/// <summary>
35
- /// Forces no sniffing to occur on the request no matter what configuration is in place
35
+ /// Forces no sniffing to occur on the request no matter what configuration is in place
36
36
/// globally
37
37
/// </summary>
38
38
bool ? DisableSniff { get ; set ; }
39
39
40
40
/// <summary>
41
- /// Under no circumstance do a ping before the actual call. If a node was previously dead a small ping with
41
+ /// Under no circumstance do a ping before the actual call. If a node was previously dead a small ping with
42
42
/// low connect timeout will be tried first in normal circumstances
43
43
/// </summary>
44
44
bool ? DisablePing { get ; set ; }
@@ -63,48 +63,76 @@ public interface IRequestConfiguration
63
63
/// The cancellation token to use to internally to cancel async operations
64
64
/// </summary>
65
65
CancellationToken CancellationToken { get ; set ; }
66
+
67
+ /// <summary>
68
+ /// Submit the request on behalf in the context of a different shield user
69
+ /// <pre/>https://www.elastic.co/guide/en/shield/current/submitting-requests-for-other-users.html
70
+ /// </summary>
71
+ string RunAs { get ; set ; }
66
72
}
67
73
68
74
public class RequestConfiguration : IRequestConfiguration
69
75
{
70
76
public TimeSpan ? RequestTimeout { get ; set ; }
71
77
public TimeSpan ? PingTimeout { get ; set ; }
72
- public string ContentType { get ; set ; }
78
+ public string ContentType { get ; set ; }
73
79
public int ? MaxRetries { get ; set ; }
74
80
public Uri ForceNode { get ; set ; }
75
81
public bool ? DisableSniff { get ; set ; }
76
82
public bool ? DisablePing { get ; set ; }
77
83
public IEnumerable < int > AllowedStatusCodes { get ; set ; }
78
84
public BasicAuthenticationCredentials BasicAuthenticationCredentials { get ; set ; }
79
85
public bool EnableHttpPipelining { get ; set ; } = true ;
80
- public CancellationToken CancellationToken { get ; set ; }
86
+ public CancellationToken CancellationToken { get ; set ; }
87
+ /// <summary>
88
+ /// Submit the request on behalf in the context of a different user
89
+ /// https://www.elastic.co/guide/en/shield/current/submitting-requests-for-other-users.html
90
+ /// </summary>
91
+ public string RunAs { get ; set ; }
81
92
}
82
93
83
94
public class RequestConfigurationDescriptor : IRequestConfiguration
84
95
{
85
- private IRequestConfiguration Self => this ;
86
96
97
+ private IRequestConfiguration Self => this ;
87
98
TimeSpan ? IRequestConfiguration . RequestTimeout { get ; set ; }
88
-
89
99
TimeSpan ? IRequestConfiguration . PingTimeout { get ; set ; }
90
-
91
100
string IRequestConfiguration . ContentType { get ; set ; }
92
-
93
101
int ? IRequestConfiguration . MaxRetries { get ; set ; }
94
-
95
102
Uri IRequestConfiguration . ForceNode { get ; set ; }
96
-
97
103
bool ? IRequestConfiguration . DisableSniff { get ; set ; }
98
-
99
104
bool ? IRequestConfiguration . DisablePing { get ; set ; }
100
-
101
105
IEnumerable < int > IRequestConfiguration . AllowedStatusCodes { get ; set ; }
102
-
103
106
BasicAuthenticationCredentials IRequestConfiguration . BasicAuthenticationCredentials { get ; set ; }
104
-
105
107
bool IRequestConfiguration . EnableHttpPipelining { get ; set ; } = true ;
106
-
107
108
CancellationToken IRequestConfiguration . CancellationToken { get ; set ; }
109
+ string IRequestConfiguration . RunAs { get ; set ; }
110
+
111
+ public RequestConfigurationDescriptor ( IRequestConfiguration config )
112
+ {
113
+ Self . RequestTimeout = config ? . RequestTimeout ;
114
+ Self . PingTimeout = config ? . PingTimeout ;
115
+ Self . ContentType = config ? . ContentType ;
116
+ Self . MaxRetries = config ? . MaxRetries ;
117
+ Self . ForceNode = config ? . ForceNode ;
118
+ Self . DisableSniff = config ? . DisableSniff ;
119
+ Self . DisablePing = config ? . DisablePing ;
120
+ Self . AllowedStatusCodes = config ? . AllowedStatusCodes ;
121
+ Self . BasicAuthenticationCredentials = config ? . BasicAuthenticationCredentials ;
122
+ Self . EnableHttpPipelining = config ? . EnableHttpPipelining ?? true ;
123
+ Self . CancellationToken = config ? . CancellationToken ?? default ( CancellationToken ) ;
124
+ Self . RunAs = config ? . RunAs ;
125
+ }
126
+
127
+ /// <summary>
128
+ /// Submit the request on behalf in the context of a different shield user
129
+ /// <pre/>https://www.elastic.co/guide/en/shield/current/submitting-requests-for-other-users.html
130
+ /// </summary>
131
+ public RequestConfigurationDescriptor RunAs ( string username )
132
+ {
133
+ Self . RunAs = username ;
134
+ return this ;
135
+ }
108
136
109
137
public RequestConfigurationDescriptor RequestTimeout ( TimeSpan requestTimeout )
110
138
{
@@ -168,7 +196,7 @@ public RequestConfigurationDescriptor BasicAuthentication(string userName, strin
168
196
{
169
197
if ( Self . BasicAuthenticationCredentials == null )
170
198
Self . BasicAuthenticationCredentials = new BasicAuthenticationCredentials ( ) ;
171
- Self . BasicAuthenticationCredentials . UserName = userName ;
199
+ Self . BasicAuthenticationCredentials . Username = userName ;
172
200
Self . BasicAuthenticationCredentials . Password = password ;
173
201
return this ;
174
202
}
@@ -179,4 +207,4 @@ public RequestConfigurationDescriptor EnableHttpPipelining(bool enable = true)
179
207
return this ;
180
208
}
181
209
}
182
- }
210
+ }
0 commit comments