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

Add DeleteManifestDirIfPresent argument to API and cli args #91

Merged
merged 3 commits into from
Aug 2, 2022
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
2 changes: 1 addition & 1 deletion analyzers.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
<Rule Id="SA1620" Action="None" />
<Rule Id="SA1621" Action="None" />
<Rule Id="SA1622" Action="None" />
<Rule Id="SA1623" Action="Warning" />
<Rule Id="SA1623" Action="None" />
aasim marked this conversation as resolved.
Show resolved Hide resolved
<Rule Id="SA1624" Action="None" />
<Rule Id="SA1625" Action="None" />
<Rule Id="SA1626" Action="None" />
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.Sbom.Api/Config/ApiConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ internal Configuration GetConfiguration(
configuration.NamespaceUriBase = GetConfigurationSetting(sanitizedRuntimeConfiguration.NamespaceUriBase);
configuration.NamespaceUriUniquePart = GetConfigurationSetting(sanitizedRuntimeConfiguration.NamespaceUriUniquePart);
configuration.FollowSymlinks = GetConfigurationSetting(sanitizedRuntimeConfiguration.FollowSymlinks);
configuration.DeleteManifestDirIfPresent = GetConfigurationSetting(sanitizedRuntimeConfiguration.DeleteManifestDirectoryIfPresent);

SetVerbosity(sanitizedRuntimeConfiguration, configuration);

Expand Down
9 changes: 9 additions & 0 deletions src/Microsoft.Sbom.Api/Config/Args/GenerationArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,14 @@ public class GenerationArgs : CommonArgs
[ArgShortcut("gt")]
[ArgDescription("A timestamp in the format 'yyyy-MM-ddTHH:mm:ssZ' that will be used as the generated timestamp for the SBOM.")]
public string GenerationTimestamp { get; set; }

/// <summary>
/// If set to true, we will delete any previous manifest directories that are already present in the ManifestDirPath without asking the user
/// for confirmation. The new manifest directory will then be created at this location and the generated SBOM will be stored there.
/// </summary>
[ArgDescription("If set to true, we will delete any previous manifest directories that are already present in the ManifestDirPath without " +
"asking the user for confirmation. The new manifest directory will then be created at this location and the generated SBOM " +
"will be stored there.")]
public bool? DeleteManifestDirIfPresent { get; set; }
}
}
6 changes: 6 additions & 0 deletions src/Microsoft.Sbom.Api/Config/ConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,11 @@ public class ConfigFile
/// Gets or sets if set to false, we will not follow symlinks while traversing the build drop folder.
/// </summary>
public bool? FollowSymlinks { get; set; }

/// <summary>
/// If set to true, we will delete any previous manifest directories that are already present in the ManifestDirPath without asking the user
/// for confirmation. The new manifest directory will then be created at this location and the generated SBOM will be stored there.
/// </summary>
public bool? DeleteManifestDirIfPresent { get; set; }
}
}
3 changes: 2 additions & 1 deletion src/Microsoft.Sbom.Api/ConfigurationProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public ConfigurationProfile()
.ForMember(nameof(Configuration.AdditionalComponentDetectorArgs), o => o.Ignore())
.ForMember(nameof(Configuration.GenerationTimestamp), o => o.Ignore())
.ForMember(nameof(Configuration.NamespaceUriUniquePart), o => o.Ignore())
.ForMember(nameof(Configuration.NamespaceUriBase), o => o.Ignore());
.ForMember(nameof(Configuration.NamespaceUriBase), o => o.Ignore())
.ForMember(nameof(Configuration.DeleteManifestDirIfPresent), o => o.Ignore());

// Create config for the generation args, ignoring other action members
CreateMap<GenerationArgs, Configuration>()
Expand Down
5 changes: 0 additions & 5 deletions src/Microsoft.Sbom.Api/SBOMGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ public async Task<SBOMGenerationResult> GenerateSBOMAsync(
string manifestDirPath = null,
string externalDocumentReferenceListFile = null)
{
if (string.IsNullOrWhiteSpace(manifestDirPath))
{
manifestDirPath = fileSystemUtils.JoinPaths(rootPath, Constants.ManifestFolder);
}

// Get scan configuration
var config = configurationBuilder.GetConfiguration(
rootPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private void RemoveExistingManifestDirectory()

Recorder.RecordSwitch(Constants.DeleteManifestDirBoolVariableName, deleteSbomDirSwitch);

if (!deleteSbomDirSwitch)
if (!deleteSbomDirSwitch && !(Configuration.DeleteManifestDirIfPresent?.Value ?? false))
{
throw new ManifestFolderExistsException(
$"The BuildDropRoot folder already contains a _manifest folder. Please" +
Expand Down
4 changes: 4 additions & 0 deletions src/Microsoft.Sbom.Common/Config/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,9 @@ public class Configuration : IConfiguration
/// <inheritdoc cref="IConfiguration.FollowSymlinks" />
[DefaultValue(true)]
public ConfigurationSetting<bool> FollowSymlinks { get; set; }

/// <inheritdoc cref="IConfiguration.DeleteManifestDirIfPresent" />
[DefaultValue(false)]
public ConfigurationSetting<bool> DeleteManifestDirIfPresent { get; set; }
}
}
8 changes: 7 additions & 1 deletion src/Microsoft.Sbom.Common/Config/IConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,14 @@ public interface IConfiguration
ConfigurationSetting<string> GenerationTimestamp { get; set; }

/// <summary>
/// Gets or sets if set to false, we will not follow symlinks while traversing the build drop folder. Default is set to 'true'.
/// If set to false, we will not follow symlinks while traversing the build drop folder. Default is set to 'true'.
/// </summary>
ConfigurationSetting<bool> FollowSymlinks { get; set; }

/// <summary>
/// If set to true, we will delete any previous manifest directories that are already present in the ManifestDirPath without asking the user
/// for confirmation. The new manifest directory will then be created at this location and the generated SBOM will be stored there.
/// </summary>
ConfigurationSetting<bool> DeleteManifestDirIfPresent { get; set; }
}
}