private dynamic SlackPayload(MitigationAction mitigation, App app)
 {
     return(new
     {
         blocks = new dynamic[] {
             new {
                 type = "section",
                 text = new
                 {
                     type = "mrkdwn",
                     text = $"You have a new mitigation request:\n*<fakeLink.com|{app.AppName}>*"
                 }
             },
             new {
                 type = "section",
                 fields = new[]
                 {
                     new {
                         type = "mrkdwn",
                         text = $"*Action:*\n{mitigation.Action}"
                     },
                     new {
                         type = "mrkdwn",
                         text = $"*Comment:*\n{mitigation.Comment}"
                     },
                     new {
                         type = "mrkdwn",
                         text = $"*Submitted:*\n{mitigation.Date}*"
                     }
                 }
             },
             new {
                 type = "actions",
                 elements = new[] {
                     new {
                         type = "button",
                         text = new {
                             type = "plain_text",
                             emoji = true,
                             text = "Approve"
                         },
                         style = "primary",
                         value = "click_me_123"
                     },
                     new {
                         type = "button",
                         text = new {
                             type = "plain_text",
                             emoji = true,
                             text = "Reject"
                         },
                         style = "danger",
                         value = "click_me_123"
                     }
                 }
             }
         }
     });
 }
Exemple #2
0
 public bool HaveIBeenMet(MitigationAction action) => action.GetType().GetProperties()
 .Where(prop => prop.Name.ToLower() == Field.ToLower())
 .Any(prop =>
      prop.GetValue(action).ToString().Equals(ExpectedValue) ||
      ExpectedValue.Equals("Any") || ExpectedValue.Equals("*")
      );
        public async Task <Tuple <string, string, int, MitigationWebhook, MitigationAction, App> > FireWebhook(MitigationWebhook webhook, MitigationAction mitigation, App app)
        {
            Console.WriteLine($"{DateTime.Now.ToLongTimeString()} : Preparing to fire {webhook.Name}");
            var webhookMessage = SlackPayload(mitigation, app);
            var json           = JsonConvert.SerializeObject(webhookMessage);

            Console.WriteLine($"{DateTime.Now.ToLongTimeString()} : {webhook.Name} Fire!");
            var response = await _httpPostService.SendMessage(json, webhook.SendAddress);

            var content = await response.Content.ReadAsStringAsync();

            Console.WriteLine($"{DateTime.Now.ToLongTimeString()} : {webhook.Name} webhook recieved HTTP Status {response.StatusCode}");
            return(new Tuple <string, string, int, MitigationWebhook, MitigationAction, App>(json, content, (int)response.StatusCode, webhook, mitigation, app));
        }