-
-
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 #291 from ekristen/amplify
feat(resource): add resource for amplify app
- Loading branch information
Showing
2 changed files
with
122 additions
and
0 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,91 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/amplify" | ||
|
||
"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 AmplifyAppResource = "AmplifyApp" | ||
|
||
func init() { | ||
registry.Register(®istry.Registration{ | ||
Name: AmplifyAppResource, | ||
Scope: nuke.Account, | ||
Lister: &AmplifyAppLister{}, | ||
}) | ||
} | ||
|
||
type AmplifyAppLister struct{} | ||
|
||
func (l *AmplifyAppLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { | ||
opts := o.(*nuke.ListerOpts) | ||
|
||
svc := amplify.New(opts.Session) | ||
resources := make([]resource.Resource, 0) | ||
|
||
params := &lify.ListAppsInput{ | ||
MaxResults: aws.Int64(100), | ||
} | ||
|
||
for { | ||
output, err := svc.ListApps(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, item := range output.Apps { | ||
resources = append(resources, &AmplifyApp{ | ||
svc: svc, | ||
AppID: item.AppId, | ||
Name: item.Name, | ||
Tags: item.Tags, | ||
}) | ||
} | ||
|
||
if output.NextToken == nil { | ||
break | ||
} | ||
|
||
params.NextToken = output.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
type AmplifyApp struct { | ||
svc *amplify.Amplify | ||
AppID *string | ||
Name *string | ||
Tags map[string]*string | ||
} | ||
|
||
func (r *AmplifyApp) Remove(_ context.Context) error { | ||
_, err := r.svc.DeleteApp(&lify.DeleteAppInput{ | ||
AppId: r.AppID, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (r *AmplifyApp) String() string { | ||
return *r.AppID | ||
} | ||
|
||
func (r *AmplifyApp) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
for key, tag := range r.Tags { | ||
properties.SetTag(&key, tag) | ||
} | ||
properties. | ||
Set("AppID", r.AppID). | ||
Set("Name", r.Name) | ||
return properties | ||
} |
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,31 @@ | ||
package resources | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gotidy/ptr" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var app = &AmplifyApp{ | ||
Name: ptr.String("app1"), | ||
AppID: ptr.String("appId1"), | ||
Tags: map[string]*string{ | ||
"key1": ptr.String("value1"), | ||
}, | ||
} | ||
|
||
func Test_AmplifyApp_Properties(t *testing.T) { | ||
a := assert.New(t) | ||
|
||
properties := app.Properties() | ||
a.Equal("app1", properties.Get("Name")) | ||
a.Equal("appId1", properties.Get("AppID")) | ||
a.Equal("value1", properties.Get("tag:key1")) | ||
} | ||
|
||
func Test_AmplifyApp_Stringer(t *testing.T) { | ||
a := assert.New(t) | ||
|
||
a.Equal("appId1", app.String()) | ||
} |