Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add IAM Roles Anywhere CRLs, Trust Anchors, and Profiles #98

Merged
merged 2 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions resources/iam-rolesanywhere-crls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package resources

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

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

const IAMRolesAnywhereCRLResource = "IAMRolesAnywhereCRL"

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

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.Resource, 0)

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

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

func (e *IAMRolesAnywhereCRL) Remove(_ context.Context) error {
_, err := e.svc.DeleteCrl(&rolesanywhere.DeleteCrlInput{
CrlId: &e.CrlID,
})
if err != nil {
return err
}

return nil
}

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

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

import (
"context"

"github.com/aws/aws-sdk-go/service/rolesanywhere"

"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 IAMRolesAnywhereProfile struct {
svc *rolesanywhere.RolesAnywhere
ProfileID string
}

const IAMRolesAnywhereProfilesResource = "IAMRolesAnywhereProfile"

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

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.Resource, 0)

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

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

func (e *IAMRolesAnywhereProfile) Remove(_ context.Context) error {
_, err := e.svc.DeleteProfile(&rolesanywhere.DeleteProfileInput{
ProfileId: &e.ProfileID,
})
if err != nil {
return err
}

return nil
}

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

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

import (
"context"

"github.com/aws/aws-sdk-go/service/rolesanywhere"

"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 IAMRolesAnywhereTrustAnchor struct {
svc *rolesanywhere.RolesAnywhere
TrustAnchorID string
}

const IAMRolesAnywhereTrustAnchorResource = "IAMRolesAnywhereTrustAnchor"

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

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.Resource, 0)

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

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

func (e *IAMRolesAnywhereTrustAnchor) Remove(_ context.Context) error {
_, err := e.svc.DeleteTrustAnchor(&rolesanywhere.DeleteTrustAnchorInput{
TrustAnchorId: &e.TrustAnchorID,
})
if err != nil {
return err
}

return nil
}

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

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