(spec *v1.PolicySpec, basePath string)
| 1140 | } |
| 1141 | |
| 1142 | func loadLegacyPolicyScript(spec *v1.PolicySpec, basePath string) ([]byte, error) { |
| 1143 | // legacy policies |
| 1144 | var content []byte |
| 1145 | var err error |
| 1146 | switch source := spec.GetSource().(type) { |
| 1147 | case *v1.PolicySpec_Embedded: |
| 1148 | content = []byte(source.Embedded) |
| 1149 | case *v1.PolicySpec_Path: |
| 1150 | var scriptPath string |
| 1151 | // If the path is a URL, use it directly. Otherwise, resolve it relative to basePath |
| 1152 | if isURLPath(source.Path) { |
| 1153 | scriptPath = source.Path |
| 1154 | } else { |
| 1155 | // path relative to policy folder |
| 1156 | scriptPath = filepath.Join(filepath.Dir(basePath), source.Path) |
| 1157 | } |
| 1158 | content, err = blob.LoadFileOrURL(scriptPath) |
| 1159 | if err != nil { |
| 1160 | return nil, fmt.Errorf("loading policy content: %w", err) |
| 1161 | } |
| 1162 | default: |
| 1163 | return nil, fmt.Errorf("policy spec is empty") |
| 1164 | } |
| 1165 | |
| 1166 | // Decode base64 if this is a base64-encoded WASM policy |
| 1167 | content = decodeIfBase64Wasm(content) |
| 1168 | |
| 1169 | return content, nil |
| 1170 | } |
| 1171 | |
| 1172 | func LogPolicyEvaluations(evaluations []*v12.PolicyEvaluation, logger *zerolog.Logger) { |
| 1173 | for _, policyEval := range evaluations { |
no test coverage detected