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

Commit

Permalink
NS-2448: Added resource for CloudFront OAI (#478)
Browse files Browse the repository at this point in the history
Co-authored-by: Joe Chung <joseph.chung@novastonemedia.com>
  • Loading branch information
joechchung and josephnova96 authored Dec 17, 2020
1 parent 7d41b37 commit 1710d34
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions resources/cloudfront-origin-access-identities.go
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
}

0 comments on commit 1710d34

Please sign in to comment.