diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 000000000..4d213e6f4 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,13 @@ +# https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes#configuring-automatically-generated-release-notes + +changelog: + categories: + - title: Notable changes + labels: + - '*' + exclude: + labels: + - dependencies + - title: Dependency updates + labels: + - dependencies diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ec4bd74a7..980065e30 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,6 +7,7 @@ on: types: [opened, reopened, synchronize] schedule: - cron: '15 3 * * 0' + workflow_dispatch: jobs: build: @@ -14,9 +15,9 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Setup Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version: '1.22' - name: Setup tools run: | go install golang.org/x/lint/golint@latest @@ -34,4 +35,4 @@ jobs: make test - name: Build Project run: | - make + make \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 617e29d44..02e0088f8 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -5,15 +5,37 @@ on: types: [created] jobs: + update_readme: + name: Update Readme + runs-on: ubuntu-22.04 + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: main + - name: Update versions in readme + run: | + sed -r -i "s/aws-nuke:v[0-9]+\.[0-9]+\.[0-9]+/aws-nuke:${{ github.ref_name }}/" README.md + sed -r -i "s/aws-nuke-v[0-9]+\.[0-9]+\.[0-9]+/aws-nuke-${{ github.ref_name }}/" README.md + sed -r -i "s/\/v[0-9]+\.[0-9]+\.[0-9]+\//\/${{ github.ref_name }}\//" README.md + - uses: peter-evans/create-pull-request@v6 + name: Create Pull Request + with: + title: Update readme for ${{ github.ref_name }} release + commit-message: Update readme for ${{ github.ref_name }} release + body: Updating version references in the readme to ${{ github.ref_name }} + branch: update-readme-${{ github.ref_name }} + delete-branch: true release: name: Publish binaries runs-on: ubuntu-22.04 steps: - name: Setup Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: - go-version: '1.21' + go-version: '1.22' - name: Checkout code uses: actions/checkout@v4 with: @@ -30,4 +52,4 @@ jobs: file: dist/aws* tag: ${{ github.ref }} overwrite: true - file_glob: true + file_glob: true \ No newline at end of file diff --git a/go.mod b/go.mod index e207b7511..efd776983 100644 --- a/go.mod +++ b/go.mod @@ -3,17 +3,17 @@ module github.com/rebuy-de/aws-nuke/v2 go 1.21 require ( - github.com/aws/aws-sdk-go v1.45.26 - github.com/fatih/color v1.15.0 + github.com/aws/aws-sdk-go v1.53.10 + github.com/fatih/color v1.17.0 github.com/golang/mock v1.6.0 - github.com/google/uuid v1.3.1 + github.com/google/uuid v1.6.0 github.com/mb0/glob v0.0.0-20160210091149-1eb79d2de6c4 github.com/pkg/errors v0.9.1 github.com/rebuy-de/rebuy-go-sdk/v4 v4.5.1 github.com/sirupsen/logrus v1.9.3 - github.com/spf13/cobra v1.7.0 - github.com/stretchr/testify v1.8.4 - golang.org/x/sync v0.4.0 + github.com/spf13/cobra v1.8.0 + github.com/stretchr/testify v1.9.0 + golang.org/x/sync v0.7.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -24,11 +24,11 @@ require ( github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.17 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/pflag v1.0.5 // indirect golang.org/x/mod v0.9.0 // indirect - golang.org/x/sys v0.6.0 // indirect + golang.org/x/sys v0.18.0 // indirect golang.org/x/tools v0.7.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect ) diff --git a/go.sum b/go.sum index 7f833c1e1..243b890e0 100644 --- a/go.sum +++ b/go.sum @@ -1,18 +1,18 @@ -github.com/aws/aws-sdk-go v1.45.26 h1:PJ2NJNY5N/yeobLYe1Y+xLdavBi67ZI8gvph6ftwVCg= -github.com/aws/aws-sdk-go v1.45.26/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= -github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/aws/aws-sdk-go v1.53.10 h1:3enP5l5WtezT9Ql+XZqs56JBf5YUd/FEzTCg///OIGY= +github.com/aws/aws-sdk-go v1.53.10/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= +github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= -github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= +github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= github.com/gemnasium/logrus-graylog-hook/v3 v3.1.0 h1:SLtCnpI5ZZaz4l7RSatEhppB1BBhUEu+DqGANJzJdEA= github.com/gemnasium/logrus-graylog-hook/v3 v3.1.0/go.mod h1:wi1zWv9tIvyLSMLCAzgRP+YR24oLVQVBHfPPKjtht44= github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= @@ -29,8 +29,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= -github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mb0/glob v0.0.0-20160210091149-1eb79d2de6c4 h1:NK3O7S5FRD/wj7ORQ5C3Mx1STpyEMuFe+/F0Lakd1Nk= github.com/mb0/glob v0.0.0-20160210091149-1eb79d2de6c4/go.mod h1:FqD3ES5hx6zpzDainDaHgkTIqrPaI9uX4CVWqYZoQjY= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -44,66 +44,51 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= -github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= +github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= +github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs= golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= -golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= -golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= -golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/resources/cloudfront-response-headers-policies.go b/resources/cloudfront-response-headers-policies.go new file mode 100644 index 000000000..e075b5d6a --- /dev/null +++ b/resources/cloudfront-response-headers-policies.go @@ -0,0 +1,83 @@ +package resources + +import ( + "fmt" + "strings" + + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/cloudfront" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" +) + +type CloudFrontResponseHeadersPolicy struct { + svc *cloudfront.CloudFront + ID *string + name *string +} + +func init() { + register("CloudFrontResponseHeadersPolicy", ListCloudFrontResponseHeadersPolicies) +} + +func ListCloudFrontResponseHeadersPolicies(sess *session.Session) ([]Resource, error) { + svc := cloudfront.New(sess) + resources := []Resource{} + params := &cloudfront.ListResponseHeadersPoliciesInput{} + + for { + resp, err := svc.ListResponseHeadersPolicies(params) + if err != nil { + return nil, err + } + + for _, item := range resp.ResponseHeadersPolicyList.Items { + resources = append(resources, &CloudFrontResponseHeadersPolicy{ + svc: svc, + ID: item.ResponseHeadersPolicy.Id, + name: item.ResponseHeadersPolicy.ResponseHeadersPolicyConfig.Name, + }) + } + + if resp.ResponseHeadersPolicyList.NextMarker == nil { + break + } + + params.Marker = resp.ResponseHeadersPolicyList.NextMarker + } + + return resources, nil +} + +func (f *CloudFrontResponseHeadersPolicy) Filter() error { + if strings.HasPrefix(*f.name, "Managed-") { + return fmt.Errorf("Cannot delete default CloudFront Response headers policy") + } + return nil +} + +func (f *CloudFrontResponseHeadersPolicy) Remove() error { + resp, err := f.svc.GetResponseHeadersPolicy(&cloudfront.GetResponseHeadersPolicyInput{ + Id: f.ID, + }) + if err != nil { + return err + } + + _, err = f.svc.DeleteResponseHeadersPolicy(&cloudfront.DeleteResponseHeadersPolicyInput{ + Id: f.ID, + IfMatch: resp.ETag, + }) + + return err +} + +func (f *CloudFrontResponseHeadersPolicy) String() string { + return *f.name +} + +func (f *CloudFrontResponseHeadersPolicy) Properties() types.Properties { + properties := types.NewProperties() + properties.Set("ID", f.ID) + properties.Set("Name", f.name) + return properties +} diff --git a/resources/elbv2-listenerrule.go b/resources/elbv2-listenerrule.go new file mode 100644 index 000000000..a4fe640e9 --- /dev/null +++ b/resources/elbv2-listenerrule.go @@ -0,0 +1,141 @@ +package resources + +import ( + "fmt" + + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/elbv2" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" + "github.com/sirupsen/logrus" +) + +var elbv2ListenerRulePageSize int64 = 400 // AWS has a limit of 100 rules per listener + +type ELBv2ListenerRule struct { + svc *elbv2.ELBV2 + ruleArn *string + lbName *string + listenerArn *string + tags []*elbv2.Tag +} + +func init() { + register("ELBv2ListenerRule", ListELBv2ListenerRules) +} + +func ListELBv2ListenerRules(sess *session.Session) ([]Resource, error) { + svc := elbv2.New(sess) + + // We need to retrieve ELBs then Listeners then Rules + lbs := make([]*elbv2.LoadBalancer, 0) + err := svc.DescribeLoadBalancersPages( + nil, + func(page *elbv2.DescribeLoadBalancersOutput, lastPage bool) bool { + for _, elbv2 := range page.LoadBalancers { + lbs = append(lbs, elbv2) + } + return !lastPage + }, + ) + if err != nil { + return nil, err + } + + // Required for batched tag retrieval later + ruleArns := make([]*string, 0) + ruleArnToResource := make(map[string]*ELBv2ListenerRule) + + resources := make([]Resource, 0) + for _, lb := range lbs { + err := svc.DescribeListenersPages( + &elbv2.DescribeListenersInput{ + LoadBalancerArn: lb.LoadBalancerArn, + }, + func(page *elbv2.DescribeListenersOutput, lastPage bool) bool { + for _, listener := range page.Listeners { + rules, err := svc.DescribeRules(&elbv2.DescribeRulesInput{ + ListenerArn: listener.ListenerArn, + PageSize: &elbv2ListenerRulePageSize, + }) + if err == nil { + for _, rule := range rules.Rules { + // Skip default rules as they cannot be deleted + if rule.IsDefault != nil && *rule.IsDefault { + continue + } + + listenerRule := &ELBv2ListenerRule{ + svc: svc, + ruleArn: rule.RuleArn, + lbName: lb.LoadBalancerName, + listenerArn: listener.ListenerArn, + } + + ruleArns = append(ruleArns, rule.RuleArn) + resources = append(resources, listenerRule) + ruleArnToResource[*rule.RuleArn] = listenerRule + } + } else { + logrus. + WithError(err). + WithField("listenerArn", listener.ListenerArn). + Error("Failed to list listener rules for listener") + } + } + + return !lastPage + }, + ) + if err != nil { + logrus. + WithError(err). + WithField("loadBalancerArn", lb.LoadBalancerArn). + Error("Failed to list listeners for load balancer") + } + } + + // Tags for Rules need to be fetched separately + // We can only specify up to 20 in a single call + // See: https://github.com/aws/aws-sdk-go/blob/0e8c61841163762f870f6976775800ded4a789b0/service/elbv2/api.go#L5398 + for _, ruleChunk := range Chunk(ruleArns, 20) { + tagResp, err := svc.DescribeTags(&elbv2.DescribeTagsInput{ + ResourceArns: ruleChunk, + }) + if err != nil { + return nil, err + } + for _, elbv2TagInfo := range tagResp.TagDescriptions { + rule := ruleArnToResource[*elbv2TagInfo.ResourceArn] + rule.tags = elbv2TagInfo.Tags + } + } + + return resources, nil +} + +func (e *ELBv2ListenerRule) Remove() error { + _, err := e.svc.DeleteRule(&elbv2.DeleteRuleInput{ + RuleArn: e.ruleArn, + }) + if err != nil { + return err + } + + return nil +} + +func (e *ELBv2ListenerRule) Properties() types.Properties { + properties := types.NewProperties(). + Set("ARN", e.ruleArn). + Set("ListenerARN", e.listenerArn). + Set("LoadBalancerName", e.lbName) + + for _, tagValue := range e.tags { + properties.SetTag(tagValue.Key, tagValue.Value) + } + return properties +} + +func (e *ELBv2ListenerRule) String() string { + return fmt.Sprintf("%s -> %s", *e.lbName, *e.ruleArn) +} diff --git a/resources/redshiftserverless-namespaces.go b/resources/redshiftserverless-namespaces.go new file mode 100644 index 000000000..adfaae07e --- /dev/null +++ b/resources/redshiftserverless-namespaces.go @@ -0,0 +1,68 @@ +package resources + +import ( + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/redshiftserverless" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" +) + +type RedshiftServerlessNamespace struct { + svc *redshiftserverless.RedshiftServerless + namespace *redshiftserverless.Namespace +} + +func init() { + register("RedshiftServerlessNamespace", ListRedshiftServerlessNamespaces) +} + +func ListRedshiftServerlessNamespaces(sess *session.Session) ([]Resource, error) { + svc := redshiftserverless.New(sess) + resources := []Resource{} + + params := &redshiftserverless.ListNamespacesInput{ + MaxResults: aws.Int64(100), + } + + for { + output, err := svc.ListNamespaces(params) + if err != nil { + return nil, err + } + + for _, namespace := range output.Namespaces { + resources = append(resources, &RedshiftServerlessNamespace{ + svc: svc, + namespace: namespace, + }) + } + + if output.NextToken == nil { + break + } + + params.NextToken = output.NextToken + } + + return resources, nil +} + +func (n *RedshiftServerlessNamespace) Properties() types.Properties { + properties := types.NewProperties(). + Set("CreationDate", n.namespace.CreationDate). + Set("NamespaceName", n.namespace.NamespaceName) + + return properties +} + +func (n *RedshiftServerlessNamespace) Remove() error { + _, err := n.svc.DeleteNamespace(&redshiftserverless.DeleteNamespaceInput{ + NamespaceName: n.namespace.NamespaceName, + }) + + return err +} + +func (n *RedshiftServerlessNamespace) String() string { + return *n.namespace.NamespaceName +} diff --git a/resources/redshiftserverless-snapshots.go b/resources/redshiftserverless-snapshots.go new file mode 100644 index 000000000..9f56c8e62 --- /dev/null +++ b/resources/redshiftserverless-snapshots.go @@ -0,0 +1,69 @@ +package resources + +import ( + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/redshiftserverless" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" +) + +type RedshiftServerlessSnapshot struct { + svc *redshiftserverless.RedshiftServerless + snapshot *redshiftserverless.Snapshot +} + +func init() { + register("RedshiftServerlessSnapshot", ListRedshiftServerlessSnapshots) +} + +func ListRedshiftServerlessSnapshots(sess *session.Session) ([]Resource, error) { + svc := redshiftserverless.New(sess) + resources := []Resource{} + + params := &redshiftserverless.ListSnapshotsInput{ + MaxResults: aws.Int64(100), + } + + for { + output, err := svc.ListSnapshots(params) + if err != nil { + return nil, err + } + + for _, snapshot := range output.Snapshots { + resources = append(resources, &RedshiftServerlessSnapshot{ + svc: svc, + snapshot: snapshot, + }) + } + + if output.NextToken == nil { + break + } + + params.NextToken = output.NextToken + } + + return resources, nil +} + +func (s *RedshiftServerlessSnapshot) Properties() types.Properties { + properties := types.NewProperties(). + Set("CreateTime", s.snapshot.SnapshotCreateTime). + Set("Namespace", s.snapshot.NamespaceName). + Set("SnapshotName", s.snapshot.SnapshotName) + + return properties +} + +func (s *RedshiftServerlessSnapshot) Remove() error { + _, err := s.svc.DeleteSnapshot(&redshiftserverless.DeleteSnapshotInput{ + SnapshotName: s.snapshot.SnapshotName, + }) + + return err +} + +func (s *RedshiftServerlessSnapshot) String() string { + return *s.snapshot.SnapshotName +} diff --git a/resources/redshiftserverless-workgroups.go b/resources/redshiftserverless-workgroups.go new file mode 100644 index 000000000..a88c8d16a --- /dev/null +++ b/resources/redshiftserverless-workgroups.go @@ -0,0 +1,69 @@ +package resources + +import ( + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/redshiftserverless" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" +) + +type RedshiftServerlessWorkgroup struct { + svc *redshiftserverless.RedshiftServerless + workgroup *redshiftserverless.Workgroup +} + +func init() { + register("RedshiftServerlessWorkgroup", ListRedshiftServerlessWorkgroups) +} + +func ListRedshiftServerlessWorkgroups(sess *session.Session) ([]Resource, error) { + svc := redshiftserverless.New(sess) + resources := []Resource{} + + params := &redshiftserverless.ListWorkgroupsInput{ + MaxResults: aws.Int64(100), + } + + for { + output, err := svc.ListWorkgroups(params) + if err != nil { + return nil, err + } + + for _, workgroup := range output.Workgroups { + resources = append(resources, &RedshiftServerlessWorkgroup{ + svc: svc, + workgroup: workgroup, + }) + } + + if output.NextToken == nil { + break + } + + params.NextToken = output.NextToken + } + + return resources, nil +} + +func (w *RedshiftServerlessWorkgroup) Properties() types.Properties { + properties := types.NewProperties(). + Set("CreationDate", w.workgroup.CreationDate). + Set("Namespace", w.workgroup.NamespaceName). + Set("WorkgroupName", w.workgroup.WorkgroupName) + + return properties +} + +func (w *RedshiftServerlessWorkgroup) Remove() error { + _, err := w.svc.DeleteWorkgroup(&redshiftserverless.DeleteWorkgroupInput{ + WorkgroupName: w.workgroup.WorkgroupName, + }) + + return err +} + +func (w *RedshiftServerlessWorkgroup) String() string { + return *w.workgroup.WorkgroupName +} diff --git a/resources/util.go b/resources/util.go index 22a3e1b2e..b61b83966 100644 --- a/resources/util.go +++ b/resources/util.go @@ -36,3 +36,21 @@ func IsAWSError(err error, code string) bool { return aerr.Code() == code } + +func Chunk[T any](slice []T, size int) [][]T { + var chunks [][]T + for i := 0; i < len(slice); { + // Clamp the last chunk to the slice bound as necessary. + end := size + if l := len(slice[i:]); l < size { + end = l + } + + // Set the capacity of each chunk so that appending to a chunk does not + // modify the original slice. + chunks = append(chunks, slice[i:i+end:i+end]) + i += end + } + + return chunks +}