Skip to content

Commit be9dc94

Browse files
committed
fix json keys; extract rego get rule name function; update debug flag desc
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
1 parent 4e4a6e2 commit be9dc94

5 files changed

Lines changed: 14 additions & 16 deletions

File tree

app/cli/cmd/output.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ type tabulatedData interface {
5555
[]*action.APITokenItem |
5656
*action.AttestationStatusMaterial |
5757
*action.ListMembershipResult |
58-
*action.PolicyEvalResult |
5958
*action.PolicyLintResult
6059
}
6160

app/cli/cmd/policy_develop_eval.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ evaluates the policy against the provided material or attestation.`,
7676
cmd.Flags().StringVarP(&policyPath, "policy", "p", "policy.yaml", "Path to custom policy file")
7777
cmd.Flags().StringSliceVar(&inputs, "input", []string{}, "Key-value pairs of policy inputs (key=value)")
7878
cmd.Flags().StringSliceVar(&allowedHostnames, "allowed-hostnames", []string{}, "Additional hostnames allowed for http.send requests in policies")
79-
cmd.Flags().BoolVarP(&debug, "debug", "", false, "Enable debug/verbose output and logging mode")
79+
cmd.Flags().BoolVarP(&debug, "debug", "", false, "Include detailed evaluation inputs/outputs in JSON output and enable verbose logging")
8080

8181
return cmd
8282
}

app/cli/internal/action/policy_develop_eval.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ type PolicyEvalOpts struct {
2929
Debug bool
3030
}
3131

32-
type PolicyEvalResult struct {
33-
Violations []string `json:"violations"`
34-
SkipReasons []string `json:"skip_reasons"`
35-
Skipped bool `json:"skipped"`
36-
Ignored bool `json:"ignored,omitempty"`
37-
RawResults []map[string]interface{} `json:"raw_results,omitempty"`
38-
}
39-
4032
type PolicyEval struct {
4133
*ActionsOpts
4234
opts *PolicyEvalOpts

app/cli/internal/policydevel/eval.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ type EvalOptions struct {
4040
}
4141

4242
type EvalResult struct {
43-
Skipped bool
44-
SkipReasons []string
45-
Violations []string
43+
Violations []string `json:"violations"`
44+
SkipReasons []string `json:"skip_reasons"`
45+
Skipped bool `json:"skipped"`
4646
}
4747

4848
type EvalSummary struct {

pkg/policies/engine/rego/rego.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (r *Engine) Verify(ctx context.Context, policy *engine.Policy, input []byte
155155
}
156156

157157
// Get raw results first
158-
if err := executeQuery(fmt.Sprintf("%s\n", parsedModule.Package.Path), r.operatingMode == EnvironmentModeRestrictive); err != nil {
158+
if err := executeQuery(getRuleName(parsedModule.Package.Path, ""), r.operatingMode == EnvironmentModeRestrictive); err != nil {
159159
return nil, err
160160
}
161161

@@ -165,15 +165,15 @@ func (r *Engine) Verify(ctx context.Context, policy *engine.Policy, input []byte
165165
}
166166

167167
// Try the main rule first
168-
if err := executeQuery(fmt.Sprintf("%v.%s\n", parsedModule.Package.Path, mainRule), r.operatingMode == EnvironmentModeRestrictive); err != nil {
168+
if err := executeQuery(getRuleName(parsedModule.Package.Path, mainRule), r.operatingMode == EnvironmentModeRestrictive); err != nil {
169169
return nil, err
170170
}
171171

172172
// If res is nil, it means that the rule hasn't been found
173173
// TODO: Remove when this deprecated rule is not used anymore
174174
if res == nil {
175175
// Try with the deprecated main rule
176-
if err := executeQuery(fmt.Sprintf("%v.%s\n", parsedModule.Package.Path, deprecatedRule), r.operatingMode == EnvironmentModeRestrictive); err != nil {
176+
if err := executeQuery(getRuleName(parsedModule.Package.Path, deprecatedRule), r.operatingMode == EnvironmentModeRestrictive); err != nil {
177177
return nil, err
178178
}
179179

@@ -325,3 +325,10 @@ func regoResultSetToRawResults(res rego.ResultSet) map[string]interface{} {
325325
}
326326
return raw
327327
}
328+
329+
func getRuleName(packagePath ast.Ref, rule string) string {
330+
if rule == "" {
331+
return fmt.Sprintf("%s\n", packagePath)
332+
}
333+
return fmt.Sprintf("%v.%s\n", packagePath, rule)
334+
}

0 commit comments

Comments
 (0)