This repository was archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 727
added global accelerator resources #524
Merged
+293
−0
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,71 @@ | ||
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/globalaccelerator" | ||
"github.com/rebuy-de/aws-nuke/pkg/types" | ||
) | ||
|
||
// GAAccelerator model | ||
type GAAccelerator struct { | ||
svc *globalaccelerator.GlobalAccelerator | ||
ARN *string | ||
} | ||
|
||
func init() { | ||
register("GAAccelerator", ListGAAccelerators) | ||
} | ||
|
||
// ListGAAccelerators enumerates all available accelerators | ||
func ListGAAccelerators(sess *session.Session) ([]Resource, error) { | ||
svc := globalaccelerator.New(sess) | ||
resources := []Resource{} | ||
|
||
params := &globalaccelerator.ListAcceleratorsInput{ | ||
MaxResults: aws.Int64(100), | ||
} | ||
|
||
for { | ||
output, err := svc.ListAccelerators(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, accelerator := range output.Accelerators { | ||
resources = append(resources, &GAAccelerator{ | ||
svc: svc, | ||
ARN: accelerator.AcceleratorArn, | ||
}) | ||
} | ||
|
||
if output.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = output.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
// Remove resource | ||
func (gaa *GAAccelerator) Remove() error { | ||
_, err := gaa.svc.DeleteAccelerator(&globalaccelerator.DeleteAcceleratorInput{ | ||
AcceleratorArn: gaa.ARN, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
// Properties definition | ||
func (gaa *GAAccelerator) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("Arn", gaa.ARN) | ||
jami marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return properties | ||
} | ||
|
||
// String representation | ||
func (gaa *GAAccelerator) String() string { | ||
return *gaa.ARN | ||
} |
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,124 @@ | ||
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/globalaccelerator" | ||
"github.com/rebuy-de/aws-nuke/pkg/types" | ||
) | ||
|
||
// GAEndpointGroup model | ||
type GAEndpointGroup struct { | ||
svc *globalaccelerator.GlobalAccelerator | ||
ARN *string | ||
} | ||
|
||
func init() { | ||
register("GAEndpointGroup", ListGAEndpointGroups) | ||
} | ||
|
||
// ListGAEndpointGroups enumerates all available accelerators | ||
func ListGAEndpointGroups(sess *session.Session) ([]Resource, error) { | ||
svc := globalaccelerator.New(sess) | ||
acceleratorARNs := []*string{} | ||
listenerARNs := []*string{} | ||
resources := []Resource{} | ||
|
||
// get all accelerator arns | ||
acceleratorParams := &globalaccelerator.ListAcceleratorsInput{ | ||
MaxResults: aws.Int64(100), | ||
} | ||
|
||
for { | ||
output, err := svc.ListAccelerators(acceleratorParams) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, accelerator := range output.Accelerators { | ||
acceleratorARNs = append(acceleratorARNs, accelerator.AcceleratorArn) | ||
} | ||
|
||
if output.NextToken == nil { | ||
break | ||
} | ||
|
||
acceleratorParams.NextToken = output.NextToken | ||
} | ||
|
||
// get all listerners arns of all accelerators | ||
for _, acceleratorARN := range acceleratorARNs { | ||
listenerParams := &globalaccelerator.ListListenersInput{ | ||
MaxResults: aws.Int64(100), | ||
AcceleratorArn: acceleratorARN, | ||
} | ||
|
||
for { | ||
output, err := svc.ListListeners(listenerParams) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, listener := range output.Listeners { | ||
listenerARNs = append(listenerARNs, listener.ListenerArn) | ||
} | ||
|
||
if output.NextToken == nil { | ||
break | ||
} | ||
|
||
listenerParams.NextToken = output.NextToken | ||
} | ||
} | ||
|
||
// get all endpoints based on all listeners based on all accelerator | ||
for _, listenerArn := range listenerARNs { | ||
params := &globalaccelerator.ListEndpointGroupsInput{ | ||
MaxResults: aws.Int64(100), | ||
ListenerArn: listenerArn, | ||
} | ||
|
||
for { | ||
output, err := svc.ListEndpointGroups(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, endpointGroup := range output.EndpointGroups { | ||
resources = append(resources, &GAEndpointGroup{ | ||
svc: svc, | ||
ARN: endpointGroup.EndpointGroupArn, | ||
}) | ||
} | ||
|
||
if output.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = output.NextToken | ||
} | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
// Remove resource | ||
func (gaeg *GAEndpointGroup) Remove() error { | ||
_, err := gaeg.svc.DeleteEndpointGroup(&globalaccelerator.DeleteEndpointGroupInput{ | ||
EndpointGroupArn: gaeg.ARN, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
// Properties definition | ||
func (gaeg *GAEndpointGroup) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("Arn", gaeg.ARN) | ||
jami marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return properties | ||
} | ||
|
||
// String representation | ||
func (gaeg *GAEndpointGroup) String() string { | ||
return *gaeg.ARN | ||
} |
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,98 @@ | ||
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/globalaccelerator" | ||
"github.com/rebuy-de/aws-nuke/pkg/types" | ||
) | ||
|
||
// GAListener model | ||
type GAListener struct { | ||
svc *globalaccelerator.GlobalAccelerator | ||
ARN *string | ||
} | ||
|
||
func init() { | ||
register("GAListener", ListGAListeners) | ||
} | ||
|
||
// ListGAListeners enumerates all available listeners of all available accelerators | ||
func ListGAListeners(sess *session.Session) ([]Resource, error) { | ||
svc := globalaccelerator.New(sess) | ||
acceleratorARNs := []*string{} | ||
resources := []Resource{} | ||
|
||
// get all accelerator arns | ||
acceleratorParams := &globalaccelerator.ListAcceleratorsInput{ | ||
MaxResults: aws.Int64(100), | ||
} | ||
|
||
for { | ||
output, err := svc.ListAccelerators(acceleratorParams) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, accelerator := range output.Accelerators { | ||
acceleratorARNs = append(acceleratorARNs, accelerator.AcceleratorArn) | ||
} | ||
|
||
if output.NextToken == nil { | ||
break | ||
} | ||
|
||
acceleratorParams.NextToken = output.NextToken | ||
} | ||
|
||
// get all listerners | ||
for _, acceleratorARN := range acceleratorARNs { | ||
params := &globalaccelerator.ListListenersInput{ | ||
MaxResults: aws.Int64(100), | ||
AcceleratorArn: acceleratorARN, | ||
} | ||
|
||
for { | ||
output, err := svc.ListListeners(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, listener := range output.Listeners { | ||
resources = append(resources, &GAListener{ | ||
svc: svc, | ||
ARN: listener.ListenerArn, | ||
}) | ||
} | ||
|
||
if output.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = output.NextToken | ||
} | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
// Remove resource | ||
func (gal *GAListener) Remove() error { | ||
_, err := gal.svc.DeleteListener(&globalaccelerator.DeleteListenerInput{ | ||
ListenerArn: gal.ARN, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
// Properties definition | ||
func (gal *GAListener) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("Arn", gal.ARN) | ||
jami marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return properties | ||
} | ||
|
||
// String representation | ||
func (gal *GAListener) String() string { | ||
return *gal.ARN | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you name it
GAAccelerator
and notGlobalAccelerator
? We usually take the prefix from the AWS SDK package name.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it is the type/resource Accelerator within the service GlobalAccelerator. The naming is in line with EC2Image, EC2Address and so on. And how should it look in your opinion for GlobalAccelerator with the 3 parts Accelerator, Listeners and EndpointGroups?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find GlobalAcceleratorAccelerator is super ugly. For GlobalAcceleratorListener and GlobalAcceleratorEndpointGroup it is ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@svenwltr @der-eismann I'm still waiting for a recommendation on how to rename it correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late response.
I prefer prefixing the resource name with the package name from the AWS SDK. Also I think it is okay to skip the later part for the actual accelerator. Therefore I suggest:
GlobalAccelerator
GlobalAcceleratorListener
GlobalAcceleratorEndpointGroup