-
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
Showing
3 changed files
with
56 additions
and
1 deletion.
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
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,45 @@ | ||
package aws | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/s3" | ||
"github.com/pkg/errors" | ||
"github.com/projectdiscovery/cloudlist/pkg/schema" | ||
) | ||
|
||
// s3Provider is a provider for aws S3 API | ||
type s3Provider struct { | ||
id string | ||
s3 *s3.S3 | ||
session *session.Session | ||
} | ||
|
||
// GetResource returns all the resources in the store for a provider. | ||
func (d *s3Provider) GetResource(ctx context.Context) (*schema.Resources, error) { | ||
list := schema.NewResources() | ||
|
||
req := &s3.ListBucketsInput{} | ||
|
||
listBucketsOutput, err := d.s3.ListBuckets(req) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "could not list s3 buckets") | ||
} | ||
for _, bucket := range listBucketsOutput.Buckets { | ||
endpointBuilder := &strings.Builder{} | ||
endpointBuilder.WriteString(aws.StringValue(bucket.Name)) | ||
endpointBuilder.WriteString(".s3.amazonaws.com") | ||
|
||
list.Append(&schema.Resource{ | ||
ID: d.id, | ||
Public: true, | ||
DNSName: endpointBuilder.String(), | ||
Provider: providerName, | ||
}) | ||
} | ||
|
||
return list, nil | ||
} |