Skip to content

Commit

Permalink
Endpoint that download and convert the cve in once added
Browse files Browse the repository at this point in the history
  • Loading branch information
Kretchen001 committed Mar 20, 2024
1 parent 5241e91 commit dd4f0a9
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using LibGit2Sharp;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using System.Security.Policy;
using CM = System.Configuration.ConfigurationManager;

namespace AmIVulnerable.Controllers {
Expand All @@ -8,6 +10,17 @@ namespace AmIVulnerable.Controllers {
[ApiController]
public class GitController : ControllerBase {

/// <summary></summary>
private readonly IConfiguration Configuration;

/// <summary></summary>
/// <param name="configuration"></param>
public GitController(IConfiguration configuration) {
Configuration = configuration;
}

private static bool isFinished = false;

Check warning on line 22 in code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs

View workflow job for this annotation

GitHub Actions / build-and-test-ubuntu-latest

The field 'GitController.isFinished' is assigned but its value is never used

Check warning on line 22 in code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs

View workflow job for this annotation

GitHub Actions / build-and-test-windows-latest

The field 'GitController.isFinished' is assigned but its value is never used

Check warning on line 22 in code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs

View workflow job for this annotation

GitHub Actions / build-and-test-macOS-latest

The field 'GitController.isFinished' is assigned but its value is never used

/// <summary>
/// API-Post route to clone a git repository
/// </summary>
Expand Down Expand Up @@ -43,6 +56,32 @@ public IActionResult CloneRepo([FromHeader] bool cveRaw, [FromBody] Tuple<string
}
}

[HttpGet]
[Route("pullCveAndConvert")]
public async Task<IActionResult> PullAndConvertCveFiles() {

Check warning on line 61 in code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs

View workflow job for this annotation

GitHub Actions / build-and-test-ubuntu-latest

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 61 in code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs

View workflow job for this annotation

GitHub Actions / build-and-test-windows-latest

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 61 in code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs

View workflow job for this annotation

GitHub Actions / build-and-test-windows-latest

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 61 in code/AmIVulnerable/AmIVulnerable/Controllers/GitController.cs

View workflow job for this annotation

GitHub Actions / build-and-test-macOS-latest

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
try {
ProcessStartInfo process = new ProcessStartInfo {
FileName = "cmd",
RedirectStandardInput = true,
WorkingDirectory = $"",
};

Process runProcess = Process.Start(process)!;
runProcess.StandardInput.WriteLine($"git " +
$"clone {CM.AppSettings["StandardCveUrlPlusTag"]!} " + // git url
$"--branch cve_2023-12-31_at_end_of_day " + // tag
$"raw"); // target dir
runProcess.StandardInput.WriteLine($"exit");
runProcess.WaitForExit();

DbController dbC = new DbController(Configuration);
return dbC.ConvertRawFilesToMySql();
}
catch (Exception ex) {
return BadRequest(ex.Message);
}
}

/// <summary>
/// Clone a git repository.
/// </summary>
Expand All @@ -62,7 +101,7 @@ await Task.Run(() => {
}
else {
try {
Process.Start("git", $"clone {url} --branch {tag} {dir}");
Process.Start("git", $"clone {url} --branch {tag} {AppDomain.CurrentDomain.BaseDirectory}{dir}");
}
catch (Exception ex) {
Console.WriteLine("Error with clone, tag?\n" + ex.Message);
Expand Down

0 comments on commit dd4f0a9

Please sign in to comment.