Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Add support for IAM RolesAnywhere TrustAnchors, Profiles, and CRLs #1186

Closed
wants to merge 3 commits into from
Closed
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
64 changes: 64 additions & 0 deletions resources/iam-rolesanywhere-crls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws/session"
"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
}

func init() {
register("IAMRolesAnywhereCrls", ListCRLs)
}

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

params := &rolesanywhere.ListCrlsInput{}
resources := make([]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,
})
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

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

return nil
}

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

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

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

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

func init() {
register("IAMRolesAnywhereProfiles", ListProfiles)
}

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

params := &rolesanywhere.ListProfilesInput{}
resources := make([]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,
})
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

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

return nil
}

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

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

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

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

func init() {
register("IAMRolesAnywhereTrustAnchors", ListTrustAnchors)
}

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

params := &rolesanywhere.ListTrustAnchorsInput{}
resources := make([]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,
})
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

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

return nil
}

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

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