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 728
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NS-2448: Added resource for CloudFront OAI (#478)
Co-authored-by: Joe Chung <joseph.chung@novastonemedia.com>
- Loading branch information
1 parent
7d41b37
commit 1710d34
Showing
1 changed file
with
58 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,58 @@ | ||
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/pkg/types" | ||
) | ||
|
||
type CloudFrontOriginAccessIdentity struct { | ||
svc *cloudfront.CloudFront | ||
ID *string | ||
} | ||
|
||
func init() { | ||
register("CloudFrontOriginAccessIdentity", ListCloudFrontOriginAccessIdentities) | ||
} | ||
|
||
func ListCloudFrontOriginAccessIdentities(sess *session.Session) ([]Resource, error) { | ||
svc := cloudfront.New(sess) | ||
resources := []Resource{} | ||
|
||
for { | ||
resp, err := svc.ListCloudFrontOriginAccessIdentities(nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, item := range resp.CloudFrontOriginAccessIdentityList.Items { | ||
resources = append(resources,&CloudFrontOriginAccessIdentity{ | ||
svc: svc, | ||
ID: item.Id, | ||
}) | ||
} | ||
return resources, nil | ||
} | ||
} | ||
|
||
func (f *CloudFrontOriginAccessIdentity) Remove() error { | ||
resp, err := f.svc.GetCloudFrontOriginAccessIdentity(&cloudfront.GetCloudFrontOriginAccessIdentityInput{ | ||
Id: f.ID, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = f.svc.DeleteCloudFrontOriginAccessIdentity(&cloudfront.DeleteCloudFrontOriginAccessIdentityInput{ | ||
Id: f.ID, | ||
IfMatch: resp.ETag, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (f *CloudFrontOriginAccessIdentity) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("ID", f.ID) | ||
return properties | ||
} |