-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f61b3d
commit 489d193
Showing
2 changed files
with
76 additions
and
13 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
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,54 @@ | ||
package aws | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/cloudfront" | ||
"github.com/pkg/errors" | ||
"github.com/projectdiscovery/cloudlist/pkg/schema" | ||
) | ||
|
||
// cloudfrontProvider is a provider for AWS CloudFront API | ||
type cloudfrontProvider struct { | ||
id string | ||
cloudFrontClient *cloudfront.CloudFront | ||
session *session.Session | ||
} | ||
|
||
// GetResource returns all the resources in the store for a provider. | ||
func (cp *cloudfrontProvider) GetResource(ctx context.Context) (*schema.Resources, error) { | ||
list := schema.NewResources() | ||
|
||
err := listCloudFrontResources(cp.cloudFrontClient, list) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "could not list CloudFront resources") | ||
} | ||
return list, nil | ||
} | ||
|
||
func listCloudFrontResources(cloudFrontClient *cloudfront.CloudFront, list *schema.Resources) error { | ||
req := &cloudfront.ListDistributionsInput{MaxItems: aws.Int64(400)} | ||
for { | ||
distributions, err := cloudFrontClient.ListDistributions(req) | ||
if err != nil { | ||
return errors.Wrap(err, "could not list distributions") | ||
} | ||
|
||
for _, distribution := range distributions.DistributionList.Items { | ||
resource := &schema.Resource{ | ||
Provider: "aws", | ||
ID: aws.StringValue(distribution.Id), | ||
DNSName: aws.StringValue(distribution.DomainName), | ||
Public: true, | ||
} | ||
list.Append(resource) | ||
} | ||
if aws.StringValue(distributions.DistributionList.NextMarker) == "" { | ||
break | ||
} | ||
req.SetMarker(aws.StringValue(distributions.DistributionList.NextMarker)) | ||
} | ||
return nil | ||
} |