MCPcopy Create free account
hub / github.com/conforma/cli / ValidateInput

Function ValidateInput

internal/input/validate.go:37–71  ·  view source on GitHub ↗
(ctx context.Context, fpath string, policy policy.Policy, detailed bool)

Source from the content-addressed store, hash-verified

35var inputFile = input.NewInput
36
37func ValidateInput(ctx context.Context, fpath string, policy policy.Policy, detailed bool) (*output.Output, error) {
38 if trace.IsEnabled() {
39 region := trace.StartRegion(ctx, "ec:validate-input")
40 defer region.End()
41 trace.Logf(ctx, "", "file=%q", fpath)
42 }
43
44 log.Debugf("Current input filePath: %q", fpath)
45 inputFiles, err := detectInput(ctx, fpath)
46 if err != nil {
47 return nil, err
48 }
49
50 p, err := inputFile(ctx, inputFiles, policy)
51 if err != nil {
52 log.Debug("Failed to create input!")
53 return nil, err
54 }
55
56 var allResults []evaluator.Outcome
57 for _, e := range p.Evaluators {
58 results, err := e.Evaluate(ctx, evaluator.EvaluationTarget{Inputs: inputFiles})
59 if err != nil {
60 return nil, fmt.Errorf("evaluating policy: %w", err)
61 }
62 allResults = append(allResults, results...)
63 }
64
65 log.Debug("Conftest policy check complete")
66
67 out := output.Output{Detailed: detailed}
68 out.SetPolicyCheck(allResults)
69
70 return &out, nil
71}
72
73// detect if a file or directory was passed. if a directory, gather all files in it
74// the order is file lookup, json lookup then yaml

Callers 1

Test_ValidatePipelineFunction · 0.85

Calls 5

SetPolicyCheckMethod · 0.95
detectInputFunction · 0.85
LogfMethod · 0.65
EvaluateMethod · 0.65
ErrorfMethod · 0.65

Tested by 1

Test_ValidatePipelineFunction · 0.68