Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class BcdeArguments : BaseArguments, IDetectionArguments
[Option("ManifestFile", Required = false, HelpText = "The file to write scan results to.")]
public FileInfo ManifestFile { get; set; }

[Option("PrintManifest", Required = false, HelpText = "Prints the manifest to standard output. Logging will be redirected to standard error.")]
public bool PrintManifest { get; set; }

public string ManifestFileSerialized => this.ManifestFile?.ToString();

[Option("DockerImagesToScan", Required = false, Separator = ',', HelpText = "Comma separated list of docker image names or hashes to execute container scanning on, ex: ubuntu:16.04, 56bab49eef2ef07505f6a1b0d5bd3a601dfc3c76ad4460f24c91d6fa298369ab")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public interface IDetectionArguments : IScanArguments

FileInfo ManifestFile { get; set; }

public bool PrintManifest { get; set; }

IEnumerable<string> DockerImagesToScan { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ public async Task<ScanResult> LoadAsync(string[] args, CancellationToken cancell
var reloadableLogger = (ReloadableLogger)Log.Logger;
reloadableLogger.Reload(configuration =>
configuration
.WriteTo.Console()
.WriteTo.Console(standardErrorFromLevel: args.Contains(
$"--{nameof(IDetectionArguments.PrintManifest)}",
StringComparer.InvariantCultureIgnoreCase)
? LogEventLevel.Debug
: null)
.WriteTo.Async(x => x.File(logFile))
.WriteTo.Providers(this.serviceProvider.GetRequiredService<LoggerProviderCollection>())
.MinimumLevel.Is(baseArguments.Verbosity switch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Microsoft.ComponentDetection.Orchestrator.Services;

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.ComponentDetection.Common;
Expand Down Expand Up @@ -53,13 +54,20 @@ private void WriteComponentManifest(IDetectionArguments detectionArguments, Scan
this.logger.LogInformation("Scan Manifest file: {ManifestFile}", this.fileWritingService.ResolveFilePath(ManifestRelativePath));
}

var manifestJson = JsonConvert.SerializeObject(scanResult, Formatting.Indented);

if (userRequestedManifestPath == null)
{
this.fileWritingService.AppendToFile(ManifestRelativePath, JsonConvert.SerializeObject(scanResult, Formatting.Indented));
this.fileWritingService.AppendToFile(ManifestRelativePath, manifestJson);
}
else
{
this.fileWritingService.WriteFile(userRequestedManifestPath, JsonConvert.SerializeObject(scanResult, Formatting.Indented));
this.fileWritingService.WriteFile(userRequestedManifestPath, manifestJson);
}

if (detectionArguments.PrintManifest)
{
Console.WriteLine(manifestJson);
}
}
}