public async Task CloneHttpBearerToken() { var headers = new Dictionary <string, string> { { "custom-header", "123" }, { "client", "InfluxDB" } }; var endpoint = new HTTPNotificationEndpoint(type: NotificationEndpointType.Http, method: HTTPNotificationEndpoint.MethodEnum.POST, url: "http://localhost:1234/mock", orgID: _orgId, name: GenerateName("http"), authMethod: HTTPNotificationEndpoint.AuthMethodEnum.Bearer, token: "bearer-token", contentTemplate: "content - template", status: NotificationEndpointBase.StatusEnum.Active, headers: headers); endpoint = (HTTPNotificationEndpoint)await _notificationEndpointsApi.CreateEndpointAsync(endpoint); var name = GenerateName("cloned-http"); var cloned = await _notificationEndpointsApi .CloneHttpEndpointBearerAsync(name, "bearer-token", endpoint); Assert.AreNotEqual(endpoint.Id, cloned.Id); Assert.AreEqual(name, cloned.Name); Assert.AreEqual(HTTPNotificationEndpoint.MethodEnum.POST, cloned.Method); Assert.AreEqual(HTTPNotificationEndpoint.AuthMethodEnum.Bearer, cloned.AuthMethod); Assert.AreEqual($"secret: {cloned.Id}-token", cloned.Token); Assert.AreEqual(2, endpoint.Headers.Count); Assert.AreEqual("123", endpoint.Headers["custom-header"]); Assert.AreEqual("InfluxDB", endpoint.Headers["client"]); Assert.AreEqual("content - template", cloned.ContentTemplate); }
/// <summary> /// Add a HTTP notification rule. /// </summary> /// <param name="name">Human-readable name describing the notification rule.</param> /// <param name="every">The notification repetition interval.</param> /// <param name="status">Status rule the notification rule attempts to match.</param> /// <param name="tagRules">List of tag rules the notification rule attempts to match.</param> /// <param name="endpoint">The endpoint to use for notification.</param> /// <param name="orgId">The ID of the organization that owns this notification rule.</param> /// <returns>Notification rule created</returns> public async Task <HTTPNotificationRule> CreateHttpRuleAsync(string name, string every, RuleStatusLevel status, List <TagRule> tagRules, HTTPNotificationEndpoint endpoint, string orgId) { var rule = new HTTPNotificationRule(HTTPNotificationRuleBase.TypeEnum.Http); return((HTTPNotificationRule) await CreateRuleAsync(name, every, status, tagRules, endpoint, orgId, rule)); }
/// <summary> /// Clone a Http Notification endpoint without authentication. /// </summary> /// <param name="name">name of cloned endpoint</param> /// <param name="endpoint">endpoint to clone</param> /// <returns>Notification endpoint cloned</returns> public async Task <HTTPNotificationEndpoint> CloneHttpEndpoint(string name, HTTPNotificationEndpoint endpoint) { Arguments.CheckNonEmptyString(name, nameof(name)); Arguments.CheckNotNull(endpoint, nameof(endpoint)); var cloned = new HTTPNotificationEndpoint(endpoint.Url, method: endpoint.Method, name: name, authMethod: HTTPNotificationEndpoint.AuthMethodEnum.None, contentTemplate: endpoint.ContentTemplate, headers: endpoint.Headers); return((HTTPNotificationEndpoint) await CloneEndpointAsync(name, endpoint, cloned)); }
/// <summary> /// Clone a Http Notification endpoint with Bearer authentication. /// </summary> /// <param name="name">name of cloned endpoint</param> /// <param name="token">Bearer token</param> /// <param name="endpoint">endpoint to clone</param> /// <returns>Notification endpoint cloned</returns> public async Task <HTTPNotificationEndpoint> CloneHttpEndpointBearerAsync(string name, string token, HTTPNotificationEndpoint endpoint) { Arguments.CheckNonEmptyString(name, nameof(name)); Arguments.CheckNonEmptyString(token, nameof(token)); Arguments.CheckNotNull(endpoint, nameof(endpoint)); var cloned = new HTTPNotificationEndpoint(endpoint.Url, token: token, name: name, method: endpoint.Method, authMethod: HTTPNotificationEndpoint.AuthMethodEnum.Bearer, contentTemplate: endpoint.ContentTemplate, headers: endpoint.Headers); return((HTTPNotificationEndpoint) await CloneEndpointAsync(name, endpoint, cloned).ConfigureAwait(false)); }
/// <summary> /// Add new HTTP notification endpoint without authentication. /// </summary> /// <param name="name">Endpoint name</param> /// <param name="url">URL</param> /// <param name="method">HTTP Method</param> /// <param name="orgId">Owner of an endpoint</param> /// <returns>created HTTP notification endpoint</returns> public async Task <HTTPNotificationEndpoint> CreateHttpEndpointAsync(string name, string url, HTTPNotificationEndpoint.MethodEnum method, string orgId) { Arguments.CheckNonEmptyString(name, nameof(name)); Arguments.CheckNonEmptyString(url, nameof(url)); Arguments.CheckNotNull(method, nameof(method)); Arguments.CheckNonEmptyString(orgId, nameof(orgId)); var endpoint = new HTTPNotificationEndpoint(type: NotificationEndpointType.Http, method: method, url: url, orgID: orgId, name: name, authMethod: HTTPNotificationEndpoint.AuthMethodEnum.None, status: NotificationEndpointBase.StatusEnum.Active); return((HTTPNotificationEndpoint) await CreateEndpointAsync(endpoint)); }
/// <summary> /// Clone a Http Notification endpoint with Http Basic authentication. /// </summary> /// <param name="name">name of cloned endpoint</param> /// <param name="username">HTTP Basic Username</param> /// <param name="password">HTTP Basic Password</param> /// <param name="endpoint">endpoint to clone</param> /// <returns>Notification endpoint cloned</returns> public async Task <HTTPNotificationEndpoint> CloneHttpEndpointBasicAuthAsync(string name, string username, string password, HTTPNotificationEndpoint endpoint) { Arguments.CheckNonEmptyString(name, nameof(name)); Arguments.CheckNonEmptyString(username, nameof(username)); Arguments.CheckNonEmptyString(password, nameof(password)); Arguments.CheckNotNull(endpoint, nameof(endpoint)); var cloned = new HTTPNotificationEndpoint(endpoint.Url, username, password, name: name, method: endpoint.Method, authMethod: HTTPNotificationEndpoint.AuthMethodEnum.Basic, contentTemplate: endpoint.ContentTemplate, headers: endpoint.Headers); return((HTTPNotificationEndpoint) await CloneEndpointAsync(name, endpoint, cloned).ConfigureAwait(false)); }
public async Task CreateHttpEndpointHeadersTemplate() { var name = GenerateName("http"); var headers = new Dictionary <string, string> { { "custom-header", "123" }, { "client", "InfluxDB" } }; var endpoint = new HTTPNotificationEndpoint(type: NotificationEndpointType.Http, method: HTTPNotificationEndpoint.MethodEnum.POST, url: "http://localhost:1234/mock", orgID: _orgId, name: name, authMethod: HTTPNotificationEndpoint.AuthMethodEnum.None, status: NotificationEndpointBase.StatusEnum.Active, headers: headers); endpoint = (HTTPNotificationEndpoint)await _notificationEndpointsApi.CreateEndpointAsync(endpoint); Assert.IsNotNull(endpoint); Assert.AreEqual(2, endpoint.Headers.Count); Assert.AreEqual("123", endpoint.Headers["custom-header"]); Assert.AreEqual("InfluxDB", endpoint.Headers["client"]); }