()
| 26 | ) |
| 27 | |
| 28 | func newPolicyDevelopEvalCmd() *cobra.Command { |
| 29 | var ( |
| 30 | materialPath string |
| 31 | kind string |
| 32 | annotations []string |
| 33 | policyPath string |
| 34 | inputs []string |
| 35 | allowedHostnames []string |
| 36 | projectName string |
| 37 | projectVersionName string |
| 38 | ) |
| 39 | |
| 40 | cmd := &cobra.Command{ |
| 41 | Use: "eval", |
| 42 | Short: "Evaluate policy against provided material", |
| 43 | Long: `Perform a full evaluation of the policy against the provided material type. |
| 44 | The command checks if there is a path in the policy for the specified kind and |
| 45 | evaluates the policy against the provided material or attestation.`, |
| 46 | Example: ` |
| 47 | # Evaluate policy against a material file |
| 48 | chainloop policy develop eval --policy policy.yaml --material sbom.json --kind SBOM_CYCLONEDX_JSON --annotation key1=value1,key2=value2 --input key3=value3`, |
| 49 | RunE: func(_ *cobra.Command, _ []string) error { |
| 50 | opts := &action.PolicyEvalOpts{ |
| 51 | MaterialPath: materialPath, |
| 52 | Kind: kind, |
| 53 | Annotations: parseKeyValue(annotations), |
| 54 | PolicyPath: policyPath, |
| 55 | Inputs: parseKeyValue(inputs), |
| 56 | AllowedHostnames: allowedHostnames, |
| 57 | Debug: flagDebug, |
| 58 | ProjectName: projectName, |
| 59 | ProjectVersionName: projectVersionName, |
| 60 | } |
| 61 | |
| 62 | policyEval, err := action.NewPolicyEval(opts, ActionOpts) |
| 63 | if err != nil { |
| 64 | return err |
| 65 | } |
| 66 | |
| 67 | result, err := policyEval.Run() |
| 68 | if err != nil { |
| 69 | return err |
| 70 | } |
| 71 | |
| 72 | return output.EncodeJSON(result) |
| 73 | }, |
| 74 | } |
| 75 | |
| 76 | cmd.Flags().StringVar(&materialPath, "material", "", "Path to material or attestation file") |
| 77 | cobra.CheckErr(cmd.MarkFlagRequired("material")) |
| 78 | cmd.Flags().StringVar(&kind, "kind", "", fmt.Sprintf("Kind of the material: %q", schemaapi.ListAvailableMaterialKind())) |
| 79 | cmd.Flags().StringSliceVar(&annotations, "annotation", []string{}, "Key-value pairs of material annotations (key=value)") |
| 80 | cmd.Flags().StringVarP(&policyPath, "policy", "p", "policy.yaml", "Policy reference (./my-policy.yaml, https://my-domain.com/my-policy.yaml, chainloop://my-stored-policy)") |
| 81 | cmd.Flags().StringArrayVar(&inputs, "input", []string{}, "Key-value pairs of policy inputs (key=value)") |
| 82 | cmd.Flags().StringSliceVar(&allowedHostnames, "allowed-hostnames", []string{}, "Additional hostnames allowed for http.send requests in policies") |
| 83 | cmd.Flags().StringVar(&projectName, "project", "", "Project name to use as engine context for chainloop.* built-ins") |
| 84 | cmd.Flags().StringVar(&projectVersionName, "project-version", "", "Project version to use as engine context for chainloop.* built-ins") |
| 85 |
no test coverage detected