diff --git a/resources/iam-rolesanywhere-crls.go b/resources/iam-rolesanywhere-crls.go new file mode 100644 index 000000000..d092809fd --- /dev/null +++ b/resources/iam-rolesanywhere-crls.go @@ -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) +} diff --git a/resources/iam-rolesanywhere-profiles.go b/resources/iam-rolesanywhere-profiles.go new file mode 100644 index 000000000..2e0a37f74 --- /dev/null +++ b/resources/iam-rolesanywhere-profiles.go @@ -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) +} diff --git a/resources/iam-rolesanywhere-trust-anchors.go b/resources/iam-rolesanywhere-trust-anchors.go new file mode 100644 index 000000000..7e830b9c9 --- /dev/null +++ b/resources/iam-rolesanywhere-trust-anchors.go @@ -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) +}