Skip to content

Commit dd66925

Browse files
ssprod_41907 | add get full policy (#513)
* add full policy * add type to request
1 parent 922da70 commit dd66925

File tree

4 files changed

+45
-29
lines changed

4 files changed

+45
-29
lines changed

sysdig/internal/client/v2/model.go

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -926,24 +926,39 @@ type PosturePolicyZoneMeta struct {
926926
}
927927

928928
type PosturePolicy struct {
929-
ID string `json:"id,omitempty"`
930-
Name string `json:"name,omitempty"`
931-
Type int `json:"type,omitempty"`
932-
Kind int `json:"kind,omitempty"`
933-
Description string `json:"description,omitempty"`
934-
Version string `json:"version,omitempty"`
935-
Link string `json:"link,omitempty"`
936-
Authors string `json:"authors,omitempty"`
937-
PublishedData string `json:"publishedDate,omitempty"`
938-
RequirementsGroup []RequirementsGroup `json:"requirementFolders,omitempty"`
939-
MinKubeVersion float64 `json:"minKubeVersion,omitempty"`
940-
MaxKubeVersion float64 `json:"maxKubeVersion,omitempty"`
941-
IsCustom bool `json:"isCustom,omitempty"`
942-
IsActive bool `json:"isActive,omitempty"`
943-
Platform string `json:"platform,omitempty"`
944-
Zones []PosturePolicyZoneMeta `json:"zones,omitempty"`
929+
ID string `json:"id,omitempty"`
930+
Name string `json:"name,omitempty"`
931+
Type int `json:"type,omitempty"`
932+
Kind int `json:"kind,omitempty"`
933+
Description string `json:"description,omitempty"`
934+
Version string `json:"version,omitempty"`
935+
Link string `json:"link,omitempty"`
936+
Authors string `json:"authors,omitempty"`
937+
PublishedData string `json:"publishedDate,omitempty"`
938+
MinKubeVersion float64 `json:"minKubeVersion,omitempty"`
939+
MaxKubeVersion float64 `json:"maxKubeVersion,omitempty"`
940+
IsCustom bool `json:"isCustom,omitempty"`
941+
IsActive bool `json:"isActive,omitempty"`
942+
Platform string `json:"platform,omitempty"`
943+
Zones []PosturePolicyZoneMeta `json:"zones,omitempty"`
944+
}
945+
946+
type FullPosturePolicy struct {
947+
ID string `json:"id,omitempty"`
948+
Name string `json:"name,omitempty"`
949+
Type string `json:"type,omitempty"`
950+
Description string `json:"description,omitempty"`
951+
Version string `json:"version,omitempty"`
952+
Link string `json:"link,omitempty"`
953+
Authors string `json:"authors,omitempty"`
954+
PublishedData string `json:"publishedDate,omitempty"`
955+
RequirementsGroup []RequirementsGroup `json:"requirementFolders,omitempty"`
956+
MinKubeVersion float64 `json:"minKubeVersion,omitempty"`
957+
MaxKubeVersion float64 `json:"maxKubeVersion,omitempty"`
958+
IsCustom bool `json:"isCustom,omitempty"`
959+
IsActive bool `json:"isActive,omitempty"`
960+
Platform string `json:"platform,omitempty"`
945961
}
946-
947962
type RequirementsGroup struct {
948963
ID string `json:"id,omitempty"`
949964
Name string `json:"name,omitempty"`
@@ -1005,6 +1020,9 @@ type PosturePolicyResponse struct {
10051020
Data PosturePolicy `json:"data"`
10061021
}
10071022

1023+
type FullPosturePolicyResponse struct {
1024+
Data FullPosturePolicy `json:"data"`
1025+
}
10081026
type PostureZonePolicyListResponse struct {
10091027
Data []PosturePolicy `json:"data"`
10101028
}

sysdig/internal/client/v2/posture_policies.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import (
99
const (
1010
PosturePolicyListPath = "%s/api/cspm/v1/policy/policies/list"
1111
PosturePolicyCreatePath = "%s/api/cspm/v1/policy"
12-
PosturePolicyGetPath = "%s/api/cspm/v1/policy/policies/view/%d"
12+
PosturePolicyGetPath = "%s/api/cspm/v1/policy/posture/policies/%d?include_controls=true"
1313
)
1414

1515
type PosturePolicyInterface interface {
1616
Base
1717
ListPosturePolicies(ctx context.Context) ([]PosturePolicy, error)
18-
CreateOrUpdatePosturePolicy(ctx context.Context, p *CreatePosturePolicy) (*PosturePolicy, string, error)
19-
GetPosturePolicy(ctx context.Context, id int64) (*PosturePolicy, error)
18+
CreateOrUpdatePosturePolicy(ctx context.Context, p *CreatePosturePolicy) (*FullPosturePolicy, string, error)
19+
GetPosturePolicy(ctx context.Context, id int64) (*FullPosturePolicy, error)
2020
}
2121

2222
func (client *Client) ListPosturePolicies(ctx context.Context) ([]PosturePolicy, error) {
@@ -34,7 +34,7 @@ func (client *Client) ListPosturePolicies(ctx context.Context) ([]PosturePolicy,
3434
return resp.Data, nil
3535
}
3636

37-
func (client *Client) CreateOrUpdatePosturePolicy(ctx context.Context, p *CreatePosturePolicy) (*PosturePolicy, string, error) {
37+
func (client *Client) CreateOrUpdatePosturePolicy(ctx context.Context, p *CreatePosturePolicy) (*FullPosturePolicy, string, error) {
3838
payload, err := Marshal(p)
3939
if err != nil {
4040
return nil, "", err
@@ -48,25 +48,24 @@ func (client *Client) CreateOrUpdatePosturePolicy(ctx context.Context, p *Create
4848
errStatus, err := client.ErrorAndStatusFromResponse(response)
4949
return nil, errStatus, err
5050
}
51-
resp, err := Unmarshal[PosturePolicyResponse](response.Body)
51+
resp, err := Unmarshal[FullPosturePolicyResponse](response.Body)
5252
if err != nil {
5353
return nil, "", err
5454
}
5555
return &resp.Data, "", nil
5656
}
5757

58-
func (client *Client) GetPosturePolicy(ctx context.Context, id int64) (*PosturePolicy, error) {
58+
func (client *Client) GetPosturePolicy(ctx context.Context, id int64) (*FullPosturePolicy, error) {
5959
response, err := client.requester.Request(ctx, http.MethodGet, client.getPolicyUrl(id), nil)
6060
if err != nil {
6161
return nil, err
6262
}
6363
defer response.Body.Close()
6464

65-
wrapper, err := Unmarshal[PosturePolicyResponse](response.Body)
65+
wrapper, err := Unmarshal[FullPosturePolicyResponse](response.Body)
6666
if err != nil {
6767
return nil, err
6868
}
69-
7069
return &wrapper.Data, nil
7170
}
7271

sysdig/resource_sysdig_secure_posture_policy.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func resourceSysdigSecurePosturePolicyCreateOrUpdate(ctx context.Context, d *sch
201201
req := &v2.CreatePosturePolicy{
202202
ID: getStringValue(d, SchemaIDKey),
203203
Name: getStringValue(d, SchemaNameKey),
204+
Type: getStringValue(d, SchemaTypeKey),
204205
Description: getStringValue(d, SchemaDescriptionKey),
205206
MinKubeVersion: getFloatValue(d, SchemaMinKubeVersionKey),
206207
MaxKubeVersion: getFloatValue(d, SchemaMaxKubeVersionKey),
@@ -249,9 +250,7 @@ func resourceSysdigSecurePosturePolicyRead(ctx context.Context, d *schema.Resour
249250
return diag.FromErr(err)
250251
}
251252

252-
strconv.Itoa(policy.Type)
253-
254-
err = d.Set(SchemaTypeKey, strconv.Itoa(policy.Type))
253+
err = d.Set(SchemaTypeKey, policy.Type)
255254
if err != nil {
256255
return diag.FromErr(err)
257256
}

sysdig/resource_sysdig_secure_posture_policy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ func createPolicyResource(name string) string {
3434
name = "policy-test-%s"
3535
description = "policy description"
3636
is_active = true
37-
type = "0"
37+
type = "Unknown"
3838
}`, name)
3939
}

0 commit comments

Comments
 (0)