From f16efbbc68be653e6ca8596575fb3a2661677714 Mon Sep 17 00:00:00 2001 From: mrinalirao Date: Tue, 1 Nov 2022 12:32:02 +1100 Subject: [PATCH] add kind for policy set creation + update tests --- policy_set.go | 13 +++++++++++++ policy_set_integration_test.go | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/policy_set.go b/policy_set.go index 85207a1f7..8aff3e199 100644 --- a/policy_set.go +++ b/policy_set.go @@ -10,6 +10,15 @@ import ( // Compile-time proof of interface implementation. var _ PolicySets = (*policySets)(nil) +// PolicyKind is an indicator of the underlying technology that the policy or policy set supports. +// There are two Policykinds documented in the enum. +type PolicyKind string + +const ( + OPA PolicyKind = "opa" + Sentinel PolicyKind = "sentinel" +) + // PolicySets describes all the policy set related methods that the Terraform // Enterprise API supports. // @@ -64,6 +73,7 @@ type PolicySet struct { ID string `jsonapi:"primary,policy-sets"` Name string `jsonapi:"attr,name"` Description string `jsonapi:"attr,description"` + Kind string `jsonapi:"attr,kind"` Global bool `jsonapi:"attr,global"` PoliciesPath string `jsonapi:"attr,policies-path"` PolicyCount int `jsonapi:"attr,policy-count"` @@ -136,6 +146,9 @@ type PolicySetCreateOptions struct { // Optional: Whether or not the policy set is global. Global *bool `jsonapi:"attr,global,omitempty"` + // Optional: The underlying technology that the policy set supports + Kind PolicyKind `jsonapi:"attr,kind,omitempty"` + // Optional: The sub-path within the attached VCS repository to ingress. All // files and directories outside of this sub-path will be ignored. // This option may only be specified when a VCS repo is present. diff --git a/policy_set_integration_test.go b/policy_set_integration_test.go index ef09b6442..a77ee26a3 100644 --- a/policy_set_integration_test.go +++ b/policy_set_integration_test.go @@ -112,6 +112,7 @@ func TestPolicySetsCreate(t *testing.T) { t.Run("with valid attributes", func(t *testing.T) { options := PolicySetCreateOptions{ Name: String("policy-set"), + Kind: OPA, } ps, err := client.PolicySets.Create(ctx, orgTest.Name, options) @@ -119,6 +120,21 @@ func TestPolicySetsCreate(t *testing.T) { assert.Equal(t, ps.Name, *options.Name) assert.Equal(t, ps.Description, "") + assert.Equal(t, ps.Kind, "opa") + assert.False(t, ps.Global) + }) + + t.Run("with kind missing", func(t *testing.T) { + options := PolicySetCreateOptions{ + Name: String("policy-set2"), + } + + ps, err := client.PolicySets.Create(ctx, orgTest.Name, options) + require.NoError(t, err) + + assert.Equal(t, ps.Name, *options.Name) + assert.Equal(t, ps.Description, "") + assert.Equal(t, ps.Kind, "sentinel") assert.False(t, ps.Global) }) @@ -126,6 +142,7 @@ func TestPolicySetsCreate(t *testing.T) { options := PolicySetCreateOptions{ Name: String("global"), Description: String("Policies in this set will be checked in ALL workspaces!"), + Kind: Sentinel, Global: Bool(true), } @@ -134,6 +151,7 @@ func TestPolicySetsCreate(t *testing.T) { assert.Equal(t, ps.Name, *options.Name) assert.Equal(t, ps.Description, *options.Description) + assert.Equal(t, ps.Kind, "sentinel") assert.True(t, ps.Global) }) @@ -146,6 +164,7 @@ func TestPolicySetsCreate(t *testing.T) { options := PolicySetCreateOptions{ Name: String("populated-policy-set"), Policies: []*Policy{pTest}, + Kind: Sentinel, Workspaces: []*Workspace{wTest}, } @@ -156,6 +175,7 @@ func TestPolicySetsCreate(t *testing.T) { assert.Equal(t, ps.PolicyCount, 1) assert.Equal(t, ps.Policies[0].ID, pTest.ID) assert.Equal(t, ps.WorkspaceCount, 1) + assert.Equal(t, ps.Kind, "sentinel") assert.Equal(t, ps.Workspaces[0].ID, wTest.ID) }) @@ -170,6 +190,7 @@ func TestPolicySetsCreate(t *testing.T) { options := PolicySetCreateOptions{ Name: String("vcs-policy-set"), + Kind: Sentinel, PoliciesPath: String("/policy-sets/foo"), VCSRepo: &VCSRepoOptions{ Branch: String("policies"), @@ -190,6 +211,7 @@ func TestPolicySetsCreate(t *testing.T) { assert.False(t, ps.Global) assert.Equal(t, ps.PoliciesPath, "/policy-sets/foo") assert.Equal(t, ps.VCSRepo.Branch, "policies") + assert.Equal(t, ps.Kind, "sentinel") assert.Equal(t, ps.VCSRepo.DisplayIdentifier, githubIdentifier) assert.Equal(t, ps.VCSRepo.Identifier, githubIdentifier) assert.Equal(t, ps.VCSRepo.IngressSubmodules, true)