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

Function runCompare

cmd/compare/compare.go:85–165  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

83}
84
85func runCompare(cmd *cobra.Command, args []string) error {
86
87 // Parse effective time
88 var effectiveTimeValue time.Time
89 switch effectiveTime {
90 case "now":
91 effectiveTimeValue = time.Now().UTC()
92 case "attestation":
93 // For now, use current time as default for attestation time
94 effectiveTimeValue = time.Now().UTC()
95 default:
96 var err error
97 effectiveTimeValue, err = time.Parse(time.RFC3339, effectiveTime)
98 if err != nil {
99 return fmt.Errorf("invalid effective time format: %w", err)
100 }
101 }
102
103 // Create image info if provided
104 var imageInfo *equivalence.ImageInfo
105 if imageDigest != "" || imageRef != "" || imageURL != "" {
106 imageInfo = &equivalence.ImageInfo{
107 Digest: imageDigest,
108 Ref: imageRef,
109 URL: imageURL,
110 }
111 }
112
113 // Load first policy
114 spec1, err := loadPolicySpec(args[0])
115 if err != nil {
116 return fmt.Errorf("failed to load first policy: %w", err)
117 }
118
119 // Load second policy
120 spec2, err := loadPolicySpec(args[1])
121 if err != nil {
122 return fmt.Errorf("failed to load second policy: %w", err)
123 }
124
125 // Create equivalence checker
126 checker := equivalence.NewEquivalenceChecker(effectiveTimeValue, imageInfo)
127
128 // Compare policies
129 equivalent, err := checker.AreEquivalent(spec1, spec2)
130 if err != nil {
131 return fmt.Errorf("failed to compare policies: %w", err)
132 }
133
134 // Output result
135 if outputFormat == "json" {
136 result := map[string]interface{}{
137 "equivalent": equivalent,
138 "effective_time": effectiveTimeValue.Format(time.RFC3339),
139 "policy1": args[0],
140 "policy2": args[1],
141 }
142 if imageInfo != nil {

Callers

nothing calls this directly

Calls 6

AreEquivalentMethod · 0.95
NewEquivalenceCheckerFunction · 0.92
loadPolicySpecFunction · 0.85
ParseMethod · 0.80
ErrorfMethod · 0.65
PrintfMethod · 0.65

Tested by

no test coverage detected