PageRenderTime 34ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/redistributable/openstack.net/src/corelib/Providers/Rackspace/Objects/Monitoring/HttpCheckDetails.cs

https://gitlab.com/rekby-archive/onlyoffice-CommunityServer
C# | 264 lines | 127 code | 28 blank | 109 comment | 15 complexity | f75a6f658935aaedc04e48c1a0e86b98 MD5 | raw file
  1. using System.Collections.ObjectModel;
  2. namespace net.openstack.Providers.Rackspace.Objects.Monitoring
  3. {
  4. using System;
  5. using System.Collections.Generic;
  6. using Newtonsoft.Json;
  7. using Newtonsoft.Json.Converters;
  8. using HttpMethod = JSIStudios.SimpleRESTServices.Client.HttpMethod;
  9. /// <summary>
  10. /// This class represents the detailed configuration parameters for a
  11. /// <see cref="CheckTypeId.RemoteHttp"/> check.
  12. /// </summary>
  13. /// <seealso cref="CheckTypeId.RemoteHttp"/>
  14. /// <threadsafety static="true" instance="false"/>
  15. /// <preliminary/>
  16. [JsonObject(MemberSerialization.OptIn)]
  17. public class HttpCheckDetails : CheckDetails
  18. {
  19. /// <summary>
  20. /// This is the backing field for the <see cref="Url"/> property.
  21. /// </summary>
  22. [JsonProperty("url", DefaultValueHandling = DefaultValueHandling.Ignore)]
  23. private string _url;
  24. /// <summary>
  25. /// This is the backing field for the <see cref="AuthPassword"/> property.
  26. /// </summary>
  27. [JsonProperty("auth_password", DefaultValueHandling = DefaultValueHandling.Ignore)]
  28. private string _authPassword;
  29. /// <summary>
  30. /// This is the backing field for the <see cref="AuthUser"/> property.
  31. /// </summary>
  32. [JsonProperty("auth_user", DefaultValueHandling = DefaultValueHandling.Ignore)]
  33. private string _authUser;
  34. /// <summary>
  35. /// This is the backing field for the <see cref="Body"/> property.
  36. /// </summary>
  37. [JsonProperty("body", DefaultValueHandling = DefaultValueHandling.Ignore)]
  38. private string _body;
  39. /// <summary>
  40. /// This is the backing field for the <see cref="BodyMatches"/> property.
  41. /// </summary>
  42. [JsonProperty("body_matches", DefaultValueHandling = DefaultValueHandling.Ignore)]
  43. private IDictionary<string, string> _bodyMatches;
  44. /// <summary>
  45. /// This is the backing field for the <see cref="FollowRedirects"/> property.
  46. /// </summary>
  47. [JsonProperty("follow_redirects", DefaultValueHandling = DefaultValueHandling.Ignore)]
  48. private bool? _followRedirects;
  49. /// <summary>
  50. /// This is the backing field for the <see cref="Headers"/> property.
  51. /// </summary>
  52. [JsonProperty("headers", DefaultValueHandling = DefaultValueHandling.Ignore)]
  53. private IDictionary<string, string> _headers;
  54. /// <summary>
  55. /// This is the backing field for the <see cref="Method"/> property.
  56. /// </summary>
  57. [JsonProperty("method", DefaultValueHandling = DefaultValueHandling.Ignore)]
  58. [JsonConverter(typeof(StringEnumConverter))]
  59. private HttpMethod? _method;
  60. /// <summary>
  61. /// This is the backing field for the <see cref="Payload"/> property.
  62. /// </summary>
  63. [JsonProperty("payload", DefaultValueHandling = DefaultValueHandling.Ignore)]
  64. private string _payload;
  65. /// <summary>
  66. /// Initializes a new instance of the <see cref="HttpCheckDetails"/> class
  67. /// during JSON deserialization.
  68. /// </summary>
  69. [JsonConstructor]
  70. protected HttpCheckDetails()
  71. {
  72. }
  73. /// <summary>
  74. /// Initializes a new instance of the <see cref="HttpCheckDetails"/> class
  75. /// with the specified values.
  76. /// </summary>
  77. /// <param name="url">The target URI.</param>
  78. /// <param name="authUser">The username of the user to authenticate over HTTP.</param>
  79. /// <param name="authPassword">The password of the user to authenticate over HTTP.</param>
  80. /// <param name="body">The regular expression to match against the body of the reply. For more information, see <see cref="Body"/>.</param>
  81. /// <param name="bodyMatches">A collection of named regular expressions to match against the body of the reply. For more information, see <see cref="BodyMatches"/>.</param>
  82. /// <param name="followRedirects"><see langword="true"/> to follow redirects; otherwise, <see langword="false"/>.</param>
  83. /// <param name="headers">A collection of additional HTTP headers which are sent with the request.</param>
  84. /// <param name="method">The HTTP method to use for the request.</param>
  85. /// <param name="payload">The body to include with the HTTP request.</param>
  86. /// <exception cref="ArgumentNullException">If <paramref name="url"/> is <see langword="null"/>.</exception>
  87. /// <exception cref="ArgumentException">
  88. /// If <paramref name="bodyMatches"/> contains any empty keys.
  89. /// <para>-or-</para>
  90. /// <para>If <paramref name="headers"/> contains any empty keys.</para>
  91. /// </exception>
  92. public HttpCheckDetails(Uri url, string authUser, string authPassword, string body, IDictionary<string, string> bodyMatches, bool? followRedirects, IDictionary<string, string> headers, HttpMethod? method, string payload)
  93. {
  94. if (url == null)
  95. throw new ArgumentNullException("url");
  96. if (bodyMatches != null && bodyMatches.ContainsKey(string.Empty))
  97. throw new ArgumentException("bodyMatches cannot contain any empty keys", "bodyMatches");
  98. if (headers != null && headers.ContainsKey(string.Empty))
  99. throw new ArgumentException("headers cannot contain any empty keys", "headers");
  100. _url = url.ToString();
  101. _authUser = authUser;
  102. _authPassword = authPassword;
  103. _body = body;
  104. _bodyMatches = bodyMatches;
  105. _followRedirects = followRedirects;
  106. _headers = headers;
  107. _method = method;
  108. _payload = payload;
  109. }
  110. /// <summary>
  111. /// Gets the target URI.
  112. /// </summary>
  113. public Uri Url
  114. {
  115. get
  116. {
  117. if (_url == null)
  118. return null;
  119. return new Uri(_url);
  120. }
  121. }
  122. /// <summary>
  123. /// Gets the password of the user to authenticate over HTTP.
  124. /// </summary>
  125. public string AuthPassword
  126. {
  127. get
  128. {
  129. return _authPassword;
  130. }
  131. }
  132. /// <summary>
  133. /// Gets the username of the user to authenticate over HTTP.
  134. /// </summary>
  135. public string AuthUser
  136. {
  137. get
  138. {
  139. return _authUser;
  140. }
  141. }
  142. /// <summary>
  143. /// Gets the regular expression to match against the body of the reply.
  144. /// </summary>
  145. /// <remarks>
  146. /// The data matched by this regular expression is provided by the
  147. /// <c>body_match</c> metric in the alarm criteria.
  148. /// </remarks>
  149. public string Body
  150. {
  151. get
  152. {
  153. return _body;
  154. }
  155. }
  156. /// <summary>
  157. /// Gets a collection of named regular expressions to match against the
  158. /// body of the reply.
  159. /// </summary>
  160. /// <remarks>
  161. /// When this property is specified, a metric will be available for each of
  162. /// the named regular expressions. The keys of this dictionary provide the
  163. /// names for each of the regular expressions and determine the names of
  164. /// alarm criteria metrics which provide the data matched by the expression.
  165. /// For example, if <see cref="BodyMatches"/> contains a key
  166. /// <c><em>helloworld</em></c>, the metric
  167. /// <c>body_match_<em>helloworld</em></c> provides the data in the body
  168. /// matched by the associated regular expression.
  169. /// </remarks>
  170. public ReadOnlyDictionary<string, string> BodyMatches
  171. {
  172. get
  173. {
  174. if (_bodyMatches == null)
  175. return null;
  176. return new ReadOnlyDictionary<string, string>(_bodyMatches);
  177. }
  178. }
  179. /// <summary>
  180. /// Gets a value indicating whether redirects should be followed.
  181. /// </summary>
  182. /// <value>
  183. /// <see langword="true"/> to follow redirects; otherwise, <see langword="false"/>.
  184. /// </value>
  185. public bool? FollowRedirects
  186. {
  187. get
  188. {
  189. return _followRedirects;
  190. }
  191. }
  192. /// <summary>
  193. /// Gets a collection of additional HTTP headers which are sent with the request.
  194. /// </summary>
  195. public ReadOnlyDictionary<string, string> Headers
  196. {
  197. get
  198. {
  199. if (_headers == null)
  200. return null;
  201. return new ReadOnlyDictionary<string, string>(_headers);
  202. }
  203. }
  204. /// <summary>
  205. /// Gets the HTTP method to use for the request.
  206. /// </summary>
  207. public HttpMethod? Method
  208. {
  209. get
  210. {
  211. return _method;
  212. }
  213. }
  214. /// <summary>
  215. /// Gets the body to send with the request.
  216. /// </summary>
  217. /// <remarks>
  218. /// If following a redirect, the payload will only be sent to the initial URI.
  219. /// </remarks>
  220. public string Payload
  221. {
  222. get
  223. {
  224. return _payload;
  225. }
  226. }
  227. /// <inheritdoc/>
  228. /// <remarks>
  229. /// This class only supports <see cref="CheckTypeId.RemoteHttp"/> checks.
  230. /// </remarks>
  231. protected internal override bool SupportsCheckType(CheckTypeId checkTypeId)
  232. {
  233. return checkTypeId == CheckTypeId.RemoteHttp;
  234. }
  235. }
  236. }