Skip to content

Commit

Permalink
Merge pull request #22 from oreillymedia/cl-807-aws-glue-support
Browse files Browse the repository at this point in the history
CL-807 Adding support for Glue features.
  • Loading branch information
swhite-oreilly authored Mar 22, 2024
2 parents 8294c3a + aada788 commit 89dc604
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 0 deletions.
67 changes: 67 additions & 0 deletions resources/glue-blueprints.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/glue"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type GlueBlueprint struct {
svc *glue.Glue
name *string
}

func init() {
register("GlueBlueprint", ListGlueBlueprints)
}

func ListGlueBlueprints(sess *session.Session) ([]Resource, error) {
svc := glue.New(sess)
resources := []Resource{}

params := &glue.ListBlueprintsInput{
MaxResults: aws.Int64(25),
}

for {
output, err := svc.ListBlueprints(params)
if err != nil {
return nil, err
}

for _, blueprint := range output.Blueprints {
resources = append(resources, &GlueBlueprint{
svc: svc,
name: blueprint,
})
}

if output.NextToken == nil {
break
}

params.NextToken = output.NextToken
}

return resources, nil
}

func (f *GlueBlueprint) Remove() error {
_, err := f.svc.DeleteBlueprint(&glue.DeleteBlueprintInput{
Name: f.name,
})

return err
}

func (f *GlueBlueprint) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Name", f.name)

return properties
}

func (f *GlueBlueprint) String() string {
return *f.name
}
67 changes: 67 additions & 0 deletions resources/glue-ml-transforms.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/glue"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type GlueMLTransform struct {
svc *glue.Glue
id *string
}

func init() {
register("GlueMLTransform", ListGlueMLTransforms)
}

func ListGlueMLTransforms(sess *session.Session) ([]Resource, error) {
svc := glue.New(sess)
resources := []Resource{}

params := &glue.ListMLTransformsInput{
MaxResults: aws.Int64(100),
}

for {
output, err := svc.ListMLTransforms(params)
if err != nil {
return nil, err
}

for _, transformId := range output.TransformIds {
resources = append(resources, &GlueMLTransform{
svc: svc,
id: transformId,
})
}

if output.NextToken == nil {
break
}

params.NextToken = output.NextToken
}

return resources, nil
}

func (f *GlueMLTransform) Remove() error {
_, err := f.svc.DeleteMLTransform(&glue.DeleteMLTransformInput{
TransformId: f.id,
})

return err
}

func (f *GlueMLTransform) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Id", f.id)

return properties
}

func (f *GlueMLTransform) String() string {
return *f.id
}
67 changes: 67 additions & 0 deletions resources/glue-sessions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/glue"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type GlueSession struct {
svc *glue.Glue
id *string
}

func init() {
register("GlueSession", ListGlueSessions)
}

func ListGlueSessions(sess *session.Session) ([]Resource, error) {
svc := glue.New(sess)
resources := []Resource{}

params := &glue.ListSessionsInput{
MaxResults: aws.Int64(25),
}

for {
output, err := svc.ListSessions(params)
if err != nil {
return nil, err
}

for _, session := range output.Sessions {
resources = append(resources, &GlueSession{
svc: svc,
id: session.Id,
})
}

if output.NextToken == nil {
break
}

params.NextToken = output.NextToken
}

return resources, nil
}

func (f *GlueSession) Remove() error {
_, err := f.svc.DeleteSession(&glue.DeleteSessionInput{
Id: f.id,
})

return err
}

func (f *GlueSession) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Id", f.id)

return properties
}

func (f *GlueSession) String() string {
return *f.id
}
67 changes: 67 additions & 0 deletions resources/glue-workflows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/glue"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type GlueWorkflow struct {
svc *glue.Glue
name *string
}

func init() {
register("GlueWorkflow", ListGlueWorkflows)
}

func ListGlueWorkflows(sess *session.Session) ([]Resource, error) {
svc := glue.New(sess)
resources := []Resource{}

params := &glue.ListWorkflowsInput{
MaxResults: aws.Int64(25),
}

for {
output, err := svc.ListWorkflows(params)
if err != nil {
return nil, err
}

for _, workflowName := range output.Workflows {
resources = append(resources, &GlueWorkflow{
svc: svc,
name: workflowName,
})
}

if output.NextToken == nil {
break
}

params.NextToken = output.NextToken
}

return resources, nil
}

func (f *GlueWorkflow) Remove() error {
_, err := f.svc.DeleteWorkflow(&glue.DeleteWorkflowInput{
Name: f.name,
})

return err
}

func (f *GlueWorkflow) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Name", f.name)

return properties
}

func (f *GlueWorkflow) String() string {
return *f.name
}

0 comments on commit 89dc604

Please sign in to comment.