Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions internal/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ package internal

import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"strings"

policyManager "github.com/compliance-framework/agent/policy-manager"
Expand Down Expand Up @@ -152,41 +149,6 @@ func certificateBaseLabels() map[string]string {
}
}

// LoadBundleRootData reads data.json from the OPA bundle root and merges it
// with overrides. When the agent downloads a policy OCI artifact it returns the
// policies/ subdirectory as policyPath; the bundle's data.json lives one level
// up in the bundle root. For local source trees the data.json lives inside the
// policies/ directory itself, so both locations are checked. overrides win on
// conflict, so operator-supplied policy_data takes precedence over bundle defaults.
func LoadBundleRootData(policyPath string, overrides map[string]interface{}) (map[string]interface{}, error) {
candidates := []string{
filepath.Join(policyPath, "data.json"),
filepath.Join(filepath.Dir(policyPath), "data.json"),
}
for _, p := range candidates {
raw, err := os.ReadFile(p)
if errors.Is(err, os.ErrNotExist) {
continue
}
if err != nil {
return nil, fmt.Errorf("reading bundle data %s: %w", p, err)
}
var bundleData map[string]interface{}
if err := json.Unmarshal(raw, &bundleData); err != nil {
return nil, fmt.Errorf("parsing bundle data %s: %w", p, err)
}
merged := make(map[string]interface{}, len(bundleData)+len(overrides))
for k, v := range bundleData {
merged[k] = v
}
for k, v := range overrides {
merged[k] = v
}
return merged, nil
}
return overrides, nil
}

// arnCertID extracts the certificate UUID from an ACM ARN.
// ARN format: arn:aws:acm:<region>:<account-id>:certificate/<uuid>
func arnCertID(arn string) string {
Expand Down
102 changes: 0 additions & 102 deletions internal/eval_test.go

This file was deleted.

13 changes: 1 addition & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,12 @@ func (l *CompliancePlugin) Eval(request *proto.EvalRequest, apiHelper runner.Api
}, fmt.Errorf("failed to fetch data: %w", err)
}

// Load bundle data.json defaults and merge with operator overrides once per
// evaluation cycle. All policy paths share the same bundle so one load suffices.
policyData := l.policyData
if paths := request.GetPolicyPaths(); len(paths) > 0 {
merged, err := internal.LoadBundleRootData(paths[0], l.policyData)
if err != nil {
return &proto.EvalResponse{Status: proto.ExecutionStatus_FAILURE}, fmt.Errorf("loading bundle data for %s: %w", paths[0], err)
}
policyData = merged
}

policyEvaluator := internal.NewPolicyEvaluator(ctx, l.logger, activities)

var allEvidences []*proto.Evidence
var evalErrors error
for _, cert := range certs {
certEvidences, err := policyEvaluator.Eval(ctx, cert, request.GetPolicyPaths(), policyData, l.config.PolicyLabels)
certEvidences, err := policyEvaluator.Eval(ctx, cert, request.GetPolicyPaths(), l.policyData, l.config.PolicyLabels)
allEvidences = append(allEvidences, certEvidences...)
if err != nil {
evalErrors = errors.Join(evalErrors, fmt.Errorf("evaluating cert %s: %w", cert.CertificateArn, err))
Expand Down
Loading