Ejemplo n.º 1
0
        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
        }
Ejemplo n.º 2
0
        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 });
        }
Ejemplo n.º 3
0
 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 });
 }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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");
        }
Ejemplo n.º 6
0
 public void Add(DivvyWebhook webhook)
 {
     DivvyLogManager.Log($"Enqueing Webhook", webhook);
     Enqueue(webhook);
 }