Files
git.stella-ops.org/src/Tools/StellaOps.Tools.WorkflowGenerator/WorkflowOptions.cs

107 lines
2.9 KiB
C#

// <copyright file="WorkflowOptions.cs" company="StellaOps">
// Copyright (c) StellaOps. Licensed under the BUSL-1.1.
// </copyright>
namespace StellaOps.Tools.WorkflowGenerator;
/// <summary>
/// Options for workflow generation.
/// Sprint: SPRINT_20260109_010_003 Task: Create models
/// </summary>
public sealed record WorkflowOptions
{
/// <summary>
/// Target CI/CD platform.
/// </summary>
public required CiPlatform Platform { get; init; }
/// <summary>
/// Workflow name.
/// </summary>
public string Name { get; init; } = "StellaOps Security Scan";
/// <summary>
/// Trigger configuration.
/// </summary>
public TriggerConfig Triggers { get; init; } = TriggerConfig.Default;
/// <summary>
/// Scan configuration.
/// </summary>
public ScanConfig Scan { get; init; } = ScanConfig.DefaultRepository;
/// <summary>
/// Upload configuration.
/// </summary>
public UploadConfig Upload { get; init; } = UploadConfig.Default;
/// <summary>
/// Runner/image to use.
/// </summary>
public string? Runner { get; init; }
/// <summary>
/// Environment variables.
/// </summary>
public IDictionary<string, string> EnvironmentVariables { get; init; } = new Dictionary<string, string>();
/// <summary>
/// Include comments in generated YAML.
/// </summary>
public bool IncludeComments { get; init; } = true;
/// <summary>
/// Creates default options for GitHub Actions.
/// </summary>
public static WorkflowOptions GitHubActionsDefault => new()
{
Platform = CiPlatform.GitHubActions,
Runner = "ubuntu-latest"
};
/// <summary>
/// Creates default options for GitLab CI.
/// </summary>
public static WorkflowOptions GitLabCiDefault => new()
{
Platform = CiPlatform.GitLabCi
};
/// <summary>
/// Creates default options for Azure DevOps.
/// </summary>
public static WorkflowOptions AzureDevOpsDefault => new()
{
Platform = CiPlatform.AzureDevOps,
Runner = "ubuntu-latest"
};
/// <summary>
/// Validates the options.
/// </summary>
public ValidationResult Validate()
{
var errors = new List<string>();
if (string.IsNullOrWhiteSpace(Name))
errors.Add("Workflow name is required");
if (Scan.ImageRef is null && Scan.ScanPath is null)
errors.Add("Either ImageRef or ScanPath must be specified");
if (Scan.ImageRef is not null && Scan.ScanPath is not null)
errors.Add("Only one of ImageRef or ScanPath should be specified");
return new ValidationResult(errors.Count == 0, errors);
}
}
/// <summary>
/// Validation result.
/// </summary>
public sealed record ValidationResult(bool IsValid, IReadOnlyList<string> Errors)
{
public static ValidationResult Success => new(true, []);
public static ValidationResult Failure(params string[] errors) => new(false, errors);
}