|
| 1 | +package resources |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/aws/aws-sdk-go/service/configservice" |
| 7 | + |
| 8 | + "github.com/ekristen/libnuke/pkg/registry" |
| 9 | + "github.com/ekristen/libnuke/pkg/resource" |
| 10 | + "github.com/ekristen/libnuke/pkg/types" |
| 11 | + |
| 12 | + "github.com/ekristen/aws-nuke/pkg/nuke" |
| 13 | +) |
| 14 | + |
| 15 | +const ConfigServiceConformancePackResource = "ConfigServiceConformancePack" |
| 16 | + |
| 17 | +func init() { |
| 18 | + registry.Register(®istry.Registration{ |
| 19 | + Name: ConfigServiceConformancePackResource, |
| 20 | + Scope: nuke.Account, |
| 21 | + Lister: &ConfigServiceConformancePackLister{}, |
| 22 | + }) |
| 23 | +} |
| 24 | + |
| 25 | +type ConfigServiceConformancePackLister struct{} |
| 26 | + |
| 27 | +func (l *ConfigServiceConformancePackLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { |
| 28 | + opts := o.(*nuke.ListerOpts) |
| 29 | + svc := configservice.New(opts.Session) |
| 30 | + var resources []resource.Resource |
| 31 | + |
| 32 | + var nextToken *string |
| 33 | + |
| 34 | + for { |
| 35 | + res, err := svc.DescribeConformancePacks(&configservice.DescribeConformancePacksInput{ |
| 36 | + NextToken: nextToken, |
| 37 | + }) |
| 38 | + if err != nil { |
| 39 | + return nil, err |
| 40 | + } |
| 41 | + |
| 42 | + for _, p := range res.ConformancePackDetails { |
| 43 | + resources = append(resources, &ConfigServiceConformancePack{ |
| 44 | + svc: svc, |
| 45 | + id: p.ConformancePackId, |
| 46 | + name: p.ConformancePackName, |
| 47 | + }) |
| 48 | + } |
| 49 | + |
| 50 | + if res.NextToken == nil { |
| 51 | + break |
| 52 | + } |
| 53 | + |
| 54 | + nextToken = res.NextToken |
| 55 | + } |
| 56 | + |
| 57 | + return resources, nil |
| 58 | +} |
| 59 | + |
| 60 | +type ConfigServiceConformancePack struct { |
| 61 | + svc *configservice.ConfigService |
| 62 | + id *string |
| 63 | + name *string |
| 64 | +} |
| 65 | + |
| 66 | +func (r *ConfigServiceConformancePack) Remove(_ context.Context) error { |
| 67 | + _, err := r.svc.DeleteConformancePack(&configservice.DeleteConformancePackInput{ |
| 68 | + ConformancePackName: r.name, |
| 69 | + }) |
| 70 | + return err |
| 71 | +} |
| 72 | + |
| 73 | +func (r *ConfigServiceConformancePack) Properties() types.Properties { |
| 74 | + props := types.NewProperties() |
| 75 | + props.Set("ID", r.id) |
| 76 | + props.Set("Name", r.name) |
| 77 | + return props |
| 78 | +} |
| 79 | + |
| 80 | +func (r *ConfigServiceConformancePack) String() string { |
| 81 | + return *r.id |
| 82 | +} |
0 commit comments