Skip to content

Commit

Permalink
Added cloudfront data support
Browse files Browse the repository at this point in the history
  • Loading branch information
sauravpanda committed Nov 28, 2023
1 parent afae149 commit 206306d
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
Binary file modified cmd/cloudstate
Binary file not shown.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
)

require (
github.com/aws/aws-sdk-go-v2/service/cloudfront v1.31.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ec2 v1.137.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.8.4 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ github.com/aws/aws-sdk-go-v2/internal/ini v1.7.1 h1:uR9lXYjdPX0xY+NhvaJ4dD8rpSRz
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.1/go.mod h1:6fQQgfuGmw8Al/3M2IgIllycxV7ZW7WCdVSqfBeUiCY=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.4 h1:40Q4X5ebZruRtknEZH/bg91sT5pR853F7/1X9QRbI54=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.4/go.mod h1:u77N7eEECzUv7F0xl2gcfK/vzc8wcjWobpy+DcrLJ5E=
github.com/aws/aws-sdk-go-v2/service/cloudfront v1.31.0 h1:D8FSJvBDs+WLHjZiN1brxI4Vn9OmjhqlIG3mobYFsnA=
github.com/aws/aws-sdk-go-v2/service/cloudfront v1.31.0/go.mod h1:r4dv59l0aGZaYd9kbQKGOJxo2J4dz6ZBC7Jmhdnd9xU=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.25.3 h1:f5MV/o9V143ZKOxDh/+LLcufe4F8B3gdfg4c5Nwasyg=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.25.3/go.mod h1:p8SrrAzcuXBoLEgNI7NEw5eHFyvkvEPABS3jSE8xOZg=
github.com/aws/aws-sdk-go-v2/service/ec2 v1.137.1 h1:J/N4ydefXQZIwKBDPtvrhxrIuP/vaaYKnAsy3bKVIvU=
Expand Down
44 changes: 44 additions & 0 deletions services/awshandler/cloudfront.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package awshandler

import (
"context"
"fmt"
"log"

"github.com/Cloud-Code-AI/cloudstate/services/utils"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
"github.com/aws/aws-sdk-go-v2/service/cloudfront/types"
)

type CloudfrontList struct {
Distributions []types.DistributionSummary `json:"websites"`
}

// Gets all the distribution of cloudfront for a given regions and
// stores the results in output/{region}/cloudfront/distributions.json file
func CloudfrontListFn(sdkConfig aws.Config) {
// Create cloudfront service client
client := cloudfront.NewFromConfig(sdkConfig)

result, err := client.ListDistributions(context.TODO(), &cloudfront.ListDistributionsInput{})
if err != nil {
log.Printf("Couldn't list distribution. Here's why: %v\n", err)
}

const (
path = "/cloudfront/distributions.json"
)

output := CloudfrontList{
Distributions: result.DistributionList.Items,
}

filepath := parentpath + sdkConfig.Region + path

err = utils.WriteJSONToFile(filepath, output)
if err != nil {
fmt.Println("Error writing cloudfront distribution lists")
}

}
4 changes: 2 additions & 2 deletions services/awshandler/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type ec2List struct {
Instances []types.Instance `json:"Instances"`
}

// Gets all the lambda functions for a given regions and
// stores the results in output/{region}/lambda/functions.json file
// Gets all the EC2 instance for a given regions and
// stores the results in output/{region}/ec2/instances.json file
func ListEc2Fn(sdkConfig aws.Config) {
const maxItems = 50

Expand Down
2 changes: 2 additions & 0 deletions services/awshandler/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ func StoreAWSData() {
DynamoDBListFn(sdkConfig)
// Get EC2 Instance info
ListEc2Fn(sdkConfig)
// Get Cloudfront info
CloudfrontListFn(sdkConfig)

}

0 comments on commit 206306d

Please sign in to comment.