-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from ekristen/rebuy-1254-athena
feat: add two resources, athena-data-catalog, athena-prepared-statment
- Loading branch information
Showing
4 changed files
with
222 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
|
||
"github.com/aws/aws-sdk-go/service/athena" | ||
|
||
"github.com/ekristen/libnuke/pkg/registry" | ||
"github.com/ekristen/libnuke/pkg/resource" | ||
"github.com/ekristen/libnuke/pkg/types" | ||
|
||
"github.com/ekristen/aws-nuke/v3/pkg/nuke" | ||
) | ||
|
||
const AthenaDataCatalogResource = "AthenaDataCatalog" | ||
|
||
func init() { | ||
registry.Register(®istry.Registration{ | ||
Name: AthenaDataCatalogResource, | ||
Scope: nuke.Account, | ||
Lister: &AthenaDataCatalogLister{}, | ||
}) | ||
} | ||
|
||
type AthenaDataCatalogLister struct{} | ||
|
||
func (l *AthenaDataCatalogLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { | ||
opts := o.(*nuke.ListerOpts) | ||
|
||
svc := athena.New(opts.Session) | ||
resources := make([]resource.Resource, 0) | ||
|
||
params := &athena.ListDataCatalogsInput{ | ||
MaxResults: aws.Int64(50), | ||
} | ||
|
||
for { | ||
output, err := svc.ListDataCatalogs(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, catalog := range output.DataCatalogsSummary { | ||
resources = append(resources, &AthenaDataCatalog{ | ||
svc: svc, | ||
Name: catalog.CatalogName, | ||
}) | ||
} | ||
|
||
if output.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = output.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
type AthenaDataCatalog struct { | ||
svc *athena.Athena | ||
Name *string | ||
} | ||
|
||
func (r *AthenaDataCatalog) Properties() types.Properties { | ||
return types.NewPropertiesFromStruct(r) | ||
} | ||
|
||
func (r *AthenaDataCatalog) Remove(_ context.Context) error { | ||
_, err := r.svc.DeleteDataCatalog(&athena.DeleteDataCatalogInput{ | ||
Name: r.Name, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (r *AthenaDataCatalog) Filter() error { | ||
if *r.Name == "AwsDataCatalog" { | ||
return fmt.Errorf("cannot delete default data source") | ||
} | ||
return nil | ||
} | ||
|
||
func (r *AthenaDataCatalog) String() string { | ||
return *r.Name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
|
||
"github.com/aws/aws-sdk-go/service/athena" | ||
|
||
"github.com/ekristen/libnuke/pkg/registry" | ||
"github.com/ekristen/libnuke/pkg/resource" | ||
"github.com/ekristen/libnuke/pkg/types" | ||
|
||
"github.com/ekristen/aws-nuke/v3/pkg/nuke" | ||
) | ||
|
||
const AthenaPreparedStatementResource = "AthenaPreparedStatement" | ||
|
||
func init() { | ||
registry.Register(®istry.Registration{ | ||
Name: AthenaPreparedStatementResource, | ||
Scope: nuke.Account, | ||
Lister: &AthenaPreparedStatementLister{}, | ||
}) | ||
} | ||
|
||
type AthenaPreparedStatementLister struct{} | ||
|
||
func (l *AthenaPreparedStatementLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { | ||
opts := o.(*nuke.ListerOpts) | ||
|
||
svc := athena.New(opts.Session) | ||
resources := make([]resource.Resource, 0) | ||
|
||
workgroups, err := svc.ListWorkGroups(&athena.ListWorkGroupsInput{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, workgroup := range workgroups.WorkGroups { | ||
params := &athena.ListPreparedStatementsInput{ | ||
WorkGroup: workgroup.Name, | ||
MaxResults: aws.Int64(50), | ||
} | ||
|
||
for { | ||
output, err := svc.ListPreparedStatements(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, statement := range output.PreparedStatements { | ||
resources = append(resources, &AthenaPreparedStatement{ | ||
svc: svc, | ||
Name: statement.StatementName, | ||
WorkGroup: workgroup.Name, | ||
}) | ||
} | ||
|
||
if output.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = output.NextToken | ||
} | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
type AthenaPreparedStatement struct { | ||
svc *athena.Athena | ||
Name *string | ||
WorkGroup *string | ||
} | ||
|
||
func (r *AthenaPreparedStatement) Properties() types.Properties { | ||
return types.NewPropertiesFromStruct(r) | ||
} | ||
|
||
func (r *AthenaPreparedStatement) Remove(_ context.Context) error { | ||
_, err := r.svc.DeletePreparedStatement(&athena.DeletePreparedStatementInput{ | ||
StatementName: r.Name, | ||
WorkGroup: r.WorkGroup, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (r *AthenaPreparedStatement) String() string { | ||
return *r.Name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters