This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding CloudFrontOriginRequestPolicy resources. (#1051)
* Adding CloudFrontOriginRequestPolicy resources. --------- Co-authored-by: Philipp Trulson <[email protected]>
- Loading branch information
1 parent
90ad6c4
commit d01537a
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |