Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enforcement level to policies #895

Merged
merged 2 commits into from Apr 29, 2024
Merged

Conversation

JarrettSpiker
Copy link
Contributor

Description

Adds support for the EnforcementLevel field for policies, and their create/update options.

The current method of adding enforcement to policies (the Enforce array) is deprecated.

Testing plan

  1. Policies can still be created with the existing enforce array
  2. Policies can be created using the preferred enforcement level string
  3. Either Enforce or EnforcementLevel must be set on policies during creation
  4. Enforce and Enforcement level may not both be set on policy creation

External links

Output from tests

go test -timeout 30s -run ^TestPoliciesCreate$ github.com/hashicorp/go-tfe

=== RUN   TestPoliciesCreate
=== RUN   TestPoliciesCreate/with_no_kind
--- PASS: TestPoliciesCreate/with_no_kind (0.47s)
=== RUN   TestPoliciesCreate/with_valid_options_-_Sentinel
--- PASS: TestPoliciesCreate/with_valid_options_-_Sentinel (0.50s)
=== RUN   TestPoliciesCreate/with_valid_options_-_OPA
--- PASS: TestPoliciesCreate/with_valid_options_-_OPA (0.42s)
=== RUN   TestPoliciesCreate/with_valid_options_-_Enforcement_Level
--- PASS: TestPoliciesCreate/with_valid_options_-_Enforcement_Level (0.60s)
=== RUN   TestPoliciesCreate/when_options_has_an_invalid_name
--- PASS: TestPoliciesCreate/when_options_has_an_invalid_name (0.00s)
=== RUN   TestPoliciesCreate/when_options_has_an_invalid_name_-_OPA
--- PASS: TestPoliciesCreate/when_options_has_an_invalid_name_-_OPA (0.00s)
=== RUN   TestPoliciesCreate/when_options_is_missing_name
--- PASS: TestPoliciesCreate/when_options_is_missing_name (0.00s)
=== RUN   TestPoliciesCreate/when_options_is_missing_name_-_OPA
--- PASS: TestPoliciesCreate/when_options_is_missing_name_-_OPA (0.00s)
=== RUN   TestPoliciesCreate/when_options_is_missing_query_-_OPA
--- PASS: TestPoliciesCreate/when_options_is_missing_query_-_OPA (0.00s)
=== RUN   TestPoliciesCreate/when_options_is_missing_an_enforcement-OPA
--- PASS: TestPoliciesCreate/when_options_is_missing_an_enforcement-OPA (0.00s)
=== RUN   TestPoliciesCreate/when_options_is_missing_an_enforcement-Sentinel
--- PASS: TestPoliciesCreate/when_options_is_missing_an_enforcement-Sentinel (0.00s)
=== RUN   TestPoliciesCreate/when_options_is_missing_enforcement_path-Sentinel
--- PASS: TestPoliciesCreate/when_options_is_missing_enforcement_path-Sentinel (0.00s)
=== RUN   TestPoliciesCreate/when_options_is_missing_enforcement_path-OPA
--- PASS: TestPoliciesCreate/when_options_is_missing_enforcement_path-OPA (0.00s)
=== RUN   TestPoliciesCreate/when_options_is_missing_enforcement_path
--- PASS: TestPoliciesCreate/when_options_is_missing_enforcement_path (0.00s)
=== RUN   TestPoliciesCreate/when_options_is_missing_enforcement_mode-OPA
--- PASS: TestPoliciesCreate/when_options_is_missing_enforcement_mode-OPA (0.00s)
=== RUN   TestPoliciesCreate/when_options_is_have_both_enforcement_level_and_enforcement_path
--- PASS: TestPoliciesCreate/when_options_is_have_both_enforcement_level_and_enforcement_path (0.00s)
=== RUN   TestPoliciesCreate/when_options_has_an_invalid_organization
--- PASS: TestPoliciesCreate/when_options_has_an_invalid_organization (0.00s)
--- PASS: TestPoliciesCreate (3.22s)
PASS
ok      github.com/hashicorp/go-tfe     3.413s

go test -timeout 30s -run ^TestPoliciesRead$ github.com/hashicorp/go-tfe

=== RUN   TestPoliciesRead
=== RUN   TestPoliciesRead/when_the_policy_exists_without_content
--- PASS: TestPoliciesRead/when_the_policy_exists_without_content (0.20s)
=== RUN   TestPoliciesRead/when_the_policy_exists_with_content
--- PASS: TestPoliciesRead/when_the_policy_exists_with_content (0.24s)
=== RUN   TestPoliciesRead/when_the_policy_does_not_exist
--- PASS: TestPoliciesRead/when_the_policy_does_not_exist (0.18s)
=== RUN   TestPoliciesRead/without_a_valid_policy_ID
--- PASS: TestPoliciesRead/without_a_valid_policy_ID (0.00s)
--- PASS: TestPoliciesRead (2.84s)
PASS
ok      github.com/hashicorp/go-tfe     3.041s

go test -timeout 30s -run ^TestPoliciesUpdate$ github.com/hashicorp/go-tfe

=== RUN   TestPoliciesUpdate
=== RUN   TestPoliciesUpdate/when_updating_with_an_existing_path
--- PASS: TestPoliciesUpdate/when_updating_with_an_existing_path (1.43s)
=== RUN   TestPoliciesUpdate/when_updating_with_a_nonexisting_path
    /Users/jarretspiker/go/src/github.com/hashicorp/go-tfe/policy_integration_test.go:516: see comment...
--- SKIP: TestPoliciesUpdate/when_updating_with_a_nonexisting_path (0.00s)
=== RUN   TestPoliciesUpdate/with_a_new_description
--- PASS: TestPoliciesUpdate/with_a_new_description (1.31s)
=== RUN   TestPoliciesUpdate/with_a_new_query
--- PASS: TestPoliciesUpdate/with_a_new_query (1.42s)
=== RUN   TestPoliciesUpdate/with_a_new_enforcement_level
--- PASS: TestPoliciesUpdate/with_a_new_enforcement_level (1.34s)
=== RUN   TestPoliciesUpdate/update_query_when_kind_is_not_OPA
--- PASS: TestPoliciesUpdate/update_query_when_kind_is_not_OPA (1.29s)
=== RUN   TestPoliciesUpdate/without_a_valid_policy_ID
--- PASS: TestPoliciesUpdate/without_a_valid_policy_ID (0.00s)
--- PASS: TestPoliciesUpdate (8.01s)
PASS
ok      github.com/hashicorp/go-tfe     8.209s

...

@JarrettSpiker JarrettSpiker requested a review from a team April 26, 2024 02:36
@JarrettSpiker JarrettSpiker requested a review from a team as a code owner April 26, 2024 02:36
Copy link
Member

@cam-stitt cam-stitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is beautiful. I haven't tested locally but looks good.

@JarrettSpiker JarrettSpiker merged commit 03314f5 into main Apr 29, 2024
7 checks passed
@JarrettSpiker JarrettSpiker deleted the jspiker/policyEnforcementLevel branch April 29, 2024 12:30
Copy link

Reminder to the contributor that merged this PR: if your changes have added important functionality or fixed a relevant bug, open a follow-up PR to update CHANGELOG.md with a note on your changes.

@Maed223 Maed223 mentioned this pull request Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants