Skip to content

Commit

Permalink
add: remove custom iam account setting password policy (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen authored Jul 11, 2023
1 parent 1e2e844 commit e71283b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
57 changes: 57 additions & 0 deletions resources/iam-account-setting-password-policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go/service/iam/iamiface"
)

type IAMAccountSettingPasswordPolicy struct {
svc iamiface.IAMAPI
policy *iam.PasswordPolicy
}

func init() {
register("IAMAccountSettingPasswordPolicy", ListIAMAccountSettingPasswordPolicy)
}

func ListIAMAccountSettingPasswordPolicy(sess *session.Session) ([]Resource, error) {
resources := make([]Resource, 0)

svc := iam.New(sess)

resp, err := svc.GetAccountPasswordPolicy(&iam.GetAccountPasswordPolicyInput{})

if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case iam.ErrCodeNoSuchEntityException:
return nil, nil
case iam.ErrCodeServiceFailureException:
return nil, aerr
default:
return nil, aerr
}
}
}

resources = append(resources, &IAMAccountSettingPasswordPolicy{
svc: svc,
policy: resp.PasswordPolicy,
})

return resources, nil
}

func (e *IAMAccountSettingPasswordPolicy) Remove() error {
_, err := e.svc.DeleteAccountPasswordPolicy(&iam.DeleteAccountPasswordPolicyInput{})
if err != nil {
return err
}
return nil
}

func (e *IAMAccountSettingPasswordPolicy) String() string {
return "custom"
}
7 changes: 5 additions & 2 deletions resources/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package resources

import (
"fmt"
"github.com/rebuy-de/aws-nuke/resources"
"strings"

"github.com/aws/aws-sdk-go/aws/session"
Expand Down Expand Up @@ -81,7 +80,7 @@ func GetLister(name string) ResourceLister {

func GetListerNames() []string {
names := []string{}
for resourceType := range resources.GetListers() {
for resourceType := range GetListers() {
names = append(names, resourceType)
}

Expand All @@ -91,3 +90,7 @@ func GetListerNames() []string {
func registerCloudControl(typeName string) {
register(typeName, NewListCloudControlResource(typeName), mapCloudControl(typeName))
}

func GetListers() ResourceListers {
return resourceListers
}

0 comments on commit e71283b

Please sign in to comment.