Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed slack URL #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 47 additions & 34 deletions githubeventslack/alertstoslack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
using System.Reflection.Emit;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using static githubeventslack.SlackText;
using Microsoft.Extensions.Primitives;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading;

namespace githubeventslack
{
public static class alertstoslack
public static class alertstoslackmsg
{


Expand All @@ -30,56 +31,68 @@ public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("Sending GitHub Payload to Slack function started");


string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
var data = JsonConvert.DeserializeObject<Githubhook.Root>(requestBody);
Payload payload = new Payload();
payload.ghsa_id = data.alert.security_advisory.ghsa_id;
payload.cve_id = data.alert.security_advisory.cve_id;
payload.summary = data.alert.security_advisory.summary;
payload.description = data.alert.security_advisory.description;
payload.severity = data.alert.security_advisory.severity;
payload.package_name = data.alert.security_vulnerability.package.name;
payload.ecosystem = data.alert.security_vulnerability.package.ecosystem;
payload.vulnerable_version_range = data.alert.security_vulnerability.vulnerable_version_range;
payload.identifier = data.alert.security_vulnerability.first_patched_version.identifier;
payload.manifest_path = data.alert.dependency.manifest_path;
payload.repository = data.repository.name;


if (data.action == "fixed")


try
{
log.LogInformation(requestBody);

log.LogInformation("Sending GitHub Payload to Slack function started");


string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
var data = JsonConvert.DeserializeObject<Githubhook.Root>(requestBody);
Payload payload = new Payload();
payload.ghsa_id = data.alert.security_advisory.ghsa_id;
payload.cve_id = data.alert.security_advisory.cve_id;
payload.summary = data.alert.security_advisory.summary;
payload.description = data.alert.security_advisory.description;
payload.severity = data.alert.security_advisory.severity;
payload.package_name = data.alert.security_vulnerability.package.name;
payload.ecosystem = data.alert.security_vulnerability.package.ecosystem;
payload.vulnerable_version_range = data.alert.security_vulnerability.vulnerable_version_range;
payload.identifier = data.alert.security_vulnerability.first_patched_version.identifier;
payload.manifest_path = data.alert.dependency.manifest_path;
payload.repository = data.repository.name;
log.LogInformation("data stored on payload");

if (data.action == "fixed")
{
log.LogInformation(requestBody);
}
else
{
await SendSlackMessage(payload);
log.LogInformation("calling slack function");
}
log.LogInformation("Message posted on slack");
Payload responseMessage = payload;
return new OkObjectResult(responseMessage);

}
else
catch(Exception ex)
{
await SendSlackMessage(payload);
log.LogInformation(ex.Message);
}

Payload responseMessage = payload;
return new OkObjectResult(responseMessage);
return default;
}

public static async Task<string> SendSlackMessage(Payload payload)
{

var slackWebHookUrl = "https://hooks.slack.com/services/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";
var slackWebHookUrl = "{your slack webhook url}";
//var slackWebHookUrl = Environment.GetEnvironmentVariable("SLACKWEBHOOKURL");

string color = string.Empty;
var severity = string.Empty;


//StringBuilder paySeverity = new StringBuilder();


if (payload.severity=="high")
{
color = "#ff0000";
severity = $"`{payload.severity}`";

//paySeverity.Append($"<html><body><b><span style='color:red'>{payload.severity}</span></b></body></html>");
//severity = $"<b><span style='color:red'>{payload.severity}</span></b>";

}

else if (payload.severity == "critical")
Expand Down
1 change: 1 addition & 0 deletions githubeventslack/githubeventslack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.1" />
</ItemGroup>
Expand Down