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 725
New support for Application Migration Service (MGN) resources #1024 #1025
Merged
der-eismann
merged 9 commits into
rebuy-de:main
from
joelee:feature/1024-Nuking_MGN_Resources
Jun 28, 2023
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a2382b8
Initial fix for issue #1024
joelee 1d193a8
Remove buggy mgn-jobs.go
joelee 186f1d0
Remove buggy mgn-jobs.go
joelee d554850
Add nuking of all MGN jobs:
joelee 0bfa068
Merge conflict on
joelee 827947f
Merge branch 'main' into feature/1024-Nuking_MGN_Resources
joelee a18a8b8
Merge remote-tracking branch 'origin/main' into feature/1024-Nuking_M…
joelee 85fb18c
Merge remote-tracking branch 'origin/feature/1024-Nuking_MGN_Resource…
joelee b19064d
#1025 - Correction of naming convention 'Arn' to 'ARN'
joelee 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 hidden or 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,76 @@ | ||
| 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/mgn" | ||
| "github.com/rebuy-de/aws-nuke/v2/pkg/types" | ||
| ) | ||
|
|
||
| type MGNJob struct { | ||
| svc *mgn.Mgn | ||
| jobID *string | ||
| arn *string | ||
| tags map[string]*string | ||
| } | ||
|
|
||
| func init() { | ||
| register("MGNJob", ListMGNJobs) | ||
| } | ||
|
|
||
| func ListMGNJobs(sess *session.Session) ([]Resource, error) { | ||
| svc := mgn.New(sess) | ||
| resources := []Resource{} | ||
|
|
||
| params := &mgn.DescribeJobsInput{ | ||
| MaxResults: aws.Int64(50), | ||
| } | ||
|
|
||
| for { | ||
| output, err := svc.DescribeJobs(params) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| for _, job := range output.Items { | ||
| resources = append(resources, &MGNJob{ | ||
| svc: svc, | ||
| jobID: job.JobID, | ||
| arn: job.Arn, | ||
| tags: job.Tags, | ||
| }) | ||
| } | ||
|
|
||
| if output.NextToken == nil { | ||
| break | ||
| } | ||
|
|
||
| params.NextToken = output.NextToken | ||
| } | ||
|
|
||
| return resources, nil | ||
| } | ||
|
|
||
| func (f *MGNJob) Remove() error { | ||
|
|
||
| _, err := f.svc.DeleteJob(&mgn.DeleteJobInput{ | ||
| JobID: f.jobID, | ||
| }) | ||
|
|
||
| return err | ||
| } | ||
|
|
||
| func (f *MGNJob) Properties() types.Properties { | ||
| properties := types.NewProperties() | ||
| properties.Set("JobID", f.jobID) | ||
| properties.Set("Arn", f.arn) | ||
|
|
||
| for key, val := range f.tags { | ||
| properties.SetTag(&key, val) | ||
| } | ||
| return properties | ||
| } | ||
|
|
||
| func (f *MGNJob) String() string { | ||
| return *f.jobID | ||
| } | ||
This file contains hidden or 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,76 @@ | ||
| 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/mgn" | ||
| "github.com/rebuy-de/aws-nuke/v2/pkg/types" | ||
| ) | ||
|
|
||
| type MGNSourceServer struct { | ||
| svc *mgn.Mgn | ||
| sourceServerID *string | ||
| arn *string | ||
| tags map[string]*string | ||
| } | ||
|
|
||
| func init() { | ||
| register("MGNSourceServer", ListMGNSourceServers) | ||
| } | ||
|
|
||
| func ListMGNSourceServers(sess *session.Session) ([]Resource, error) { | ||
| svc := mgn.New(sess) | ||
| resources := []Resource{} | ||
|
|
||
| params := &mgn.DescribeSourceServersInput{ | ||
| MaxResults: aws.Int64(50), | ||
| } | ||
|
|
||
| for { | ||
| output, err := svc.DescribeSourceServers(params) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| for _, sourceServer := range output.Items { | ||
| resources = append(resources, &MGNSourceServer{ | ||
| svc: svc, | ||
| sourceServerID: sourceServer.SourceServerID, | ||
| arn: sourceServer.Arn, | ||
| tags: sourceServer.Tags, | ||
| }) | ||
| } | ||
|
|
||
| if output.NextToken == nil { | ||
| break | ||
| } | ||
|
|
||
| params.NextToken = output.NextToken | ||
| } | ||
|
|
||
| return resources, nil | ||
| } | ||
|
|
||
| func (f *MGNSourceServer) Remove() error { | ||
|
|
||
| _, err := f.svc.DeleteSourceServer(&mgn.DeleteSourceServerInput{ | ||
| SourceServerID: f.sourceServerID, | ||
| }) | ||
|
|
||
| return err | ||
| } | ||
|
|
||
| func (f *MGNSourceServer) Properties() types.Properties { | ||
| properties := types.NewProperties() | ||
| properties.Set("SourceServerID", f.sourceServerID) | ||
| properties.Set("Arn", f.arn) | ||
joelee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| for key, val := range f.tags { | ||
| properties.SetTag(&key, val) | ||
| } | ||
| return properties | ||
| } | ||
|
|
||
| func (f *MGNSourceServer) String() string { | ||
| return *f.sourceServerID | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.