public override void OnActionExecuting(ActionExecutingContext filterContext) { DivvyManager.Init(); // This will immediately return if Init has already occured // If Divvy is disabled, no one is getting in if (DivvyManager.Settings.Mode == DivvyMode.Disabled) { DivvyLogManager.Log("Divvy Integration Not Enabled. Aborting."); filterContext.Result = new HttpStatusCodeResult(HttpStatusCode.Forbidden, "Divvy disabled. Divvy integration is installed but not enabled in this Episerver instance."); return; // Reject } // If they're logged into the debug role, they're good... if (DivvyManager.Settings.DebugRole != null && filterContext.HttpContext.User.IsInRole(DivvyManager.Settings.DebugRole)) { return; // Allow } // If their auth token validated, they're good var result = DivvyAccessToken.Validate(); if (result.Authorized) { return; // Allow } DivvyLogManager.Log(result.Message); filterContext.Result = new HttpUnauthorizedResult(result.Message); return; // Default reject everything that gets here }
private void Execute(DivvyWebhook webhook) { DivvyLogManager.Log($"Executing Webhook", webhook); var sw = Stopwatch.StartNew(); var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", DivvyManager.Settings.AccessToken.ToString()); var result = httpClient.PostAsJsonAsync <object>(webhook.Uri.AbsoluteUri, webhook.Data).Result; DivvyLogManager.Log($"Webhook Executed in {sw.ElapsedMilliseconds}ms", new { result.StatusCode }); }
public DivvyWebhookManager() { timer = new System.Timers.Timer { Interval = DivvyManager.Settings.WebhookTimerInterval }; timer.Elapsed += (s, e) => { if (!working) { Process(); } }; timer.Start(); DivvyLogManager.Log($"Webhook Manager Initialized", new { timer.Interval }); }
public JsonResult Gateway() { if (DivvyManager.Settings.LogRequestDebugData) { DivvyLogManager.Log("Gateway Request Started", new { RequestKey = DivvyLogManager.GetRequestLogKey() }); } var requestBody = GetRequestBody(); var responseBody = DivvyManager.ProcessDivvyInput(requestBody); if (DivvyManager.Settings.LogRequestDebugData) { DivvyLogManager.Log("Gateway Request Ended"); } return(Json(responseBody)); }
private void Process() { if (!this.Any()) { return; } DivvyLogManager.Log($"Processing Webhook Queue. {this.Count()} item(s)"); working = true; while (this.Any()) { var webhook = Dequeue(); Execute(webhook); Thread.Sleep(DivvyManager.Settings.WebhookTimerInterval); } ; working = false; DivvyLogManager.Log($"Webhook Queue Processing Complete"); }
public void Add(DivvyWebhook webhook) { DivvyLogManager.Log($"Enqueing Webhook", webhook); Enqueue(webhook); }