Skip to content

Commit

Permalink
chore: refactor to libnuke resource format
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Feb 24, 2024
1 parent b9bb5fd commit 693d2d2
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 54 deletions.
52 changes: 34 additions & 18 deletions resources/iam-rolesanywhere-crls.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws/session"
"context"

"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"

"github.com/aws/aws-sdk-go/service/rolesanywhere"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type Crl struct {
svc *rolesanywhere.RolesAnywhere
CrlId string
type IAMRolesAnywhereCRL struct {
svc *rolesanywhere.RolesAnywhere
CrlID string
}

const IAMRolesAnywhereCRLResource = "IAMRolesAnywhereCRL"

func init() {
register("IAMRolesAnywhereCrls", ListCRLs)
registry.Register(&registry.Registration{
Name: IAMRolesAnywhereCRLResource,
Scope: nuke.Account,
Lister: &IAMRolesAnywhereCRLLister{},
})
}

func ListCRLs(sess *session.Session) ([]Resource, error) {
svc := rolesanywhere.New(sess)
type IAMRolesAnywhereCRLLister struct{}

func (l *IAMRolesAnywhereCRLLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)

svc := rolesanywhere.New(opts.Session)

params := &rolesanywhere.ListCrlsInput{}
resources := make([]Resource, 0)
resources := make([]resource.Resource, 0)

for {
resp, err := svc.ListCrls(params)
if err != nil {
return nil, err
}
for _, crl := range resp.Crls {
resources = append(resources, &Crl{
svc: svc,
CrlId: *crl.CrlId,
resources = append(resources, &IAMRolesAnywhereCRL{
svc: svc,
CrlID: *crl.CrlId,
})
}

Expand All @@ -43,9 +59,9 @@ func ListCRLs(sess *session.Session) ([]Resource, error) {
return resources, nil
}

func (e *Crl) Remove() error {
func (e *IAMRolesAnywhereCRL) Remove(_ context.Context) error {
_, err := e.svc.DeleteCrl(&rolesanywhere.DeleteCrlInput{
CrlId: &e.CrlId,
CrlId: &e.CrlID,
})
if err != nil {
return err
Expand All @@ -54,11 +70,11 @@ func (e *Crl) Remove() error {
return nil
}

func (e *Crl) String() string {
return e.CrlId
func (e *IAMRolesAnywhereCRL) String() string {
return e.CrlID
}

func (e *Crl) Properties() types.Properties {
func (e *IAMRolesAnywhereCRL) Properties() types.Properties {
return types.NewProperties().
Set("CrlId", e.CrlId)
Set("CrlId", e.CrlID)
}
52 changes: 34 additions & 18 deletions resources/iam-rolesanywhere-profiles.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws/session"
"context"

"github.com/aws/aws-sdk-go/service/rolesanywhere"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"

"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"
)

type Profile struct {
svc *rolesanywhere.RolesAnywhere
ProfileId string
type IAMRolesAnywhereProfile struct {
svc *rolesanywhere.RolesAnywhere
ProfileID string
}

const IAMRolesAnywhereProfilesResource = "IAMRolesAnywhereProfile"

func init() {
register("IAMRolesAnywhereProfiles", ListProfiles)
registry.Register(&registry.Registration{
Name: IAMRolesAnywhereProfilesResource,
Scope: nuke.Account,
Lister: &IAMRolesAnywhereProfilesLister{},
})
}

func ListProfiles(sess *session.Session) ([]Resource, error) {
svc := rolesanywhere.New(sess)
type IAMRolesAnywhereProfilesLister struct{}

func (l *IAMRolesAnywhereProfilesLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)

svc := rolesanywhere.New(opts.Session)

params := &rolesanywhere.ListProfilesInput{}
resources := make([]Resource, 0)
resources := make([]resource.Resource, 0)

for {
resp, err := svc.ListProfiles(params)
if err != nil {
return nil, err
}
for _, profile := range resp.Profiles {
resources = append(resources, &Profile{
svc: svc,
ProfileId: *profile.ProfileId,
resources = append(resources, &IAMRolesAnywhereProfile{
svc: svc,
ProfileID: *profile.ProfileId,
})
}

Expand All @@ -43,9 +59,9 @@ func ListProfiles(sess *session.Session) ([]Resource, error) {
return resources, nil
}

func (e *Profile) Remove() error {
func (e *IAMRolesAnywhereProfile) Remove(_ context.Context) error {
_, err := e.svc.DeleteProfile(&rolesanywhere.DeleteProfileInput{
ProfileId: &e.ProfileId,
ProfileId: &e.ProfileID,
})
if err != nil {
return err
Expand All @@ -54,11 +70,11 @@ func (e *Profile) Remove() error {
return nil
}

func (e *Profile) String() string {
return e.ProfileId
func (e *IAMRolesAnywhereProfile) String() string {
return e.ProfileID
}

func (e *Profile) Properties() types.Properties {
func (e *IAMRolesAnywhereProfile) Properties() types.Properties {
return types.NewProperties().
Set("ProfileId", e.ProfileId)
Set("ProfileId", e.ProfileID)
}
52 changes: 34 additions & 18 deletions resources/iam-rolesanywhere-trust-anchors.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws/session"
"context"

"github.com/aws/aws-sdk-go/service/rolesanywhere"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"

"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"
)

type TrustAnchor struct {
svc *rolesanywhere.RolesAnywhere
TrustAnchorId string
type IAMRolesAnywhereTrustAnchor struct {
svc *rolesanywhere.RolesAnywhere
TrustAnchorID string
}

const IAMRolesAnywhereTrustAnchorResource = "IAMRolesAnywhereTrustAnchor"

func init() {
register("IAMRolesAnywhereTrustAnchors", ListTrustAnchors)
registry.Register(&registry.Registration{
Name: IAMRolesAnywhereTrustAnchorResource,
Scope: nuke.Account,
Lister: &IAMRolesAnywhereTrustAnchorLister{},
})
}

func ListTrustAnchors(sess *session.Session) ([]Resource, error) {
svc := rolesanywhere.New(sess)
type IAMRolesAnywhereTrustAnchorLister struct{}

func (l *IAMRolesAnywhereTrustAnchorLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)

svc := rolesanywhere.New(opts.Session)

params := &rolesanywhere.ListTrustAnchorsInput{}
resources := make([]Resource, 0)
resources := make([]resource.Resource, 0)

for {
resp, err := svc.ListTrustAnchors(params)
if err != nil {
return nil, err
}
for _, trustAnchor := range resp.TrustAnchors {
resources = append(resources, &TrustAnchor{
svc: svc,
TrustAnchorId: *trustAnchor.TrustAnchorId,
resources = append(resources, &IAMRolesAnywhereTrustAnchor{
svc: svc,
TrustAnchorID: *trustAnchor.TrustAnchorId,
})
}

Expand All @@ -43,9 +59,9 @@ func ListTrustAnchors(sess *session.Session) ([]Resource, error) {
return resources, nil
}

func (e *TrustAnchor) Remove() error {
func (e *IAMRolesAnywhereTrustAnchor) Remove(_ context.Context) error {
_, err := e.svc.DeleteTrustAnchor(&rolesanywhere.DeleteTrustAnchorInput{
TrustAnchorId: &e.TrustAnchorId,
TrustAnchorId: &e.TrustAnchorID,
})
if err != nil {
return err
Expand All @@ -54,11 +70,11 @@ func (e *TrustAnchor) Remove() error {
return nil
}

func (e *TrustAnchor) String() string {
return e.TrustAnchorId
func (e *IAMRolesAnywhereTrustAnchor) String() string {
return e.TrustAnchorID
}

func (e *TrustAnchor) Properties() types.Properties {
func (e *IAMRolesAnywhereTrustAnchor) Properties() types.Properties {
return types.NewProperties().
Set("TrustAnchorId", e.TrustAnchorId)
Set("TrustAnchorId", e.TrustAnchorID)
}

0 comments on commit 693d2d2

Please sign in to comment.