├── .github └── workflows │ ├── build.yml │ └── test.yml ├── .gitignore ├── .goreleaser.yml ├── LICENSE ├── Makefile ├── README.md ├── arn ├── main.go └── main_test.go ├── cache.go ├── cmd └── awsets │ ├── cache │ └── cache.go │ ├── cmd │ ├── list.go │ ├── process.go │ ├── regions.go │ ├── root.go │ ├── shared.go │ └── types.go │ ├── go.mod │ ├── go.sum │ └── main.go ├── context ├── context.go └── status.go ├── go.mod ├── go.sum ├── lister ├── accessanalyzer_analyzer.go ├── acm_certificate.go ├── amplify_app.go ├── apigateway_apikey.go ├── apigateway_domainname.go ├── apigateway_restapi.go ├── apigateway_vpclink.go ├── apigatewayv2_api.go ├── apigatewayv2_domainname.go ├── applicationautoscaling_scalablepolicy.go ├── applicationautoscaling_scalabletarget.go ├── appmesh_mesh.go ├── appsync_graphqlapi.go ├── athena_datacatalog.go ├── athena_namedquery.go ├── autoscaling_group.go ├── autoscaling_launchconfig.go ├── autoscaling_policy.go ├── backup_plan.go ├── backup_vault.go ├── batch_computeenvironment.go ├── batch_jobdefinition.go ├── batch_jobqueue.go ├── budgets_budget.go ├── cloud9_environment.go ├── cloudformation_stack.go ├── cloudformation_stackset.go ├── cloudfront_cachepolicy.go ├── cloudfront_distribution.go ├── cloudfront_keygroup.go ├── cloudfront_originaccessidentity.go ├── cloudfront_originrequestpolicy.go ├── cloudfront_publickey.go ├── cloudfront_streamingdistribution.go ├── cloudtrail_trail.go ├── cloudwatch_alarm.go ├── cloudwatch_dashboard.go ├── cloudwatchevents_eventbus.go ├── cloudwatchevents_rule.go ├── cloudwatchlogs_loggroup.go ├── cloudwatchlogs_querydefinition.go ├── codebuild_project.go ├── codebuild_sourcecredential.go ├── codecommit_repository.go ├── codedeploy_application.go ├── codedeploy_deploymentconfig.go ├── codepipeline_pipeline.go ├── codepipeline_webhook.go ├── codestar_project.go ├── cognito_identitypool.go ├── cognito_userpool.go ├── config_aggregationauthorization.go ├── config_configurationaggregator.go ├── config_configurationrecorder.go ├── config_conformancepack.go ├── config_deliverychannel.go ├── config_organizationconfigrule.go ├── config_organizationconformancepack.go ├── config_rule.go ├── dax_cluster.go ├── dax_parametergroup.go ├── dax_subnetgroup.go ├── dms_endpoint.go ├── dms_replicationinstance.go ├── dms_replicationsubnetgroup.go ├── dms_replicationtask.go ├── docdb_cluster.go ├── docdb_instance.go ├── docdb_parametergroup.go ├── docdb_subnetgroup.go ├── dynamodb_backup.go ├── dynamodb_table.go ├── dynamodbstreams_stream.go ├── ec2_customergateway.go ├── ec2_dhcpoption.go ├── ec2_eip.go ├── ec2_flowlog.go ├── ec2_image.go ├── ec2_instance.go ├── ec2_internetgateway.go ├── ec2_keypair.go ├── ec2_launchtemplate.go ├── ec2_natgateway.go ├── ec2_networkacl.go ├── ec2_networkinterface.go ├── ec2_routetable.go ├── ec2_securitygroup.go ├── ec2_snapshot.go ├── ec2_spotfleet.go ├── ec2_subnet.go ├── ec2_transitgateway.go ├── ec2_volume.go ├── ec2_vpc.go ├── ec2_vpcendpoint.go ├── ec2_vpcendpointservice.go ├── ec2_vpcpeering.go ├── ec2_vpnconnection.go ├── ec2_vpngateway.go ├── ecr_repository.go ├── ecs_cluster.go ├── ecs_taskdefinition.go ├── efs_filesystem.go ├── eks_cluster.go ├── elasticache_cluster.go ├── elasticache_parametergroup.go ├── elasticache_replicationgroup.go ├── elasticache_securitygroup.go ├── elasticache_snapshot.go ├── elasticache_subnetgroup.go ├── elasticbeanstalk_application.go ├── elasticbeanstalk_environment.go ├── elasticsearch_domain.go ├── elb_loadbalancer.go ├── elbv2_loadbalancer.go ├── emr_cluster.go ├── emr_securityconfiguration.go ├── firehose_firehose.go ├── fsx_backup.go ├── fsx_filesystem.go ├── glue_classifier.go ├── glue_connection.go ├── glue_crawler.go ├── glue_database.go ├── glue_job.go ├── glue_workflow.go ├── greengrass_connectordefinition.go ├── greengrass_coredefinition.go ├── greengrass_devicedefinition.go ├── greengrass_functiondefinition.go ├── greengrass_group.go ├── greengrass_loggerdefinition.go ├── greengrass_resourcedefinition.go ├── greengrass_subscriptiondefinition.go ├── guardduty_detector.go ├── iam_group.go ├── iam_instanceprofile.go ├── iam_policy.go ├── iam_role.go ├── iam_user.go ├── imagebuilder_component.go ├── imagebuilder_distributionconfig.go ├── imagebuilder_image.go ├── imagebuilder_imagepipeline.go ├── imagebuilder_imagerecipe.go ├── imagebuilder_infrastructureconfig.go ├── iot_cacertificate.go ├── iot_certificate.go ├── iot_policy.go ├── iot_thing.go ├── iot_thinggroup.go ├── iot_thingtype.go ├── iot_topicrule.go ├── iot_topicruledestination.go ├── iotsitewise_assetmodel.go ├── iotsitewise_gateway.go ├── kafka_cluster.go ├── kinesis_stream.go ├── kms_alias.go ├── kms_key.go ├── lambda_function.go ├── lambda_layer.go ├── main.go ├── main_test.go ├── mq_broker.go ├── mq_brokerconfiguration.go ├── neptune_dbcluster.go ├── neptune_dbclusterparametergroup.go ├── neptune_dbclustersnapshot.go ├── neptune_dbinstance.go ├── neptune_dbparametergroup.go ├── neptune_dbsubnetgroup.go ├── qldb_ledgers.go ├── rds_cluster.go ├── rds_clusterparametergroup.go ├── rds_clustersnapshot.go ├── rds_dbproxy.go ├── rds_instance.go ├── rds_parametergroup.go ├── rds_snapshot.go ├── rds_subnetgroup.go ├── redshift_cluster.go ├── redshift_parametergroup.go ├── redshift_securitygroup.go ├── redshift_snapshot.go ├── redshift_subnetgroup.go ├── route53_healthcheck.go ├── route53_hostedzone.go ├── s3_bucket.go ├── sagemaker_endpoint.go ├── sagemaker_endpointconfig.go ├── sagemaker_model.go ├── sagemaker_notebookinstance.go ├── sagemaker_notebookinstancelifecycleconfig.go ├── secretmanager_secret.go ├── servicecatalog_acceptedportfolioshare.go ├── servicecatalog_portfolio.go ├── servicediscovery_namespace.go ├── servicediscovery_service.go ├── ses_configurationset.go ├── ses_receiptfilter.go ├── ses_receiptrule.go ├── ses_template.go ├── signer_signingprofile.go ├── sns_topic.go ├── sqs_queue.go ├── ssm_association.go ├── ssm_document.go ├── ssm_maintenancewindow.go ├── ssm_parameter.go ├── ssm_patchbaseline.go ├── stepfunction_statemachine.go ├── transfer_server.go ├── waf_bytematchset.go ├── waf_ipset.go ├── waf_rule.go ├── waf_sizeconstraintset.go ├── waf_sqlinjectionmatchset.go ├── waf_webacl.go ├── waf_xssmatchset.go ├── wafregional_bytematchset.go ├── wafregional_geomatchset.go ├── wafregional_ipset.go ├── wafregional_ratebasedrule.go ├── wafregional_regexpatternset.go ├── wafregional_rule.go ├── wafregional_sizeconstraintset.go ├── wafregional_sqlinjectionmatchset.go ├── wafregional_webacl.go ├── wafregional_xssmatchset.go ├── wafv2_ipset.go ├── wafv2_regexpatternset.go ├── wafv2_rulegroup.go ├── wafv2_webacl.go └── workspaces_workspace.go ├── main.go ├── main_test.go ├── options.go ├── resource ├── cfn.go ├── cfn_test.go ├── cfn_update_test.go ├── resource.go ├── resource_test.go ├── types.go └── types_test.go ├── supported_resources.txt └── supportedresources_test.go /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | tags: 6 | - "v*" 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Install Go 13 | uses: actions/setup-go@v2 14 | with: 15 | go-version: 1.18 16 | - name: Checkout code 17 | uses: actions/checkout@v2 18 | with: 19 | fetch-depth: 0 20 | - name: Test 21 | run: go test ./... 22 | - name: Run GoReleaser 23 | if: success() 24 | uses: goreleaser/goreleaser-action@v2 25 | with: 26 | version: ${{ github.event.release.tag_name }} 27 | args: release --rm-dist 28 | env: 29 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 30 | HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_PAT }} -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: test 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | 9 | jobs: 10 | test: 11 | strategy: 12 | matrix: 13 | go-version: [1.17.x, 1.18.x] 14 | os: [ ubuntu-latest, macos-latest, windows-latest ] 15 | runs-on: ${{ matrix.os }} 16 | steps: 17 | - name: Install Go 18 | uses: actions/setup-go@v2 19 | with: 20 | go-version: ${{ matrix.go-version }} 21 | - name: Checkout code 22 | uses: actions/checkout@v2 23 | with: 24 | fetch-depth: 0 25 | - name: Test 26 | run: go test ./... -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.json 2 | dist 3 | cmd/awsets/awsets -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Trek10 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: test 2 | 3 | check-updates: 4 | go test -tags check_updates ./resource 5 | 6 | test: 7 | go test ./... 8 | -------------------------------------------------------------------------------- /cache.go: -------------------------------------------------------------------------------- 1 | package awsets 2 | 3 | import "github.com/trek10inc/awsets/resource" 4 | 5 | // Cacher is an interface that defines the necessary functions for an AWSets 6 | // cache. 7 | type Cacher interface { 8 | Initialize(accountId string) error 9 | IsCached(region string, kind ListerName) bool 10 | SaveGroup(kind ListerName, group *resource.Group) error 11 | LoadGroup(region string, kind ListerName) (*resource.Group, error) 12 | } 13 | 14 | // NoOpCache is the default cache provided by AWSets. It does nothing, and 15 | // will never load nor save any data. 16 | type NoOpCache struct { 17 | } 18 | 19 | func (c NoOpCache) Initialize(accountId string) error { 20 | return nil 21 | } 22 | 23 | func (c NoOpCache) IsCached(region string, kind ListerName) bool { 24 | return false 25 | } 26 | 27 | func (c NoOpCache) SaveGroup(kind ListerName, group *resource.Group) error { 28 | return nil 29 | } 30 | 31 | func (c NoOpCache) LoadGroup(region string, kind ListerName) (*resource.Group, error) { 32 | return resource.NewGroup(), nil 33 | } 34 | -------------------------------------------------------------------------------- /cmd/awsets/cmd/regions.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "sort" 7 | 8 | "github.com/trek10inc/awsets" 9 | "github.com/urfave/cli/v2" 10 | ) 11 | 12 | var regionsCmd = &cli.Command{ 13 | Name: "regions", 14 | Usage: "lists regions supported by account", 15 | ArgsUsage: "[region prefixes]", 16 | Flags: []cli.Flag{ 17 | &cli.StringFlag{ 18 | Name: "profile", 19 | Value: "", 20 | Usage: "AWS profile to use", 21 | }, 22 | }, 23 | Action: func(c *cli.Context) error { 24 | 25 | awscfg, err := configureAWS(c) 26 | if err != nil { 27 | log.Fatalf("failed to load aws config: %v\n", err) 28 | } 29 | 30 | regions, err := awsets.Regions(awscfg, c.Args().Slice()...) 31 | if err != nil { 32 | log.Fatalf("failed to list regions: %v", err) 33 | } 34 | 35 | ret := make([]string, 0) 36 | 37 | for _, t := range regions { 38 | ret = append(ret, t) 39 | } 40 | 41 | sort.Strings(ret) 42 | 43 | for _, t := range ret { 44 | fmt.Printf("%s\n", t) 45 | } 46 | 47 | return nil 48 | }, 49 | } 50 | -------------------------------------------------------------------------------- /cmd/awsets/cmd/root.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | 8 | "github.com/aws/aws-sdk-go-v2/aws" 9 | "github.com/aws/aws-sdk-go-v2/config" 10 | "github.com/urfave/cli/v2" 11 | ) 12 | 13 | func Execute(buildInfo map[string]string) { 14 | app := &cli.App{ 15 | Name: "awsets", 16 | Usage: "query aws resources", 17 | Commands: []*cli.Command{ 18 | listCmd, 19 | regionsCmd, 20 | typesCmd, 21 | processCmd, 22 | versionCmd(buildInfo), 23 | }, 24 | } 25 | if err := app.Run(os.Args); err != nil { 26 | log.Fatal(err) 27 | } 28 | } 29 | 30 | func configureAWS(ctx *cli.Context) (aws.Config, error) { 31 | if ctx.String("profile") != "" { 32 | return config.LoadDefaultConfig(ctx.Context, config.WithSharedConfigProfile(ctx.String("profile"))) 33 | } 34 | return config.LoadDefaultConfig(ctx.Context) 35 | } 36 | 37 | func validateNumArgs(nArgs int) cli.BeforeFunc { 38 | return func(ctx *cli.Context) error { 39 | if ctx.NArg() != nArgs { 40 | return fmt.Errorf("expected %d arguments, but received %d", nArgs, ctx.NArg()) 41 | } 42 | return nil 43 | } 44 | } 45 | 46 | func versionCmd(buildInfo map[string]string) *cli.Command { 47 | return &cli.Command{ 48 | Name: "version", 49 | Usage: "prints version information", 50 | Action: func(c *cli.Context) error { 51 | fmt.Printf("awsets - version: %s\tcommit: %s\tdate: %s\n", buildInfo["version"], buildInfo["commit"], buildInfo["date"]) 52 | return nil 53 | }, 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /cmd/awsets/cmd/shared.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io/ioutil" 7 | 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type IdLite struct { 12 | Region string 13 | Id string 14 | //Version string 15 | Type resource.ResourceType 16 | } 17 | 18 | func loadData(fname string) (map[IdLite]resource.Resource, error) { 19 | var resources []resource.Resource 20 | data, err := ioutil.ReadFile(fname) 21 | if err != nil { 22 | return nil, err 23 | } 24 | err = json.Unmarshal(data, &resources) 25 | if err != nil { 26 | return nil, err 27 | } 28 | 29 | res := make(map[IdLite]resource.Resource) 30 | 31 | for i := range resources { 32 | r := resources[i] 33 | id := genId(r.Identifier) 34 | if _, exists := res[id]; exists { 35 | fmt.Printf("Hm... already exists - %v\n", id) 36 | } 37 | res[id] = r 38 | } 39 | 40 | return res, nil 41 | } 42 | 43 | func genId(identifier resource.Identifier) IdLite { 44 | return IdLite{ 45 | Region: identifier.Region, 46 | Id: identifier.Id, 47 | Type: identifier.Type, 48 | //Version: identifier.Version, 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /cmd/awsets/cmd/types.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "sort" 6 | "strings" 7 | 8 | "github.com/trek10inc/awsets" 9 | "github.com/urfave/cli/v2" 10 | ) 11 | 12 | var typesCmd = &cli.Command{ 13 | Name: "types", 14 | Usage: "lists supported resource types", 15 | ArgsUsage: " ", 16 | Before: validateNumArgs(0), 17 | Flags: []cli.Flag{ 18 | &cli.StringFlag{ 19 | Name: "include", 20 | Value: "", 21 | Usage: "comma separated list of resource type prefixes to include", 22 | }, 23 | &cli.StringFlag{ 24 | Name: "exclude", 25 | Value: "", 26 | Usage: "comma separated list of resource type prefixes to exclude", 27 | }, 28 | }, 29 | Action: func(c *cli.Context) error { 30 | 31 | types := awsets.Types(strings.Split(c.String("include"), ","), strings.Split(c.String("exclude"), ",")) 32 | ret := make([]string, 0) 33 | 34 | for _, t := range types { 35 | ret = append(ret, t.String()) 36 | } 37 | 38 | sort.Strings(ret) 39 | 40 | for _, t := range ret { 41 | fmt.Printf("%s\n", t) 42 | } 43 | 44 | return nil 45 | }, 46 | } 47 | -------------------------------------------------------------------------------- /cmd/awsets/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/trek10inc/awsets/cmd/awsets/cmd" 4 | 5 | var ( 6 | version = "dev" 7 | commit = "none" 8 | date = "unknown" 9 | ) 10 | 11 | func main() { 12 | cmd.Execute(map[string]string{ 13 | "version": version, 14 | "commit": commit, 15 | "date": date, 16 | }) 17 | } 18 | -------------------------------------------------------------------------------- /context/context.go: -------------------------------------------------------------------------------- 1 | package context 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | ) 8 | 9 | type AWSetsCtx struct { 10 | AWSCfg aws.Config 11 | AccountId string 12 | WorkerId int 13 | Context context.Context 14 | Lister string 15 | StatusChan chan<- StatusUpdate 16 | TotalJobs int 17 | } 18 | 19 | func (c *AWSetsCtx) Region() string { 20 | return c.AWSCfg.Region 21 | } 22 | 23 | func (c *AWSetsCtx) Copy(region string) *AWSetsCtx { 24 | 25 | cop := &AWSetsCtx{ 26 | AWSCfg: c.AWSCfg.Copy(), 27 | AccountId: c.AccountId, 28 | Context: c.Context, 29 | StatusChan: c.StatusChan, 30 | Lister: c.Lister, 31 | WorkerId: c.WorkerId, 32 | TotalJobs: c.TotalJobs, 33 | } 34 | cop.AWSCfg.Region = region 35 | return cop 36 | } 37 | 38 | func (c *AWSetsCtx) SendStatus(statusType StatusType, msg string) { 39 | if c.StatusChan == nil { 40 | return 41 | } 42 | su := StatusUpdate{ 43 | Type: statusType, 44 | Lister: c.Lister, 45 | Region: c.Region(), 46 | Message: msg, 47 | WorkerId: c.WorkerId, 48 | TotalJobs: c.TotalJobs, 49 | } 50 | c.StatusChan <- su 51 | } 52 | 53 | func (c *AWSetsCtx) Close() { 54 | if c.StatusChan != nil { 55 | close(c.StatusChan) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /context/status.go: -------------------------------------------------------------------------------- 1 | package context 2 | 3 | type StatusType string 4 | 5 | const ( 6 | StatusLogInfo StatusType = "logInfo" 7 | StatusLogDebug StatusType = "logDebug" 8 | StatusLogError StatusType = "logError" 9 | StatusProcessing StatusType = "processing" 10 | StatusComplete StatusType = "complete" 11 | StatusCompleteWithError StatusType = "completeWithError" 12 | ) 13 | 14 | type StatusUpdate struct { 15 | Type StatusType 16 | Lister string 17 | Region string 18 | Message string 19 | WorkerId int 20 | TotalJobs int 21 | } 22 | -------------------------------------------------------------------------------- /lister/accessanalyzer_analyzer.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/accessanalyzer" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSAccessAnalyzerAnalyzer struct { 11 | } 12 | 13 | func init() { 14 | i := AWSAccessAnalyzerAnalyzer{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSAccessAnalyzerAnalyzer) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.AccessAnalyzerAnalyzer} 20 | } 21 | 22 | func (l AWSAccessAnalyzerAnalyzer) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := accessanalyzer.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | 27 | paginator := accessanalyzer.NewListAnalyzersPaginator(svc, &accessanalyzer.ListAnalyzersInput{ 28 | MaxResults: aws.Int32(100), 29 | }) 30 | 31 | for paginator.HasMorePages() { 32 | page, err := paginator.NextPage(ctx.Context) 33 | if err != nil { 34 | return nil, err 35 | } 36 | for _, v := range page.Analyzers { 37 | r := resource.New(ctx, resource.AccessAnalyzerAnalyzer, v.Name, v.Name, v) 38 | rg.AddResource(r) 39 | } 40 | } 41 | return rg, nil 42 | } 43 | -------------------------------------------------------------------------------- /lister/apigateway_vpclink.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | 7 | "github.com/aws/aws-sdk-go-v2/aws" 8 | "github.com/aws/aws-sdk-go-v2/service/apigateway" 9 | "github.com/trek10inc/awsets/context" 10 | "github.com/trek10inc/awsets/resource" 11 | ) 12 | 13 | type AWSApiGatewayVpcLink struct { 14 | } 15 | 16 | func init() { 17 | i := AWSApiGatewayVpcLink{} 18 | listers = append(listers, i) 19 | } 20 | 21 | func (l AWSApiGatewayVpcLink) Types() []resource.ResourceType { 22 | return []resource.ResourceType{resource.ApiGatewayVpcLink} 23 | } 24 | 25 | func (l AWSApiGatewayVpcLink) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | svc := apigateway.NewFromConfig(ctx.AWSCfg) 27 | 28 | rg := resource.NewGroup() 29 | 30 | err := Paginator(func(nt *string) (*string, error) { 31 | res, err := svc.GetVpcLinks(ctx.Context, &apigateway.GetVpcLinksInput{ 32 | Limit: aws.Int32(500), 33 | Position: nt, 34 | }) 35 | if err != nil { 36 | if strings.Contains(err.Error(), "AccessDeniedException") { 37 | // If api gateway is not supported in a region, returns access denied 38 | return nil, nil 39 | } 40 | return nil, fmt.Errorf("failed to get vpc links: %w", err) 41 | } 42 | for _, v := range res.Items { 43 | r := resource.New(ctx, resource.ApiGatewayVpcLink, v.Id, v.Name, v) 44 | rg.AddResource(r) 45 | // TODO: parse target ARNs to find relationships? 46 | } 47 | return res.Position, nil 48 | }) 49 | return rg, err 50 | } 51 | -------------------------------------------------------------------------------- /lister/athena_datacatalog.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/athena" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSAthenaDataCatalog struct { 11 | } 12 | 13 | func init() { 14 | i := AWSAthenaDataCatalog{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSAthenaDataCatalog) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.AthenaDataCatalog} 20 | } 21 | 22 | func (l AWSAthenaDataCatalog) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := athena.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | 27 | err := Paginator(func(nt *string) (*string, error) { 28 | res, err := svc.ListDataCatalogs(ctx.Context, &athena.ListDataCatalogsInput{ 29 | MaxResults: aws.Int32(50), 30 | NextToken: nt, 31 | }) 32 | if err != nil { 33 | return nil, err 34 | } 35 | for _, dcSummary := range res.DataCatalogsSummary { 36 | r := resource.New(ctx, resource.AthenaDataCatalog, dcSummary.CatalogName, dcSummary.CatalogName, dcSummary) 37 | 38 | dc, err := svc.GetDataCatalog(ctx.Context, &athena.GetDataCatalogInput{ 39 | Name: dcSummary.CatalogName, 40 | }) 41 | if err != nil { 42 | //ctx.SendStatus(context.StatusLogError, fmt.Sprintf("failed to get data catalog %s of type %v: %v\n", *dcSummary.CatalogName, dcSummary.Type, err)) 43 | } else if v := dc.DataCatalog; v != nil { 44 | r.AddAttribute("Description", v.Description) 45 | r.AddAttribute("Parameters", v.Parameters) 46 | } 47 | rg.AddResource(r) 48 | } 49 | return res.NextToken, nil 50 | }) 51 | 52 | return rg, err 53 | } 54 | -------------------------------------------------------------------------------- /lister/autoscaling_launchconfig.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/autoscaling" 6 | "github.com/trek10inc/awsets/arn" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSAutoscalingLaunchConfiguration struct { 12 | } 13 | 14 | func init() { 15 | i := AWSAutoscalingLaunchConfiguration{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSAutoscalingLaunchConfiguration) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.AutoscalingLaunchConfig} 21 | } 22 | 23 | func (l AWSAutoscalingLaunchConfiguration) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := autoscaling.NewFromConfig(ctx.AWSCfg) 25 | 26 | rg := resource.NewGroup() 27 | err := Paginator(func(nt *string) (*string, error) { 28 | res, err := svc.DescribeLaunchConfigurations(ctx.Context, &autoscaling.DescribeLaunchConfigurationsInput{ 29 | MaxRecords: aws.Int32(100), 30 | NextToken: nt, 31 | }) 32 | if err != nil { 33 | return nil, err 34 | } 35 | for _, v := range res.LaunchConfigurations { 36 | 37 | configArn := arn.ParseP(v.LaunchConfigurationARN) 38 | r := resource.New(ctx, resource.AutoscalingLaunchConfig, configArn.ResourceId, v.LaunchConfigurationName, v) 39 | 40 | for _, sg := range v.SecurityGroups { 41 | r.AddRelation(resource.Ec2SecurityGroup, sg, "") 42 | } 43 | rg.AddResource(r) 44 | } 45 | 46 | return res.NextToken, nil 47 | }) 48 | return rg, err 49 | } 50 | -------------------------------------------------------------------------------- /lister/autoscaling_policy.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/autoscaling" 6 | "github.com/trek10inc/awsets/arn" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSAutoscalingPolicies struct { 12 | } 13 | 14 | func init() { 15 | i := AWSAutoscalingPolicies{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSAutoscalingPolicies) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.AutoscalingPolicy} 21 | } 22 | 23 | func (l AWSAutoscalingPolicies) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := autoscaling.NewFromConfig(ctx.AWSCfg) 25 | 26 | rg := resource.NewGroup() 27 | 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.DescribePolicies(ctx.Context, &autoscaling.DescribePoliciesInput{ 30 | MaxRecords: aws.Int32(100), 31 | NextToken: nt, 32 | }) 33 | if err != nil { 34 | return nil, err 35 | } 36 | for _, v := range res.ScalingPolicies { 37 | policyArn := arn.ParseP(v.PolicyARN) 38 | r := resource.New(ctx, resource.AutoscalingPolicy, policyArn.ResourceId, v.PolicyName, v) 39 | r.AddRelation(resource.AutoscalingGroup, v.AutoScalingGroupName, "") 40 | //TODO relation to autoscaling alarms? 41 | rg.AddResource(r) 42 | } 43 | 44 | return res.NextToken, nil 45 | }) 46 | 47 | return rg, err 48 | } 49 | -------------------------------------------------------------------------------- /lister/batch_computeenvironment.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/batch" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSBatchComputeEnvironment struct { 11 | } 12 | 13 | func init() { 14 | i := AWSBatchComputeEnvironment{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSBatchComputeEnvironment) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.BatchComputeEnvironment} 20 | } 21 | 22 | func (l AWSBatchComputeEnvironment) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := batch.NewFromConfig(ctx.AWSCfg) 24 | rg := resource.NewGroup() 25 | 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeComputeEnvironments(ctx.Context, &batch.DescribeComputeEnvironmentsInput{ 28 | MaxResults: aws.Int32(100), 29 | NextToken: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, v := range res.ComputeEnvironments { 35 | r := resource.New(ctx, resource.BatchComputeEnvironment, v.ComputeEnvironmentName, v.ComputeEnvironmentName, v) 36 | if c := v.ComputeResources; c != nil { 37 | r.AddRelation(resource.Ec2Image, c.ImageId, "") 38 | r.AddRelation(resource.Ec2KeyPair, c.Ec2KeyPair, "") 39 | for _, sn := range c.Subnets { 40 | r.AddRelation(resource.Ec2Subnet, sn, "") 41 | } 42 | for _, sg := range c.SecurityGroupIds { 43 | r.AddRelation(resource.Ec2SecurityGroup, sg, "") 44 | } 45 | r.AddARNRelation(resource.IamRole, c.InstanceRole) 46 | r.AddARNRelation(resource.IamRole, c.SpotIamFleetRole) 47 | } 48 | rg.AddResource(r) 49 | } 50 | 51 | return res.NextToken, nil 52 | }) 53 | return rg, err 54 | } 55 | -------------------------------------------------------------------------------- /lister/batch_jobdefinition.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/batch" 6 | 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSBatchJobDefinition struct { 12 | } 13 | 14 | func init() { 15 | i := AWSBatchJobDefinition{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSBatchJobDefinition) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.BatchJobDefinition} 21 | } 22 | 23 | func (l AWSBatchJobDefinition) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := batch.NewFromConfig(ctx.AWSCfg) 25 | rg := resource.NewGroup() 26 | 27 | err := Paginator(func(nt *string) (*string, error) { 28 | res, err := svc.DescribeJobDefinitions(ctx.Context, &batch.DescribeJobDefinitionsInput{ 29 | MaxResults: aws.Int32(100), 30 | NextToken: nt, 31 | }) 32 | if err != nil { 33 | return nil, err 34 | } 35 | for _, v := range res.JobDefinitions { 36 | r := resource.New(ctx, resource.BatchJobDefinition, v.JobDefinitionName, v.JobDefinitionName, v) 37 | rg.AddResource(r) 38 | } 39 | 40 | return res.NextToken, nil 41 | }) 42 | return rg, err 43 | } 44 | -------------------------------------------------------------------------------- /lister/batch_jobqueue.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/batch" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSBatchJobQueue struct { 11 | } 12 | 13 | func init() { 14 | i := AWSBatchJobQueue{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSBatchJobQueue) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.BatchJobQueue} 20 | } 21 | 22 | func (l AWSBatchJobQueue) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := batch.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | 27 | err := Paginator(func(nt *string) (*string, error) { 28 | res, err := svc.DescribeJobQueues(ctx.Context, &batch.DescribeJobQueuesInput{ 29 | MaxResults: aws.Int32(100), 30 | NextToken: nt, 31 | }) 32 | if err != nil { 33 | return nil, err 34 | } 35 | for _, v := range res.JobQueues { 36 | r := resource.New(ctx, resource.BatchJobQueue, v.JobQueueName, v.JobQueueName, v) 37 | for _, ce := range v.ComputeEnvironmentOrder { 38 | r.AddARNRelation(resource.BatchComputeEnvironment, ce.ComputeEnvironment) 39 | } 40 | rg.AddResource(r) 41 | } 42 | return res.NextToken, nil 43 | }) 44 | return rg, err 45 | } 46 | -------------------------------------------------------------------------------- /lister/budgets_budget.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/budgets" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSBudgetsBudget struct { 11 | } 12 | 13 | func init() { 14 | i := AWSBudgetsBudget{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSBudgetsBudget) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.BudgetsBudget} 20 | } 21 | 22 | func (l AWSBudgetsBudget) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := budgets.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | 27 | err := Paginator(func(nt *string) (*string, error) { 28 | res, err := svc.DescribeBudgets(ctx.Context, &budgets.DescribeBudgetsInput{ 29 | AccountId: &ctx.AccountId, 30 | MaxResults: aws.Int32(100), 31 | NextToken: nt, 32 | }) 33 | if err != nil { 34 | return nil, err 35 | } 36 | for _, budget := range res.Budgets { 37 | r := resource.New(ctx, resource.BudgetsBudget, budget.BudgetName, budget.BudgetName, budget) 38 | rg.AddResource(r) 39 | } 40 | return res.NextToken, nil 41 | }) 42 | return rg, err 43 | } 44 | -------------------------------------------------------------------------------- /lister/cloud9_environment.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/cloud9" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSCloud9Environment struct { 13 | } 14 | 15 | func init() { 16 | i := AWSCloud9Environment{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSCloud9Environment) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.Cloud9Environment} 22 | } 23 | 24 | func (l AWSCloud9Environment) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | svc := cloud9.NewFromConfig(ctx.AWSCfg) 26 | rg := resource.NewGroup() 27 | 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.ListEnvironments(ctx.Context, &cloud9.ListEnvironmentsInput{ 30 | MaxResults: aws.Int32(25), 31 | NextToken: nt, 32 | }) 33 | if err != nil { 34 | return nil, err 35 | } 36 | if len(res.EnvironmentIds) == 0 { 37 | return nil, nil 38 | } 39 | environments, err := svc.DescribeEnvironments(ctx.Context, &cloud9.DescribeEnvironmentsInput{ 40 | EnvironmentIds: res.EnvironmentIds, 41 | }) 42 | if err != nil { 43 | return nil, fmt.Errorf("failed to describe environments: %w", err) 44 | } 45 | for _, v := range environments.Environments { 46 | r := resource.New(ctx, resource.Cloud9Environment, v.Name, v.Name, v) 47 | rg.AddResource(r) 48 | } 49 | return res.NextToken, nil 50 | }) 51 | return rg, err 52 | } 53 | -------------------------------------------------------------------------------- /lister/cloudformation_stackset.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | 7 | "github.com/aws/aws-sdk-go-v2/aws" 8 | "github.com/aws/aws-sdk-go-v2/service/cloudformation" 9 | "github.com/trek10inc/awsets/context" 10 | "github.com/trek10inc/awsets/resource" 11 | ) 12 | 13 | type AWSCloudFormationStackSet struct { 14 | } 15 | 16 | func init() { 17 | i := AWSCloudFormationStackSet{} 18 | listers = append(listers, i) 19 | } 20 | 21 | func (l AWSCloudFormationStackSet) Types() []resource.ResourceType { 22 | return []resource.ResourceType{resource.CloudFormationStackSet} 23 | } 24 | 25 | func (l AWSCloudFormationStackSet) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | svc := cloudformation.NewFromConfig(ctx.AWSCfg) 27 | 28 | rg := resource.NewGroup() 29 | err := Paginator(func(nt *string) (*string, error) { 30 | res, err := svc.ListStackSets(ctx.Context, &cloudformation.ListStackSetsInput{ 31 | MaxResults: aws.Int32(100), 32 | NextToken: nt, 33 | }) 34 | if err != nil { 35 | if strings.Contains(err.Error(), "StackSets is not supported in this region") { 36 | // If StackSets are not supported in a region, returns validation exception 37 | return nil, nil 38 | } 39 | return nil, err 40 | } 41 | for _, summary := range res.Summaries { 42 | v, err := svc.DescribeStackSet(ctx.Context, &cloudformation.DescribeStackSetInput{ 43 | StackSetName: summary.StackSetName, 44 | }) 45 | if err != nil { 46 | return nil, fmt.Errorf("failed to describe stack set %s: %w", *summary.StackSetName, err) 47 | } 48 | r := resource.New(ctx, resource.CloudFormationStackSet, v.StackSet.StackSetId, v.StackSet.StackSetName, v.StackSet) 49 | rg.AddResource(r) 50 | } 51 | return res.NextToken, nil 52 | }) 53 | return rg, err 54 | } 55 | -------------------------------------------------------------------------------- /lister/cloudfront_cachepolicy.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | 7 | "github.com/aws/aws-sdk-go-v2/aws" 8 | 9 | "github.com/aws/aws-sdk-go-v2/service/cloudfront" 10 | "github.com/trek10inc/awsets/context" 11 | "github.com/trek10inc/awsets/resource" 12 | ) 13 | 14 | var listCloudfrontCachePolicyOnce sync.Once 15 | 16 | type AWSCloudfrontCachePolicy struct { 17 | } 18 | 19 | func init() { 20 | i := AWSCloudfrontCachePolicy{} 21 | listers = append(listers, i) 22 | } 23 | 24 | func (l AWSCloudfrontCachePolicy) Types() []resource.ResourceType { 25 | return []resource.ResourceType{resource.CloudFrontCachePolicy} 26 | } 27 | 28 | func (l AWSCloudfrontCachePolicy) List(ctx context.AWSetsCtx) (*resource.Group, error) { 29 | svc := cloudfront.NewFromConfig(ctx.AWSCfg) 30 | 31 | rg := resource.NewGroup() 32 | var outerErr error 33 | listCloudfrontCachePolicyOnce.Do(func() { 34 | err := Paginator(func(nt *string) (*string, error) { 35 | res, err := svc.ListCachePolicies(ctx.Context, &cloudfront.ListCachePoliciesInput{ 36 | Marker: nt, 37 | MaxItems: aws.Int32(100), 38 | }) 39 | if err != nil { 40 | return nil, fmt.Errorf("failed to list cache policies: %w", err) 41 | } 42 | if policies := res.CachePolicyList; policies != nil { 43 | for _, v := range policies.Items { 44 | r := resource.NewGlobal(ctx, resource.CloudFrontCachePolicy, v.CachePolicy.Id, v.CachePolicy.Id, v) 45 | rg.AddResource(r) 46 | } 47 | return policies.NextMarker, nil 48 | } else { 49 | return nil, nil 50 | } 51 | }) 52 | if err != nil { 53 | outerErr = err 54 | } 55 | }) 56 | 57 | return rg, outerErr 58 | } 59 | -------------------------------------------------------------------------------- /lister/cloudfront_keygroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "sync" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/cloudfront" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | var listCloudfrontKeyGroupOnce sync.Once 13 | 14 | type AWSCloudfrontKeyGroup struct { 15 | } 16 | 17 | func init() { 18 | i := AWSCloudfrontKeyGroup{} 19 | listers = append(listers, i) 20 | } 21 | 22 | func (l AWSCloudfrontKeyGroup) Types() []resource.ResourceType { 23 | return []resource.ResourceType{resource.CloudFrontKeyGroup} 24 | } 25 | 26 | func (l AWSCloudfrontKeyGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | svc := cloudfront.NewFromConfig(ctx.AWSCfg) 28 | 29 | rg := resource.NewGroup() 30 | var outerErr error 31 | 32 | listCloudfrontKeyGroupOnce.Do(func() { 33 | err := Paginator(func(nt *string) (*string, error) { 34 | res, err := svc.ListKeyGroups(ctx.Context, &cloudfront.ListKeyGroupsInput{ 35 | MaxItems: aws.Int32(100), 36 | Marker: nt, 37 | }) 38 | if err != nil { 39 | return nil, err 40 | } 41 | if res.KeyGroupList == nil { 42 | return nil, nil 43 | } 44 | for _, item := range res.KeyGroupList.Items { 45 | kg := item.KeyGroup 46 | r := resource.NewGlobal(ctx, resource.CloudFrontKeyGroup, kg.Id, kg.Id, kg) 47 | 48 | rg.AddResource(r) 49 | } 50 | return res.KeyGroupList.NextMarker, nil 51 | }) 52 | if err != nil { 53 | outerErr = err 54 | } 55 | }) 56 | 57 | return rg, outerErr 58 | } 59 | -------------------------------------------------------------------------------- /lister/cloudfront_originaccessidentity.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "sync" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/cloudfront" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | var listCloudfrontOAIOnce sync.Once 13 | 14 | type AWSCloudfrontOriginAccessIdentify struct { 15 | } 16 | 17 | func init() { 18 | i := AWSCloudfrontOriginAccessIdentify{} 19 | listers = append(listers, i) 20 | } 21 | 22 | func (l AWSCloudfrontOriginAccessIdentify) Types() []resource.ResourceType { 23 | return []resource.ResourceType{resource.CloudFrontOriginAccessIdentity} 24 | } 25 | 26 | func (l AWSCloudfrontOriginAccessIdentify) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | svc := cloudfront.NewFromConfig(ctx.AWSCfg) 28 | 29 | rg := resource.NewGroup() 30 | var outerErr error 31 | 32 | listCloudfrontOAIOnce.Do(func() { 33 | 34 | err := Paginator(func(nt *string) (*string, error) { 35 | res, err := svc.ListCloudFrontOriginAccessIdentities(ctx.Context, &cloudfront.ListCloudFrontOriginAccessIdentitiesInput{ 36 | MaxItems: aws.Int32(100), 37 | Marker: nt, 38 | }) 39 | if err != nil { 40 | return nil, err 41 | } 42 | if res.CloudFrontOriginAccessIdentityList == nil { 43 | return nil, nil 44 | } 45 | for _, item := range res.CloudFrontOriginAccessIdentityList.Items { 46 | r := resource.NewGlobal(ctx, resource.CloudFrontOriginAccessIdentity, item.Id, item.Id, item) 47 | rg.AddResource(r) 48 | } 49 | return res.CloudFrontOriginAccessIdentityList.NextMarker, nil 50 | }) 51 | if err != nil { 52 | outerErr = err 53 | } 54 | }) 55 | 56 | return rg, outerErr 57 | } 58 | -------------------------------------------------------------------------------- /lister/cloudfront_originrequestpolicy.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | 7 | "github.com/aws/aws-sdk-go-v2/aws" 8 | "github.com/aws/aws-sdk-go-v2/service/cloudfront" 9 | "github.com/trek10inc/awsets/context" 10 | "github.com/trek10inc/awsets/resource" 11 | ) 12 | 13 | var listCloudfrontOriginRequestPolicyOnce sync.Once 14 | 15 | type AWSCloudfrontOriginRequestPolicy struct { 16 | } 17 | 18 | func init() { 19 | i := AWSCloudfrontOriginRequestPolicy{} 20 | listers = append(listers, i) 21 | } 22 | 23 | func (l AWSCloudfrontOriginRequestPolicy) Types() []resource.ResourceType { 24 | return []resource.ResourceType{resource.CloudFrontOriginRequestPolicy} 25 | } 26 | 27 | func (l AWSCloudfrontOriginRequestPolicy) List(ctx context.AWSetsCtx) (*resource.Group, error) { 28 | svc := cloudfront.NewFromConfig(ctx.AWSCfg) 29 | 30 | rg := resource.NewGroup() 31 | var outerErr error 32 | listCloudfrontOriginRequestPolicyOnce.Do(func() { 33 | err := Paginator(func(nt *string) (*string, error) { 34 | res, err := svc.ListOriginRequestPolicies(ctx.Context, &cloudfront.ListOriginRequestPoliciesInput{ 35 | Marker: nt, 36 | MaxItems: aws.Int32(100), 37 | }) 38 | if err != nil { 39 | return nil, err 40 | } 41 | if policies := res.OriginRequestPolicyList; policies != nil { 42 | for _, v := range policies.Items { 43 | r := resource.NewGlobal(ctx, resource.CloudFrontOriginRequestPolicy, v.OriginRequestPolicy.Id, v.OriginRequestPolicy.Id, v) 44 | rg.AddResource(r) 45 | } 46 | return policies.NextMarker, nil 47 | } else { 48 | return nil, nil 49 | } 50 | }) 51 | if err != nil { 52 | outerErr = fmt.Errorf("failed to list origin request policies: %w", err) 53 | } 54 | }) 55 | 56 | return rg, outerErr 57 | } 58 | -------------------------------------------------------------------------------- /lister/cloudfront_publickey.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "sync" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/cloudfront" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | var listCloudfrontPublicKeyOnce sync.Once 13 | 14 | type AWSCloudfrontPublicKey struct { 15 | } 16 | 17 | func init() { 18 | i := AWSCloudfrontPublicKey{} 19 | listers = append(listers, i) 20 | } 21 | 22 | func (l AWSCloudfrontPublicKey) Types() []resource.ResourceType { 23 | return []resource.ResourceType{resource.CloudFrontPublicKey} 24 | } 25 | 26 | func (l AWSCloudfrontPublicKey) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | svc := cloudfront.NewFromConfig(ctx.AWSCfg) 28 | 29 | rg := resource.NewGroup() 30 | var outerErr error 31 | 32 | listCloudfrontPublicKeyOnce.Do(func() { 33 | err := Paginator(func(nt *string) (*string, error) { 34 | res, err := svc.ListPublicKeys(ctx.Context, &cloudfront.ListPublicKeysInput{ 35 | MaxItems: aws.Int32(100), 36 | Marker: nt, 37 | }) 38 | if err != nil { 39 | return nil, err 40 | } 41 | if res.PublicKeyList == nil { 42 | return nil, nil 43 | } 44 | for _, item := range res.PublicKeyList.Items { 45 | r := resource.NewGlobal(ctx, resource.CloudFrontPublicKey, item.Id, item.Name, item) 46 | 47 | rg.AddResource(r) 48 | } 49 | return res.PublicKeyList.NextMarker, nil 50 | }) 51 | if err != nil { 52 | outerErr = err 53 | } 54 | }) 55 | 56 | return rg, outerErr 57 | } 58 | -------------------------------------------------------------------------------- /lister/cloudwatch_alarm.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/cloudwatch" 6 | "github.com/trek10inc/awsets/arn" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSCloudwatchAlarm struct { 12 | } 13 | 14 | func init() { 15 | i := AWSCloudwatchAlarm{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSCloudwatchAlarm) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.CloudwatchAlarm} 21 | } 22 | 23 | func (l AWSCloudwatchAlarm) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | 25 | svc := cloudwatch.NewFromConfig(ctx.AWSCfg) 26 | 27 | rg := resource.NewGroup() 28 | 29 | err := Paginator(func(nt *string) (*string, error) { 30 | res, err := svc.DescribeAlarms(ctx.Context, &cloudwatch.DescribeAlarmsInput{ 31 | MaxRecords: aws.Int32(100), 32 | NextToken: nt, 33 | }) 34 | if err != nil { 35 | return nil, err 36 | } 37 | for _, alarm := range res.CompositeAlarms { 38 | alarmArn := arn.ParseP(alarm.AlarmArn) 39 | r := resource.New(ctx, resource.CloudwatchAlarm, alarmArn.ResourceId, alarm.AlarmName, alarm) 40 | rg.AddResource(r) 41 | } 42 | for _, alarm := range res.MetricAlarms { 43 | alarmArn := arn.ParseP(alarm.AlarmArn) 44 | r := resource.New(ctx, resource.CloudwatchAlarm, alarmArn.ResourceId, alarm.AlarmName, alarm) 45 | rg.AddResource(r) 46 | } 47 | return res.NextToken, nil 48 | }) 49 | return rg, err 50 | } 51 | -------------------------------------------------------------------------------- /lister/cloudwatch_dashboard.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/cloudwatch" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSCloudwatchDashboard struct { 12 | } 13 | 14 | func init() { 15 | i := AWSCloudwatchDashboard{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSCloudwatchDashboard) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.CloudwatchDashboard} 21 | } 22 | 23 | func (l AWSCloudwatchDashboard) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | 25 | svc := cloudwatch.NewFromConfig(ctx.AWSCfg) 26 | 27 | rg := resource.NewGroup() 28 | 29 | err := Paginator(func(nt *string) (*string, error) { 30 | res, err := svc.ListDashboards(ctx.Context, &cloudwatch.ListDashboardsInput{ 31 | NextToken: nt, 32 | }) 33 | if err != nil { 34 | return nil, fmt.Errorf("failed to list cloudwatch dashbards: %w", err) 35 | } 36 | for _, v := range res.DashboardEntries { 37 | dashboard, err := svc.GetDashboard(ctx.Context, &cloudwatch.GetDashboardInput{ 38 | DashboardName: v.DashboardName, 39 | }) 40 | if err != nil { 41 | return nil, fmt.Errorf("failed to get dashboard %s: %w", *v.DashboardName, err) 42 | } 43 | r := resource.New(ctx, resource.CloudwatchDashboard, dashboard.DashboardName, dashboard.DashboardName, dashboard) 44 | rg.AddResource(r) 45 | } 46 | return res.NextToken, nil 47 | }) 48 | return rg, err 49 | } 50 | -------------------------------------------------------------------------------- /lister/cloudwatchevents_eventbus.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/cloudwatchevents" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSCloudwatchEventsBus struct { 13 | } 14 | 15 | func init() { 16 | i := AWSCloudwatchEventsBus{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSCloudwatchEventsBus) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.EventsBus} 22 | } 23 | 24 | func (l AWSCloudwatchEventsBus) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | 26 | svc := cloudwatchevents.NewFromConfig(ctx.AWSCfg) 27 | 28 | rg := resource.NewGroup() 29 | 30 | err := Paginator(func(nt *string) (*string, error) { 31 | res, err := svc.ListEventBuses(ctx.Context, &cloudwatchevents.ListEventBusesInput{ 32 | Limit: aws.Int32(100), 33 | NextToken: nt, 34 | }) 35 | if err != nil { 36 | return nil, fmt.Errorf("failed to list cloudwatch event buses: %w", err) 37 | } 38 | for _, bus := range res.EventBuses { 39 | r := resource.New(ctx, resource.EventsBus, bus.Name, bus.Name, bus) 40 | rg.AddResource(r) 41 | } 42 | return res.NextToken, nil 43 | }) 44 | return rg, err 45 | } 46 | -------------------------------------------------------------------------------- /lister/cloudwatchevents_rule.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/cloudwatchevents" 8 | "github.com/trek10inc/awsets/arn" 9 | "github.com/trek10inc/awsets/context" 10 | "github.com/trek10inc/awsets/resource" 11 | ) 12 | 13 | type AWSCloudwatchEventsRule struct { 14 | } 15 | 16 | func init() { 17 | i := AWSCloudwatchEventsRule{} 18 | listers = append(listers, i) 19 | } 20 | 21 | func (l AWSCloudwatchEventsRule) Types() []resource.ResourceType { 22 | return []resource.ResourceType{resource.EventsRule} 23 | } 24 | 25 | func (l AWSCloudwatchEventsRule) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | 27 | svc := cloudwatchevents.NewFromConfig(ctx.AWSCfg) 28 | 29 | rg := resource.NewGroup() 30 | 31 | err := Paginator(func(nt *string) (*string, error) { 32 | res, err := svc.ListRules(ctx.Context, &cloudwatchevents.ListRulesInput{ 33 | Limit: aws.Int32(100), 34 | NextToken: nt, 35 | }) 36 | if err != nil { 37 | return nil, fmt.Errorf("failed to list cloudwatch event rules: %w", err) 38 | } 39 | for _, rule := range res.Rules { 40 | r := resource.New(ctx, resource.EventsRule, rule.Name, rule.Name, rule) 41 | r.AddRelation(resource.EventsBus, rule.EventBusName, "") 42 | if rule.RoleArn != nil { 43 | roleArn := arn.ParseP(rule.RoleArn) 44 | r.AddRelation(resource.IamRole, roleArn.ResourceId, roleArn.ResourceVersion) 45 | } 46 | rg.AddResource(r) 47 | } 48 | return res.NextToken, nil 49 | }) 50 | return rg, err 51 | } 52 | -------------------------------------------------------------------------------- /lister/cloudwatchlogs_querydefinition.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSCloudwatchLogsQueryDefinition struct { 11 | } 12 | 13 | func init() { 14 | i := AWSCloudwatchLogsQueryDefinition{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSCloudwatchLogsQueryDefinition) Types() []resource.ResourceType { 19 | return []resource.ResourceType{ 20 | resource.LogQueryDefinition, 21 | } 22 | } 23 | 24 | func (l AWSCloudwatchLogsQueryDefinition) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | svc := cloudwatchlogs.NewFromConfig(ctx.AWSCfg) 26 | 27 | rg := resource.NewGroup() 28 | 29 | err := Paginator(func(nt *string) (*string, error) { 30 | res, err := svc.DescribeQueryDefinitions(ctx.Context, &cloudwatchlogs.DescribeQueryDefinitionsInput{ 31 | MaxResults: aws.Int32(100), 32 | NextToken: nt, 33 | }) 34 | if err != nil { 35 | return nil, err 36 | } 37 | for _, v := range res.QueryDefinitions { 38 | r := resource.New(ctx, resource.LogQueryDefinition, v.QueryDefinitionId, v.Name, v) 39 | for _, lg := range v.LogGroupNames { 40 | r.AddRelation(resource.LogGroup, lg, "") 41 | } 42 | rg.AddResource(r) 43 | } 44 | 45 | return res.NextToken, nil 46 | }) 47 | return rg, err 48 | } 49 | -------------------------------------------------------------------------------- /lister/codebuild_sourcecredential.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/codebuild" 7 | "github.com/trek10inc/awsets/arn" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSCodebuildSourceCredential struct { 13 | } 14 | 15 | func init() { 16 | i := AWSCodebuildSourceCredential{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSCodebuildSourceCredential) Types() []resource.ResourceType { 21 | return []resource.ResourceType{ 22 | resource.CodeBuildSourceCredential, 23 | } 24 | } 25 | 26 | func (l AWSCodebuildSourceCredential) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | 28 | svc := codebuild.NewFromConfig(ctx.AWSCfg) 29 | rg := resource.NewGroup() 30 | 31 | res, err := svc.ListSourceCredentials(ctx.Context, &codebuild.ListSourceCredentialsInput{}) 32 | if err != nil { 33 | return nil, fmt.Errorf("failed to list codebuild source credentials: %w", err) 34 | } 35 | for _, sc := range res.SourceCredentialsInfos { 36 | credArn := arn.ParseP(sc.Arn) 37 | r := resource.New(ctx, resource.CodeBuildProject, credArn.ResourceId, credArn.ResourceType, sc) 38 | rg.AddResource(r) 39 | } 40 | return rg, err 41 | } 42 | -------------------------------------------------------------------------------- /lister/codecommit_repository.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/codecommit" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSCodeCommitRepository struct { 12 | } 13 | 14 | func init() { 15 | i := AWSCodeCommitRepository{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSCodeCommitRepository) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.CodeCommitRepository} 21 | } 22 | 23 | func (l AWSCodeCommitRepository) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | 25 | svc := codecommit.NewFromConfig(ctx.AWSCfg) 26 | rg := resource.NewGroup() 27 | 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.ListRepositories(ctx.Context, &codecommit.ListRepositoriesInput{ 30 | NextToken: nt, 31 | }) 32 | if err != nil { 33 | return nil, err 34 | } 35 | for _, id := range res.Repositories { 36 | repo, err := svc.GetRepository(ctx.Context, &codecommit.GetRepositoryInput{ 37 | RepositoryName: id.RepositoryName, 38 | }) 39 | if err != nil { 40 | return nil, fmt.Errorf("failed to get repository %s: %w", *id.RepositoryId, err) 41 | } 42 | if v := repo.RepositoryMetadata; v != nil { 43 | r := resource.New(ctx, resource.CodeCommitRepository, v.RepositoryId, v.RepositoryName, v) 44 | rg.AddResource(r) 45 | } 46 | } 47 | return res.NextToken, nil 48 | }) 49 | return rg, err 50 | } 51 | -------------------------------------------------------------------------------- /lister/codedeploy_deploymentconfig.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/codedeploy" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSCodeDeployDeploymentConfig struct { 12 | } 13 | 14 | func init() { 15 | i := AWSCodeDeployDeploymentConfig{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSCodeDeployDeploymentConfig) Types() []resource.ResourceType { 20 | return []resource.ResourceType{ 21 | resource.CodeDeployDeploymentConfig, 22 | } 23 | } 24 | 25 | func (l AWSCodeDeployDeploymentConfig) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | svc := codedeploy.NewFromConfig(ctx.AWSCfg) 27 | 28 | rg := resource.NewGroup() 29 | err := Paginator(func(nt *string) (*string, error) { 30 | res, err := svc.ListDeploymentConfigs(ctx.Context, &codedeploy.ListDeploymentConfigsInput{ 31 | NextToken: nt, 32 | }) 33 | if err != nil { 34 | return nil, err 35 | } 36 | for _, config := range res.DeploymentConfigsList { 37 | configRes, err := svc.GetDeploymentConfig(ctx.Context, &codedeploy.GetDeploymentConfigInput{ 38 | DeploymentConfigName: &config, 39 | }) 40 | if err != nil { 41 | return nil, fmt.Errorf("failed to get codedeploy deployment config %s: %w", config, err) 42 | } 43 | v := configRes.DeploymentConfigInfo 44 | if v == nil { 45 | continue 46 | } 47 | r := resource.New(ctx, resource.CodeDeployDeploymentConfig, v.DeploymentConfigId, v.DeploymentConfigName, v) 48 | rg.AddResource(r) 49 | } 50 | return res.NextToken, nil 51 | }) 52 | return rg, err 53 | } 54 | -------------------------------------------------------------------------------- /lister/codepipeline_pipeline.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/codepipeline" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSCodepipelinePipeline struct { 12 | } 13 | 14 | func init() { 15 | i := AWSCodepipelinePipeline{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSCodepipelinePipeline) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.CodePipelinePipeline} 21 | } 22 | 23 | func (l AWSCodepipelinePipeline) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | 25 | svc := codepipeline.NewFromConfig(ctx.AWSCfg) 26 | rg := resource.NewGroup() 27 | 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.ListPipelines(ctx.Context, &codepipeline.ListPipelinesInput{ 30 | NextToken: nt, 31 | }) 32 | if err != nil { 33 | return nil, err 34 | } 35 | for _, v := range res.Pipelines { 36 | pipeline, err := svc.GetPipeline(ctx.Context, &codepipeline.GetPipelineInput{ 37 | Name: v.Name, 38 | Version: v.Version, 39 | }) 40 | if err != nil { 41 | return nil, fmt.Errorf("failed to get pipeline %s: %w", *v.Name, err) 42 | } 43 | r := resource.New(ctx, resource.CodePipelinePipeline, v.Name, v.Name, v) 44 | r.AddAttribute("Metadata", pipeline.Metadata) 45 | r.AddAttribute("Pipeline", pipeline.Pipeline) 46 | rg.AddResource(r) 47 | } 48 | return res.NextToken, nil 49 | }) 50 | return rg, err 51 | } 52 | -------------------------------------------------------------------------------- /lister/codepipeline_webhook.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/service/codepipeline" 5 | "github.com/trek10inc/awsets/arn" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSCodepipelineWebhook struct { 11 | } 12 | 13 | func init() { 14 | i := AWSCodepipelineWebhook{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSCodepipelineWebhook) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.CodePipelineWebhook} 20 | } 21 | 22 | func (l AWSCodepipelineWebhook) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | 24 | svc := codepipeline.NewFromConfig(ctx.AWSCfg) 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.ListWebhooks(ctx.Context, &codepipeline.ListWebhooksInput{ 28 | NextToken: nt, 29 | }) 30 | if err != nil { 31 | return nil, err 32 | } 33 | for _, v := range res.Webhooks { 34 | whArn := arn.ParseP(v.Arn) 35 | r := resource.New(ctx, resource.CodePipelineWebhook, whArn.ResourceId, whArn.ResourceId, v) 36 | if v.Definition != nil { 37 | r.AddRelation(resource.CodePipelinePipeline, v.Definition.TargetPipeline, "") 38 | } 39 | rg.AddResource(r) 40 | } 41 | return res.NextToken, nil 42 | }) 43 | return rg, err 44 | } 45 | -------------------------------------------------------------------------------- /lister/codestar_project.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/codestar" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSCodestarProject struct { 12 | } 13 | 14 | func init() { 15 | i := AWSCodestarProject{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSCodestarProject) Types() []resource.ResourceType { 20 | return []resource.ResourceType{ 21 | resource.CodeStarProject, 22 | } 23 | } 24 | 25 | func (l AWSCodestarProject) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | 27 | svc := codestar.NewFromConfig(ctx.AWSCfg) 28 | rg := resource.NewGroup() 29 | err := Paginator(func(nt *string) (*string, error) { 30 | res, err := svc.ListProjects(ctx.Context, &codestar.ListProjectsInput{ 31 | MaxResults: 100, 32 | NextToken: nt, 33 | }) 34 | if err != nil { 35 | return nil, fmt.Errorf("failed to list codestar projects: %w", err) 36 | } 37 | if len(res.Projects) == 0 { 38 | return nil, nil 39 | } 40 | for _, project := range res.Projects { 41 | v, err := svc.DescribeProject(ctx.Context, &codestar.DescribeProjectInput{ 42 | Id: project.ProjectId, 43 | }) 44 | if err != nil { 45 | return nil, fmt.Errorf("failed to get project %s: %w", *project.ProjectId, err) 46 | } 47 | r := resource.New(ctx, resource.CodeStarProject, v.Id, v.Name, v) 48 | rg.AddResource(r) 49 | } 50 | return res.NextToken, nil 51 | }) 52 | return rg, err 53 | } 54 | -------------------------------------------------------------------------------- /lister/config_aggregationauthorization.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/configservice" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSConfigAggregationAuthorization struct { 12 | } 13 | 14 | func init() { 15 | i := AWSConfigAggregationAuthorization{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSConfigAggregationAuthorization) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.ConfigAggregationAuthorization} 21 | } 22 | 23 | func (l AWSConfigAggregationAuthorization) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | 25 | svc := configservice.NewFromConfig(ctx.AWSCfg) 26 | rg := resource.NewGroup() 27 | 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.DescribeAggregationAuthorizations(ctx.Context, &configservice.DescribeAggregationAuthorizationsInput{ 30 | Limit: 100, 31 | NextToken: nt, 32 | }) 33 | if err != nil { 34 | return nil, fmt.Errorf("failed to list config aggregation authorizations: %w", err) 35 | } 36 | for _, v := range res.AggregationAuthorizations { 37 | r := resource.New(ctx, resource.ConfigAggregationAuthorization, v.AuthorizedAccountId, v.AuthorizedAccountId, v) 38 | rg.AddResource(r) 39 | } 40 | return res.NextToken, nil 41 | }) 42 | return rg, err 43 | } 44 | -------------------------------------------------------------------------------- /lister/config_configurationaggregator.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/configservice" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSConfigConfigurationAggregator struct { 12 | } 13 | 14 | func init() { 15 | i := AWSConfigConfigurationAggregator{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSConfigConfigurationAggregator) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.ConfigConfigurationAggregator} 21 | } 22 | 23 | func (l AWSConfigConfigurationAggregator) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | 25 | svc := configservice.NewFromConfig(ctx.AWSCfg) 26 | rg := resource.NewGroup() 27 | 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.DescribeConfigurationAggregators(ctx.Context, &configservice.DescribeConfigurationAggregatorsInput{ 30 | Limit: 100, 31 | NextToken: nt, 32 | }) 33 | if err != nil { 34 | return nil, fmt.Errorf("failed to list config aggregators: %w", err) 35 | } 36 | for _, v := range res.ConfigurationAggregators { 37 | r := resource.New(ctx, resource.ConfigConfigurationAggregator, v.ConfigurationAggregatorName, v.ConfigurationAggregatorName, v) 38 | rg.AddResource(r) 39 | } 40 | return res.NextToken, nil 41 | }) 42 | return rg, err 43 | } 44 | -------------------------------------------------------------------------------- /lister/config_configurationrecorder.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/configservice" 7 | "github.com/trek10inc/awsets/arn" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSConfigConfigurationRecorder struct { 13 | } 14 | 15 | func init() { 16 | i := AWSConfigConfigurationRecorder{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSConfigConfigurationRecorder) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.ConfigConfigurationRecorder} 22 | } 23 | 24 | func (l AWSConfigConfigurationRecorder) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | 26 | svc := configservice.NewFromConfig(ctx.AWSCfg) 27 | rg := resource.NewGroup() 28 | 29 | recorders, err := svc.DescribeConfigurationRecorders(ctx.Context, &configservice.DescribeConfigurationRecordersInput{}) 30 | if err != nil { 31 | return nil, fmt.Errorf("failed to list configuration recorders: %w", err) 32 | } 33 | for _, v := range recorders.ConfigurationRecorders { 34 | r := resource.New(ctx, resource.ConfigConfigurationRecorder, v.Name, v.Name, v) 35 | if v.RoleARN != nil { 36 | roleArn := arn.ParseP(v.RoleARN) 37 | r.AddRelation(resource.IamRole, roleArn.ResourceId, roleArn.ResourceVersion) 38 | } 39 | rg.AddResource(r) 40 | } 41 | return rg, nil 42 | } 43 | -------------------------------------------------------------------------------- /lister/config_conformancepack.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/configservice" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSConfigConformancePack struct { 12 | } 13 | 14 | func init() { 15 | i := AWSConfigConformancePack{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSConfigConformancePack) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.ConfigConformancePack} 21 | } 22 | 23 | func (l AWSConfigConformancePack) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | 25 | svc := configservice.NewFromConfig(ctx.AWSCfg) 26 | rg := resource.NewGroup() 27 | err := Paginator(func(nt *string) (*string, error) { 28 | res, err := svc.DescribeConformancePacks(ctx.Context, &configservice.DescribeConformancePacksInput{ 29 | NextToken: nt, 30 | }) 31 | if err != nil { 32 | return nil, fmt.Errorf("failed to list config conformance packs: %w", err) 33 | } 34 | for _, v := range res.ConformancePackDetails { 35 | r := resource.New(ctx, resource.ConfigConformancePack, v.ConformancePackId, v.ConformancePackId, v) 36 | r.AddRelation(resource.S3Bucket, v.DeliveryS3Bucket, "") 37 | rg.AddResource(r) 38 | } 39 | return res.NextToken, nil 40 | }) 41 | return rg, err 42 | } 43 | -------------------------------------------------------------------------------- /lister/config_deliverychannel.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/configservice" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSConfigDeliveryChannel struct { 12 | } 13 | 14 | func init() { 15 | i := AWSConfigDeliveryChannel{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSConfigDeliveryChannel) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.ConfigDeliveryChannel} 21 | } 22 | 23 | func (l AWSConfigDeliveryChannel) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | 25 | svc := configservice.NewFromConfig(ctx.AWSCfg) 26 | rg := resource.NewGroup() 27 | 28 | channels, err := svc.DescribeDeliveryChannels(ctx.Context, &configservice.DescribeDeliveryChannelsInput{}) 29 | if err != nil { 30 | return nil, fmt.Errorf("failed to list config delivery channels: %w", err) 31 | } 32 | for _, v := range channels.DeliveryChannels { 33 | r := resource.New(ctx, resource.ConfigDeliveryChannel, v.Name, v.Name, v) 34 | r.AddRelation(resource.S3Bucket, v.S3BucketName, "") 35 | rg.AddResource(r) 36 | } 37 | 38 | return rg, nil 39 | } 40 | -------------------------------------------------------------------------------- /lister/config_organizationconfigrule.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/configservice" 7 | "github.com/trek10inc/awsets/arn" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSConfigOrganizationConfigRule struct { 13 | } 14 | 15 | func init() { 16 | i := AWSConfigOrganizationConfigRule{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSConfigOrganizationConfigRule) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.ConfigOrganizationConfigRule} 22 | } 23 | 24 | func (l AWSConfigOrganizationConfigRule) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | 26 | svc := configservice.NewFromConfig(ctx.AWSCfg) 27 | rg := resource.NewGroup() 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.DescribeOrganizationConfigRules(ctx.Context, &configservice.DescribeOrganizationConfigRulesInput{ 30 | NextToken: nt, 31 | }) 32 | if err != nil { 33 | return nil, fmt.Errorf("failed to list config organization config rules: %w", err) 34 | } 35 | for _, v := range res.OrganizationConfigRules { 36 | ruleArn := arn.ParseP(v.OrganizationConfigRuleArn) 37 | r := resource.New(ctx, resource.ConfigOrganizationConfigRule, ruleArn.ResourceId, v.OrganizationConfigRuleName, v) 38 | if v.OrganizationCustomRuleMetadata != nil { 39 | r.AddARNRelation(resource.LambdaFunction, v.OrganizationCustomRuleMetadata.LambdaFunctionArn) 40 | } 41 | rg.AddResource(r) 42 | } 43 | return res.NextToken, nil 44 | }) 45 | return rg, err 46 | } 47 | -------------------------------------------------------------------------------- /lister/config_organizationconformancepack.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/configservice" 7 | "github.com/trek10inc/awsets/arn" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSConfigOrganizationConformancePack struct { 13 | } 14 | 15 | func init() { 16 | i := AWSConfigOrganizationConformancePack{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSConfigOrganizationConformancePack) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.ConfigOrganizationConformancePack} 22 | } 23 | 24 | func (l AWSConfigOrganizationConformancePack) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | 26 | svc := configservice.NewFromConfig(ctx.AWSCfg) 27 | rg := resource.NewGroup() 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.DescribeOrganizationConformancePacks(ctx.Context, &configservice.DescribeOrganizationConformancePacksInput{ 30 | NextToken: nt, 31 | }) 32 | if err != nil { 33 | return nil, fmt.Errorf("failed to list config organization conformance packs: %w", err) 34 | } 35 | for _, v := range res.OrganizationConformancePacks { 36 | packArn := arn.ParseP(v.OrganizationConformancePackArn) 37 | r := resource.New(ctx, resource.ConfigOrganizationConformancePack, packArn.ResourceId, v.OrganizationConformancePackName, v) 38 | r.AddRelation(resource.S3Bucket, v.DeliveryS3Bucket, "") 39 | rg.AddResource(r) 40 | } 41 | return res.NextToken, nil 42 | }) 43 | return rg, err 44 | } 45 | -------------------------------------------------------------------------------- /lister/dax_parametergroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | 7 | "github.com/aws/aws-sdk-go-v2/aws" 8 | "github.com/aws/aws-sdk-go-v2/service/dax" 9 | "github.com/trek10inc/awsets/context" 10 | "github.com/trek10inc/awsets/resource" 11 | ) 12 | 13 | type AWSDAXParameterGroup struct { 14 | } 15 | 16 | func init() { 17 | i := AWSDAXParameterGroup{} 18 | listers = append(listers, i) 19 | } 20 | 21 | func (l AWSDAXParameterGroup) Types() []resource.ResourceType { 22 | return []resource.ResourceType{resource.DAXParameterGroup} 23 | } 24 | 25 | func (l AWSDAXParameterGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | 27 | svc := dax.NewFromConfig(ctx.AWSCfg) 28 | rg := resource.NewGroup() 29 | err := Paginator(func(nt *string) (*string, error) { 30 | res, err := svc.DescribeParameterGroups(ctx.Context, &dax.DescribeParameterGroupsInput{ 31 | MaxResults: aws.Int32(100), 32 | NextToken: nt, 33 | }) 34 | if err != nil { 35 | if strings.Contains(err.Error(), "Access Denied to API Version: DAX_V3") { 36 | // Regions that don't support DAX return access denied 37 | return nil, nil 38 | } 39 | return nil, fmt.Errorf("failed to list dax parameter groups: %w", err) 40 | } 41 | for _, v := range res.ParameterGroups { 42 | r := resource.New(ctx, resource.DAXParameterGroup, v.ParameterGroupName, v.ParameterGroupName, v) 43 | rg.AddResource(r) 44 | } 45 | return res.NextToken, nil 46 | }) 47 | return rg, err 48 | } 49 | -------------------------------------------------------------------------------- /lister/dax_subnetgroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | 7 | "github.com/aws/aws-sdk-go-v2/aws" 8 | "github.com/aws/aws-sdk-go-v2/service/dax" 9 | "github.com/trek10inc/awsets/context" 10 | "github.com/trek10inc/awsets/resource" 11 | ) 12 | 13 | type AWSDAXSubnetGroup struct { 14 | } 15 | 16 | func init() { 17 | i := AWSDAXSubnetGroup{} 18 | listers = append(listers, i) 19 | } 20 | 21 | func (l AWSDAXSubnetGroup) Types() []resource.ResourceType { 22 | return []resource.ResourceType{resource.DAXSubnetGroup} 23 | } 24 | 25 | func (l AWSDAXSubnetGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | 27 | svc := dax.NewFromConfig(ctx.AWSCfg) 28 | rg := resource.NewGroup() 29 | err := Paginator(func(nt *string) (*string, error) { 30 | res, err := svc.DescribeSubnetGroups(ctx.Context, &dax.DescribeSubnetGroupsInput{ 31 | MaxResults: aws.Int32(100), 32 | NextToken: nt, 33 | }) 34 | if err != nil { 35 | if strings.Contains(err.Error(), "Access Denied to API Version: DAX_V3") { 36 | // Regions that don't support DAX return access denied 37 | return nil, nil 38 | } 39 | return nil, fmt.Errorf("failed to list dax subnet groups: %w", err) 40 | } 41 | for _, v := range res.SubnetGroups { 42 | r := resource.New(ctx, resource.DAXSubnetGroup, v.SubnetGroupName, v.SubnetGroupName, v) 43 | r.AddRelation(resource.Ec2Vpc, v.VpcId, "") 44 | for _, sn := range v.Subnets { 45 | r.AddRelation(resource.Ec2Subnet, sn.SubnetIdentifier, "") 46 | } 47 | rg.AddResource(r) 48 | } 49 | return res.NextToken, nil 50 | }) 51 | return rg, err 52 | } 53 | -------------------------------------------------------------------------------- /lister/dms_endpoint.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/databasemigrationservice" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSDMSEndpoint struct { 13 | } 14 | 15 | func init() { 16 | i := AWSDMSEndpoint{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSDMSEndpoint) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.DMSEndpoint} 22 | } 23 | 24 | func (l AWSDMSEndpoint) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | svc := databasemigrationservice.NewFromConfig(ctx.AWSCfg) 26 | 27 | rg := resource.NewGroup() 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.DescribeEndpoints(ctx.Context, &databasemigrationservice.DescribeEndpointsInput{ 30 | MaxRecords: aws.Int32(100), 31 | Marker: nt, 32 | }) 33 | if err != nil { 34 | if strings.Contains(err.Error(), "exceeded maximum number of attempts") { 35 | // If DMS is not supported in a region, it triggers this error 36 | return nil, nil 37 | } 38 | return nil, err 39 | } 40 | for _, v := range res.Endpoints { 41 | r := resource.New(ctx, resource.DMSEndpoint, v.EndpointIdentifier, v.EndpointIdentifier, v) 42 | r.AddARNRelation(resource.KmsKey, v.KmsKeyId) 43 | r.AddARNRelation(resource.AcmCertificate, v.CertificateArn) 44 | 45 | if setting := v.S3Settings; setting != nil { 46 | r.AddRelation(resource.S3Bucket, setting.BucketName, "") 47 | } 48 | r.AddARNRelation(resource.IamRole, v.ServiceAccessRoleArn) 49 | rg.AddResource(r) 50 | } 51 | return res.Marker, nil 52 | }) 53 | return rg, err 54 | } 55 | -------------------------------------------------------------------------------- /lister/dms_replicationsubnetgroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/databasemigrationservice" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSDMSReplicationSubnetGroup struct { 13 | } 14 | 15 | func init() { 16 | i := AWSDMSReplicationSubnetGroup{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSDMSReplicationSubnetGroup) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.DMSReplicationSubnetGroup} 22 | } 23 | 24 | func (l AWSDMSReplicationSubnetGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | svc := databasemigrationservice.NewFromConfig(ctx.AWSCfg) 26 | 27 | rg := resource.NewGroup() 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.DescribeReplicationSubnetGroups(ctx.Context, &databasemigrationservice.DescribeReplicationSubnetGroupsInput{ 30 | MaxRecords: aws.Int32(100), 31 | Marker: nt, 32 | }) 33 | if err != nil { 34 | if strings.Contains(err.Error(), "exceeded maximum number of attempts") { 35 | // If DMS is not supported in a region, it triggers this error 36 | return nil, nil 37 | } 38 | return nil, err 39 | } 40 | for _, v := range res.ReplicationSubnetGroups { 41 | r := resource.New(ctx, resource.DMSReplicationSubnetGroup, v.ReplicationSubnetGroupIdentifier, v.ReplicationSubnetGroupIdentifier, v) 42 | r.AddRelation(resource.Ec2Vpc, v.VpcId, "") 43 | for _, sn := range v.Subnets { 44 | r.AddRelation(resource.Ec2Subnet, sn.SubnetIdentifier, "") 45 | } 46 | rg.AddResource(r) 47 | } 48 | return res.Marker, nil 49 | }) 50 | return rg, err 51 | } 52 | -------------------------------------------------------------------------------- /lister/dms_replicationtask.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/databasemigrationservice" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSDMSReplicationTask struct { 13 | } 14 | 15 | func init() { 16 | i := AWSDMSReplicationTask{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSDMSReplicationTask) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.DMSReplicationTask} 22 | } 23 | 24 | func (l AWSDMSReplicationTask) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | svc := databasemigrationservice.NewFromConfig(ctx.AWSCfg) 26 | 27 | rg := resource.NewGroup() 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.DescribeReplicationTasks(ctx.Context, &databasemigrationservice.DescribeReplicationTasksInput{ 30 | MaxRecords: aws.Int32(100), 31 | Marker: nt, 32 | }) 33 | if err != nil { 34 | if strings.Contains(err.Error(), "exceeded maximum number of attempts") { 35 | // If DMS is not supported in a region, it triggers this error 36 | return nil, nil 37 | } 38 | return nil, err 39 | } 40 | for _, v := range res.ReplicationTasks { 41 | r := resource.New(ctx, resource.DMSReplicationTask, v.ReplicationTaskIdentifier, v.ReplicationTaskIdentifier, v) 42 | r.AddARNRelation(resource.DMSReplicationInstance, v.ReplicationInstanceArn) 43 | rg.AddResource(r) 44 | } 45 | return res.Marker, nil 46 | }) 47 | return rg, err 48 | } 49 | -------------------------------------------------------------------------------- /lister/docdb_subnetgroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/docdb" 6 | "github.com/trek10inc/awsets/arn" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSDocDBSubnetGroup struct { 12 | } 13 | 14 | func init() { 15 | i := AWSDocDBSubnetGroup{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSDocDBSubnetGroup) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.DocDBSubnetGroup} 21 | } 22 | 23 | func (l AWSDocDBSubnetGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := docdb.NewFromConfig(ctx.AWSCfg) 25 | 26 | rg := resource.NewGroup() 27 | 28 | paginator := docdb.NewDescribeDBSubnetGroupsPaginator(svc, &docdb.DescribeDBSubnetGroupsInput{ 29 | MaxRecords: aws.Int32(100), 30 | }) 31 | for paginator.HasMorePages() { 32 | page, err := paginator.NextPage(ctx.Context) 33 | if err != nil { 34 | return nil, err 35 | } 36 | for _, v := range page.DBSubnetGroups { 37 | subnetArn := arn.ParseP(v.DBSubnetGroupArn) 38 | if subnetArn.Service != "docdb" { 39 | continue 40 | } 41 | r := resource.New(ctx, resource.DocDBSubnetGroup, v.DBSubnetGroupName, v.DBSubnetGroupName, v) 42 | r.AddRelation(resource.Ec2Vpc, v.VpcId, "") 43 | for _, sn := range v.Subnets { 44 | r.AddRelation(resource.Ec2Subnet, sn.SubnetIdentifier, "") 45 | } 46 | rg.AddResource(r) 47 | } 48 | } 49 | return rg, nil 50 | } 51 | -------------------------------------------------------------------------------- /lister/dynamodb_backup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/dynamodb" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSDynamoDBBackup struct { 13 | } 14 | 15 | func init() { 16 | i := AWSDynamoDBBackup{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSDynamoDBBackup) Types() []resource.ResourceType { 21 | return []resource.ResourceType{ 22 | resource.DynamoDbBackup, 23 | } 24 | } 25 | 26 | func (l AWSDynamoDBBackup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | svc := dynamodb.NewFromConfig(ctx.AWSCfg) 28 | 29 | rg := resource.NewGroup() 30 | err := Paginator(func(nt *string) (*string, error) { 31 | res, err := svc.ListBackups(ctx.Context, &dynamodb.ListBackupsInput{ 32 | BackupType: types.BackupTypeFilterAll, 33 | Limit: aws.Int32(100), 34 | ExclusiveStartBackupArn: nt, 35 | }) 36 | if err != nil { 37 | return nil, err 38 | } 39 | for _, bk := range res.BackupSummaries { 40 | bkr := resource.New(ctx, resource.DynamoDbBackup, bk.BackupName, bk.BackupName, bk) 41 | bkr.AddRelation(resource.DynamoDbTable, bk.TableName, "") 42 | rg.AddResource(bkr) 43 | } 44 | return res.LastEvaluatedBackupArn, nil 45 | }) 46 | return rg, err 47 | } 48 | -------------------------------------------------------------------------------- /lister/dynamodb_table.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/dynamodb" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSDynamoDBTable struct { 13 | } 14 | 15 | func init() { 16 | i := AWSDynamoDBTable{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSDynamoDBTable) Types() []resource.ResourceType { 21 | return []resource.ResourceType{ 22 | resource.DynamoDbTable, 23 | } 24 | } 25 | 26 | func (l AWSDynamoDBTable) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | svc := dynamodb.NewFromConfig(ctx.AWSCfg) 28 | 29 | rg := resource.NewGroup() 30 | err := Paginator(func(nt *string) (*string, error) { 31 | res, err := svc.ListTables(ctx.Context, &dynamodb.ListTablesInput{ 32 | Limit: aws.Int32(100), 33 | ExclusiveStartTableName: nt, 34 | }) 35 | if err != nil { 36 | return nil, err 37 | } 38 | for _, table := range res.TableNames { 39 | tableRes, err := svc.DescribeTable(ctx.Context, &dynamodb.DescribeTableInput{ 40 | TableName: &table, 41 | }) 42 | if err != nil { 43 | return nil, fmt.Errorf("failed to describe table %s: %w", table, err) 44 | } 45 | r := resource.New(ctx, resource.DynamoDbTable, tableRes.Table.TableName, tableRes.Table.TableName, tableRes.Table) 46 | rg.AddResource(r) 47 | } 48 | return res.LastEvaluatedTableName, nil 49 | }) 50 | return rg, err 51 | } 52 | -------------------------------------------------------------------------------- /lister/dynamodbstreams_stream.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/dynamodbstreams" 8 | "github.com/trek10inc/awsets/arn" 9 | "github.com/trek10inc/awsets/context" 10 | "github.com/trek10inc/awsets/resource" 11 | ) 12 | 13 | type AWSDynamoDBStreamStream struct { 14 | } 15 | 16 | func init() { 17 | i := AWSDynamoDBStreamStream{} 18 | listers = append(listers, i) 19 | } 20 | 21 | func (l AWSDynamoDBStreamStream) Types() []resource.ResourceType { 22 | return []resource.ResourceType{ 23 | resource.DynamoDbStreamStream, 24 | } 25 | } 26 | 27 | func (l AWSDynamoDBStreamStream) List(ctx context.AWSetsCtx) (*resource.Group, error) { 28 | svc := dynamodbstreams.NewFromConfig(ctx.AWSCfg) 29 | 30 | rg := resource.NewGroup() 31 | err := Paginator(func(nt *string) (*string, error) { 32 | res, err := svc.ListStreams(ctx.Context, &dynamodbstreams.ListStreamsInput{ 33 | ExclusiveStartStreamArn: nt, 34 | Limit: aws.Int32(100), 35 | }) 36 | if err != nil { 37 | return nil, err 38 | } 39 | for _, stream := range res.Streams { 40 | v, err := svc.DescribeStream(ctx.Context, &dynamodbstreams.DescribeStreamInput{ 41 | StreamArn: stream.StreamArn, 42 | }) 43 | if err != nil { 44 | return nil, fmt.Errorf("failed to describe ddb stream %s: %w", *stream.TableName, err) 45 | } 46 | streamArn := arn.ParseP(v.StreamDescription.StreamArn) 47 | r := resource.New(ctx, resource.DynamoDbStreamStream, streamArn.ResourceId, streamArn.ResourceId, v.StreamDescription) 48 | r.AddRelation(resource.DynamoDbTable, v.StreamDescription.TableName, "") 49 | rg.AddResource(r) 50 | } 51 | return res.LastEvaluatedStreamArn, nil 52 | }) 53 | return rg, err 54 | } 55 | -------------------------------------------------------------------------------- /lister/ec2_customergateway.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/ec2" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSEc2CustomerGateway struct { 12 | } 13 | 14 | func init() { 15 | i := AWSEc2CustomerGateway{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSEc2CustomerGateway) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.Ec2CustomerGateway} 21 | } 22 | 23 | func (l AWSEc2CustomerGateway) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := ec2.NewFromConfig(ctx.AWSCfg) 25 | 26 | rg := resource.NewGroup() 27 | res, err := svc.DescribeCustomerGateways(ctx.Context, &ec2.DescribeCustomerGatewaysInput{}) 28 | if err != nil { 29 | return nil, fmt.Errorf("failed to get customer gateways: %w", err) 30 | } 31 | for _, v := range res.CustomerGateways { 32 | r := resource.New(ctx, resource.Ec2CustomerGateway, v.CustomerGatewayId, v.CustomerGatewayId, v) 33 | rg.AddResource(r) 34 | } 35 | return rg, err 36 | } 37 | -------------------------------------------------------------------------------- /lister/ec2_dhcpoption.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/ec2" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSEc2DHCPOption struct { 11 | } 12 | 13 | func init() { 14 | i := AWSEc2DHCPOption{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSEc2DHCPOption) Types() []resource.ResourceType { 19 | return []resource.ResourceType{ 20 | resource.Ec2DHCPOption, 21 | } 22 | } 23 | 24 | func (l AWSEc2DHCPOption) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | svc := ec2.NewFromConfig(ctx.AWSCfg) 26 | rg := resource.NewGroup() 27 | err := Paginator(func(nt *string) (*string, error) { 28 | res, err := svc.DescribeDhcpOptions(ctx.Context, &ec2.DescribeDhcpOptionsInput{ 29 | MaxResults: aws.Int32(100), 30 | NextToken: nt, 31 | }) 32 | if err != nil { 33 | return nil, err 34 | } 35 | for _, v := range res.DhcpOptions { 36 | r := resource.New(ctx, resource.Ec2DHCPOption, v.DhcpOptionsId, v.DhcpOptionsId, v) 37 | rg.AddResource(r) 38 | } 39 | return res.NextToken, nil 40 | }) 41 | return rg, err 42 | } 43 | -------------------------------------------------------------------------------- /lister/ec2_eip.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/service/ec2" 5 | "github.com/trek10inc/awsets/context" 6 | "github.com/trek10inc/awsets/resource" 7 | ) 8 | 9 | type AWSEc2Eip struct { 10 | } 11 | 12 | func init() { 13 | i := AWSEc2Eip{} 14 | listers = append(listers, i) 15 | } 16 | 17 | func (l AWSEc2Eip) Types() []resource.ResourceType { 18 | return []resource.ResourceType{resource.Ec2Eip} 19 | } 20 | 21 | func (l AWSEc2Eip) List(ctx context.AWSetsCtx) (*resource.Group, error) { 22 | svc := ec2.NewFromConfig(ctx.AWSCfg) 23 | 24 | rg := resource.NewGroup() 25 | res, err := svc.DescribeAddresses(ctx.Context, &ec2.DescribeAddressesInput{}) 26 | if err != nil { 27 | return rg, err 28 | } 29 | 30 | for _, v := range res.Addresses { 31 | r := resource.New(ctx, resource.Ec2Eip, v.PublicIp, v.PublicIp, v) 32 | r.AddRelation(resource.Ec2Instance, v.InstanceId, "") 33 | rg.AddResource(r) 34 | } 35 | return rg, nil 36 | } 37 | -------------------------------------------------------------------------------- /lister/ec2_flowlog.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/ec2" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSEc2FlowLog struct { 11 | } 12 | 13 | func init() { 14 | i := AWSEc2FlowLog{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSEc2FlowLog) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.Ec2FlowLog} 20 | } 21 | 22 | func (l AWSEc2FlowLog) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := ec2.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeFlowLogs(ctx.Context, &ec2.DescribeFlowLogsInput{ 28 | MaxResults: aws.Int32(1000), 29 | NextToken: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, v := range res.FlowLogs { 35 | r := resource.New(ctx, resource.Ec2FlowLog, v.FlowLogId, v.FlowLogId, v) 36 | r.AddRelation(resource.LogGroup, v.LogGroupName, "") 37 | rg.AddResource(r) 38 | } 39 | return res.NextToken, nil 40 | }) 41 | return rg, err 42 | } 43 | -------------------------------------------------------------------------------- /lister/ec2_image.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/ec2" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSEc2Image struct { 12 | } 13 | 14 | func init() { 15 | i := AWSEc2Image{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSEc2Image) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.Ec2Image} 21 | } 22 | 23 | func (l AWSEc2Image) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | 25 | svc := ec2.NewFromConfig(ctx.AWSCfg) 26 | 27 | rg := resource.NewGroup() 28 | 29 | images, err := svc.DescribeImages(ctx.Context, &ec2.DescribeImagesInput{ 30 | Owners: []string{ctx.AccountId}, 31 | }) 32 | if err != nil { 33 | return nil, fmt.Errorf("failed to list ec2 images: %w", err) 34 | } 35 | for _, image := range images.Images { 36 | r := resource.New(ctx, resource.Ec2Image, image.ImageId, image.Name, image) 37 | for _, bm := range image.BlockDeviceMappings { 38 | if bm.Ebs != nil { 39 | r.AddRelation(resource.KmsKey, bm.Ebs.KmsKeyId, "") 40 | r.AddRelation(resource.Ec2Snapshot, bm.Ebs.SnapshotId, "") 41 | } 42 | } 43 | rg.AddResource(r) 44 | } 45 | 46 | return rg, nil 47 | } 48 | -------------------------------------------------------------------------------- /lister/ec2_internetgateway.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/ec2" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSEc2InternetGateway struct { 11 | } 12 | 13 | func init() { 14 | i := AWSEc2InternetGateway{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSEc2InternetGateway) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.Ec2InternetGateway} 20 | } 21 | 22 | func (l AWSEc2InternetGateway) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := ec2.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | 28 | res, err := svc.DescribeInternetGateways(ctx.Context, &ec2.DescribeInternetGatewaysInput{ 29 | MaxResults: aws.Int32(1000), 30 | NextToken: nt, 31 | }) 32 | if err != nil { 33 | return nil, err 34 | } 35 | for _, v := range res.InternetGateways { 36 | r := resource.New(ctx, resource.Ec2InternetGateway, v.InternetGatewayId, v.InternetGatewayId, v) 37 | rg.AddResource(r) 38 | } 39 | return res.NextToken, nil 40 | }) 41 | return rg, err 42 | } 43 | -------------------------------------------------------------------------------- /lister/ec2_keypair.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/service/ec2" 5 | "github.com/trek10inc/awsets/context" 6 | "github.com/trek10inc/awsets/resource" 7 | ) 8 | 9 | type AWSEc2KeyPair struct { 10 | } 11 | 12 | func init() { 13 | i := AWSEc2KeyPair{} 14 | listers = append(listers, i) 15 | } 16 | 17 | func (l AWSEc2KeyPair) Types() []resource.ResourceType { 18 | return []resource.ResourceType{resource.Ec2KeyPair} 19 | } 20 | 21 | func (l AWSEc2KeyPair) List(ctx context.AWSetsCtx) (*resource.Group, error) { 22 | svc := ec2.NewFromConfig(ctx.AWSCfg) 23 | 24 | rg := resource.NewGroup() 25 | res, err := svc.DescribeKeyPairs(ctx.Context, &ec2.DescribeKeyPairsInput{}) 26 | if err != nil { 27 | return rg, err 28 | } 29 | for _, kp := range res.KeyPairs { 30 | r := resource.New(ctx, resource.Ec2KeyPair, kp.KeyName, kp.KeyName, kp) 31 | rg.AddResource(r) 32 | } 33 | return rg, nil 34 | } 35 | -------------------------------------------------------------------------------- /lister/ec2_natgateway.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/ec2" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSEc2NatGateway struct { 11 | } 12 | 13 | func init() { 14 | i := AWSEc2NatGateway{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSEc2NatGateway) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.Ec2NatGateway} 20 | } 21 | 22 | func (l AWSEc2NatGateway) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := ec2.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeNatGateways(ctx.Context, &ec2.DescribeNatGatewaysInput{ 28 | MaxResults: aws.Int32(1000), 29 | NextToken: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, v := range res.NatGateways { 35 | r := resource.New(ctx, resource.Ec2NatGateway, v.NatGatewayId, v.NatGatewayId, v) 36 | if v.SubnetId != nil { 37 | r.AddRelation(resource.Ec2Subnet, v.SubnetId, "") 38 | } 39 | if v.VpcId != nil { 40 | r.AddRelation(resource.Ec2Vpc, v.VpcId, "") 41 | } 42 | for _, gwAddress := range v.NatGatewayAddresses { 43 | r.AddRelation(resource.Ec2NetworkInterface, gwAddress.NetworkInterfaceId, "") 44 | } 45 | rg.AddResource(r) 46 | } 47 | return res.NextToken, nil 48 | }) 49 | return rg, err 50 | } 51 | -------------------------------------------------------------------------------- /lister/ec2_networkacl.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/ec2" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSEc2NetworkACL struct { 11 | } 12 | 13 | func init() { 14 | i := AWSEc2NetworkACL{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSEc2NetworkACL) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.Ec2NetworkACL} 20 | } 21 | 22 | func (l AWSEc2NetworkACL) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := ec2.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeNetworkAcls(ctx.Context, &ec2.DescribeNetworkAclsInput{ 28 | MaxResults: aws.Int32(100), 29 | NextToken: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, nacl := range res.NetworkAcls { 35 | r := resource.New(ctx, resource.Ec2NetworkACL, nacl.NetworkAclId, nacl.NetworkAclId, nacl) 36 | r.AddRelation(resource.Ec2Vpc, nacl.VpcId, "") 37 | for _, a := range nacl.Associations { 38 | r.AddRelation(resource.Ec2Subnet, a.SubnetId, "") 39 | } 40 | rg.AddResource(r) 41 | } 42 | return res.NextToken, nil 43 | }) 44 | return rg, err 45 | } 46 | -------------------------------------------------------------------------------- /lister/ec2_networkinterface.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/ec2" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSEc2NetworkInterface struct { 11 | } 12 | 13 | func init() { 14 | i := AWSEc2NetworkInterface{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSEc2NetworkInterface) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.Ec2NetworkInterface} 20 | } 21 | 22 | func (l AWSEc2NetworkInterface) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := ec2.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeNetworkInterfaces(ctx.Context, &ec2.DescribeNetworkInterfacesInput{ 28 | MaxResults: aws.Int32(100), 29 | NextToken: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, eni := range res.NetworkInterfaces { 35 | r := resource.New(ctx, resource.Ec2NetworkInterface, eni.NetworkInterfaceId, eni.NetworkInterfaceId, eni) 36 | r.AddRelation(resource.Ec2Vpc, eni.VpcId, "") 37 | r.AddRelation(resource.Ec2Subnet, eni.SubnetId, "") 38 | rg.AddResource(r) 39 | } 40 | return res.NextToken, nil 41 | }) 42 | return rg, err 43 | } 44 | -------------------------------------------------------------------------------- /lister/ec2_routetable.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/ec2" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSEc2RouteTable struct { 11 | } 12 | 13 | func init() { 14 | i := AWSEc2RouteTable{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSEc2RouteTable) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.Ec2RouteTable} 20 | } 21 | 22 | func (l AWSEc2RouteTable) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := ec2.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeRouteTables(ctx.Context, &ec2.DescribeRouteTablesInput{ 28 | MaxResults: aws.Int32(100), 29 | NextToken: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, v := range res.RouteTables { 35 | r := resource.New(ctx, resource.Ec2RouteTable, v.RouteTableId, v.RouteTableId, v) 36 | r.AddRelation(resource.Ec2Vpc, v.VpcId, "") 37 | for _, a := range v.Associations { 38 | r.AddRelation(resource.Ec2Subnet, a.SubnetId, "") 39 | } 40 | for _, route := range v.Routes { 41 | r.AddRelation(resource.Ec2Instance, route.InstanceId, "") 42 | r.AddRelation(resource.Ec2NatGateway, route.NatGatewayId, "") 43 | r.AddRelation(resource.Ec2VpcPeering, route.VpcPeeringConnectionId, "") 44 | r.AddRelation(resource.Ec2TransitGateway, route.TransitGatewayId, "") 45 | r.AddRelation(resource.Ec2NetworkInterface, route.NetworkInterfaceId, "") 46 | } 47 | rg.AddResource(r) 48 | } 49 | return res.NextToken, nil 50 | }) 51 | return rg, err 52 | } 53 | -------------------------------------------------------------------------------- /lister/ec2_securitygroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/ec2" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSEc2SecurityGroup struct { 11 | } 12 | 13 | func init() { 14 | i := AWSEc2SecurityGroup{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSEc2SecurityGroup) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.Ec2SecurityGroup} 20 | } 21 | 22 | func (l AWSEc2SecurityGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := ec2.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeSecurityGroups(ctx.Context, &ec2.DescribeSecurityGroupsInput{ 28 | MaxResults: aws.Int32(1000), 29 | NextToken: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, v := range res.SecurityGroups { 35 | r := resource.New(ctx, resource.Ec2SecurityGroup, v.GroupId, v.GroupName, v) 36 | if v.VpcId != nil { 37 | r.AddRelation(resource.Ec2Vpc, v.VpcId, "") 38 | } 39 | rg.AddResource(r) 40 | } 41 | return res.NextToken, nil 42 | }) 43 | return rg, err 44 | } 45 | -------------------------------------------------------------------------------- /lister/ec2_snapshot.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/ec2" 6 | "github.com/aws/aws-sdk-go-v2/service/ec2/types" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSEc2Snapshot struct { 12 | } 13 | 14 | func init() { 15 | i := AWSEc2Snapshot{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSEc2Snapshot) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.Ec2Snapshot} 21 | } 22 | 23 | func (l AWSEc2Snapshot) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := ec2.NewFromConfig(ctx.AWSCfg) 25 | 26 | rg := resource.NewGroup() 27 | err := Paginator(func(nt *string) (*string, error) { 28 | res, err := svc.DescribeSnapshots(ctx.Context, &ec2.DescribeSnapshotsInput{ 29 | Filters: []types.Filter{{ 30 | Name: aws.String("owner-id"), 31 | Values: []string{ctx.AccountId}, 32 | }}, 33 | MaxResults: aws.Int32(100), 34 | NextToken: nt, 35 | }) 36 | if err != nil { 37 | return nil, err 38 | } 39 | for _, v := range res.Snapshots { 40 | r := resource.New(ctx, resource.Ec2Snapshot, v.SnapshotId, v.SnapshotId, v) 41 | r.AddARNRelation(resource.KmsKey, v.KmsKeyId) 42 | r.AddRelation(resource.Ec2Volume, v.VolumeId, "") 43 | rg.AddResource(r) 44 | } 45 | return res.NextToken, nil 46 | }) 47 | return rg, err 48 | } 49 | -------------------------------------------------------------------------------- /lister/ec2_subnet.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/ec2" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSEc2Subnet struct { 11 | } 12 | 13 | func init() { 14 | i := AWSEc2Subnet{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSEc2Subnet) Types() []resource.ResourceType { 19 | return []resource.ResourceType{ 20 | resource.Ec2Subnet, 21 | } 22 | } 23 | 24 | func (l AWSEc2Subnet) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | svc := ec2.NewFromConfig(ctx.AWSCfg) 26 | 27 | rg := resource.NewGroup() 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.DescribeSubnets(ctx.Context, &ec2.DescribeSubnetsInput{ 30 | MaxResults: aws.Int32(100), 31 | NextToken: nt, 32 | }) 33 | if err != nil { 34 | return nil, err 35 | } 36 | for _, v := range res.Subnets { 37 | r := resource.New(ctx, resource.Ec2Subnet, v.SubnetId, v.SubnetArn, v) 38 | r.AddRelation(resource.Ec2Vpc, v.VpcId, "") 39 | rg.AddResource(r) 40 | } 41 | return res.NextToken, nil 42 | }) 43 | return rg, err 44 | } 45 | -------------------------------------------------------------------------------- /lister/ec2_volume.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/ec2" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSEc2Volume struct { 11 | } 12 | 13 | func init() { 14 | i := AWSEc2Volume{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSEc2Volume) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.Ec2Volume} 20 | } 21 | 22 | func (l AWSEc2Volume) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := ec2.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeVolumes(ctx.Context, &ec2.DescribeVolumesInput{ 28 | MaxResults: aws.Int32(100), 29 | NextToken: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, v := range res.Volumes { 35 | r := resource.New(ctx, resource.Ec2Volume, v.VolumeId, v.VolumeId, v) 36 | r.AddARNRelation(resource.KmsKey, v.KmsKeyId) 37 | for _, va := range v.Attachments { 38 | r.AddRelation(resource.Ec2Instance, va.InstanceId, "") 39 | } 40 | rg.AddResource(r) 41 | } 42 | return res.NextToken, nil 43 | }) 44 | return rg, err 45 | } 46 | -------------------------------------------------------------------------------- /lister/ec2_vpc.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/ec2" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSEc2Vpc struct { 11 | } 12 | 13 | func init() { 14 | i := AWSEc2Vpc{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSEc2Vpc) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.Ec2Vpc} 20 | } 21 | 22 | func (l AWSEc2Vpc) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := ec2.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeVpcs(ctx.Context, &ec2.DescribeVpcsInput{ 28 | MaxResults: aws.Int32(100), 29 | NextToken: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, v := range res.Vpcs { 35 | r := resource.New(ctx, resource.Ec2Vpc, v.VpcId, v.VpcId, v) 36 | r.AddRelation(resource.Ec2DHCPOption, v.DhcpOptionsId, "") 37 | rg.AddResource(r) 38 | } 39 | return res.NextToken, nil 40 | }) 41 | return rg, err 42 | } 43 | -------------------------------------------------------------------------------- /lister/ec2_vpcpeering.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/ec2" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSEc2VpcPeering struct { 11 | } 12 | 13 | func init() { 14 | i := AWSEc2VpcPeering{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSEc2VpcPeering) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.Ec2VpcPeering} 20 | } 21 | 22 | func (l AWSEc2VpcPeering) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := ec2.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeVpcPeeringConnections(ctx.Context, &ec2.DescribeVpcPeeringConnectionsInput{ 28 | MaxResults: aws.Int32(100), 29 | NextToken: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, v := range res.VpcPeeringConnections { 35 | r := resource.New(ctx, resource.Ec2VpcPeering, v.VpcPeeringConnectionId, v.VpcPeeringConnectionId, v) 36 | if v.AccepterVpcInfo != nil { 37 | r.AddCrossRelation(ctx.AccountId, v.AccepterVpcInfo.Region, resource.Ec2Vpc, v.AccepterVpcInfo.VpcId, "") 38 | } 39 | if v.RequesterVpcInfo != nil { 40 | r.AddCrossRelation(ctx.AccountId, v.RequesterVpcInfo.Region, resource.Ec2Vpc, v.RequesterVpcInfo.VpcId, "") 41 | } 42 | rg.AddResource(r) 43 | } 44 | return res.NextToken, nil 45 | }) 46 | return rg, err 47 | } 48 | -------------------------------------------------------------------------------- /lister/ec2_vpnconnection.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/ec2" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSEc2VpnConnection struct { 12 | } 13 | 14 | func init() { 15 | i := AWSEc2VpnConnection{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSEc2VpnConnection) Types() []resource.ResourceType { 20 | return []resource.ResourceType{ 21 | resource.Ec2VpnConnection, 22 | } 23 | } 24 | 25 | func (l AWSEc2VpnConnection) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | svc := ec2.NewFromConfig(ctx.AWSCfg) 27 | 28 | rg := resource.NewGroup() 29 | res, err := svc.DescribeVpnConnections(ctx.Context, &ec2.DescribeVpnConnectionsInput{ 30 | //VpnConnectionIds: nil, 31 | }) 32 | if err != nil { 33 | return nil, fmt.Errorf("failed to get vpn connections: %w", err) 34 | } 35 | for _, v := range res.VpnConnections { 36 | r := resource.New(ctx, resource.Ec2VpnConnection, v.VpnConnectionId, v.VpnConnectionId, v) 37 | r.AddRelation(resource.Ec2CustomerGateway, v.CustomerGatewayId, "") 38 | r.AddRelation(resource.Ec2TransitGateway, v.TransitGatewayId, "") 39 | r.AddRelation(resource.Ec2VpnGateway, v.VpnGatewayId, "") 40 | rg.AddResource(r) 41 | } 42 | 43 | return rg, err 44 | } 45 | -------------------------------------------------------------------------------- /lister/ec2_vpngateway.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/ec2" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSEc2VpnGateway struct { 12 | } 13 | 14 | func init() { 15 | i := AWSEc2VpnGateway{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSEc2VpnGateway) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.Ec2VpnGateway} 21 | } 22 | 23 | func (l AWSEc2VpnGateway) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := ec2.NewFromConfig(ctx.AWSCfg) 25 | 26 | rg := resource.NewGroup() 27 | 28 | gateways, err := svc.DescribeVpnGateways(ctx.Context, &ec2.DescribeVpnGatewaysInput{}) 29 | if err != nil { 30 | return nil, fmt.Errorf("failed to list vpn gateways: %w", err) 31 | } 32 | 33 | for _, v := range gateways.VpnGateways { 34 | r := resource.New(ctx, resource.Ec2VpnGateway, v.VpnGatewayId, v.VpnGatewayId, v) 35 | for _, a := range v.VpcAttachments { 36 | r.AddRelation(resource.Ec2Vpc, a.VpcId, "") 37 | } 38 | rg.AddResource(r) 39 | } 40 | 41 | return rg, nil 42 | } 43 | -------------------------------------------------------------------------------- /lister/ecr_repository.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/ecr" 6 | "github.com/trek10inc/awsets/arn" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSEcrRepository struct { 12 | } 13 | 14 | func init() { 15 | i := AWSEcrRepository{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSEcrRepository) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.EcrRepository} 21 | } 22 | 23 | func (l AWSEcrRepository) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := ecr.NewFromConfig(ctx.AWSCfg) 25 | 26 | rg := resource.NewGroup() 27 | err := Paginator(func(nt *string) (*string, error) { 28 | res, err := svc.DescribeRepositories(ctx.Context, &ecr.DescribeRepositoriesInput{ 29 | MaxResults: aws.Int32(1000), 30 | NextToken: nt, 31 | }) 32 | if err != nil { 33 | return nil, err 34 | } 35 | for _, repo := range res.Repositories { 36 | repoArn := arn.ParseP(repo.RepositoryArn) 37 | r := resource.New(ctx, resource.EcrRepository, repoArn.ResourceId, repo.RepositoryName, repo) 38 | rg.AddResource(r) 39 | } 40 | return res.NextToken, nil 41 | }) 42 | return rg, err 43 | } 44 | -------------------------------------------------------------------------------- /lister/elasticache_parametergroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/elasticache" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSElasticacheParameterGroup struct { 11 | } 12 | 13 | func init() { 14 | i := AWSElasticacheParameterGroup{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSElasticacheParameterGroup) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.ElasticacheParameterGroup} 20 | } 21 | 22 | func (l AWSElasticacheParameterGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := elasticache.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeCacheParameterGroups(ctx.Context, &elasticache.DescribeCacheParameterGroupsInput{ 28 | MaxRecords: aws.Int32(100), 29 | Marker: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, group := range res.CacheParameterGroups { 35 | 36 | r := resource.New(ctx, resource.ElasticacheParameterGroup, group.CacheParameterGroupName, group.CacheParameterGroupName, group) 37 | rg.AddResource(r) 38 | } 39 | return res.Marker, nil 40 | }) 41 | return rg, err 42 | } 43 | -------------------------------------------------------------------------------- /lister/elasticache_replicationgroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/elasticache" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSElasticacheReplicationGroup struct { 11 | } 12 | 13 | func init() { 14 | i := AWSElasticacheReplicationGroup{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSElasticacheReplicationGroup) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.ElasticacheReplicationGroup} 20 | } 21 | 22 | func (l AWSElasticacheReplicationGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := elasticache.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeReplicationGroups(ctx.Context, &elasticache.DescribeReplicationGroupsInput{ 28 | MaxRecords: aws.Int32(100), 29 | Marker: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, group := range res.ReplicationGroups { 35 | r := resource.New(ctx, resource.ElasticacheReplicationGroup, group.ReplicationGroupId, group.ReplicationGroupId, group) 36 | 37 | if group.KmsKeyId != nil && *group.KmsKeyId != "" { 38 | r.AddRelation(resource.KmsKey, group.KmsKeyId, "") 39 | } 40 | 41 | for _, mc := range group.MemberClusters { 42 | r.AddRelation(resource.ElasticacheCluster, mc, "") 43 | } 44 | 45 | rg.AddResource(r) 46 | } 47 | return res.Marker, nil 48 | }) 49 | return rg, err 50 | } 51 | -------------------------------------------------------------------------------- /lister/elasticache_snapshot.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/elasticache" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSElasticacheSnapshot struct { 11 | } 12 | 13 | func init() { 14 | i := AWSElasticacheSnapshot{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSElasticacheSnapshot) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.ElasticacheSnapshot} 20 | } 21 | 22 | func (l AWSElasticacheSnapshot) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := elasticache.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeSnapshots(ctx.Context, &elasticache.DescribeSnapshotsInput{ 28 | MaxRecords: aws.Int32(50), 29 | Marker: nt, 30 | }) 31 | 32 | if err != nil { 33 | return nil, err 34 | } 35 | for _, v := range res.Snapshots { 36 | r := resource.New(ctx, resource.ElasticacheSnapshot, v.SnapshotName, v.SnapshotName, v) 37 | r.AddRelation(resource.Ec2Vpc, v.VpcId, "") 38 | r.AddRelation(resource.KmsKey, v.KmsKeyId, "") 39 | r.AddRelation(resource.ElasticacheParameterGroup, v.CacheParameterGroupName, "") 40 | r.AddRelation(resource.ElasticacheSubnetGroup, v.CacheSubnetGroupName, "") 41 | r.AddRelation(resource.ElasticacheCluster, v.CacheClusterId, "") 42 | r.AddRelation(resource.ElasticacheReplicationGroup, v.ReplicationGroupId, "") 43 | 44 | rg.AddResource(r) 45 | } 46 | return res.Marker, nil 47 | }) 48 | return rg, err 49 | } 50 | -------------------------------------------------------------------------------- /lister/elasticache_subnetgroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/elasticache" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSElasticacheSubnetGroup struct { 11 | } 12 | 13 | func init() { 14 | i := AWSElasticacheSubnetGroup{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSElasticacheSubnetGroup) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.ElasticacheSubnetGroup} 20 | } 21 | 22 | func (l AWSElasticacheSubnetGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := elasticache.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeCacheSubnetGroups(ctx.Context, &elasticache.DescribeCacheSubnetGroupsInput{ 28 | MaxRecords: aws.Int32(100), 29 | Marker: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, sg := range res.CacheSubnetGroups { 35 | r := resource.New(ctx, resource.ElasticacheSubnetGroup, sg.CacheSubnetGroupName, sg.CacheSubnetGroupName, sg) 36 | if sg.VpcId != nil && *sg.VpcId != "" { 37 | r.AddRelation(resource.Ec2Vpc, sg.VpcId, "") 38 | } 39 | for _, subnet := range sg.Subnets { 40 | r.AddRelation(resource.Ec2Subnet, subnet.SubnetIdentifier, "") 41 | } 42 | rg.AddResource(r) 43 | } 44 | return res.Marker, nil 45 | }) 46 | return rg, err 47 | } 48 | -------------------------------------------------------------------------------- /lister/elasticbeanstalk_application.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSElasticBeanstalkApplication struct { 12 | } 13 | 14 | func init() { 15 | i := AWSElasticBeanstalkApplication{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSElasticBeanstalkApplication) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.ElasticBeanstalkApplication} 21 | } 22 | 23 | func (l AWSElasticBeanstalkApplication) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | 25 | svc := elasticbeanstalk.NewFromConfig(ctx.AWSCfg) 26 | 27 | rg := resource.NewGroup() 28 | 29 | apps, err := svc.DescribeApplications(ctx.Context, &elasticbeanstalk.DescribeApplicationsInput{}) 30 | if err != nil { 31 | return nil, fmt.Errorf("failed to list elastic beanstalk applications: %w", err) 32 | } 33 | for _, v := range apps.Applications { 34 | r := resource.New(ctx, resource.ElasticBeanstalkApplication, v.ApplicationName, v.ApplicationName, v) 35 | rg.AddResource(r) 36 | } 37 | 38 | return rg, nil 39 | } 40 | -------------------------------------------------------------------------------- /lister/elb_loadbalancer.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" 5 | "github.com/trek10inc/awsets/context" 6 | "github.com/trek10inc/awsets/resource" 7 | ) 8 | 9 | type AWSElbLoadbalancer struct { 10 | } 11 | 12 | func init() { 13 | i := AWSElbLoadbalancer{} 14 | listers = append(listers, i) 15 | } 16 | 17 | func (l AWSElbLoadbalancer) Types() []resource.ResourceType { 18 | return []resource.ResourceType{resource.ElbLoadBalancer} 19 | } 20 | 21 | func (l AWSElbLoadbalancer) List(ctx context.AWSetsCtx) (*resource.Group, error) { 22 | svc := elasticloadbalancing.NewFromConfig(ctx.AWSCfg) 23 | 24 | rg := resource.NewGroup() 25 | err := Paginator(func(nt *string) (*string, error) { 26 | res, err := svc.DescribeLoadBalancers(ctx.Context, &elasticloadbalancing.DescribeLoadBalancersInput{ 27 | Marker: nt, 28 | }) 29 | if err != nil { 30 | return nil, err 31 | } 32 | for _, v := range res.LoadBalancerDescriptions { 33 | r := resource.New(ctx, resource.ElbLoadBalancer, v.LoadBalancerName, v.LoadBalancerName, v) 34 | 35 | if v.VPCId != nil && *v.VPCId != "" { 36 | r.AddRelation(resource.Ec2Vpc, v.VPCId, "") 37 | } 38 | for _, i := range v.Instances { 39 | r.AddRelation(resource.Ec2Instance, i.InstanceId, "") 40 | } 41 | for _, s := range v.Subnets { 42 | r.AddRelation(resource.Ec2Subnet, s, "") 43 | } 44 | for _, sg := range v.SecurityGroups { 45 | r.AddRelation(resource.Ec2SecurityGroup, sg, "") 46 | } 47 | rg.AddResource(r) 48 | } 49 | return res.NextMarker, nil 50 | }) 51 | return rg, err 52 | } 53 | -------------------------------------------------------------------------------- /lister/emr_securityconfiguration.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/emr" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSEMRSecurityConfiguration struct { 12 | } 13 | 14 | func init() { 15 | i := AWSEMRSecurityConfiguration{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSEMRSecurityConfiguration) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.EmrSecurityConfiguration} 21 | } 22 | 23 | func (l AWSEMRSecurityConfiguration) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := emr.NewFromConfig(ctx.AWSCfg) 25 | 26 | rg := resource.NewGroup() 27 | err := Paginator(func(nt *string) (*string, error) { 28 | res, err := svc.ListSecurityConfigurations(ctx.Context, &emr.ListSecurityConfigurationsInput{}) 29 | if err != nil { 30 | return nil, err 31 | } 32 | for _, id := range res.SecurityConfigurations { 33 | v, err := svc.DescribeSecurityConfiguration(ctx.Context, &emr.DescribeSecurityConfigurationInput{ 34 | Name: id.Name, 35 | }) 36 | if err != nil { 37 | return nil, fmt.Errorf("failed to describe security config %s: %w", *id.Name, err) 38 | } 39 | r := resource.New(ctx, resource.EmrSecurityConfiguration, v.Name, v.Name, v) 40 | rg.AddResource(r) 41 | } 42 | return res.Marker, nil 43 | }) 44 | return rg, err 45 | } 46 | -------------------------------------------------------------------------------- /lister/fsx_backup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/fsx" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSFSxBackup struct { 11 | } 12 | 13 | func init() { 14 | i := AWSFSxBackup{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSFSxBackup) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.FSxBackup} 20 | } 21 | 22 | func (l AWSFSxBackup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := fsx.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeBackups(ctx.Context, &fsx.DescribeBackupsInput{ 28 | MaxResults: aws.Int32(100), 29 | NextToken: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, v := range res.Backups { 35 | r := resource.New(ctx, resource.FSxBackup, v.BackupId, v.BackupId, v) 36 | r.AddARNRelation(resource.KmsKey, v.KmsKeyId) 37 | if v.FileSystem != nil { 38 | r.AddRelation(resource.FSxFileSystem, v.FileSystem.FileSystemId, "") 39 | } 40 | rg.AddResource(r) 41 | } 42 | return res.NextToken, nil 43 | }) 44 | return rg, err 45 | } 46 | -------------------------------------------------------------------------------- /lister/fsx_filesystem.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/fsx" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSFSxFileSystem struct { 11 | } 12 | 13 | func init() { 14 | i := AWSFSxFileSystem{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSFSxFileSystem) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.FSxFileSystem} 20 | } 21 | 22 | func (l AWSFSxFileSystem) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := fsx.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeFileSystems(ctx.Context, &fsx.DescribeFileSystemsInput{ 28 | MaxResults: aws.Int32(100), 29 | NextToken: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, v := range res.FileSystems { 35 | r := resource.New(ctx, resource.FSxFileSystem, v.FileSystemId, v.FileSystemId, v) 36 | r.AddRelation(resource.Ec2Vpc, v.VpcId, "") 37 | r.AddARNRelation(resource.KmsKey, v.KmsKeyId) 38 | for _, sn := range v.SubnetIds { 39 | r.AddRelation(resource.Ec2Subnet, sn, "") 40 | } 41 | for _, eni := range v.NetworkInterfaceIds { 42 | r.AddRelation(resource.Ec2NetworkInterface, eni, "") 43 | } 44 | rg.AddResource(r) 45 | } 46 | return res.NextToken, nil 47 | }) 48 | return rg, err 49 | } 50 | -------------------------------------------------------------------------------- /lister/glue_classifier.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/glue" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSGlueClassifier struct { 11 | } 12 | 13 | func init() { 14 | i := AWSGlueClassifier{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSGlueClassifier) Types() []resource.ResourceType { 19 | return []resource.ResourceType{ 20 | resource.GlueClassifier, 21 | } 22 | } 23 | 24 | func (l AWSGlueClassifier) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | svc := glue.NewFromConfig(ctx.AWSCfg) 26 | 27 | rg := resource.NewGroup() 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.GetClassifiers(ctx.Context, &glue.GetClassifiersInput{ 30 | MaxResults: aws.Int32(100), 31 | NextToken: nt, 32 | }) 33 | if err != nil { 34 | return nil, err 35 | } 36 | for _, v := range res.Classifiers { 37 | 38 | if x := v.CsvClassifier; x != nil { 39 | r := resource.NewVersion(ctx, resource.GlueClassifier, x.Name, x.Name, x.Version, x) 40 | rg.AddResource(r) 41 | } else if x := v.GrokClassifier; x != nil { 42 | r := resource.NewVersion(ctx, resource.GlueClassifier, x.Name, x.Name, x.Version, x) 43 | rg.AddResource(r) 44 | } else if x := v.JsonClassifier; x != nil { 45 | r := resource.NewVersion(ctx, resource.GlueClassifier, x.Name, x.Name, x.Version, x) 46 | rg.AddResource(r) 47 | } else if x := v.XMLClassifier; x != nil { 48 | r := resource.NewVersion(ctx, resource.GlueClassifier, x.Name, x.Name, x.Version, x) 49 | rg.AddResource(r) 50 | } 51 | } 52 | return res.NextToken, nil 53 | }) 54 | return rg, err 55 | } 56 | -------------------------------------------------------------------------------- /lister/glue_connection.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/glue" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSGlueConnection struct { 11 | } 12 | 13 | func init() { 14 | i := AWSGlueConnection{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSGlueConnection) Types() []resource.ResourceType { 19 | return []resource.ResourceType{ 20 | resource.GlueConnection, 21 | } 22 | } 23 | 24 | func (l AWSGlueConnection) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | svc := glue.NewFromConfig(ctx.AWSCfg) 26 | 27 | rg := resource.NewGroup() 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.GetConnections(ctx.Context, &glue.GetConnectionsInput{ 30 | HidePassword: true, 31 | MaxResults: aws.Int32(100), 32 | NextToken: nt, 33 | }) 34 | if err != nil { 35 | return nil, err 36 | } 37 | for _, v := range res.ConnectionList { 38 | r := resource.New(ctx, resource.GlueConnection, v.Name, v.Name, v) 39 | rg.AddResource(r) 40 | } 41 | return res.NextToken, nil 42 | }) 43 | return rg, err 44 | } 45 | -------------------------------------------------------------------------------- /lister/glue_crawler.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/glue" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSGlueCrawler struct { 11 | } 12 | 13 | func init() { 14 | i := AWSGlueCrawler{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSGlueCrawler) Types() []resource.ResourceType { 19 | return []resource.ResourceType{ 20 | resource.GlueCrawler, 21 | } 22 | } 23 | 24 | func (l AWSGlueCrawler) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | svc := glue.NewFromConfig(ctx.AWSCfg) 26 | 27 | rg := resource.NewGroup() 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.GetCrawlers(ctx.Context, &glue.GetCrawlersInput{ 30 | MaxResults: aws.Int32(100), 31 | NextToken: nt, 32 | }) 33 | if err != nil { 34 | return nil, err 35 | } 36 | for _, v := range res.Crawlers { 37 | r := resource.NewVersion(ctx, resource.GlueCrawler, v.Name, v.Name, v.Version, v) 38 | r.AddRelation(resource.IamRole, v.Role, "") 39 | r.AddRelation(resource.GlueDatabase, v.DatabaseName, "") 40 | // TODO: review relationships to s3, ddb, jdbc 41 | 42 | rg.AddResource(r) 43 | } 44 | return res.NextToken, nil 45 | }) 46 | return rg, err 47 | } 48 | -------------------------------------------------------------------------------- /lister/glue_workflow.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/glue" 7 | 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | 11 | "github.com/aws/aws-sdk-go-v2/aws" 12 | ) 13 | 14 | type AWSGlueWorkflow struct { 15 | } 16 | 17 | func init() { 18 | i := AWSGlueWorkflow{} 19 | listers = append(listers, i) 20 | } 21 | 22 | func (l AWSGlueWorkflow) Types() []resource.ResourceType { 23 | return []resource.ResourceType{ 24 | resource.GlueWorkflow, 25 | } 26 | } 27 | 28 | func (l AWSGlueWorkflow) List(ctx context.AWSetsCtx) (*resource.Group, error) { 29 | svc := glue.NewFromConfig(ctx.AWSCfg) 30 | 31 | rg := resource.NewGroup() 32 | err := Paginator(func(nt *string) (*string, error) { 33 | res, err := svc.ListWorkflows(ctx.Context, &glue.ListWorkflowsInput{ 34 | MaxResults: aws.Int32(25), 35 | }) 36 | if err != nil { 37 | return nil, err 38 | } 39 | if len(res.Workflows) == 0 { 40 | return nil, nil 41 | } 42 | workflows, err := svc.BatchGetWorkflows(ctx.Context, &glue.BatchGetWorkflowsInput{ 43 | IncludeGraph: aws.Bool(true), 44 | Names: res.Workflows, 45 | }) 46 | if err != nil { 47 | return nil, fmt.Errorf("failed to get glue workflows: %w", err) 48 | } 49 | for _, wf := range workflows.Workflows { 50 | r := resource.New(ctx, resource.GlueWorkflow, wf.Name, wf.Name, wf) 51 | rg.AddResource(r) 52 | // TODO: explore nodes/edges 53 | } 54 | return res.NextToken, nil 55 | }) 56 | return rg, err 57 | } 58 | -------------------------------------------------------------------------------- /lister/iam_group.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "sync" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/iam" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | var listGroupsOnce sync.Once 13 | 14 | type AWSIamGroup struct { 15 | } 16 | 17 | func init() { 18 | i := AWSIamGroup{} 19 | listers = append(listers, i) 20 | } 21 | 22 | func (l AWSIamGroup) Types() []resource.ResourceType { 23 | return []resource.ResourceType{resource.IamGroup} 24 | } 25 | 26 | func (l AWSIamGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | svc := iam.NewFromConfig(ctx.AWSCfg) 28 | 29 | rg := resource.NewGroup() 30 | var outerErr error 31 | 32 | listGroupsOnce.Do(func() { 33 | outerErr = Paginator(func(nt *string) (*string, error) { 34 | res, err := svc.ListGroups(ctx.Context, &iam.ListGroupsInput{ 35 | MaxItems: aws.Int32(100), 36 | Marker: nt, 37 | }) 38 | if err != nil { 39 | return nil, err 40 | } 41 | for _, group := range res.Groups { 42 | r := resource.NewGlobal(ctx, resource.IamGroup, group.GroupId, group.GroupName, group) 43 | rg.AddResource(r) 44 | } 45 | return res.Marker, nil 46 | }) 47 | }) 48 | 49 | return rg, outerErr 50 | } 51 | -------------------------------------------------------------------------------- /lister/iam_instanceprofile.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "sync" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/iam" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | var listInstanceProfilesOnce sync.Once 13 | 14 | type AWSIamInstanceProfile struct { 15 | } 16 | 17 | func init() { 18 | i := AWSIamInstanceProfile{} 19 | listers = append(listers, i) 20 | } 21 | 22 | func (l AWSIamInstanceProfile) Types() []resource.ResourceType { 23 | return []resource.ResourceType{resource.IamInstanceProfile} 24 | } 25 | 26 | func (l AWSIamInstanceProfile) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | svc := iam.NewFromConfig(ctx.AWSCfg) 28 | 29 | rg := resource.NewGroup() 30 | var outerErr error 31 | 32 | listInstanceProfilesOnce.Do(func() { 33 | outerErr = Paginator(func(nt *string) (*string, error) { 34 | res, err := svc.ListInstanceProfiles(ctx.Context, &iam.ListInstanceProfilesInput{ 35 | MaxItems: aws.Int32(100), 36 | Marker: nt, 37 | }) 38 | if err != nil { 39 | return nil, err 40 | } 41 | for _, profile := range res.InstanceProfiles { 42 | r := resource.NewGlobal(ctx, resource.IamInstanceProfile, profile.InstanceProfileId, profile.InstanceProfileName, profile) 43 | rg.AddResource(r) 44 | } 45 | return res.Marker, nil 46 | }) 47 | }) 48 | 49 | return rg, outerErr 50 | } 51 | -------------------------------------------------------------------------------- /lister/iam_policy.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "sync" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/iam" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | var listPoliciesOnce sync.Once 13 | 14 | type AWSIamPolicy struct { 15 | } 16 | 17 | func init() { 18 | i := AWSIamPolicy{} 19 | listers = append(listers, i) 20 | } 21 | 22 | func (l AWSIamPolicy) Types() []resource.ResourceType { 23 | return []resource.ResourceType{resource.IamPolicy} 24 | } 25 | 26 | func (l AWSIamPolicy) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | svc := iam.NewFromConfig(ctx.AWSCfg) 28 | 29 | rg := resource.NewGroup() 30 | var outerErr error 31 | 32 | listPoliciesOnce.Do(func() { 33 | outerErr = Paginator(func(nt *string) (*string, error) { 34 | res, err := svc.ListPolicies(ctx.Context, &iam.ListPoliciesInput{ 35 | MaxItems: aws.Int32(100), 36 | Marker: nt, 37 | }) 38 | if err != nil { 39 | return nil, err 40 | } 41 | for _, policy := range res.Policies { 42 | r := resource.NewGlobal(ctx, resource.IamPolicy, policy.PolicyId, policy.PolicyName, policy) 43 | rg.AddResource(r) 44 | } 45 | return res.Marker, nil 46 | }) 47 | }) 48 | 49 | return rg, outerErr 50 | } 51 | -------------------------------------------------------------------------------- /lister/iam_role.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "sync" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/iam" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | var listIAMRolesOnce sync.Once 13 | 14 | type AWSIamRole struct { 15 | } 16 | 17 | func init() { 18 | i := AWSIamRole{} 19 | listers = append(listers, i) 20 | } 21 | 22 | func (l AWSIamRole) Types() []resource.ResourceType { 23 | return []resource.ResourceType{resource.IamRole} 24 | } 25 | 26 | func (l AWSIamRole) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | svc := iam.NewFromConfig(ctx.AWSCfg) 28 | 29 | rg := resource.NewGroup() 30 | var outerErr error 31 | 32 | listIAMRolesOnce.Do(func() { 33 | outerErr = Paginator(func(nt *string) (*string, error) { 34 | res, err := svc.ListRoles(ctx.Context, &iam.ListRolesInput{ 35 | MaxItems: aws.Int32(100), 36 | Marker: nt, 37 | }) 38 | if err != nil { 39 | return nil, err 40 | } 41 | for _, role := range res.Roles { 42 | r := resource.NewGlobal(ctx, resource.IamRole, role.RoleName, role.RoleName, role) 43 | rg.AddResource(r) 44 | } 45 | return res.Marker, nil 46 | }) 47 | }) 48 | 49 | return rg, outerErr 50 | } 51 | -------------------------------------------------------------------------------- /lister/imagebuilder_component.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/imagebuilder" 7 | "github.com/trek10inc/awsets/arn" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSImageBuilderComponent struct { 13 | } 14 | 15 | func init() { 16 | i := AWSImageBuilderComponent{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSImageBuilderComponent) Types() []resource.ResourceType { 21 | return []resource.ResourceType{ 22 | resource.ImageBuilderComponent, 23 | } 24 | } 25 | 26 | func (l AWSImageBuilderComponent) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | 28 | svc := imagebuilder.NewFromConfig(ctx.AWSCfg) 29 | rg := resource.NewGroup() 30 | err := Paginator(func(nt *string) (*string, error) { 31 | res, err := svc.ListComponents(ctx.Context, &imagebuilder.ListComponentsInput{ 32 | MaxResults: 100, 33 | NextToken: nt, 34 | }) 35 | if err != nil { 36 | return nil, fmt.Errorf("failed to list imagebuilder components: %w", err) 37 | } 38 | for _, cv := range res.ComponentVersionList { 39 | v, err := svc.GetComponent(ctx.Context, &imagebuilder.GetComponentInput{ 40 | ComponentBuildVersionArn: cv.Arn, 41 | }) 42 | if err != nil { 43 | return nil, fmt.Errorf("failed to get imagebuilder component %s: %w", *cv.Name, err) 44 | } 45 | cArn := arn.ParseP(v.Component.Arn) 46 | r := resource.NewVersion(ctx, resource.ImageBuilderComponent, cArn.ResourceId, cArn.ResourceVersion, v.Component.Name, v.Component) 47 | r.AddARNRelation(resource.KmsKey, v.Component.KmsKeyId) 48 | rg.AddResource(r) 49 | } 50 | return res.NextToken, nil 51 | }) 52 | return rg, err 53 | } 54 | -------------------------------------------------------------------------------- /lister/imagebuilder_imagepipeline.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/imagebuilder" 7 | "github.com/trek10inc/awsets/arn" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSImageBuilderImagePipeline struct { 13 | } 14 | 15 | func init() { 16 | i := AWSImageBuilderImagePipeline{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSImageBuilderImagePipeline) Types() []resource.ResourceType { 21 | return []resource.ResourceType{ 22 | resource.ImageBuilderImagePipeline, 23 | } 24 | } 25 | 26 | func (l AWSImageBuilderImagePipeline) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | 28 | svc := imagebuilder.NewFromConfig(ctx.AWSCfg) 29 | rg := resource.NewGroup() 30 | err := Paginator(func(nt *string) (*string, error) { 31 | res, err := svc.ListImagePipelines(ctx.Context, &imagebuilder.ListImagePipelinesInput{ 32 | MaxResults: 100, 33 | NextToken: nt, 34 | }) 35 | if err != nil { 36 | return nil, fmt.Errorf("failed to list imagebuilder image pipelines: %w", err) 37 | } 38 | for _, v := range res.ImagePipelineList { 39 | plArn := arn.ParseP(v.Arn) 40 | r := resource.New(ctx, resource.ImageBuilderImagePipeline, plArn.ResourceId, v.Name, v) 41 | r.AddARNRelation(resource.ImageBuilderImageRecipe, v.ImageRecipeArn) 42 | rg.AddResource(r) 43 | } 44 | return res.NextToken, nil 45 | }) 46 | return rg, err 47 | } 48 | -------------------------------------------------------------------------------- /lister/iot_certificate.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/iot" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSIoTCertificate struct { 13 | } 14 | 15 | func init() { 16 | i := AWSIoTCertificate{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSIoTCertificate) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.IoTCertificate} 22 | } 23 | 24 | func (l AWSIoTCertificate) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | 26 | svc := iot.NewFromConfig(ctx.AWSCfg) 27 | rg := resource.NewGroup() 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.ListCertificates(ctx.Context, &iot.ListCertificatesInput{ 30 | PageSize: aws.Int32(100), 31 | Marker: nt, 32 | }) 33 | if err != nil { 34 | return nil, fmt.Errorf("failed to list iot certificates: %w", err) 35 | } 36 | for _, cert := range res.Certificates { 37 | r := resource.New(ctx, resource.IoTCertificate, cert.CertificateId, cert.CertificateId, cert) 38 | rg.AddResource(r) 39 | } 40 | return res.NextMarker, nil 41 | }) 42 | return rg, err 43 | } 44 | -------------------------------------------------------------------------------- /lister/iot_policy.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/iot" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSIoTPolicy struct { 13 | } 14 | 15 | func init() { 16 | i := AWSIoTPolicy{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSIoTPolicy) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.IoTPolicy} 22 | } 23 | 24 | func (l AWSIoTPolicy) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | 26 | svc := iot.NewFromConfig(ctx.AWSCfg) 27 | rg := resource.NewGroup() 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.ListPolicies(ctx.Context, &iot.ListPoliciesInput{ 30 | PageSize: aws.Int32(100), 31 | Marker: nt, 32 | }) 33 | if err != nil { 34 | return nil, fmt.Errorf("failed to list iot policies: %w", err) 35 | } 36 | for _, policy := range res.Policies { 37 | // TODO policy principals 38 | r := resource.New(ctx, resource.IoTPolicy, policy.PolicyName, policy.PolicyName, policy) 39 | rg.AddResource(r) 40 | } 41 | return res.NextMarker, nil 42 | }) 43 | return rg, err 44 | } 45 | -------------------------------------------------------------------------------- /lister/iot_thing.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/iot" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSIoTThing struct { 13 | } 14 | 15 | func init() { 16 | i := AWSIoTThing{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSIoTThing) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.IoTThing} 22 | } 23 | 24 | func (l AWSIoTThing) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | 26 | svc := iot.NewFromConfig(ctx.AWSCfg) 27 | rg := resource.NewGroup() 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.ListThings(ctx.Context, &iot.ListThingsInput{ 30 | MaxResults: aws.Int32(100), 31 | NextToken: nt, 32 | }) 33 | if err != nil { 34 | return nil, fmt.Errorf("failed to list iot thing: %w", err) 35 | } 36 | for _, thing := range res.Things { 37 | r := resource.New(ctx, resource.IoTThing, thing.ThingName, thing.ThingName, thing) 38 | r.AddRelation(resource.IoTThingType, thing.ThingTypeName, "") 39 | rg.AddResource(r) 40 | } 41 | return res.NextToken, nil 42 | }) 43 | return rg, err 44 | } 45 | -------------------------------------------------------------------------------- /lister/iot_thinggroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/iot" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSIoTThingGroup struct { 13 | } 14 | 15 | func init() { 16 | i := AWSIoTThingGroup{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSIoTThingGroup) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.IoTThingGroup} 22 | } 23 | 24 | func (l AWSIoTThingGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | 26 | svc := iot.NewFromConfig(ctx.AWSCfg) 27 | rg := resource.NewGroup() 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.ListThingGroups(ctx.Context, &iot.ListThingGroupsInput{ 30 | MaxResults: aws.Int32(100), 31 | NextToken: nt, 32 | }) 33 | if err != nil { 34 | return nil, fmt.Errorf("failed to list iot thing groups: %w", err) 35 | } 36 | for _, group := range res.ThingGroups { 37 | r := resource.New(ctx, resource.IoTThingGroup, group.GroupName, group.GroupName, group) 38 | rg.AddResource(r) 39 | } 40 | return res.NextToken, nil 41 | }) 42 | return rg, err 43 | } 44 | -------------------------------------------------------------------------------- /lister/iot_thingtype.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/iot" 8 | "github.com/trek10inc/awsets/arn" 9 | "github.com/trek10inc/awsets/context" 10 | "github.com/trek10inc/awsets/resource" 11 | ) 12 | 13 | type AWSIoTThingType struct { 14 | } 15 | 16 | func init() { 17 | i := AWSIoTThingType{} 18 | listers = append(listers, i) 19 | } 20 | 21 | func (l AWSIoTThingType) Types() []resource.ResourceType { 22 | return []resource.ResourceType{resource.IoTThingType} 23 | } 24 | 25 | func (l AWSIoTThingType) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | 27 | svc := iot.NewFromConfig(ctx.AWSCfg) 28 | rg := resource.NewGroup() 29 | err := Paginator(func(nt *string) (*string, error) { 30 | res, err := svc.ListThingTypes(ctx.Context, &iot.ListThingTypesInput{ 31 | MaxResults: aws.Int32(100), 32 | NextToken: nt, 33 | }) 34 | if err != nil { 35 | return nil, fmt.Errorf("failed to list iot thing types: %w", err) 36 | } 37 | for _, thingType := range res.ThingTypes { 38 | ttArn := arn.ParseP(thingType.ThingTypeArn) 39 | r := resource.New(ctx, resource.IoTThingType, ttArn.ResourceId, thingType.ThingTypeName, thingType) 40 | rg.AddResource(r) 41 | } 42 | return res.NextToken, nil 43 | }) 44 | return rg, err 45 | } 46 | -------------------------------------------------------------------------------- /lister/iot_topicrule.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/iot" 8 | "github.com/trek10inc/awsets/arn" 9 | "github.com/trek10inc/awsets/context" 10 | "github.com/trek10inc/awsets/resource" 11 | ) 12 | 13 | type AWSIoTTopicRule struct { 14 | } 15 | 16 | func init() { 17 | i := AWSIoTTopicRule{} 18 | listers = append(listers, i) 19 | } 20 | 21 | func (l AWSIoTTopicRule) Types() []resource.ResourceType { 22 | return []resource.ResourceType{resource.IotTopicRule} 23 | } 24 | 25 | func (l AWSIoTTopicRule) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | 27 | svc := iot.NewFromConfig(ctx.AWSCfg) 28 | 29 | rg := resource.NewGroup() 30 | err := Paginator(func(nt *string) (*string, error) { 31 | res, err := svc.ListTopicRules(ctx.Context, &iot.ListTopicRulesInput{ 32 | MaxResults: aws.Int32(100), 33 | NextToken: nt, 34 | }) 35 | if err != nil { 36 | return nil, fmt.Errorf("failed to list iot topic rules: %w", err) 37 | } 38 | for _, rule := range res.Rules { 39 | ruleArn := arn.ParseP(rule.RuleArn) 40 | r := resource.New(ctx, resource.IotTopicRule, ruleArn.ResourceId, rule.RuleName, rule) 41 | 42 | rg.AddResource(r) 43 | } 44 | return res.NextToken, nil 45 | }) 46 | return rg, err 47 | } 48 | -------------------------------------------------------------------------------- /lister/iot_topicruledestination.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/iot" 8 | "github.com/trek10inc/awsets/arn" 9 | "github.com/trek10inc/awsets/context" 10 | "github.com/trek10inc/awsets/resource" 11 | ) 12 | 13 | type AWSIoTTopicRuleDestination struct { 14 | } 15 | 16 | func init() { 17 | i := AWSIoTTopicRuleDestination{} 18 | listers = append(listers, i) 19 | } 20 | 21 | func (l AWSIoTTopicRuleDestination) Types() []resource.ResourceType { 22 | return []resource.ResourceType{resource.IotTopicRuleDestination} 23 | } 24 | 25 | func (l AWSIoTTopicRuleDestination) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | 27 | svc := iot.NewFromConfig(ctx.AWSCfg) 28 | 29 | rg := resource.NewGroup() 30 | err := Paginator(func(nt *string) (*string, error) { 31 | res, err := svc.ListTopicRuleDestinations(ctx.Context, &iot.ListTopicRuleDestinationsInput{ 32 | MaxResults: aws.Int32(100), 33 | NextToken: nt, 34 | }) 35 | if err != nil { 36 | return nil, fmt.Errorf("failed to list iot topic rule destinations: %w", err) 37 | } 38 | for _, destination := range res.DestinationSummaries { 39 | dArn := arn.ParseP(destination.Arn) 40 | r := resource.New(ctx, resource.IotTopicRuleDestination, dArn.ResourceId, dArn.ResourceId, destination) 41 | 42 | rg.AddResource(r) 43 | } 44 | return res.NextToken, nil 45 | }) 46 | return rg, err 47 | } 48 | -------------------------------------------------------------------------------- /lister/iotsitewise_gateway.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/iotsitewise" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSIoTSiteWiseGateway struct { 13 | } 14 | 15 | func init() { 16 | i := AWSIoTSiteWiseGateway{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSIoTSiteWiseGateway) Types() []resource.ResourceType { 21 | return []resource.ResourceType{ 22 | resource.IoTSiteWiseGateway, 23 | } 24 | } 25 | 26 | func (l AWSIoTSiteWiseGateway) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | svc := iotsitewise.NewFromConfig(ctx.AWSCfg) 28 | 29 | rg := resource.NewGroup() 30 | err := Paginator(func(nt *string) (*string, error) { 31 | res, err := svc.ListGateways(ctx.Context, &iotsitewise.ListGatewaysInput{ 32 | MaxResults: aws.Int32(100), 33 | NextToken: nt, 34 | }) 35 | if err != nil { 36 | return nil, err 37 | } 38 | for _, gateway := range res.GatewaySummaries { 39 | v, err := svc.DescribeGateway(ctx.Context, &iotsitewise.DescribeGatewayInput{ 40 | GatewayId: gateway.GatewayId, 41 | }) 42 | if err != nil { 43 | return nil, fmt.Errorf("failed to describe siteways gateway %s: %w", *gateway.GatewayId, err) 44 | } 45 | 46 | r := resource.New(ctx, resource.IoTSiteWiseGateway, v.GatewayId, v.GatewayName, v) 47 | if v.GatewayPlatform != nil { 48 | r.AddARNRelation(resource.GreengrassGroup, v.GatewayPlatform.Greengrass.GroupArn) 49 | } 50 | rg.AddResource(r) 51 | } 52 | return res.NextToken, nil 53 | }) 54 | return rg, err 55 | } 56 | -------------------------------------------------------------------------------- /lister/kafka_cluster.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/service/kafka" 5 | "github.com/trek10inc/awsets/arn" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSKafkaCluster struct { 11 | } 12 | 13 | func init() { 14 | i := AWSKafkaCluster{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSKafkaCluster) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.KafkaCluster} 20 | } 21 | 22 | func (l AWSKafkaCluster) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := kafka.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.ListClusters(ctx.Context, &kafka.ListClustersInput{ 28 | MaxResults: 100, 29 | NextToken: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, cluster := range res.ClusterInfoList { 35 | clusterArn := arn.ParseP(cluster.ClusterArn) 36 | r := resource.New(ctx, resource.KafkaCluster, clusterArn.ResourceId, cluster.ClusterName, cluster) 37 | 38 | rg.AddResource(r) 39 | } 40 | return res.NextToken, nil 41 | }) 42 | return rg, err 43 | } 44 | -------------------------------------------------------------------------------- /lister/kinesis_stream.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/kinesis" 8 | "github.com/trek10inc/awsets/arn" 9 | "github.com/trek10inc/awsets/context" 10 | "github.com/trek10inc/awsets/resource" 11 | ) 12 | 13 | type AWSKinesisStream struct { 14 | } 15 | 16 | func init() { 17 | i := AWSKinesisStream{} 18 | listers = append(listers, i) 19 | } 20 | 21 | func (l AWSKinesisStream) Types() []resource.ResourceType { 22 | return []resource.ResourceType{resource.KinesisStream} 23 | } 24 | 25 | func (l AWSKinesisStream) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | svc := kinesis.NewFromConfig(ctx.AWSCfg) 27 | 28 | rg := resource.NewGroup() 29 | err := Paginator(func(nt *string) (*string, error) { 30 | res, err := svc.ListStreams(ctx.Context, &kinesis.ListStreamsInput{ 31 | Limit: aws.Int32(100), 32 | ExclusiveStartStreamName: nt, 33 | }) 34 | if err != nil { 35 | return nil, err 36 | } 37 | var lastName string 38 | for i, stream := range res.StreamNames { 39 | lastName = res.StreamNames[i] 40 | res, err := svc.DescribeStream(ctx.Context, &kinesis.DescribeStreamInput{ 41 | Limit: aws.Int32(100), 42 | StreamName: &stream, 43 | }) 44 | if err != nil { 45 | return nil, fmt.Errorf("failed to describe kinesis streams %s: %w", stream, err) 46 | } 47 | streamArn := arn.ParseP(res.StreamDescription.StreamARN) 48 | r := resource.New(ctx, resource.KinesisStream, streamArn.ResourceId, res.StreamDescription.StreamName, res.StreamDescription) 49 | rg.AddResource(r) 50 | // TODO the rest of this... relationships to shards and whatnot 51 | } 52 | return &lastName, nil 53 | }) 54 | return rg, err 55 | } 56 | -------------------------------------------------------------------------------- /lister/kms_alias.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/kms" 6 | "github.com/trek10inc/awsets/arn" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSKmsAlias struct { 12 | } 13 | 14 | func init() { 15 | i := AWSKmsAlias{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSKmsAlias) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.KmsAlias} 21 | } 22 | 23 | func (l AWSKmsAlias) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := kms.NewFromConfig(ctx.AWSCfg) 25 | 26 | rg := resource.NewGroup() 27 | err := Paginator(func(nt *string) (*string, error) { 28 | res, err := svc.ListAliases(ctx.Context, &kms.ListAliasesInput{ 29 | Limit: aws.Int32(100), 30 | Marker: nt, 31 | }) 32 | if err != nil { 33 | return nil, err 34 | } 35 | for _, alias := range res.Aliases { 36 | aliasArn := arn.ParseP(alias.AliasArn) 37 | r := resource.New(ctx, resource.KmsAlias, aliasArn.ResourceId, alias.AliasName, alias) 38 | if alias.TargetKeyId != nil { 39 | r.AddRelation(resource.KmsKey, alias.TargetKeyId, "") 40 | } 41 | rg.AddResource(r) 42 | } 43 | return res.NextMarker, nil 44 | }) 45 | return rg, err 46 | } 47 | -------------------------------------------------------------------------------- /lister/kms_key.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/kms" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSKmsKey struct { 13 | } 14 | 15 | func init() { 16 | i := AWSKmsKey{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSKmsKey) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.KmsKey} 22 | } 23 | 24 | func (l AWSKmsKey) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | svc := kms.NewFromConfig(ctx.AWSCfg) 26 | 27 | rg := resource.NewGroup() 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.ListKeys(ctx.Context, &kms.ListKeysInput{ 30 | Limit: aws.Int32(100), 31 | Marker: nt, 32 | }) 33 | if err != nil { 34 | return nil, err 35 | } 36 | for _, key := range res.Keys { 37 | keyDetail, err := svc.DescribeKey(ctx.Context, &kms.DescribeKeyInput{ 38 | GrantTokens: nil, 39 | KeyId: key.KeyId, 40 | }) 41 | if err != nil { 42 | return nil, fmt.Errorf("failed to describe key %s: %w", *key.KeyId, err) 43 | } 44 | if v := keyDetail.KeyMetadata; v != nil { 45 | r := resource.New(ctx, resource.KmsKey, v.KeyId, v.KeyId, v) 46 | // TODO: relationshio to HSM? 47 | rg.AddResource(r) 48 | } 49 | } 50 | return res.NextMarker, nil 51 | }) 52 | return rg, err 53 | } 54 | -------------------------------------------------------------------------------- /lister/main.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/trek10inc/awsets/context" 5 | "github.com/trek10inc/awsets/resource" 6 | ) 7 | 8 | var listers = make([]Lister, 0) 9 | 10 | type Lister interface { 11 | Types() []resource.ResourceType 12 | List(ctx context.AWSetsCtx) (*resource.Group, error) 13 | } 14 | 15 | func AllListers() []Lister { 16 | return listers 17 | } 18 | 19 | func Paginator(f func(*string) (*string, error)) error { 20 | var nt *string 21 | for { 22 | t, err := f(nt) 23 | if err != nil { 24 | return err 25 | } 26 | if t == nil { 27 | break 28 | } 29 | nt = t 30 | } 31 | return nil 32 | } 33 | -------------------------------------------------------------------------------- /lister/main_test.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/trek10inc/awsets/resource" 7 | ) 8 | 9 | func Test_DuplicateCheck(t *testing.T) { 10 | types := make(map[resource.ResourceType]struct{}) 11 | dupes := make([]string, 0) 12 | for _, l := range listers { 13 | for _, kind := range l.Types() { 14 | if _, ok := types[kind]; ok { 15 | dupes = append(dupes, kind.String()) 16 | } 17 | types[kind] = struct{}{} 18 | } 19 | } 20 | if len(dupes) > 0 { 21 | t.Fatalf("found duplicate types: %v\n", dupes) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lister/mq_brokerconfiguration.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/mq" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSAmazonMQBrokerConfiguration struct { 12 | } 13 | 14 | func init() { 15 | i := AWSAmazonMQBrokerConfiguration{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSAmazonMQBrokerConfiguration) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.AmazonMQBrokerConfiguration} 21 | } 22 | 23 | func (l AWSAmazonMQBrokerConfiguration) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := mq.NewFromConfig(ctx.AWSCfg) 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.ListConfigurations(ctx.Context, &mq.ListConfigurationsInput{ 28 | MaxResults: 100, 29 | NextToken: nt, 30 | }) 31 | if err != nil { 32 | return nil, fmt.Errorf("failed to list mq broker configurations: %w", err) 33 | } 34 | for _, v := range res.Configurations { 35 | r := resource.New(ctx, resource.AmazonMQBrokerConfiguration, v.Id, v.Name, v) 36 | 37 | rg.AddResource(r) 38 | } 39 | return res.NextToken, nil 40 | }) 41 | return rg, err 42 | } 43 | -------------------------------------------------------------------------------- /lister/neptune_dbclusterparametergroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | 7 | "github.com/aws/aws-sdk-go-v2/aws" 8 | "github.com/aws/aws-sdk-go-v2/service/neptune" 9 | "github.com/trek10inc/awsets/arn" 10 | "github.com/trek10inc/awsets/context" 11 | "github.com/trek10inc/awsets/resource" 12 | ) 13 | 14 | type AWSNeptuneDbClusterParameterGroup struct { 15 | } 16 | 17 | func init() { 18 | i := AWSNeptuneDbClusterParameterGroup{} 19 | listers = append(listers, i) 20 | } 21 | 22 | func (l AWSNeptuneDbClusterParameterGroup) Types() []resource.ResourceType { 23 | return []resource.ResourceType{resource.NeptuneDbClusterParameterGroup} 24 | } 25 | 26 | func (l AWSNeptuneDbClusterParameterGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | svc := neptune.NewFromConfig(ctx.AWSCfg) 28 | 29 | rg := resource.NewGroup() 30 | 31 | paginator := neptune.NewDescribeDBClusterParameterGroupsPaginator(svc, &neptune.DescribeDBClusterParameterGroupsInput{ 32 | MaxRecords: aws.Int32(100), 33 | }) 34 | 35 | for paginator.HasMorePages() { 36 | page, err := paginator.NextPage(ctx.Context) 37 | if err != nil { 38 | return nil, fmt.Errorf("failed to list neptune cluster parameter groups: %w", err) 39 | } 40 | for _, v := range page.DBClusterParameterGroups { 41 | if !strings.Contains(*v.DBParameterGroupFamily, "neptune") { 42 | continue 43 | } 44 | groupArn := arn.ParseP(v.DBClusterParameterGroupArn) 45 | r := resource.New(ctx, resource.NeptuneDbClusterParameterGroup, groupArn.ResourceId, "", v) 46 | rg.AddResource(r) 47 | } 48 | } 49 | return rg, nil 50 | } 51 | -------------------------------------------------------------------------------- /lister/neptune_dbclustersnapshot.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | 7 | "github.com/aws/aws-sdk-go-v2/aws" 8 | "github.com/aws/aws-sdk-go-v2/service/neptune" 9 | "github.com/trek10inc/awsets/context" 10 | "github.com/trek10inc/awsets/resource" 11 | ) 12 | 13 | type AWSNeptuneDbClusterSnapshot struct { 14 | } 15 | 16 | func init() { 17 | i := AWSNeptuneDbClusterSnapshot{} 18 | listers = append(listers, i) 19 | } 20 | 21 | func (l AWSNeptuneDbClusterSnapshot) Types() []resource.ResourceType { 22 | return []resource.ResourceType{resource.NeptuneDbClusterSnapshot} 23 | } 24 | 25 | func (l AWSNeptuneDbClusterSnapshot) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | svc := neptune.NewFromConfig(ctx.AWSCfg) 27 | 28 | rg := resource.NewGroup() 29 | 30 | paginator := neptune.NewDescribeDBClusterSnapshotsPaginator(svc, &neptune.DescribeDBClusterSnapshotsInput{ 31 | MaxRecords: aws.Int32(100), 32 | }) 33 | 34 | for paginator.HasMorePages() { 35 | page, err := paginator.NextPage(ctx.Context) 36 | if err != nil { 37 | return nil, fmt.Errorf("failed to list neptune cluster snapshots: %w", err) 38 | } 39 | for _, v := range page.DBClusterSnapshots { 40 | if !strings.Contains(*v.Engine, "neptune") { 41 | continue 42 | } 43 | r := resource.New(ctx, resource.NeptuneDbClusterSnapshot, v.DBClusterSnapshotIdentifier, v.DBClusterSnapshotIdentifier, v) 44 | r.AddARNRelation(resource.KmsKey, v.KmsKeyId) 45 | r.AddRelation(resource.NeptuneDbCluster, v.DBClusterIdentifier, "") 46 | r.AddRelation(resource.Ec2Vpc, v.VpcId, "") 47 | 48 | rg.AddResource(r) 49 | } 50 | } 51 | return rg, nil 52 | } 53 | -------------------------------------------------------------------------------- /lister/neptune_dbparametergroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/neptune" 8 | "github.com/trek10inc/awsets/arn" 9 | "github.com/trek10inc/awsets/context" 10 | "github.com/trek10inc/awsets/resource" 11 | ) 12 | 13 | type AWSNeptuneDbParameterGroup struct { 14 | } 15 | 16 | func init() { 17 | i := AWSNeptuneDbParameterGroup{} 18 | listers = append(listers, i) 19 | } 20 | 21 | func (l AWSNeptuneDbParameterGroup) Types() []resource.ResourceType { 22 | return []resource.ResourceType{resource.NeptuneDbParameterGroup} 23 | } 24 | 25 | func (l AWSNeptuneDbParameterGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | svc := neptune.NewFromConfig(ctx.AWSCfg) 27 | 28 | rg := resource.NewGroup() 29 | 30 | paginator := neptune.NewDescribeDBParameterGroupsPaginator(svc, &neptune.DescribeDBParameterGroupsInput{ 31 | MaxRecords: aws.Int32(100), 32 | }) 33 | 34 | for paginator.HasMorePages() { 35 | page, err := paginator.NextPage(ctx.Context) 36 | if err != nil { 37 | return nil, err 38 | } 39 | for _, v := range page.DBParameterGroups { 40 | if !strings.Contains(*v.DBParameterGroupFamily, "neptune") { 41 | continue 42 | } 43 | groupArn := arn.ParseP(v.DBParameterGroupArn) 44 | r := resource.New(ctx, resource.NeptuneDbParameterGroup, groupArn.ResourceId, "", v) 45 | rg.AddResource(r) 46 | } 47 | } 48 | return rg, nil 49 | } 50 | -------------------------------------------------------------------------------- /lister/neptune_dbsubnetgroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/neptune" 6 | "github.com/trek10inc/awsets/arn" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSNeptuneDbSubnetGroup struct { 12 | } 13 | 14 | func init() { 15 | i := AWSNeptuneDbSubnetGroup{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSNeptuneDbSubnetGroup) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.NeptuneDbSubnetGroup} 21 | } 22 | 23 | func (l AWSNeptuneDbSubnetGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := neptune.NewFromConfig(ctx.AWSCfg) 25 | 26 | rg := resource.NewGroup() 27 | 28 | paginator := neptune.NewDescribeDBSubnetGroupsPaginator(svc, &neptune.DescribeDBSubnetGroupsInput{ 29 | MaxRecords: aws.Int32(100), 30 | }) 31 | 32 | for paginator.HasMorePages() { 33 | page, err := paginator.NextPage(ctx.Context) 34 | if err != nil { 35 | return nil, err 36 | } 37 | for _, v := range page.DBSubnetGroups { 38 | subnetArn := arn.ParseP(v.DBSubnetGroupArn) 39 | if subnetArn.Service != "neptune" { 40 | continue 41 | } 42 | r := resource.New(ctx, resource.NeptuneDbSubnetGroup, subnetArn.ResourceId, "", v) 43 | r.AddRelation(resource.Ec2Vpc, v.VpcId, "") 44 | for _, subnet := range v.Subnets { 45 | r.AddRelation(resource.Ec2Subnet, subnet.SubnetIdentifier, "") 46 | } 47 | rg.AddResource(r) 48 | } 49 | } 50 | return rg, nil 51 | } 52 | -------------------------------------------------------------------------------- /lister/qldb_ledgers.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/qldb" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSQLDBLedger struct { 11 | } 12 | 13 | func init() { 14 | i := AWSQLDBLedger{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSQLDBLedger) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.QLDBLedger} 20 | } 21 | 22 | func (l AWSQLDBLedger) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := qldb.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | 27 | paginator := qldb.NewListLedgersPaginator(svc, &qldb.ListLedgersInput{ 28 | MaxResults: aws.Int32(100), 29 | }) 30 | 31 | for paginator.HasMorePages() { 32 | page, err := paginator.NextPage(ctx.Context) 33 | if err != nil { 34 | return nil, err 35 | } 36 | for _, v := range page.Ledgers { 37 | r := resource.New(ctx, resource.QLDBLedger, v.Name, v.Name, v) 38 | rg.AddResource(r) 39 | } 40 | } 41 | return rg, nil 42 | } 43 | -------------------------------------------------------------------------------- /lister/rds_clusterparametergroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/rds" 8 | "github.com/trek10inc/awsets/arn" 9 | "github.com/trek10inc/awsets/context" 10 | "github.com/trek10inc/awsets/resource" 11 | ) 12 | 13 | type AWSRdsDbClusterParameterGroup struct { 14 | } 15 | 16 | func init() { 17 | i := AWSRdsDbClusterParameterGroup{} 18 | listers = append(listers, i) 19 | } 20 | 21 | func (l AWSRdsDbClusterParameterGroup) Types() []resource.ResourceType { 22 | return []resource.ResourceType{resource.RdsDbClusterParameterGroup} 23 | } 24 | 25 | func (l AWSRdsDbClusterParameterGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | svc := rds.NewFromConfig(ctx.AWSCfg) 27 | 28 | rg := resource.NewGroup() 29 | 30 | paginator := rds.NewDescribeDBClusterParameterGroupsPaginator(svc, &rds.DescribeDBClusterParameterGroupsInput{ 31 | MaxRecords: aws.Int32(100), 32 | }) 33 | 34 | for paginator.HasMorePages() { 35 | page, err := paginator.NextPage(ctx.Context) 36 | if err != nil { 37 | return nil, err 38 | } 39 | for _, pGroup := range page.DBClusterParameterGroups { 40 | if strings.Contains(*pGroup.DBParameterGroupFamily, "neptune") || strings.Contains(*pGroup.DBParameterGroupFamily, "docdb") { 41 | continue 42 | } 43 | groupArn := arn.ParseP(pGroup.DBClusterParameterGroupArn) 44 | r := resource.New(ctx, resource.RdsDbParameterGroup, groupArn.ResourceId, "", pGroup) 45 | rg.AddResource(r) 46 | } 47 | } 48 | return rg, nil 49 | } 50 | -------------------------------------------------------------------------------- /lister/rds_clustersnapshot.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/rds" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSRdsDbClusterSnapshot struct { 13 | } 14 | 15 | func init() { 16 | i := AWSRdsDbClusterSnapshot{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSRdsDbClusterSnapshot) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.RdsDbClusterSnapshot} 22 | } 23 | 24 | func (l AWSRdsDbClusterSnapshot) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | svc := rds.NewFromConfig(ctx.AWSCfg) 26 | 27 | ignoredEngines := map[string]struct{}{ 28 | "docdb": {}, 29 | "neptune": {}, 30 | } 31 | 32 | rg := resource.NewGroup() 33 | 34 | paginator := rds.NewDescribeDBClusterSnapshotsPaginator(svc, &rds.DescribeDBClusterSnapshotsInput{ 35 | MaxRecords: aws.Int32(100), 36 | }) 37 | 38 | for paginator.HasMorePages() { 39 | page, err := paginator.NextPage(ctx.Context) 40 | if err != nil { 41 | return nil, fmt.Errorf("failed to list rds db cluster snapshots: %w", err) 42 | } 43 | for _, v := range page.DBClusterSnapshots { 44 | if _, ok := ignoredEngines[*v.Engine]; ok { 45 | continue 46 | } 47 | r := resource.New(ctx, resource.RdsDbClusterSnapshot, v.DBClusterSnapshotIdentifier, v.DBClusterSnapshotIdentifier, v) 48 | r.AddARNRelation(resource.KmsKey, v.KmsKeyId) 49 | r.AddRelation(resource.RdsDbCluster, v.DBClusterIdentifier, "") 50 | r.AddRelation(resource.Ec2Vpc, v.VpcId, "") 51 | 52 | rg.AddResource(r) 53 | } 54 | } 55 | return rg, nil 56 | } 57 | -------------------------------------------------------------------------------- /lister/rds_parametergroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/rds" 8 | "github.com/trek10inc/awsets/arn" 9 | "github.com/trek10inc/awsets/context" 10 | "github.com/trek10inc/awsets/resource" 11 | ) 12 | 13 | type AWSRdsDbParameterGroup struct { 14 | } 15 | 16 | func init() { 17 | i := AWSRdsDbParameterGroup{} 18 | listers = append(listers, i) 19 | } 20 | 21 | func (l AWSRdsDbParameterGroup) Types() []resource.ResourceType { 22 | return []resource.ResourceType{resource.RdsDbParameterGroup} 23 | } 24 | 25 | func (l AWSRdsDbParameterGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | svc := rds.NewFromConfig(ctx.AWSCfg) 27 | 28 | rg := resource.NewGroup() 29 | 30 | paginator := rds.NewDescribeDBParameterGroupsPaginator(svc, &rds.DescribeDBParameterGroupsInput{ 31 | MaxRecords: aws.Int32(100), 32 | }) 33 | 34 | for paginator.HasMorePages() { 35 | page, err := paginator.NextPage(ctx.Context) 36 | if err != nil { 37 | return nil, err 38 | } 39 | for _, pGroup := range page.DBParameterGroups { 40 | if strings.Contains(*pGroup.DBParameterGroupFamily, "neptune") || strings.Contains(*pGroup.DBParameterGroupFamily, "docdb") { 41 | continue 42 | } 43 | groupArn := arn.ParseP(pGroup.DBParameterGroupArn) 44 | r := resource.New(ctx, resource.RdsDbParameterGroup, groupArn.ResourceId, "", pGroup) 45 | rg.AddResource(r) 46 | } 47 | } 48 | return rg, nil 49 | } 50 | -------------------------------------------------------------------------------- /lister/rds_snapshot.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/rds" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSRdsDbSnapshot struct { 11 | } 12 | 13 | func init() { 14 | i := AWSRdsDbSnapshot{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSRdsDbSnapshot) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.RDSDbSnapshot} 20 | } 21 | 22 | func (l AWSRdsDbSnapshot) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := rds.NewFromConfig(ctx.AWSCfg) 24 | 25 | ignoredEngines := map[string]struct{}{ 26 | "docdb": {}, 27 | "neptune": {}, 28 | } 29 | 30 | rg := resource.NewGroup() 31 | 32 | paginator := rds.NewDescribeDBSnapshotsPaginator(svc, &rds.DescribeDBSnapshotsInput{ 33 | MaxRecords: aws.Int32(100), 34 | }) 35 | 36 | for paginator.HasMorePages() { 37 | page, err := paginator.NextPage(ctx.Context) 38 | if err != nil { 39 | return nil, err 40 | } 41 | for _, v := range page.DBSnapshots { 42 | if _, ok := ignoredEngines[*v.Engine]; ok { 43 | continue 44 | } 45 | r := resource.New(ctx, resource.RDSDbSnapshot, v.DBSnapshotIdentifier, v.DBSnapshotIdentifier, v) 46 | r.AddARNRelation(resource.KmsKey, v.KmsKeyId) 47 | r.AddRelation(resource.RdsDbInstance, v.DBInstanceIdentifier, "") 48 | r.AddRelation(resource.Ec2Vpc, v.VpcId, "") 49 | 50 | rg.AddResource(r) 51 | } 52 | } 53 | return rg, nil 54 | } 55 | -------------------------------------------------------------------------------- /lister/rds_subnetgroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/rds" 6 | "github.com/trek10inc/awsets/arn" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSRdsDbSubnetGroup struct { 12 | } 13 | 14 | func init() { 15 | i := AWSRdsDbSubnetGroup{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSRdsDbSubnetGroup) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.RdsDbSubnetGroup} 21 | } 22 | 23 | func (l AWSRdsDbSubnetGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := rds.NewFromConfig(ctx.AWSCfg) 25 | 26 | rg := resource.NewGroup() 27 | 28 | paginator := rds.NewDescribeDBSubnetGroupsPaginator(svc, &rds.DescribeDBSubnetGroupsInput{ 29 | MaxRecords: aws.Int32(100), 30 | }) 31 | 32 | for paginator.HasMorePages() { 33 | page, err := paginator.NextPage(ctx.Context) 34 | if err != nil { 35 | return nil, err 36 | } 37 | for _, subnetGroup := range page.DBSubnetGroups { 38 | subnetArn := arn.ParseP(subnetGroup.DBSubnetGroupArn) 39 | if subnetArn.Service != "rds" { 40 | continue 41 | } 42 | r := resource.New(ctx, resource.RdsDbSubnetGroup, subnetArn.ResourceId, "", subnetGroup) 43 | r.AddRelation(resource.Ec2Vpc, subnetGroup.VpcId, "") 44 | for _, subnet := range subnetGroup.Subnets { 45 | r.AddRelation(resource.Ec2Subnet, subnet.SubnetIdentifier, "") 46 | } 47 | rg.AddResource(r) 48 | } 49 | } 50 | return rg, nil 51 | } 52 | -------------------------------------------------------------------------------- /lister/redshift_parametergroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/redshift" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSRedshiftParameterGroup struct { 11 | } 12 | 13 | func init() { 14 | i := AWSRedshiftParameterGroup{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSRedshiftParameterGroup) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.RedshiftParameterGroup} 20 | } 21 | 22 | func (l AWSRedshiftParameterGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := redshift.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeClusterParameterGroups(ctx.Context, &redshift.DescribeClusterParameterGroupsInput{ 28 | MaxRecords: aws.Int32(100), 29 | Marker: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, pg := range res.ParameterGroups { 35 | r := resource.New(ctx, resource.RedshiftParameterGroup, pg.ParameterGroupName, pg.ParameterGroupName, pg) 36 | rg.AddResource(r) 37 | } 38 | return res.Marker, nil 39 | }) 40 | return rg, err 41 | } 42 | -------------------------------------------------------------------------------- /lister/redshift_securitygroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/redshift" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSRedshiftSecurityGroup struct { 13 | } 14 | 15 | func init() { 16 | i := AWSRedshiftSecurityGroup{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSRedshiftSecurityGroup) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.RedshiftSecurityGroup} 22 | } 23 | 24 | func (l AWSRedshiftSecurityGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | svc := redshift.NewFromConfig(ctx.AWSCfg) 26 | 27 | rg := resource.NewGroup() 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.DescribeClusterSecurityGroups(ctx.Context, &redshift.DescribeClusterSecurityGroupsInput{ 30 | MaxRecords: aws.Int32(100), 31 | Marker: nt, 32 | }) 33 | if err != nil { 34 | if strings.Contains(err.Error(), "VPC-by-Default customers cannot use cluster security groups") { 35 | // EC2-Classic thing 36 | return nil, nil 37 | } 38 | return nil, err 39 | } 40 | for _, sg := range res.ClusterSecurityGroups { 41 | r := resource.New(ctx, resource.RedshiftSecurityGroup, sg.ClusterSecurityGroupName, sg.ClusterSecurityGroupName, sg) 42 | for _, ec2sg := range sg.EC2SecurityGroups { 43 | r.AddRelation(resource.Ec2SecurityGroup, ec2sg.EC2SecurityGroupName, "") 44 | } 45 | rg.AddResource(r) 46 | } 47 | return res.Marker, nil 48 | }) 49 | 50 | return rg, err 51 | } 52 | -------------------------------------------------------------------------------- /lister/redshift_snapshot.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/redshift" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSRedshiftSnapshot struct { 11 | } 12 | 13 | func init() { 14 | i := AWSRedshiftSnapshot{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSRedshiftSnapshot) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.RedshiftSnapshot} 20 | } 21 | 22 | func (l AWSRedshiftSnapshot) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := redshift.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeClusterSnapshots(ctx.Context, &redshift.DescribeClusterSnapshotsInput{ 28 | MaxRecords: aws.Int32(100), 29 | Marker: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, v := range res.Snapshots { 35 | r := resource.New(ctx, resource.RedshiftSnapshot, v.SnapshotIdentifier, v.SnapshotIdentifier, v) 36 | r.AddRelation(resource.Ec2Vpc, v.VpcId, "") 37 | r.AddARNRelation(resource.KmsKey, v.KmsKeyId) 38 | r.AddRelation(resource.RedshiftCluster, v.ClusterIdentifier, "") 39 | 40 | rg.AddResource(r) 41 | } 42 | return res.Marker, nil 43 | }) 44 | return rg, err 45 | } 46 | -------------------------------------------------------------------------------- /lister/redshift_subnetgroup.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | "github.com/aws/aws-sdk-go-v2/service/redshift" 6 | "github.com/trek10inc/awsets/context" 7 | "github.com/trek10inc/awsets/resource" 8 | ) 9 | 10 | type AWSRedshiftSubnetGroup struct { 11 | } 12 | 13 | func init() { 14 | i := AWSRedshiftSubnetGroup{} 15 | listers = append(listers, i) 16 | } 17 | 18 | func (l AWSRedshiftSubnetGroup) Types() []resource.ResourceType { 19 | return []resource.ResourceType{resource.RedshiftSubnetGroup} 20 | } 21 | 22 | func (l AWSRedshiftSubnetGroup) List(ctx context.AWSetsCtx) (*resource.Group, error) { 23 | svc := redshift.NewFromConfig(ctx.AWSCfg) 24 | 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.DescribeClusterSubnetGroups(ctx.Context, &redshift.DescribeClusterSubnetGroupsInput{ 28 | MaxRecords: aws.Int32(100), 29 | Marker: nt, 30 | }) 31 | if err != nil { 32 | return nil, err 33 | } 34 | for _, sg := range res.ClusterSubnetGroups { 35 | r := resource.New(ctx, resource.RedshiftSubnetGroup, sg.ClusterSubnetGroupName, sg.ClusterSubnetGroupName, sg) 36 | r.AddRelation(resource.Ec2Vpc, sg.VpcId, "") 37 | rg.AddResource(r) 38 | } 39 | return res.Marker, nil 40 | }) 41 | return rg, err 42 | } 43 | -------------------------------------------------------------------------------- /lister/route53_healthcheck.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "sync" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/route53" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | var listRoute53HealthChecksOnce sync.Once 12 | 13 | type AWSRoute53HealthCheck struct { 14 | } 15 | 16 | func init() { 17 | i := AWSRoute53HealthCheck{} 18 | listers = append(listers, i) 19 | } 20 | 21 | func (l AWSRoute53HealthCheck) Types() []resource.ResourceType { 22 | return []resource.ResourceType{resource.Route53HealthCheck} 23 | } 24 | 25 | func (l AWSRoute53HealthCheck) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | svc := route53.NewFromConfig(ctx.AWSCfg) 27 | 28 | rg := resource.NewGroup() 29 | var outerErr error 30 | 31 | listRoute53HealthChecksOnce.Do(func() { 32 | outerErr = Paginator(func(nt *string) (*string, error) { 33 | res, err := svc.ListHealthChecks(ctx.Context, &route53.ListHealthChecksInput{ 34 | Marker: nt, 35 | }) 36 | if err != nil { 37 | return nil, err 38 | } 39 | for _, healthCheck := range res.HealthChecks { 40 | r := resource.NewGlobal(ctx, resource.Route53HealthCheck, healthCheck.Id, healthCheck.Id, healthCheck) 41 | rg.AddResource(r) 42 | } 43 | return res.Marker, nil 44 | }) 45 | }) 46 | 47 | return rg, outerErr 48 | } 49 | -------------------------------------------------------------------------------- /lister/sagemaker_endpoint.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/sagemaker" 8 | "github.com/trek10inc/awsets/arn" 9 | "github.com/trek10inc/awsets/context" 10 | "github.com/trek10inc/awsets/resource" 11 | ) 12 | 13 | type AWSSagemakerEndpoint struct { 14 | } 15 | 16 | func init() { 17 | i := AWSSagemakerEndpoint{} 18 | listers = append(listers, i) 19 | } 20 | 21 | func (l AWSSagemakerEndpoint) Types() []resource.ResourceType { 22 | return []resource.ResourceType{ 23 | resource.SagemakerEndpoint, 24 | } 25 | } 26 | 27 | func (l AWSSagemakerEndpoint) List(ctx context.AWSetsCtx) (*resource.Group, error) { 28 | svc := sagemaker.NewFromConfig(ctx.AWSCfg) 29 | 30 | rg := resource.NewGroup() 31 | err := Paginator(func(nt *string) (*string, error) { 32 | res, err := svc.ListEndpoints(ctx.Context, &sagemaker.ListEndpointsInput{ 33 | MaxResults: aws.Int32(100), 34 | NextToken: nt, 35 | }) 36 | if err != nil { 37 | return nil, err 38 | } 39 | for _, ep := range res.Endpoints { 40 | v, err := svc.DescribeEndpoint(ctx.Context, &sagemaker.DescribeEndpointInput{ 41 | EndpointName: ep.EndpointName, 42 | }) 43 | if err != nil { 44 | return nil, fmt.Errorf("failed to describe endpoint %s: %w", *ep.EndpointName, err) 45 | } 46 | epArn := arn.ParseP(v.EndpointArn) 47 | r := resource.New(ctx, resource.SagemakerEndpoint, epArn.ResourceId, v.EndpointName, v) 48 | if v.DataCaptureConfig != nil { 49 | r.AddARNRelation(resource.KmsKey, v.DataCaptureConfig.KmsKeyId) 50 | } 51 | rg.AddResource(r) 52 | } 53 | return res.NextToken, nil 54 | }) 55 | return rg, err 56 | } 57 | -------------------------------------------------------------------------------- /lister/secretmanager_secret.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/secretsmanager" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSSecretManagerSecret struct { 12 | } 13 | 14 | func init() { 15 | i := AWSSecretManagerSecret{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSSecretManagerSecret) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.SecretManagerSecret} 21 | } 22 | 23 | func (l AWSSecretManagerSecret) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := secretsmanager.NewFromConfig(ctx.AWSCfg) 25 | 26 | rg := resource.NewGroup() 27 | err := Paginator(func(nt *string) (*string, error) { 28 | res, err := svc.ListSecrets(ctx.Context, &secretsmanager.ListSecretsInput{ 29 | MaxResults: 100, 30 | NextToken: nt, 31 | }) 32 | if err != nil { 33 | return nil, err 34 | } 35 | for _, v := range res.SecretList { 36 | r := resource.New(ctx, resource.SecretManagerSecret, v.Name, v.Name, v) 37 | r.AddARNRelation(resource.KmsKey, v.KmsKeyId) 38 | policy, err := svc.GetResourcePolicy(ctx.Context, &secretsmanager.GetResourcePolicyInput{ 39 | SecretId: v.Name, 40 | }) 41 | if err != nil { 42 | return nil, fmt.Errorf("failed to get secret policy for %s: %w", *v.Name, err) 43 | } 44 | r.AddAttribute("ResourcePolicy", policy.ResourcePolicy) 45 | rg.AddResource(r) 46 | } 47 | return res.NextToken, nil 48 | }) 49 | return rg, err 50 | } 51 | -------------------------------------------------------------------------------- /lister/servicecatalog_acceptedportfolioshare.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/servicecatalog" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSServiceCatalogAcceptedPortfolioShare struct { 12 | } 13 | 14 | func init() { 15 | i := AWSServiceCatalogAcceptedPortfolioShare{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSServiceCatalogAcceptedPortfolioShare) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.ServiceCatalogAcceptedPortfolioShare} 21 | } 22 | 23 | func (l AWSServiceCatalogAcceptedPortfolioShare) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := servicecatalog.NewFromConfig(ctx.AWSCfg) 25 | 26 | rg := resource.NewGroup() 27 | err := Paginator(func(nt *string) (*string, error) { 28 | res, err := svc.ListAcceptedPortfolioShares(ctx.Context, &servicecatalog.ListAcceptedPortfolioSharesInput{ 29 | PageSize: 20, 30 | PageToken: nt, 31 | }) 32 | if err != nil { 33 | return nil, err 34 | } 35 | for _, v := range res.PortfolioDetails { 36 | detail, err := svc.DescribePortfolio(ctx.Context, &servicecatalog.DescribePortfolioInput{ 37 | Id: v.Id, 38 | }) 39 | if err != nil { 40 | return nil, fmt.Errorf("failed to describe service catalog portfolio %s: %w", *v.Id, err) 41 | } 42 | r := resource.New(ctx, resource.ServiceCatalogAcceptedPortfolioShare, v.Id, v.DisplayName, detail) 43 | rg.AddResource(r) 44 | } 45 | return res.NextPageToken, nil 46 | }) 47 | return rg, err 48 | } 49 | -------------------------------------------------------------------------------- /lister/servicediscovery_namespace.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/servicediscovery" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSServiceDiscoveryNamespace struct { 13 | } 14 | 15 | func init() { 16 | i := AWSServiceDiscoveryNamespace{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSServiceDiscoveryNamespace) Types() []resource.ResourceType { 21 | return []resource.ResourceType{ 22 | resource.ServiceDiscoveryNamespace, 23 | } 24 | } 25 | 26 | func (l AWSServiceDiscoveryNamespace) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | svc := servicediscovery.NewFromConfig(ctx.AWSCfg) 28 | 29 | rg := resource.NewGroup() 30 | err := Paginator(func(nt *string) (*string, error) { 31 | res, err := svc.ListNamespaces(ctx.Context, &servicediscovery.ListNamespacesInput{ 32 | MaxResults: aws.Int32(100), 33 | NextToken: nt, 34 | }) 35 | if err != nil { 36 | return nil, err 37 | } 38 | for _, ns := range res.Namespaces { 39 | v, err := svc.GetNamespace(ctx.Context, &servicediscovery.GetNamespaceInput{ 40 | Id: ns.Id, 41 | }) 42 | if err != nil { 43 | return nil, fmt.Errorf("failed to describe service discovery namespace %s: %w", *ns.Id, err) 44 | } 45 | r := resource.New(ctx, resource.ServiceDiscoveryNamespace, v.Namespace.Id, v.Namespace.Name, v.Namespace) 46 | if v.Namespace.Properties != nil { 47 | if v.Namespace.Properties.DnsProperties != nil { 48 | r.AddRelation(resource.Route53HostedZone, *v.Namespace.Properties.DnsProperties.HostedZoneId, "") 49 | } 50 | } 51 | rg.AddResource(r) 52 | } 53 | return res.NextToken, nil 54 | }) 55 | return rg, err 56 | } 57 | -------------------------------------------------------------------------------- /lister/ses_receiptfilter.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "strings" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/ses" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSSESReceiptFilter struct { 12 | } 13 | 14 | func init() { 15 | i := AWSSESReceiptFilter{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSSESReceiptFilter) Types() []resource.ResourceType { 20 | return []resource.ResourceType{ 21 | resource.SesReceiptFilter, 22 | } 23 | } 24 | 25 | func (l AWSSESReceiptFilter) List(ctx context.AWSetsCtx) (*resource.Group, error) { 26 | svc := ses.NewFromConfig(ctx.AWSCfg) 27 | 28 | rg := resource.NewGroup() 29 | 30 | filters, err := svc.ListReceiptFilters(ctx.Context, &ses.ListReceiptFiltersInput{}) 31 | if err != nil { 32 | if strings.Contains(err.Error(), "Unavailable Operation") { 33 | // If SES isn't available in a region, returns Unavailable Operation error 34 | return rg, nil 35 | } 36 | return rg, err 37 | } 38 | for _, v := range filters.Filters { 39 | r := resource.New(ctx, resource.SesReceiptFilter, v.Name, v.Name, v) 40 | rg.AddResource(r) 41 | } 42 | return rg, err 43 | } 44 | -------------------------------------------------------------------------------- /lister/ses_template.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/aws" 7 | "github.com/aws/aws-sdk-go-v2/service/ses" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSSESTemplate struct { 13 | } 14 | 15 | func init() { 16 | i := AWSSESTemplate{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSSESTemplate) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.SesTemplate} 22 | } 23 | 24 | func (l AWSSESTemplate) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | svc := ses.NewFromConfig(ctx.AWSCfg) 26 | 27 | rg := resource.NewGroup() 28 | err := Paginator(func(nt *string) (*string, error) { 29 | res, err := svc.ListTemplates(ctx.Context, &ses.ListTemplatesInput{ 30 | MaxItems: aws.Int32(10), 31 | NextToken: nt, 32 | }) 33 | if err != nil { 34 | return nil, err 35 | } 36 | for _, template := range res.TemplatesMetadata { 37 | v, err := svc.GetTemplate(ctx.Context, &ses.GetTemplateInput{ 38 | TemplateName: template.Name, 39 | }) 40 | if err != nil { 41 | return nil, fmt.Errorf("failed to get email template %s: %w", *template.Name, err) 42 | } 43 | r := resource.New(ctx, resource.SesTemplate, v.Template.TemplateName, v.Template.TemplateName, v.Template) 44 | 45 | rg.AddResource(r) 46 | } 47 | return res.NextToken, nil 48 | }) 49 | return rg, err 50 | } 51 | -------------------------------------------------------------------------------- /lister/signer_signingprofile.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/aws" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/signer" 7 | "github.com/trek10inc/awsets/arn" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSSignerSigningProfile struct { 13 | } 14 | 15 | func init() { 16 | i := AWSSignerSigningProfile{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSSignerSigningProfile) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.SignerSigningProfile} 22 | } 23 | 24 | func (l AWSSignerSigningProfile) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | svc := signer.NewFromConfig(ctx.AWSCfg) 26 | rg := resource.NewGroup() 27 | err := Paginator(func(nt *string) (*string, error) { 28 | res, err := svc.ListSigningProfiles(ctx.Context, &signer.ListSigningProfilesInput{ 29 | MaxResults: aws.Int32(100), 30 | NextToken: nt, 31 | }) 32 | if err != nil { 33 | return nil, err 34 | } 35 | for _, v := range res.Profiles { 36 | profileArn := arn.ParseP(v.Arn) 37 | r := resource.New(ctx, resource.SignerSigningProfile, profileArn.ResourceId, v.ProfileName, v) 38 | 39 | rg.AddResource(r) 40 | } 41 | return res.NextToken, nil 42 | }) 43 | return rg, err 44 | } 45 | -------------------------------------------------------------------------------- /lister/ssm_association.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/service/ssm" 5 | "github.com/trek10inc/awsets/context" 6 | "github.com/trek10inc/awsets/resource" 7 | ) 8 | 9 | type AWSSsmAssociation struct { 10 | } 11 | 12 | func init() { 13 | i := AWSSsmAssociation{} 14 | listers = append(listers, i) 15 | } 16 | 17 | func (l AWSSsmAssociation) Types() []resource.ResourceType { 18 | return []resource.ResourceType{ 19 | resource.SsmAssociation, 20 | } 21 | } 22 | 23 | func (l AWSSsmAssociation) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := ssm.NewFromConfig(ctx.AWSCfg) 25 | 26 | rg := resource.NewGroup() 27 | err := Paginator(func(nt *string) (*string, error) { 28 | res, err := svc.ListAssociations(ctx.Context, &ssm.ListAssociationsInput{ 29 | MaxResults: 50, 30 | NextToken: nt, 31 | }) 32 | if err != nil { 33 | return nil, err 34 | } 35 | for _, v := range res.Associations { 36 | r := resource.New(ctx, resource.SsmAssociation, v.AssociationId, v.AssociationName, v) 37 | r.AddRelation(resource.Ec2Instance, v.InstanceId, "") 38 | rg.AddResource(r) 39 | } 40 | return res.NextToken, nil 41 | }) 42 | return rg, err 43 | } 44 | -------------------------------------------------------------------------------- /lister/ssm_document.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/service/ssm" 5 | "github.com/trek10inc/awsets/context" 6 | "github.com/trek10inc/awsets/resource" 7 | ) 8 | 9 | type AWSSsmDocument struct { 10 | } 11 | 12 | func init() { 13 | i := AWSSsmDocument{} 14 | listers = append(listers, i) 15 | } 16 | 17 | func (l AWSSsmDocument) Types() []resource.ResourceType { 18 | return []resource.ResourceType{resource.SsmDocument} 19 | } 20 | 21 | func (l AWSSsmDocument) List(ctx context.AWSetsCtx) (*resource.Group, error) { 22 | svc := ssm.NewFromConfig(ctx.AWSCfg) 23 | 24 | rg := resource.NewGroup() 25 | err := Paginator(func(nt *string) (*string, error) { 26 | res, err := svc.ListDocuments(ctx.Context, &ssm.ListDocumentsInput{ 27 | MaxResults: 50, 28 | NextToken: nt, 29 | }) 30 | if err != nil { 31 | return nil, err 32 | } 33 | for _, docId := range res.DocumentIdentifiers { 34 | if docId.Owner != nil && *docId.Owner != "Amazon" { // TODO: should Amazon things be filtered? 35 | r := resource.New(ctx, resource.SsmDocument, docId.Name, docId.Name, docId) 36 | rg.AddResource(r) 37 | } 38 | } 39 | return res.NextToken, nil 40 | }) 41 | return rg, err 42 | } 43 | -------------------------------------------------------------------------------- /lister/ssm_parameter.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/service/ssm" 5 | "github.com/trek10inc/awsets/context" 6 | "github.com/trek10inc/awsets/resource" 7 | ) 8 | 9 | type AWSSsmParameter struct { 10 | } 11 | 12 | func init() { 13 | i := AWSSsmParameter{} 14 | listers = append(listers, i) 15 | } 16 | 17 | func (l AWSSsmParameter) Types() []resource.ResourceType { 18 | return []resource.ResourceType{resource.SsmParameter} 19 | } 20 | 21 | func (l AWSSsmParameter) List(ctx context.AWSetsCtx) (*resource.Group, error) { 22 | svc := ssm.NewFromConfig(ctx.AWSCfg) 23 | 24 | rg := resource.NewGroup() 25 | err := Paginator(func(nt *string) (*string, error) { 26 | res, err := svc.DescribeParameters(ctx.Context, &ssm.DescribeParametersInput{ 27 | MaxResults: 50, 28 | NextToken: nt, 29 | }) 30 | if err != nil { 31 | return nil, err 32 | } 33 | for _, parameter := range res.Parameters { 34 | r := resource.New(ctx, resource.SsmParameter, parameter.Name, parameter.Name, parameter) 35 | rg.AddResource(r) 36 | } 37 | return res.NextToken, nil 38 | }) 39 | return rg, err 40 | } 41 | -------------------------------------------------------------------------------- /lister/ssm_patchbaseline.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/ssm" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSSsmPatchBaseline struct { 12 | } 13 | 14 | func init() { 15 | i := AWSSsmPatchBaseline{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSSsmPatchBaseline) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.SsmPatchBaseline} 21 | } 22 | 23 | func (l AWSSsmPatchBaseline) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := ssm.NewFromConfig(ctx.AWSCfg) 25 | 26 | rg := resource.NewGroup() 27 | err := Paginator(func(nt *string) (*string, error) { 28 | res, err := svc.DescribePatchBaselines(ctx.Context, &ssm.DescribePatchBaselinesInput{ 29 | MaxResults: 50, 30 | NextToken: nt, 31 | }) 32 | if err != nil { 33 | return nil, err 34 | } 35 | for _, bl := range res.BaselineIdentities { 36 | v, err := svc.GetPatchBaseline(ctx.Context, &ssm.GetPatchBaselineInput{ 37 | BaselineId: bl.BaselineId, 38 | }) 39 | if err != nil { 40 | return nil, fmt.Errorf("failed to get patch baseline %s: %w", *bl.BaselineId, err) 41 | } 42 | 43 | r := resource.New(ctx, resource.SsmPatchBaseline, v.BaselineId, v.Name, v) 44 | rg.AddResource(r) 45 | } 46 | return res.NextToken, nil 47 | }) 48 | return rg, err 49 | } 50 | -------------------------------------------------------------------------------- /lister/stepfunction_statemachine.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/sfn" 7 | "github.com/trek10inc/awsets/arn" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | type AWSStepFunctionStateMachine struct { 13 | } 14 | 15 | func init() { 16 | i := AWSStepFunctionStateMachine{} 17 | listers = append(listers, i) 18 | } 19 | 20 | func (l AWSStepFunctionStateMachine) Types() []resource.ResourceType { 21 | return []resource.ResourceType{resource.StepFunctionStateMachine} 22 | } 23 | 24 | func (l AWSStepFunctionStateMachine) List(ctx context.AWSetsCtx) (*resource.Group, error) { 25 | 26 | svc := sfn.NewFromConfig(ctx.AWSCfg) 27 | 28 | rg := resource.NewGroup() 29 | err := Paginator(func(nt *string) (*string, error) { 30 | res, err := svc.ListStateMachines(ctx.Context, &sfn.ListStateMachinesInput{ 31 | MaxResults: 100, 32 | NextToken: nt, 33 | }) 34 | if err != nil { 35 | return nil, err 36 | } 37 | for _, sm := range res.StateMachines { 38 | 39 | res, err := svc.DescribeStateMachine(ctx.Context, &sfn.DescribeStateMachineInput{ 40 | StateMachineArn: sm.StateMachineArn, 41 | }) 42 | if err != nil { 43 | return nil, fmt.Errorf("failed to get state machine %s: %w", *sm.Name, err) 44 | } 45 | smArn := arn.ParseP(res.StateMachineArn) 46 | r := resource.New(ctx, resource.StepFunctionStateMachine, smArn.ResourceId, sm.Name, res) 47 | rg.AddResource(r) 48 | } 49 | return res.NextToken, nil 50 | }) 51 | return rg, err 52 | } 53 | -------------------------------------------------------------------------------- /lister/waf_bytematchset.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | 7 | "github.com/aws/aws-sdk-go-v2/service/waf" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | var listWafByteMatchSetsOnce sync.Once 13 | 14 | type AWSWafByteMatchSet struct { 15 | } 16 | 17 | func init() { 18 | i := AWSWafByteMatchSet{} 19 | listers = append(listers, i) 20 | } 21 | 22 | func (l AWSWafByteMatchSet) Types() []resource.ResourceType { 23 | return []resource.ResourceType{resource.WafByteMatchSet} 24 | } 25 | 26 | func (l AWSWafByteMatchSet) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | svc := waf.NewFromConfig(ctx.AWSCfg) 28 | rg := resource.NewGroup() 29 | 30 | var outerErr error 31 | 32 | listWafByteMatchSetsOnce.Do(func() { 33 | outerErr = Paginator(func(nt *string) (*string, error) { 34 | res, err := svc.ListByteMatchSets(ctx.Context, &waf.ListByteMatchSetsInput{ 35 | Limit: 100, 36 | NextMarker: nt, 37 | }) 38 | if err != nil { 39 | return nil, fmt.Errorf("failed to list byte match sets: %w", err) 40 | } 41 | for _, id := range res.ByteMatchSets { 42 | byteMatchSet, err := svc.GetByteMatchSet(ctx.Context, &waf.GetByteMatchSetInput{ 43 | ByteMatchSetId: id.ByteMatchSetId, 44 | }) 45 | if err != nil { 46 | return nil, fmt.Errorf("failed to get byte match stringset %s: %w", *id.ByteMatchSetId, err) 47 | } 48 | if v := byteMatchSet.ByteMatchSet; v != nil { 49 | r := resource.NewGlobal(ctx, resource.WafByteMatchSet, v.ByteMatchSetId, v.Name, v) 50 | rg.AddResource(r) 51 | } 52 | } 53 | return res.NextMarker, nil 54 | }) 55 | }) 56 | return rg, outerErr 57 | } 58 | -------------------------------------------------------------------------------- /lister/waf_ipset.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | 7 | "github.com/aws/aws-sdk-go-v2/service/waf" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | var listWafIpSetsOnce sync.Once 13 | 14 | type AWSWafIpSet struct { 15 | } 16 | 17 | func init() { 18 | i := AWSWafIpSet{} 19 | listers = append(listers, i) 20 | } 21 | 22 | func (l AWSWafIpSet) Types() []resource.ResourceType { 23 | return []resource.ResourceType{resource.WafIpSet} 24 | } 25 | 26 | func (l AWSWafIpSet) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | svc := waf.NewFromConfig(ctx.AWSCfg) 28 | rg := resource.NewGroup() 29 | 30 | var outerErr error 31 | 32 | listWafIpSetsOnce.Do(func() { 33 | outerErr = Paginator(func(nt *string) (*string, error) { 34 | res, err := svc.ListIPSets(ctx.Context, &waf.ListIPSetsInput{ 35 | Limit: 100, 36 | NextMarker: nt, 37 | }) 38 | if err != nil { 39 | return nil, fmt.Errorf("failed to list ip sets: %w", err) 40 | } 41 | for _, ipsetId := range res.IPSets { 42 | ipset, err := svc.GetIPSet(ctx.Context, &waf.GetIPSetInput{IPSetId: ipsetId.IPSetId}) 43 | if err != nil { 44 | return nil, fmt.Errorf("failed to get ipset %s: %w", *ipsetId.IPSetId, err) 45 | } 46 | if ipset.IPSet == nil { 47 | continue 48 | } 49 | r := resource.NewGlobal(ctx, resource.WafIpSet, ipset.IPSet.IPSetId, ipset.IPSet.Name, ipset.IPSet) 50 | rg.AddResource(r) 51 | } 52 | return res.NextMarker, nil 53 | }) 54 | }) 55 | return rg, outerErr 56 | } 57 | -------------------------------------------------------------------------------- /lister/waf_rule.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | 7 | "github.com/aws/aws-sdk-go-v2/service/waf" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | var listWafRulesOnce sync.Once 13 | 14 | type AWSWafRule struct { 15 | } 16 | 17 | func init() { 18 | i := AWSWafRule{} 19 | listers = append(listers, i) 20 | } 21 | 22 | func (l AWSWafRule) Types() []resource.ResourceType { 23 | return []resource.ResourceType{resource.WafRule} 24 | } 25 | 26 | func (l AWSWafRule) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | svc := waf.NewFromConfig(ctx.AWSCfg) 28 | rg := resource.NewGroup() 29 | 30 | var outerErr error 31 | 32 | listWafRulesOnce.Do(func() { 33 | outerErr = Paginator(func(nt *string) (*string, error) { 34 | res, err := svc.ListRules(ctx.Context, &waf.ListRulesInput{ 35 | Limit: 100, 36 | NextMarker: nt, 37 | }) 38 | if err != nil { 39 | return nil, fmt.Errorf("failed to list rules: %w", err) 40 | } 41 | for _, ruleId := range res.Rules { 42 | rule, err := svc.GetRule(ctx.Context, &waf.GetRuleInput{RuleId: ruleId.RuleId}) 43 | if err != nil { 44 | return nil, fmt.Errorf("failed to get rule %s: %w", *ruleId.RuleId, err) 45 | } 46 | if rule.Rule == nil { 47 | continue 48 | } 49 | r := resource.NewGlobal(ctx, resource.WafRule, rule.Rule.RuleId, rule.Rule.Name, rule.Rule) 50 | rg.AddResource(r) 51 | } 52 | return res.NextMarker, nil 53 | }) 54 | }) 55 | 56 | return rg, outerErr 57 | } 58 | -------------------------------------------------------------------------------- /lister/waf_webacl.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | 7 | "github.com/aws/aws-sdk-go-v2/service/waf" 8 | "github.com/trek10inc/awsets/arn" 9 | "github.com/trek10inc/awsets/context" 10 | "github.com/trek10inc/awsets/resource" 11 | ) 12 | 13 | var listWafWebAclsOnce sync.Once 14 | 15 | type AWSWafWebAcl struct { 16 | } 17 | 18 | func init() { 19 | i := AWSWafWebAcl{} 20 | listers = append(listers, i) 21 | } 22 | 23 | func (l AWSWafWebAcl) Types() []resource.ResourceType { 24 | return []resource.ResourceType{resource.WafWebACL} 25 | } 26 | 27 | func (l AWSWafWebAcl) List(ctx context.AWSetsCtx) (*resource.Group, error) { 28 | svc := waf.NewFromConfig(ctx.AWSCfg) 29 | rg := resource.NewGroup() 30 | 31 | var outerErr error 32 | 33 | listWafWebAclsOnce.Do(func() { 34 | outerErr = Paginator(func(nt *string) (*string, error) { 35 | res, err := svc.ListWebACLs(ctx.Context, &waf.ListWebACLsInput{ 36 | Limit: 100, 37 | NextMarker: nt, 38 | }) 39 | if err != nil { 40 | return nil, fmt.Errorf("failed to list webacls: %w", err) 41 | } 42 | for _, webaclId := range res.WebACLs { 43 | webacl, err := svc.GetWebACL(ctx.Context, &waf.GetWebACLInput{WebACLId: webaclId.WebACLId}) 44 | if err != nil { 45 | return nil, fmt.Errorf("failed to get webacl %s: %w", *webaclId.WebACLId, err) 46 | } 47 | if webacl.WebACL == nil { 48 | continue 49 | } 50 | webaclArn := arn.ParseP(webacl.WebACL.WebACLArn) 51 | r := resource.NewGlobal(ctx, resource.WafWebACL, webaclArn.ResourceId, webacl.WebACL.Name, webacl.WebACL) 52 | rg.AddResource(r) 53 | } 54 | return res.NextMarker, nil 55 | }) 56 | }) 57 | 58 | return rg, outerErr 59 | } 60 | -------------------------------------------------------------------------------- /lister/waf_xssmatchset.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | 7 | "github.com/aws/aws-sdk-go-v2/service/waf" 8 | "github.com/trek10inc/awsets/context" 9 | "github.com/trek10inc/awsets/resource" 10 | ) 11 | 12 | var listWafXssMatchSetsOnce sync.Once 13 | 14 | type AWSWafXssMatchSet struct { 15 | } 16 | 17 | func init() { 18 | i := AWSWafXssMatchSet{} 19 | listers = append(listers, i) 20 | } 21 | 22 | func (l AWSWafXssMatchSet) Types() []resource.ResourceType { 23 | return []resource.ResourceType{resource.WafXssMatchSet} 24 | } 25 | 26 | func (l AWSWafXssMatchSet) List(ctx context.AWSetsCtx) (*resource.Group, error) { 27 | svc := waf.NewFromConfig(ctx.AWSCfg) 28 | rg := resource.NewGroup() 29 | 30 | var outerErr error 31 | 32 | listWafXssMatchSetsOnce.Do(func() { 33 | outerErr = Paginator(func(nt *string) (*string, error) { 34 | res, err := svc.ListXssMatchSets(ctx.Context, &waf.ListXssMatchSetsInput{ 35 | Limit: 100, 36 | NextMarker: nt, 37 | }) 38 | if err != nil { 39 | return nil, fmt.Errorf("failed to list xss match sets: %w", err) 40 | } 41 | for _, id := range res.XssMatchSets { 42 | xssMatchSet, err := svc.GetXssMatchSet(ctx.Context, &waf.GetXssMatchSetInput{ 43 | XssMatchSetId: id.XssMatchSetId, 44 | }) 45 | if err != nil { 46 | return nil, fmt.Errorf("failed to get xss match stringset %s: %w", *id.XssMatchSetId, err) 47 | } 48 | if v := xssMatchSet.XssMatchSet; v != nil { 49 | r := resource.NewGlobal(ctx, resource.WafXssMatchSet, v.XssMatchSetId, v.Name, v) 50 | rg.AddResource(r) 51 | } 52 | } 53 | return res.NextMarker, nil 54 | }) 55 | }) 56 | return rg, outerErr 57 | } 58 | -------------------------------------------------------------------------------- /lister/wafregional_bytematchset.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/wafregional" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSWafRegionalByteMatchSet struct { 12 | } 13 | 14 | func init() { 15 | i := AWSWafRegionalByteMatchSet{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSWafRegionalByteMatchSet) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.WafRegionalByteMatchSet} 21 | } 22 | 23 | func (l AWSWafRegionalByteMatchSet) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := wafregional.NewFromConfig(ctx.AWSCfg) 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.ListByteMatchSets(ctx.Context, &wafregional.ListByteMatchSetsInput{ 28 | Limit: 100, 29 | NextMarker: nt, 30 | }) 31 | if err != nil { 32 | return nil, fmt.Errorf("failed to list regional byte match sets: %w", err) 33 | } 34 | for _, id := range res.ByteMatchSets { 35 | matchSet, err := svc.GetByteMatchSet(ctx.Context, &wafregional.GetByteMatchSetInput{ 36 | ByteMatchSetId: id.ByteMatchSetId, 37 | }) 38 | if err != nil { 39 | return nil, fmt.Errorf("failed to get byte match set %s: %w", *id.ByteMatchSetId, err) 40 | } 41 | if v := matchSet.ByteMatchSet; v != nil { 42 | r := resource.New(ctx, resource.WafRegionalByteMatchSet, v.ByteMatchSetId, v.Name, v) 43 | rg.AddResource(r) 44 | } 45 | } 46 | return res.NextMarker, nil 47 | }) 48 | return rg, err 49 | } 50 | -------------------------------------------------------------------------------- /lister/wafregional_geomatchset.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/wafregional" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSWafRegionalGeoMatchSet struct { 12 | } 13 | 14 | func init() { 15 | i := AWSWafRegionalGeoMatchSet{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSWafRegionalGeoMatchSet) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.WafRegionalGeoMatchSet} 21 | } 22 | 23 | func (l AWSWafRegionalGeoMatchSet) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := wafregional.NewFromConfig(ctx.AWSCfg) 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.ListGeoMatchSets(ctx.Context, &wafregional.ListGeoMatchSetsInput{ 28 | Limit: 100, 29 | NextMarker: nt, 30 | }) 31 | if err != nil { 32 | return nil, fmt.Errorf("failed to list regional geo match sets: %w", err) 33 | } 34 | for _, id := range res.GeoMatchSets { 35 | matchSet, err := svc.GetGeoMatchSet(ctx.Context, &wafregional.GetGeoMatchSetInput{ 36 | GeoMatchSetId: id.GeoMatchSetId, 37 | }) 38 | if err != nil { 39 | return nil, fmt.Errorf("failed to get geo match set %s: %w", *id.GeoMatchSetId, err) 40 | } 41 | if v := matchSet.GeoMatchSet; v != nil { 42 | r := resource.New(ctx, resource.WafRegionalGeoMatchSet, v.GeoMatchSetId, v.Name, v) 43 | rg.AddResource(r) 44 | } 45 | } 46 | return res.NextMarker, nil 47 | }) 48 | return rg, err 49 | } 50 | -------------------------------------------------------------------------------- /lister/wafregional_ipset.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/wafregional" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSWafRegionalIpSet struct { 12 | } 13 | 14 | func init() { 15 | i := AWSWafRegionalIpSet{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSWafRegionalIpSet) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.WafRegionalIpSet} 21 | } 22 | 23 | func (l AWSWafRegionalIpSet) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := wafregional.NewFromConfig(ctx.AWSCfg) 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.ListIPSets(ctx.Context, &wafregional.ListIPSetsInput{ 28 | Limit: 100, 29 | NextMarker: nt, 30 | }) 31 | if err != nil { 32 | return nil, fmt.Errorf("failed to list ip sets: %w", err) 33 | } 34 | for _, id := range res.IPSets { 35 | ipset, err := svc.GetIPSet(ctx.Context, &wafregional.GetIPSetInput{ 36 | IPSetId: id.IPSetId, 37 | }) 38 | if err != nil { 39 | return nil, fmt.Errorf("failed to get ipset %s: %w", *id.IPSetId, err) 40 | } 41 | if v := ipset.IPSet; v != nil { 42 | r := resource.New(ctx, resource.WafRegionalIpSet, v.IPSetId, v.Name, v) 43 | rg.AddResource(r) 44 | } 45 | } 46 | return res.NextMarker, nil 47 | }) 48 | return rg, err 49 | } 50 | -------------------------------------------------------------------------------- /lister/wafregional_ratebasedrule.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/wafregional" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSWafRegionalRateBasedRule struct { 12 | } 13 | 14 | func init() { 15 | i := AWSWafRegionalRateBasedRule{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSWafRegionalRateBasedRule) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.WafRegionalRateBasedRule} 21 | } 22 | 23 | func (l AWSWafRegionalRateBasedRule) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := wafregional.NewFromConfig(ctx.AWSCfg) 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.ListRateBasedRules(ctx.Context, &wafregional.ListRateBasedRulesInput{ 28 | Limit: 100, 29 | NextMarker: nt, 30 | }) 31 | if err != nil { 32 | return nil, fmt.Errorf("failed to list regional rate based rule: %w", err) 33 | } 34 | for _, id := range res.Rules { 35 | rule, err := svc.GetRateBasedRule(ctx.Context, &wafregional.GetRateBasedRuleInput{ 36 | RuleId: id.RuleId, 37 | }) 38 | if err != nil { 39 | return nil, fmt.Errorf("failed to get rate based rule %s: %w", *id.RuleId, err) 40 | } 41 | if v := rule.Rule; v != nil { 42 | r := resource.New(ctx, resource.WafRegionalRateBasedRule, v.RuleId, v.Name, v) 43 | rg.AddResource(r) 44 | } 45 | } 46 | return res.NextMarker, nil 47 | }) 48 | return rg, err 49 | } 50 | -------------------------------------------------------------------------------- /lister/wafregional_regexpatternset.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/wafregional" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSWafRegionalRegexPatternSet struct { 12 | } 13 | 14 | func init() { 15 | i := AWSWafRegionalRegexPatternSet{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSWafRegionalRegexPatternSet) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.WafRegionalRegexPatternSet} 21 | } 22 | 23 | func (l AWSWafRegionalRegexPatternSet) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := wafregional.NewFromConfig(ctx.AWSCfg) 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.ListRegexPatternSets(ctx.Context, &wafregional.ListRegexPatternSetsInput{ 28 | Limit: 100, 29 | NextMarker: nt, 30 | }) 31 | if err != nil { 32 | return nil, fmt.Errorf("failed to list regional regex pattern sets: %w", err) 33 | } 34 | for _, id := range res.RegexPatternSets { 35 | matchSet, err := svc.GetRegexPatternSet(ctx.Context, &wafregional.GetRegexPatternSetInput{ 36 | RegexPatternSetId: id.RegexPatternSetId, 37 | }) 38 | if err != nil { 39 | return nil, fmt.Errorf("failed to get regex pattern set %s: %w", *id.RegexPatternSetId, err) 40 | } 41 | if v := matchSet.RegexPatternSet; v != nil { 42 | r := resource.New(ctx, resource.WafRegionalRegexPatternSet, v.RegexPatternSetId, v.Name, v) 43 | rg.AddResource(r) 44 | } 45 | } 46 | return res.NextMarker, nil 47 | }) 48 | return rg, err 49 | } 50 | -------------------------------------------------------------------------------- /lister/wafregional_rule.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/wafregional" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSWafRegionalRule struct { 12 | } 13 | 14 | func init() { 15 | i := AWSWafRegionalRule{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSWafRegionalRule) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.WafRegionalRule} 21 | } 22 | 23 | func (l AWSWafRegionalRule) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := wafregional.NewFromConfig(ctx.AWSCfg) 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.ListRules(ctx.Context, &wafregional.ListRulesInput{ 28 | Limit: 100, 29 | NextMarker: nt, 30 | }) 31 | if err != nil { 32 | return nil, fmt.Errorf("failed to list webacls: %w", err) 33 | } 34 | for _, ruleId := range res.Rules { 35 | rule, err := svc.GetRule(ctx.Context, &wafregional.GetRuleInput{RuleId: ruleId.RuleId}) 36 | if err != nil { 37 | return nil, fmt.Errorf("failed to get rule %s: %w", *ruleId.RuleId, err) 38 | } 39 | if rule.Rule == nil { 40 | continue 41 | } 42 | r := resource.New(ctx, resource.WafRegionalRule, rule.Rule.RuleId, rule.Rule.Name, rule.Rule) 43 | rg.AddResource(r) 44 | } 45 | return res.NextMarker, nil 46 | }) 47 | return rg, err 48 | } 49 | -------------------------------------------------------------------------------- /lister/wafregional_sizeconstraintset.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/wafregional" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSWafRegionalSizeConstraintSet struct { 12 | } 13 | 14 | func init() { 15 | i := AWSWafRegionalSizeConstraintSet{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSWafRegionalSizeConstraintSet) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.WafRegionalSizeConstraint} 21 | } 22 | 23 | func (l AWSWafRegionalSizeConstraintSet) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := wafregional.NewFromConfig(ctx.AWSCfg) 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.ListSizeConstraintSets(ctx.Context, &wafregional.ListSizeConstraintSetsInput{ 28 | Limit: 100, 29 | NextMarker: nt, 30 | }) 31 | if err != nil { 32 | return nil, fmt.Errorf("failed to list regional size constraint sets: %w", err) 33 | } 34 | for _, id := range res.SizeConstraintSets { 35 | matchSet, err := svc.GetSizeConstraintSet(ctx.Context, &wafregional.GetSizeConstraintSetInput{ 36 | SizeConstraintSetId: id.SizeConstraintSetId, 37 | }) 38 | if err != nil { 39 | return nil, fmt.Errorf("failed to get size constraint set %s: %w", *id.SizeConstraintSetId, err) 40 | } 41 | if v := matchSet.SizeConstraintSet; v != nil { 42 | r := resource.New(ctx, resource.WafRegionalSizeConstraint, v.SizeConstraintSetId, v.Name, v) 43 | rg.AddResource(r) 44 | } 45 | } 46 | return res.NextMarker, nil 47 | }) 48 | return rg, err 49 | } 50 | -------------------------------------------------------------------------------- /lister/wafregional_sqlinjectionmatchset.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/wafregional" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSWafRegionalSqlInjectionMatchSet struct { 12 | } 13 | 14 | func init() { 15 | i := AWSWafRegionalSqlInjectionMatchSet{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSWafRegionalSqlInjectionMatchSet) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.WafRegionalSqlInjectionMatchSet} 21 | } 22 | 23 | func (l AWSWafRegionalSqlInjectionMatchSet) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := wafregional.NewFromConfig(ctx.AWSCfg) 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.ListSqlInjectionMatchSets(ctx.Context, &wafregional.ListSqlInjectionMatchSetsInput{ 28 | Limit: 100, 29 | NextMarker: nt, 30 | }) 31 | if err != nil { 32 | return nil, fmt.Errorf("failed to list regional sql injection match sets: %w", err) 33 | } 34 | for _, id := range res.SqlInjectionMatchSets { 35 | matchSet, err := svc.GetSqlInjectionMatchSet(ctx.Context, &wafregional.GetSqlInjectionMatchSetInput{ 36 | SqlInjectionMatchSetId: id.SqlInjectionMatchSetId, 37 | }) 38 | if err != nil { 39 | return nil, fmt.Errorf("failed to get sql injection match set %s: %w", *id.SqlInjectionMatchSetId, err) 40 | } 41 | if v := matchSet.SqlInjectionMatchSet; v != nil { 42 | r := resource.New(ctx, resource.WafRegionalSqlInjectionMatchSet, v.SqlInjectionMatchSetId, v.Name, v) 43 | rg.AddResource(r) 44 | } 45 | } 46 | return res.NextMarker, nil 47 | }) 48 | return rg, err 49 | } 50 | -------------------------------------------------------------------------------- /lister/wafregional_xssmatchset.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/aws/aws-sdk-go-v2/service/wafregional" 7 | "github.com/trek10inc/awsets/context" 8 | "github.com/trek10inc/awsets/resource" 9 | ) 10 | 11 | type AWSWafRegionalXssMatchSet struct { 12 | } 13 | 14 | func init() { 15 | i := AWSWafRegionalXssMatchSet{} 16 | listers = append(listers, i) 17 | } 18 | 19 | func (l AWSWafRegionalXssMatchSet) Types() []resource.ResourceType { 20 | return []resource.ResourceType{resource.WafRegionalXssMatchSet} 21 | } 22 | 23 | func (l AWSWafRegionalXssMatchSet) List(ctx context.AWSetsCtx) (*resource.Group, error) { 24 | svc := wafregional.NewFromConfig(ctx.AWSCfg) 25 | rg := resource.NewGroup() 26 | err := Paginator(func(nt *string) (*string, error) { 27 | res, err := svc.ListXssMatchSets(ctx.Context, &wafregional.ListXssMatchSetsInput{ 28 | Limit: 100, 29 | NextMarker: nt, 30 | }) 31 | if err != nil { 32 | return nil, fmt.Errorf("failed to list regional xss match sets: %w", err) 33 | } 34 | for _, id := range res.XssMatchSets { 35 | matchSet, err := svc.GetXssMatchSet(ctx.Context, &wafregional.GetXssMatchSetInput{ 36 | XssMatchSetId: id.XssMatchSetId, 37 | }) 38 | if err != nil { 39 | return nil, fmt.Errorf("failed to get xss match set %s: %w", *id.XssMatchSetId, err) 40 | } 41 | if v := matchSet.XssMatchSet; v != nil { 42 | r := resource.New(ctx, resource.WafRegionalXssMatchSet, v.XssMatchSetId, v.Name, v) 43 | rg.AddResource(r) 44 | } 45 | } 46 | return res.NextMarker, nil 47 | }) 48 | return rg, err 49 | } 50 | -------------------------------------------------------------------------------- /lister/workspaces_workspace.go: -------------------------------------------------------------------------------- 1 | package lister 2 | 3 | import ( 4 | "github.com/aws/aws-sdk-go-v2/service/workspaces" 5 | "github.com/trek10inc/awsets/context" 6 | "github.com/trek10inc/awsets/resource" 7 | ) 8 | 9 | type AWSWorkspacesWorkspace struct { 10 | } 11 | 12 | func init() { 13 | i := AWSWorkspacesWorkspace{} 14 | listers = append(listers, i) 15 | } 16 | 17 | func (l AWSWorkspacesWorkspace) Types() []resource.ResourceType { 18 | return []resource.ResourceType{resource.WorkspacesWorkspace} 19 | } 20 | 21 | func (l AWSWorkspacesWorkspace) List(ctx context.AWSetsCtx) (*resource.Group, error) { 22 | svc := workspaces.NewFromConfig(ctx.AWSCfg) 23 | 24 | rg := resource.NewGroup() 25 | err := Paginator(func(nt *string) (*string, error) { 26 | res, err := svc.DescribeWorkspaces(ctx.Context, &workspaces.DescribeWorkspacesInput{ 27 | NextToken: nt, 28 | }) 29 | if err != nil { 30 | return nil, err 31 | } 32 | for _, v := range res.Workspaces { 33 | r := resource.New(ctx, resource.WorkspacesWorkspace, v.WorkspaceId, v.WorkspaceId, v) 34 | r.AddRelation(resource.Ec2Subnet, v.SubnetId, "") 35 | rg.AddResource(r) 36 | } 37 | return res.NextToken, nil 38 | }) 39 | return rg, err 40 | } 41 | -------------------------------------------------------------------------------- /main_test.go: -------------------------------------------------------------------------------- 1 | package awsets 2 | 3 | import ( 4 | "strings" 5 | "testing" 6 | ) 7 | 8 | func Test_Types(t *testing.T) { 9 | types := Types([]string{""}, []string{""}) 10 | if len(types) == 0 { 11 | t.Fatalf("expected all types") 12 | } 13 | types = Types(nil, nil) 14 | if len(types) == 0 { 15 | t.Fatalf("expected all types") 16 | } 17 | types = Types([]string{""}, []string{"ec2"}) 18 | for _, rt := range types { 19 | if strings.HasPrefix(rt.String(), "ec2") { 20 | t.Fatalf("expected ec2* resource types to have been filtered out") 21 | } 22 | } 23 | types = Types([]string{"ec2"}, []string{""}) 24 | for _, rt := range types { 25 | if !strings.HasPrefix(rt.String(), "ec2") { 26 | t.Fatalf("on expected ec2* resource types to be present") 27 | } 28 | } 29 | } 30 | 31 | func Test_Listers(t *testing.T) { 32 | listers := Listers([]string{""}, []string{""}) 33 | if len(listers) == 0 { 34 | t.Fatalf("expected all listers") 35 | } 36 | listers = Listers(nil, nil) 37 | if len(listers) == 0 { 38 | t.Fatalf("expected all listers") 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /resource/cfn_test.go: -------------------------------------------------------------------------------- 1 | package resource 2 | 3 | import ( 4 | "errors" 5 | "reflect" 6 | "testing" 7 | ) 8 | 9 | func Test_FromCfn(t *testing.T) { 10 | tests := map[string]struct { 11 | res string 12 | err error 13 | }{ 14 | "Not::A::Resource": { 15 | res: "Not/A/Resource", 16 | err: errors.New("no type defined for Not::A::Resource"), 17 | }, 18 | "AWS::EC2::Instance": { 19 | res: Ec2Instance.String(), 20 | err: nil, 21 | }, 22 | } 23 | for k, v := range tests { 24 | t.Run(k, func(t *testing.T) { 25 | r, err := FromCfn(k) 26 | if !reflect.DeepEqual(err, v.err) || r.String() != v.res { 27 | t.Errorf("expected %s-%v, got %s-%v", v.res, v.err, r, err) 28 | } 29 | }) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /resource/types_test.go: -------------------------------------------------------------------------------- 1 | package resource 2 | 3 | import "testing" 4 | 5 | func Test_ResourceTypeStringer(t *testing.T) { 6 | tests := map[ResourceType]string{ 7 | Unmapped: "unmapped", 8 | Unnecessary: "unnecessary", 9 | AcmCertificate: "acm/certificate", 10 | } 11 | for k, v := range tests { 12 | t.Run(k.String(), func(t *testing.T) { 13 | if v != k.String() { 14 | t.Errorf("wanted %s, got %s\n", v, k.String()) 15 | } 16 | }) 17 | } 18 | } 19 | --------------------------------------------------------------------------------