Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Adding CloudFrontOriginRequestPolicy resources. (#1051)
Browse files Browse the repository at this point in the history
* Adding CloudFrontOriginRequestPolicy resources.

---------

Co-authored-by: Philipp Trulson <[email protected]>
  • Loading branch information
MikeSchouw and der-eismann authored Aug 3, 2023
1 parent 90ad6c4 commit d01537a
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions resources/cloudfront-origin-request-policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudfront"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type CloudFrontOriginRequestPolicy struct {
svc *cloudfront.CloudFront
ID *string
}

func init() {
register("CloudFrontOriginRequestPolicy", ListCloudFrontOriginRequestPolicies)
}

func ListCloudFrontOriginRequestPolicies(sess *session.Session) ([]Resource, error) {
svc := cloudfront.New(sess)
resources := []Resource{}
params := &cloudfront.ListOriginRequestPoliciesInput{}

for {
resp, err := svc.ListOriginRequestPolicies(params)
if err != nil {
return nil, err
}

for _, item := range resp.OriginRequestPolicyList.Items {
if *item.Type == "custom" {
resources = append(resources, &CloudFrontOriginRequestPolicy{
svc: svc,
ID: item.OriginRequestPolicy.Id,
})
}
}

if resp.OriginRequestPolicyList.NextMarker == nil {
break
}

params.Marker = resp.OriginRequestPolicyList.NextMarker
}

return resources, nil
}

func (f *CloudFrontOriginRequestPolicy) Remove() error {
resp, err := f.svc.GetOriginRequestPolicy(&cloudfront.GetOriginRequestPolicyInput{
Id: f.ID,
})
if err != nil {
return err
}

_, err = f.svc.DeleteOriginRequestPolicy(&cloudfront.DeleteOriginRequestPolicyInput{
Id: f.ID,
IfMatch: resp.ETag,
})

return err
}

func (f *CloudFrontOriginRequestPolicy) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("ID", f.ID)
return properties
}

0 comments on commit d01537a

Please sign in to comment.