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

14 single package analysis #25

Merged
merged 11 commits into from
Jan 24, 2024
Prev Previous commit
Next Next commit
Serilog to track time for search added
  • Loading branch information
Kretchen001 committed Jan 22, 2024
commit a995871c4ae3ffb2c4597e2dd01478f693a81d01
2 changes: 2 additions & 0 deletions code/AmIVulnerable/AmIVulnerable/AmIVulnerable.csproj
Original file line number Diff line number Diff line change
@@ -22,6 +22,8 @@
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="SerilogTimings" Version="3.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

8 changes: 7 additions & 1 deletion code/AmIVulnerable/AmIVulnerable/Controllers/DbController.cs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Mvc;
using Modells;
using Newtonsoft.Json;
using SerilogTimings;
using System.Text.RegularExpressions;

namespace AmIVulnerable.Controllers {
@@ -65,7 +66,10 @@ public IActionResult CheckSinglePackage([FromHeader] string packageName,
if (packageVersion.Equals("")) { // search all versions
if (isDbSearch) {
SearchDbController searchDbController = new SearchDbController();
List<CveResult> res = searchDbController.SearchSinglePackage(packageName);
List<CveResult> res = [];
using(Operation.Time($"{packageName}")) {
res = searchDbController.SearchSinglePackage(packageName);
}
if (res.Count > 0) {
return Ok(JsonConvert.SerializeObject(res));
}
@@ -90,6 +94,7 @@ public IActionResult CheckSinglePackage([FromHeader] string packageName,
}
// search in the files
List<CveResult> results = [];
using (Operation.Time($"Packge \"{packageName}\"")) {
int start = 0;
foreach (int i in Enumerable.Range(start, fileList.Count - start)) {
CVEcomp item = JsonConvert.DeserializeObject<CVEcomp>(System.IO.File.ReadAllText(fileList[i]))!;
@@ -110,6 +115,7 @@ public IActionResult CheckSinglePackage([FromHeader] string packageName,
}
}
}
}
return Ok(JsonConvert.SerializeObject(results));
}
}
13 changes: 13 additions & 0 deletions code/AmIVulnerable/AmIVulnerable/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using Serilog;
using Serilog.Events;

namespace AmIVulnerable {

public class Program {
@@ -20,6 +23,16 @@ public static void Main (string[] args) {
app.UseSwaggerUI();
}

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.File(
path: AppDomain.CurrentDomain.BaseDirectory + "Log/Logs.txt",
rollingInterval: RollingInterval.Day
)
.CreateLogger();

app.UseHttpsRedirection();

app.UseAuthorization();