2026-05-23 14:03:31 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2026-11-20 05:23:32 +00:00
|
|
|
"errors"
|
2026-05-23 14:03:31 +00:00
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// SessionValidate performs a read-only session preflight.
|
|
|
|
|
func SessionValidate(ctx context.Context, args []string, out io.Writer) error {
|
2026-09-05 18:00:50 +00:00
|
|
|
return sessionValidateWithDependencies(ctx, args, out, commandDependencies{})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func sessionValidateWithDependencies(ctx context.Context, args []string, out io.Writer, deps commandDependencies) error {
|
|
|
|
|
deps = normalizeCommandDependencies(deps)
|
2026-05-23 14:03:31 +00:00
|
|
|
fs := flag.NewFlagSet("session validate", flag.ContinueOnError)
|
|
|
|
|
fs.SetOutput(io.Discard)
|
|
|
|
|
var flags commonConfigFlags
|
|
|
|
|
addCommonConfigFlags(fs, &flags)
|
|
|
|
|
if err := parseSessionAwareFlags("session validate", fs, args, &flags.sessionID); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if strings.TrimSpace(flags.sessionID) == "" {
|
|
|
|
|
return fmt.Errorf("session validate: session_id is required")
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-07 04:13:58 +00:00
|
|
|
loaded, err := loadCommandConfigWithDependencies(ctx, flags.pipelinePath, flags.campaignPath, flags.campaignFilePath, flags.sessionPath, flags.sessionOptions(), flags.secretsDir.pointer(), deps)
|
2026-05-23 14:03:31 +00:00
|
|
|
if err != nil {
|
2026-11-20 05:23:32 +00:00
|
|
|
return renderFindings(out, "", "", []finding{errorFinding("config", err.Error())})
|
2026-05-23 14:03:31 +00:00
|
|
|
}
|
2026-08-10 21:41:00 +00:00
|
|
|
defer func() { _ = loaded.Close() }()
|
2026-11-20 05:23:32 +00:00
|
|
|
report, err := inspectSessionValidation(ctx, loaded.Config, deps)
|
|
|
|
|
if report == nil {
|
|
|
|
|
return err
|
2026-05-23 14:03:31 +00:00
|
|
|
}
|
2026-11-20 05:23:32 +00:00
|
|
|
return errors.Join(err, renderFindings(out, report.Campaign, report.SessionID, report.Findings))
|
2026-05-23 14:03:31 +00:00
|
|
|
}
|
2026-08-10 21:20:59 +00:00
|
|
|
|
|
|
|
|
func previousRequirementSkipped(values []string, name string) bool {
|
|
|
|
|
for _, value := range values {
|
|
|
|
|
if value == name {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|