-
-
Notifications
You must be signed in to change notification settings - Fork 34
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 #178 from ekristen/conformation-packs
feat: support config conformance pack removal
- Loading branch information
Showing
2 changed files
with
90 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
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,82 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go/service/configservice" | ||
|
||
"github.com/ekristen/libnuke/pkg/registry" | ||
"github.com/ekristen/libnuke/pkg/resource" | ||
"github.com/ekristen/libnuke/pkg/types" | ||
|
||
"github.com/ekristen/aws-nuke/pkg/nuke" | ||
) | ||
|
||
const ConfigServiceConformancePackResource = "ConfigServiceConformancePack" | ||
|
||
func init() { | ||
registry.Register(®istry.Registration{ | ||
Name: ConfigServiceConformancePackResource, | ||
Scope: nuke.Account, | ||
Lister: &ConfigServiceConformancePackLister{}, | ||
}) | ||
} | ||
|
||
type ConfigServiceConformancePackLister struct{} | ||
|
||
func (l *ConfigServiceConformancePackLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { | ||
opts := o.(*nuke.ListerOpts) | ||
svc := configservice.New(opts.Session) | ||
var resources []resource.Resource | ||
|
||
var nextToken *string | ||
|
||
for { | ||
res, err := svc.DescribeConformancePacks(&configservice.DescribeConformancePacksInput{ | ||
NextToken: nextToken, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, p := range res.ConformancePackDetails { | ||
resources = append(resources, &ConfigServiceConformancePack{ | ||
svc: svc, | ||
id: p.ConformancePackId, | ||
name: p.ConformancePackName, | ||
}) | ||
} | ||
|
||
if res.NextToken == nil { | ||
break | ||
} | ||
|
||
nextToken = res.NextToken | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
type ConfigServiceConformancePack struct { | ||
svc *configservice.ConfigService | ||
id *string | ||
name *string | ||
} | ||
|
||
func (r *ConfigServiceConformancePack) Remove(_ context.Context) error { | ||
_, err := r.svc.DeleteConformancePack(&configservice.DeleteConformancePackInput{ | ||
ConformancePackName: r.name, | ||
}) | ||
return err | ||
} | ||
|
||
func (r *ConfigServiceConformancePack) Properties() types.Properties { | ||
props := types.NewProperties() | ||
props.Set("ID", r.id) | ||
props.Set("Name", r.name) | ||
return props | ||
} | ||
|
||
func (r *ConfigServiceConformancePack) String() string { | ||
return *r.id | ||
} |