-
-
Notifications
You must be signed in to change notification settings - Fork 38
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 #101 from ekristen/feat-delete-core-network
feat: delete core network manager resources
- Loading branch information
Showing
5 changed files
with
393 additions
and
2 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
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,93 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/gotidy/ptr" | ||
|
||
"github.com/aws/aws-sdk-go/service/networkmanager" | ||
|
||
"github.com/ekristen/libnuke/pkg/registry" | ||
"github.com/ekristen/libnuke/pkg/resource" | ||
"github.com/ekristen/libnuke/pkg/types" | ||
|
||
"github.com/ekristen/aws-nuke/pkg/awsutil" | ||
"github.com/ekristen/aws-nuke/pkg/nuke" | ||
) | ||
|
||
type NetworkManagerConnectPeer struct { | ||
svc *networkmanager.NetworkManager | ||
peer *networkmanager.ConnectPeerSummary | ||
} | ||
|
||
const NetworkManagerConnectPeerResource = "NetworkManagerConnectPeer" | ||
|
||
func init() { | ||
registry.Register(®istry.Registration{ | ||
Name: NetworkManagerConnectPeerResource, | ||
Scope: nuke.Account, | ||
Lister: &NetworkManagerConnectPeerLister{}, | ||
}) | ||
} | ||
|
||
type NetworkManagerConnectPeerLister struct{} | ||
|
||
func (l *NetworkManagerConnectPeerLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { | ||
opts := o.(*nuke.ListerOpts) | ||
|
||
svc := networkmanager.New(opts.Session) | ||
params := &networkmanager.ListConnectPeersInput{} | ||
resources := make([]resource.Resource, 0) | ||
|
||
resp, err := svc.ListConnectPeers(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, connectPeer := range resp.ConnectPeers { | ||
resources = append(resources, &NetworkManagerConnectPeer{ | ||
svc: svc, | ||
peer: connectPeer, | ||
}) | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (n *NetworkManagerConnectPeer) Remove(_ context.Context) error { | ||
params := &networkmanager.DeleteConnectPeerInput{ | ||
ConnectPeerId: n.peer.ConnectPeerId, | ||
} | ||
|
||
_, err := n.svc.DeleteConnectPeer(params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (n *NetworkManagerConnectPeer) Filter() error { | ||
if strings.EqualFold(ptr.ToString(n.peer.ConnectPeerState), awsutil.StateDeleted) { | ||
return fmt.Errorf("already deleted") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (n *NetworkManagerConnectPeer) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("ID", n.peer.ConnectPeerId) | ||
|
||
for _, tagValue := range n.peer.Tags { | ||
properties.SetTag(tagValue.Key, tagValue.Value) | ||
} | ||
|
||
return properties | ||
} | ||
|
||
func (n *NetworkManagerConnectPeer) String() string { | ||
return *n.peer.ConnectPeerId | ||
} |
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,94 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/gotidy/ptr" | ||
|
||
"github.com/aws/aws-sdk-go/service/networkmanager" | ||
|
||
"github.com/ekristen/libnuke/pkg/registry" | ||
"github.com/ekristen/libnuke/pkg/resource" | ||
"github.com/ekristen/libnuke/pkg/types" | ||
|
||
"github.com/ekristen/aws-nuke/pkg/awsutil" | ||
"github.com/ekristen/aws-nuke/pkg/nuke" | ||
) | ||
|
||
type NetworkManagerCoreNetwork struct { | ||
svc *networkmanager.NetworkManager | ||
network *networkmanager.CoreNetworkSummary | ||
} | ||
|
||
const NetworkManagerCoreNetworkResource = "NetworkManagerCoreNetwork" | ||
|
||
func init() { | ||
registry.Register(®istry.Registration{ | ||
Name: NetworkManagerCoreNetworkResource, | ||
Scope: nuke.Account, | ||
Lister: &NetworkManagerCoreNetworkLister{}, | ||
}) | ||
} | ||
|
||
type NetworkManagerCoreNetworkLister struct{} | ||
|
||
func (l *NetworkManagerCoreNetworkLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { | ||
opts := o.(*nuke.ListerOpts) | ||
|
||
svc := networkmanager.New(opts.Session) | ||
params := &networkmanager.ListCoreNetworksInput{} | ||
resources := make([]resource.Resource, 0) | ||
|
||
resp, err := svc.ListCoreNetworks(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, network := range resp.CoreNetworks { | ||
resources = append(resources, &NetworkManagerCoreNetwork{ | ||
svc: svc, | ||
network: network, | ||
}) | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (n *NetworkManagerCoreNetwork) Remove(_ context.Context) error { | ||
params := &networkmanager.DeleteCoreNetworkInput{ | ||
CoreNetworkId: n.network.CoreNetworkId, | ||
} | ||
|
||
_, err := n.svc.DeleteCoreNetwork(params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (n *NetworkManagerCoreNetwork) Filter() error { | ||
if strings.EqualFold(ptr.ToString(n.network.State), awsutil.StateDeleted) { | ||
return fmt.Errorf("already deleted") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (n *NetworkManagerCoreNetwork) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
properties.Set("ID", n.network.CoreNetworkId) | ||
properties.Set("ARN", n.network.CoreNetworkArn) | ||
|
||
for _, tagValue := range n.network.Tags { | ||
properties.SetTag(tagValue.Key, tagValue.Value) | ||
} | ||
|
||
return properties | ||
} | ||
|
||
func (n *NetworkManagerCoreNetwork) String() string { | ||
return *n.network.CoreNetworkId | ||
} |
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,106 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/gotidy/ptr" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/networkmanager" | ||
|
||
"github.com/ekristen/libnuke/pkg/registry" | ||
"github.com/ekristen/libnuke/pkg/resource" | ||
"github.com/ekristen/libnuke/pkg/types" | ||
|
||
"github.com/ekristen/aws-nuke/pkg/awsutil" | ||
"github.com/ekristen/aws-nuke/pkg/nuke" | ||
) | ||
|
||
type NetworkManagerGlobalNetwork struct { | ||
svc *networkmanager.NetworkManager | ||
network *networkmanager.GlobalNetwork | ||
} | ||
|
||
const NetworkManagerGlobalNetworkResource = "NetworkManagerGlobalNetwork" | ||
|
||
func init() { | ||
registry.Register(®istry.Registration{ | ||
Name: NetworkManagerGlobalNetworkResource, | ||
Scope: nuke.Account, | ||
Lister: &NetworkManagerGlobalNetworkLister{}, | ||
}) | ||
} | ||
|
||
type NetworkManagerGlobalNetworkLister struct{} | ||
|
||
func (l *NetworkManagerGlobalNetworkLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { | ||
opts := o.(*nuke.ListerOpts) | ||
|
||
svc := networkmanager.New(opts.Session) | ||
resources := make([]resource.Resource, 0) | ||
|
||
params := &networkmanager.DescribeGlobalNetworksInput{ | ||
MaxResults: aws.Int64(100), | ||
} | ||
|
||
for { | ||
resp, err := svc.DescribeGlobalNetworks(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, network := range resp.GlobalNetworks { | ||
resources = append(resources, &NetworkManagerGlobalNetwork{ | ||
svc: svc, | ||
network: network, | ||
}) | ||
} | ||
if resp.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = resp.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (n *NetworkManagerGlobalNetwork) Remove(_ context.Context) error { | ||
params := &networkmanager.DeleteGlobalNetworkInput{ | ||
GlobalNetworkId: n.network.GlobalNetworkId, | ||
} | ||
|
||
_, err := n.svc.DeleteGlobalNetwork(params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (n *NetworkManagerGlobalNetwork) Filter() error { | ||
if strings.EqualFold(ptr.ToString(n.network.State), awsutil.StateDeleted) { | ||
return fmt.Errorf("already deleted") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (n *NetworkManagerGlobalNetwork) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
|
||
properties.Set("ID", n.network.GlobalNetworkId) | ||
properties.Set("ARN", n.network.GlobalNetworkArn) | ||
|
||
for _, tagValue := range n.network.Tags { | ||
properties.SetTag(tagValue.Key, tagValue.Value) | ||
} | ||
|
||
return properties | ||
} | ||
|
||
func (n *NetworkManagerGlobalNetwork) String() string { | ||
return *n.network.GlobalNetworkId | ||
} |
Oops, something went wrong.