addVSAFlags adds all the command flags with Cobra's built-in validation
(cmd *cobra.Command, data *validateVSAData)
| 209 | |
| 210 | // addVSAFlags adds all the command flags with Cobra's built-in validation |
| 211 | func addVSAFlags(cmd *cobra.Command, data *validateVSAData) { |
| 212 | // Input options |
| 213 | cmd.Flags().StringVarP(&data.vsaIdentifier, "vsa", "v", "", "VSA identifier (image digest, file path)") |
| 214 | cmd.Flags().StringVar(&data.images, "images", "", "Application snapshot file") |
| 215 | cmd.Flags().StringVarP(&data.policyConfig, "policy", "p", "", "Policy configuration") |
| 216 | |
| 217 | // VSA retrieval options |
| 218 | cmd.Flags().StringSliceVar(&data.vsaRetrieval, "vsa-retrieval", []string{}, "VSA retrieval backends (rekor@, file@)") |
| 219 | |
| 220 | // Policy comparison options |
| 221 | cmd.Flags().StringVar(&data.effectiveTime, "effective-time", "now", "Effective time for comparison") |
| 222 | |
| 223 | // VSA options |
| 224 | cmd.Flags().StringVar(&data.vsaExpirationStr, "vsa-expiration", DefaultVSAExpiration, "VSA expiration threshold (e.g., 24h, 7d, 1w, 1m)") |
| 225 | |
| 226 | // Signature verification options |
| 227 | cmd.Flags().BoolVar(&data.ignoreSignatureVerification, "ignore-signature-verification", false, "Ignore VSA signature verification (signature verification is enabled by default)") |
| 228 | cmd.Flags().StringVar(&data.publicKeyPath, "vsa-public-key", "", "Path to public key for VSA signature verification (required by default)") |
| 229 | |
| 230 | // Fallback options |
| 231 | cmd.Flags().BoolVar(&data.noFallback, "no-fallback", false, "Disable fallback to image validation when VSA validation fails (fallback is enabled by default)") |
| 232 | cmd.Flags().StringVar(&data.fallbackPublicKey, "fallback-public-key", "", "Public key to use for fallback image validation (different from VSA verification key)") |
| 233 | // Output options |
| 234 | validOutputFormats := []string{outputFormatJSON, outputFormatYAML, outputFormatText, outputFormatStatus} |
| 235 | cmd.Flags().StringSliceVar(&data.output, "output", []string{}, hd.Doc(` |
| 236 | write output to a file in a specific format. Use empty string path for stdout. |
| 237 | May be used multiple times. Possible formats are: |
| 238 | `+strings.Join(validOutputFormats, ", ")+`. In following format and file path |
| 239 | additional options can be provided in key=value form following the question |
| 240 | mark (?) sign, for example: --output text=output.txt?show-successes=false |
| 241 | `)) |
| 242 | cmd.Flags().BoolVar(&data.strict, "strict", DefaultStrictMode, "Exit with non-zero code if validation fails") |
| 243 | |
| 244 | // Parallel processing options |
| 245 | cmd.Flags().IntVar(&data.workers, "workers", DefaultWorkers, "Number of worker threads for parallel processing") |
| 246 | |
| 247 | // Output formatting options |
| 248 | cmd.Flags().BoolVar(&data.noColor, "no-color", false, "Disable color when using text output even when the current terminal supports it") |
| 249 | cmd.Flags().BoolVar(&data.forceColor, "color", false, "Enable color when using text output even when the current terminal does not support it") |
| 250 | |
| 251 | // ===== COBRA BUILT-IN VALIDATION ===== |
| 252 | |
| 253 | // 1. Required flags |
| 254 | if err := cmd.MarkFlagRequired("policy"); err != nil { |
| 255 | log.Warnf("Failed to mark policy flag as required: %v", err) |
| 256 | } |
| 257 | |
| 258 | // 2. Mutual exclusivity: --vsa and --images are mutually exclusive |
| 259 | cmd.MarkFlagsMutuallyExclusive("vsa", "images") |
| 260 | |
| 261 | } |
| 262 | |
| 263 | // runValidateVSA is the main command execution function |
| 264 | func runValidateVSA(cmd *cobra.Command, data *validateVSAData, args []string) error { |
no test coverage detected