コード例 #1
0
        private void ProcessEvent(WebhookPushEvent _event)
        {
            Pusher pusher = _event.Pusher;
            string name   = pusher.Name;

            Log("Webhook received: New Push from " + name);
            string       commitSha = _event.HeadCommit;
            GithubCommit commit    = FetchCommit(commitSha);

            if (commit == null)
            {
                return;
            }

            GithubWebhookService.Models.File[] changedFiles = commit.Files;

            foreach (GithubWebhookService.Models.File changedFile in changedFiles)
            {
                string filename = changedFile.Filename;
                if (filename.Contains("surveyQuestionService.json"))
                {
                    Log("Changes to Consul-Configuration have been detected!");
                    Console.WriteLine("Changes to Consul-Configuration have been detected!");
                }
            }
        }
コード例 #2
0
        public ActionResult Receive([FromBody] WebhookPushEvent _event)
        {
            StringValues signature;
            string       stringContent = _event.ToJson();

            try
            {
                bool signatureExists = Request.Headers.TryGetValue("X-Hub-Signature", out signature);

                if (!signatureExists)
                {
                    throw new ArgumentNullException();
                }
            }
            catch (ArgumentNullException ex)
            {
                Log("Could not verify integrity of received webhook! " + ex);
                //Console.WriteLine("Missing Siugnature!");
                return(NotFound());
            }

            string calculatedHmac = CalculateHmac(stringContent);

            signature = signature.ToString().Replace("{", "").Replace("}", "");

            if (!signature.ToString().Equals(calculatedHmac))
            {
                Log("Webhook could not be verified - returning 404");
                //Console.WriteLine("Webhook could not be verified - returning 404");
                return(NotFound());
            }

            ProcessEvent(_event);

            return(Ok());
        }