Skip to content

Commit

Permalink
Merge branch 'mr/TF-1450-policy-evaluation' into mr/TF-1450-policy-ov…
Browse files Browse the repository at this point in the history
…erride
  • Loading branch information
mrinalirao committed Nov 10, 2022
2 parents 48d277b + e9f6b08 commit 34558b1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Add OPA support to the Policy Set APIs by @mrinalirao [#575](https://github.com/hashicorp/go-tfe/pull/575)
* Add OPA support to the Policy APIs by @mrinalirao [#579](https://github.com/hashicorp/go-tfe/pull/579)
* Add Policy Evaluation and Policy Set Outcome APIs by @mrinalirao [#583](https://github.com/hashicorp/go-tfe/pull/583)

# v1.12.0

Expand Down
3 changes: 2 additions & 1 deletion helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,8 @@ func createPolicyWithOptions(t *testing.T, client *Client, org *Organization, op
Enforce: []*EnforcementOptions{
{
Path: String(path),
Mode: opts.Enforce[0].Mode},
Mode: opts.Enforce[0].Mode,
},
},
}

Expand Down
8 changes: 4 additions & 4 deletions mocks/policy_evaluation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 31 additions & 8 deletions policy_evaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ import (
// Compile-time proof of interface implementation.
var _ PolicyEvaluations = (*policyEvaluation)(nil)

// PolicyEvaluationStatus is an enum that represents all possible statuses for a policy evaluation
type PolicyEvaluationStatus string

const (
PolicyEvaluationPassed PolicyEvaluationStatus = "passed"
PolicyEvaluationFailed PolicyEvaluationStatus = "failed"
PolicyEvaluationPending PolicyEvaluationStatus = "pending"
PolicyEvaluationRunning PolicyEvaluationStatus = "running"
PolicyEvaluationUnreachable PolicyEvaluationStatus = "unreachable"
PolicyEvaluationOverridden PolicyEvaluationStatus = "overridden"
PolicyEvaluationCanceled PolicyEvaluationStatus = "canceled"
PolicyEvaluationErrored PolicyEvaluationStatus = "errored"
)

// PolicyResultCount represents the count of the policy results
type PolicyResultCount struct {
AdvisoryFailed int `jsonapi:"attr,advisory-failed"`
Expand All @@ -24,15 +38,24 @@ type PolicyAttachable struct {
Type string `jsonapi:"attr,type"`
}

// PolicyEvaluationStatusTimestamps represents the set of timestamps recorded for a policy evaluation
type PolicyEvaluationStatusTimestamps struct {
ErroredAt time.Time `jsonapi:"attr,errored-at,rfc3339"`
RunningAt time.Time `jsonapi:"attr,running-at,rfc3339"`
CanceledAt time.Time `jsonapi:"attr,canceled-at,rfc3339"`
FailedAt time.Time `jsonapi:"attr,failed-at,rfc3339"`
PassedAt time.Time `jsonapi:"attr,passed-at,rfc3339"`
}

// PolicyEvaluation represents the policy evaluations that are part of the task stage.
type PolicyEvaluation struct {
ID string `jsonapi:"primary,policy-evaluations"`
Status TaskResultStatus `jsonapi:"attr,status"`
PolicyKind PolicyKind `jsonapi:"attr,policy-kind"`
StatusTimestamps TaskResultStatusTimestamps `jsonapi:"attr,status-timestamps"`
ResultCount *PolicyResultCount `jsonapi:"attr,result-count"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
UpdatedAt time.Time `jsonapi:"attr,updated-at,iso8601"`
ID string `jsonapi:"primary,policy-evaluations"`
Status PolicyEvaluationStatus `jsonapi:"attr,status"`
PolicyKind PolicyKind `jsonapi:"attr,policy-kind"`
StatusTimestamps PolicyEvaluationStatusTimestamps `jsonapi:"attr,status-timestamps"`
ResultCount *PolicyResultCount `jsonapi:"attr,result-count"`
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
UpdatedAt time.Time `jsonapi:"attr,updated-at,iso8601"`

// The task stage this evaluation belongs to
TaskStage *PolicyAttachable `jsonapi:"relation,policy-attachable"`
Expand Down Expand Up @@ -101,7 +124,7 @@ type PolicySetOutcomes interface {

// **Note: This method is still in BETA and subject to change.**
// Read a policy set outcome by its ID. Only available for OPA policies.
Read(ctx context.Context, policy_set_outcome_id string) (*PolicySetOutcome, error)
Read(ctx context.Context, policySetOutcomeID string) (*PolicySetOutcome, error)
}

// policySetOutcome implements PolicySetOutcomes.
Expand Down

0 comments on commit 34558b1

Please sign in to comment.