pax_global_header00006660000000000000000000000064141113741540014513gustar00rootroot0000000000000052 comment=048c4bb92e38f8a119fb5d988f548cc622fb1b26 aws-nuke-2.16.0/000077500000000000000000000000001411137415400133335ustar00rootroot00000000000000aws-nuke-2.16.0/.dockerignore000066400000000000000000000000141411137415400160020ustar00rootroot00000000000000dist vendor aws-nuke-2.16.0/.github/000077500000000000000000000000001411137415400146735ustar00rootroot00000000000000aws-nuke-2.16.0/.github/CODEOWNERS000066400000000000000000000000311411137415400162600ustar00rootroot00000000000000* @rebuy-de/prp-aws-nuke aws-nuke-2.16.0/.github/workflows/000077500000000000000000000000001411137415400167305ustar00rootroot00000000000000aws-nuke-2.16.0/.github/workflows/ci.yaml000066400000000000000000000041031411137415400202050ustar00rootroot00000000000000name: Golang CI on: push: branches: [main] pull_request: types: [opened, reopened, synchronize] schedule: - cron: '15 3 * * 0' jobs: build: name: CI Build runs-on: ubuntu-latest steps: - name: Setup Go uses: actions/setup-go@v2 with: go-version: '1.16' - name: Setup tools run: | go get golang.org/x/lint/golint - name: Checkout code uses: actions/checkout@v2 - name: Test Project run: | make test - name: Build Project run: | make docker_build: runs-on: ubuntu-20.04 name: Docker Build if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'rebuy-de/aws-nuke' }} steps: - uses: actions/checkout@v2 with: fetch-depth: 0 - name: Generate image tags shell: bash run: | if [ "${GITHUB_EVENT_NAME}" == "pull_request" ]; then echo "##[set-output name=tags;]quay.io/rebuy/aws-nuke:${GITHUB_HEAD_REF},docker.io/rebuy/aws-nuke:${GITHUB_HEAD_REF}" else echo "##[set-output name=tags;]quay.io/rebuy/aws-nuke:main,docker.io/rebuy/aws-nuke:main,\ quay.io/rebuy/aws-nuke:latest,docker.io/rebuy/aws-nuke:latest" fi id: generate_tags - name: Set up QEMU id: qemu uses: docker/setup-qemu-action@v1 with: platforms: arm64 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 with: install: true - name: Login to Docker Hub uses: docker/login-action@v1 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Login to Quay.io uses: docker/login-action@v1 with: registry: quay.io username: ${{ secrets.QUAY_USERNAME }} password: ${{ secrets.QUAY_PASSWORD }} - name: Build and push uses: docker/build-push-action@v2 with: context: . push: true tags: ${{ steps.generate_tags.outputs.tags }} platforms: linux/amd64,linux/arm64 aws-nuke-2.16.0/.github/workflows/release.yaml000066400000000000000000000035321411137415400212370ustar00rootroot00000000000000name: Publish release artifacts on: release: types: [created] jobs: release: name: Publish binaries runs-on: ubuntu-latest steps: - name: Setup Go uses: actions/setup-go@v2 with: go-version: '1.16' - name: Checkout code uses: actions/checkout@v2 with: fetch-depth: 0 - name: Build Project binaries env: CGO_ENABLED: 0 run: | make xc - name: Upload binaries to release uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} file: dist/aws* tag: ${{ github.ref }} overwrite: true file_glob: true docker_build: runs-on: ubuntu-20.04 name: Docker Build steps: - uses: actions/checkout@v2 with: fetch-depth: 0 - name: Generate image tags shell: bash run: echo "##[set-output name=tags;]quay.io/rebuy/aws-nuke:${GITHUB_REF#refs/tags/},docker.io/rebuy/aws-nuke:${GITHUB_REF#refs/tags/}" id: generate_tags - name: Set up QEMU id: qemu uses: docker/setup-qemu-action@v1 with: platforms: arm64,arm/v7 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 with: install: true - name: Login to Docker Hub uses: docker/login-action@v1 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Login to Quay.io uses: docker/login-action@v1 with: registry: quay.io username: ${{ secrets.QUAY_USERNAME }} password: ${{ secrets.QUAY_PASSWORD }} - name: Build and push uses: docker/build-push-action@v2 with: context: . push: true tags: ${{ steps.generate_tags.outputs.tags }} platforms: linux/amd64,linux/arm64,linux/arm/v7 aws-nuke-2.16.0/.gitignore000066400000000000000000000000651411137415400153240ustar00rootroot00000000000000/vendor /aws-nuke /aws-nuke-* /dist /releases /mocks aws-nuke-2.16.0/CONTRIBUTING.md000066400000000000000000000112601411137415400155640ustar00rootroot00000000000000# Contributing Thank you for wanting to contribute to *aws-nuke*. Because of the amount of AWS services and their rate of change, we rely on your participation. For the same reason we can only act retroactive on changes of AWS services. Otherwise it would be a fulltime job to keep up with AWS. ## How Can I Contribute? ### Some Resource Is Not Supported by *aws-nuke* If a resource is not yet supported by *aws-nuke*, you have two options to resolve this: * File [an issue](https://github.com/rebuy-de/aws-nuke/issues/new) and describe which resource is missing. This way someone can take care of it. * Add the resource yourself and open a Pull Request. Please follow the guidelines below to see how to create such a resource. ### Some Resource Does Not Get Deleted Please check the following points before creating a bug issue: * Is the resource actually supported by *aws-nuke*? If not, please follow the guidelines above. * Are there permission problems? In this case *aws-nuke* will print errors that usually contain the status code `403`. * Did you just get scared by an error that was printed? *aws-nuke* does not know about dependencies between resources. To work around this it will just retry deleting all resources in multiple iterations. Therefore it is normal that there are a lot of dependency errors in the first one. The iterations are separated by lines starting with `Removal requested: ` and only the errors in the last block indicate actual errros. File [an issue](https://github.com/rebuy-de/aws-nuke/issues/new) and describe as accurately as possible how to generate the resource on AWS that cause the errors in *aws-nuke*. Ideally this is provided in a reproducible way like a Terraform template or AWS CLI commands. ### I Have Ideas to Improve *aws-nuke* You should take these steps if you have an idea how to improve *aws-nuke*: 1. Check the [issues page](https://github.com/rebuy-de/aws-nuke/issues), whether someone already had the same or a similar idea. 2. Also check the [closed issues](https://github.com/rebuy-de/aws-nuke/issues?utf8=%E2%9C%93&q=is%3Aissue), because this might have already been implemented, but not yet released. Also the idea might not be viable for unobvious reasons. 3. Join the discussion, if there is already an related issue. If this is not the case, open a new issue and describe your idea. Afterwards, we can discuss this idea and form a proposal. ### I Just Have a Question Please use our mailing list for questions: aws-nuke@googlegroups.com. You can also search in the mailing list archive, whether someone already had the same problem: https://groups.google.com/d/forum/aws-nuke ## Resource Guidelines ### Consider Pagination Most AWS resources are paginated and all resources should handle that. ### Use Properties Instead of String Functions Currently, each resource can offer two functions to describe itself, that are used by the user to identify it and by *aws-nuke* to filter it. The String function is deprecated: ```go String() string ``` The Properties function should be used instead: ```go Properties() types.Properties ``` The interface for the String function is still there, because not all resources are migrated yet. Please use the Properties function for new resources. ### Filter Resources That Cannot Get Removed Some AWS APIs list resources, that cannot be deleted. For example: * Resources that are already deleted, but still listed for some time (eg EC2 Instances). * Resources that are created by AWS, but cannot be deleted by the user (eg some IAM Roles). Those resources should be excluded in the filter step, rather than in the list step. ## Styleguide ### Go #### Code Format Like almost all Go projects, we are using `go fmt` as a single source of truth for formatting the source code. Please use `go fmt` before committing any change. ### Git #### Setup Email We prefer having the commit linked to the GitHub account, that is creating the Pull Request. To make this happen, *git* must be configured with an email, that is registered with a GitHub account. To set the email for all git commits, you can use this command: ``` git config --global user.email "email@example.com" ``` If you want to change the email only for the *aws-nuke* repository, you can skip the `--global` flag. You have to make sure that you are executing this in the *aws-nuke* directory: ``` git config user.email "email@example.com" ``` If you already committed something with a wrong email, you can use this command: ``` git commit --amend --author="Author Name " ``` This changes the email of the lastest commit. If you have multiple commits in your branch, please squash them and change the author afterwards. aws-nuke-2.16.0/Dockerfile000066400000000000000000000010331411137415400153220ustar00rootroot00000000000000FROM golang:1.16-alpine as builder RUN apk add --no-cache git make curl openssl # Configure Go ENV GOPATH=/go PATH=/go/bin:$PATH CGO_ENABLED=0 GO111MODULE=on RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin WORKDIR /src COPY go.mod . COPY go.sum . RUN go mod download COPY . . RUN set -x \ && make build \ && cp /src/dist/aws-nuke /usr/local/bin/ FROM alpine:latest RUN apk add --no-cache ca-certificates COPY --from=builder /usr/local/bin/* /usr/local/bin/ RUN adduser -D aws-nuke USER aws-nuke ENTRYPOINT ["/usr/local/bin/aws-nuke"] aws-nuke-2.16.0/LICENSE000066400000000000000000000021001411137415400143310ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2016 reBuy reCommerce GmbH Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. aws-nuke-2.16.0/Makefile000066400000000000000000000000701411137415400147700ustar00rootroot00000000000000PACKAGE=github.com/rebuy-de/aws-nuke include golang.mk aws-nuke-2.16.0/README.md000066400000000000000000000565011411137415400146210ustar00rootroot00000000000000# aws-nuke ![Build Status](https://github.com/rebuy-de/aws-nuke/workflows/Golang%20CI/badge.svg?branch=main) [![license](https://img.shields.io/github/license/rebuy-de/aws-nuke.svg)](https://github.com/rebuy-de/aws-nuke/blob/main/LICENSE) [![GitHub release](https://img.shields.io/github/release/rebuy-de/aws-nuke.svg)](https://github.com/rebuy-de/aws-nuke/releases) [![Docker Hub](https://img.shields.io/docker/pulls/rebuy/aws-nuke)](https://hub.docker.com/r/rebuy/aws-nuke) Remove all resources from an AWS account. > **Development Status** *aws-nuke* is stable, but it is likely that not all AWS resources are covered by it. Be encouraged to add missing resources and create a Pull Request or to create an [Issue](https://github.com/rebuy-de/aws-nuke/issues/new). ## Caution! Be aware that *aws-nuke* is a very destructive tool, hence you have to be very careful while using it. Otherwise you might delete production data. **We strongly advise you to not run this application on any AWS account, where you cannot afford to lose all resources.** To reduce the blast radius of accidents, there are some safety precautions: 1. By default *aws-nuke* only lists all nukeable resources. You need to add `--no-dry-run` to actually delete resources. 2. *aws-nuke* asks you twice to confirm the deletion by entering the account alias. The first time is directly after the start and the second time after listing all nukeable resources. 3. To avoid just displaying a account ID, which might gladly be ignored by humans, it is required to actually set an [Account Alias](https://docs.aws.amazon.com/IAM/latest/UserGuide/console_account-alias.html) for your account. Otherwise *aws-nuke* will abort. 4. The Account Alias must not contain the string `prod`. This string is hardcoded and it is recommended to add it to every actual production account (eg `mycompany-production-ecr`). 5. The config file contains a blocklist field. If the Account ID of the account you want to nuke is part of this blocklist, *aws-nuke* will abort. It is recommended, that you add every production account to this blocklist. 6. To ensure you don't just ignore the blocklisting feature, the blocklist must contain at least one Account ID. 7. The config file contains account specific settings (eg. filters). The account you want to nuke must be explicitly listed there. 8. To ensure to not accidentally delete a random account, it is required to specify a config file. It is recommended to have only a single config file and add it to a central repository. This way the account blocklist is way easier to manage and keep up to date. Feel free to create an issue, if you have any ideas to improve the safety procedures. ## Use Cases * We are testing our [Terraform](https://www.terraform.io/) code with Jenkins. Sometimes a Terraform run fails during development and messes up the account. With *aws-nuke* we can simply clean up the failed account so it can be reused for the next build. * Our platform developers have their own AWS Accounts where they can create their own Kubernetes clusters for testing purposes. With *aws-nuke* it is very easy to clean up these account at the end of the day and keep the costs low. ## Releases We usually release a new version once enough changes came together and have been tested for a while. You can find Linux, macOS and Windows binaries on the [releases page](https://github.com/rebuy-de/aws-nuke/releases), but we also provide containerized versions on [quay.io/rebuy/aws-nuke](https://quay.io/rebuy/aws-nuke) and [docker.io/rebuy/aws-nuke](https://hub.docker.com/r/rebuy/aws-nuke). Both are available for multiple architectures (amd64, arm64 & armv7). ## Usage At first you need to create a config file for *aws-nuke*. This is a minimal one: ```yaml regions: - eu-west-1 - global account-blocklist: - "999999999999" # production accounts: "000000000000": {} # aws-nuke-example ``` With this config we can run *aws-nuke*: ``` $ aws-nuke -c config/nuke-config.yml --profile aws-nuke-example aws-nuke version v1.0.39.gc2f318f - Fri Jul 28 16:26:41 CEST 2017 - c2f318f37b7d2dec0e646da3d4d05ab5296d5bce Do you really want to nuke the account with the ID 000000000000 and the alias 'aws-nuke-example'? Do you want to continue? Enter account alias to continue. > aws-nuke-example eu-west-1 - EC2DHCPOption - 'dopt-bf2ec3d8' - would remove eu-west-1 - EC2Instance - 'i-01b489457a60298dd' - would remove eu-west-1 - EC2KeyPair - 'test' - would remove eu-west-1 - EC2NetworkACL - 'acl-6482a303' - cannot delete default VPC eu-west-1 - EC2RouteTable - 'rtb-ffe91e99' - would remove eu-west-1 - EC2SecurityGroup - 'sg-220e945a' - cannot delete group 'default' eu-west-1 - EC2SecurityGroup - 'sg-f20f958a' - would remove eu-west-1 - EC2Subnet - 'subnet-154d844e' - would remove eu-west-1 - EC2Volume - 'vol-0ddfb15461a00c3e2' - would remove eu-west-1 - EC2VPC - 'vpc-c6159fa1' - would remove eu-west-1 - IAMUserAccessKey - 'my-user -> ABCDEFGHIJKLMNOPQRST' - would remove eu-west-1 - IAMUserPolicyAttachment - 'my-user -> AdministratorAccess' - [UserName: "my-user", PolicyArn: "arn:aws:iam::aws:policy/AdministratorAccess", PolicyName: "AdministratorAccess"] - would remove eu-west-1 - IAMUser - 'my-user' - would remove Scan complete: 13 total, 11 nukeable, 2 filtered. Would delete these resources. Provide --no-dry-run to actually destroy resources. ``` As we see, *aws-nuke* only lists all found resources and exits. This is because the `--no-dry-run` flag is missing. Also it wants to delete the administrator. We don't want to do this, because we use this user to access our account. Therefore we have to extend the config so it ignores this user: ```yaml regions: - eu-west-1 account-blocklist: - "999999999999" # production accounts: "000000000000": # aws-nuke-example filters: IAMUser: - "my-user" IAMUserPolicyAttachment: - "my-user -> AdministratorAccess" IAMUserAccessKey: - "my-user -> ABCDEFGHIJKLMNOPQRST" ``` ``` $ aws-nuke -c config/nuke-config.yml --profile aws-nuke-example --no-dry-run aws-nuke version v1.0.39.gc2f318f - Fri Jul 28 16:26:41 CEST 2017 - c2f318f37b7d2dec0e646da3d4d05ab5296d5bce Do you really want to nuke the account with the ID 000000000000 and the alias 'aws-nuke-example'? Do you want to continue? Enter account alias to continue. > aws-nuke-example eu-west-1 - EC2DHCPOption - 'dopt-bf2ec3d8' - would remove eu-west-1 - EC2Instance - 'i-01b489457a60298dd' - would remove eu-west-1 - EC2KeyPair - 'test' - would remove eu-west-1 - EC2NetworkACL - 'acl-6482a303' - cannot delete default VPC eu-west-1 - EC2RouteTable - 'rtb-ffe91e99' - would remove eu-west-1 - EC2SecurityGroup - 'sg-220e945a' - cannot delete group 'default' eu-west-1 - EC2SecurityGroup - 'sg-f20f958a' - would remove eu-west-1 - EC2Subnet - 'subnet-154d844e' - would remove eu-west-1 - EC2Volume - 'vol-0ddfb15461a00c3e2' - would remove eu-west-1 - EC2VPC - 'vpc-c6159fa1' - would remove eu-west-1 - IAMUserAccessKey - 'my-user -> ABCDEFGHIJKLMNOPQRST' - filtered by config eu-west-1 - IAMUserPolicyAttachment - 'my-user -> AdministratorAccess' - [UserName: "my-user", PolicyArn: "arn:aws:iam::aws:policy/AdministratorAccess", PolicyName: "AdministratorAccess"] - would remove eu-west-1 - IAMUser - 'my-user' - filtered by config Scan complete: 13 total, 8 nukeable, 5 filtered. Do you really want to nuke these resources on the account with the ID 000000000000 and the alias 'aws-nuke-example'? Do you want to continue? Enter account alias to continue. > aws-nuke-example eu-west-1 - EC2DHCPOption - 'dopt-bf2ec3d8' - failed eu-west-1 - EC2Instance - 'i-01b489457a60298dd' - triggered remove eu-west-1 - EC2KeyPair - 'test' - triggered remove eu-west-1 - EC2RouteTable - 'rtb-ffe91e99' - failed eu-west-1 - EC2SecurityGroup - 'sg-f20f958a' - failed eu-west-1 - EC2Subnet - 'subnet-154d844e' - failed eu-west-1 - EC2Volume - 'vol-0ddfb15461a00c3e2' - failed eu-west-1 - EC2VPC - 'vpc-c6159fa1' - failed eu-west-1 - S3Object - 's3://rebuy-terraform-state-138758637120/run-terraform.lock' - triggered remove Removal requested: 2 waiting, 6 failed, 5 skipped, 0 finished eu-west-1 - EC2DHCPOption - 'dopt-bf2ec3d8' - failed eu-west-1 - EC2Instance - 'i-01b489457a60298dd' - waiting eu-west-1 - EC2KeyPair - 'test' - removed eu-west-1 - EC2RouteTable - 'rtb-ffe91e99' - failed eu-west-1 - EC2SecurityGroup - 'sg-f20f958a' - failed eu-west-1 - EC2Subnet - 'subnet-154d844e' - failed eu-west-1 - EC2Volume - 'vol-0ddfb15461a00c3e2' - failed eu-west-1 - EC2VPC - 'vpc-c6159fa1' - failed Removal requested: 1 waiting, 6 failed, 5 skipped, 1 finished --- truncating long output --- ``` As you see *aws-nuke* now tries to delete all resources which aren't filtered, without caring about the dependencies between them. This results in API errors which can be ignored. These errors are shown at the end of the *aws-nuke* run, if they keep to appear. *aws-nuke* retries deleting all resources until all specified ones are deleted or until there are only resources with errors left. ### AWS Credentials There are two ways to authenticate *aws-nuke*. There are static credentials and profiles. The later one can be configured in the shared credentials file (ie `~/.aws/credentials`) or the shared config file (ie `~/.aws/config`). To use *static credentials* the command line flags `--access-key-id` and `--secret-access-key` are required. The flag `--session-token` is only required for temporary sessions. To use *shared profiles* the command line flag `--profile` is required. The profile must be either defined with static credentials in the [shared credential file](https://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html) or in [shared config file](https://docs.aws.amazon.com/cli/latest/userguide/cli-roles.html) with an assuming role. ### Using custom AWS endpoint It is possible to configure aws-nuke to run against non-default AWS endpoints. It could be used for integration testing pointing to a local endpoint such as an S3 appliance or a Stratoscale cluster for example. To configure aws-nuke to use custom endpoints, add the configuration directives as shown in the following example: ```yaml regions: - demo10 # inspired by https://www.terraform.io/docs/providers/aws/guides/custom-service-endpoints.html endpoints: - region: demo10 tls_insecure_skip_verify: true services: - service: ec2 url: https://10.16.145.115/api/v2/aws/ec2 - service: s3 url: https://10.16.145.115:1060 - service: rds url: https://10.16.145.115/api/v2/aws/rds - service: elbv2 url: https://10.16.145.115/api/v2/aws/elbv2 - service: efs url: https://10.16.145.115/api/v2/aws/efs - service: emr url: https://10.16.145.115/api/v2/aws/emr - service: autoscaling url: https://10.16.145.115/api/v2/aws/autoscaling - service: cloudwatch url: https://10.16.145.115/api/v2/aws/cloudwatch - service: sns url: https://10.16.145.115/api/v2/aws/sns - service: iam url: https://10.16.145.115/api/v2/aws/iam - service: acm url: https://10.16.145.115/api/v2/aws/acm account-blocklist: - "account-id-of-custom-region-prod" # production accounts: "account-id-of-custom-region-demo10": ``` This can then be used as follows: ```buildoutcfg $ aws-nuke -c config/my.yaml --access-key-id --secret-access-key --default-region demo10 aws-nuke version v2.11.0.2.gf0ad3ac.dirty - Tue Nov 26 19:15:12 IST 2019 - f0ad3aca55eb66b93b88ce2375f8ad06a7ca856f Do you really want to nuke the account with the ID account-id-of-custom-region-demo10 and the alias 'account-id-of-custom-region-demo10'? Do you want to continue? Enter account alias to continue. > account-id-of-custom-region-demo10 demo10 - EC2Volume - vol-099aa1bb08454fd5bc3499897f175fd8 - [tag:Name: "volume_of_5559b38e-0a56-4078-9a6f-eb446c21cadf"] - would remove demo10 - EC2Volume - vol-11e9b09c71924354bcb4ee77e547e7db - [tag:Name: "volume_of_e4f8c806-0235-4578-8c08-dce45d4c2952"] - would remove demo10 - EC2Volume - vol-1a10cb3f3119451997422c435abf4275 - [tag:Name: "volume-dd2e4c4a"] - would remove demo10 - EC2Volume - vol-1a2e649df1ef449686ef8771a078bb4e - [tag:Name: "web-server-5"] - would remove demo10 - EC2Volume - vol-481d09bbeb334ec481c12beee6f3012e - [tag:Name: "volume_of_15b606ce-9dcd-4573-b7b1-4329bc236726"] - would remove demo10 - EC2Volume - vol-48f6bd2bebb945848b029c80b0f2de02 - [tag:Name: "Data volume for 555e9f8a"] - would remove demo10 - EC2Volume - vol-49f0762d84f0439da805d11b6abc1fee - [tag:Name: "Data volume for acb7f3a5"] - would remove demo10 - EC2Volume - vol-4c34656f823542b2837ac4eaff64762b - [tag:Name: "wpdb"] - would remove demo10 - EC2Volume - vol-875f091078134fee8d1fe3b1156a4fce - [tag:Name: "volume-f1a7c95f"] - would remove demo10 - EC2Volume - vol-8776a0d5bd4e4aefadfa8038425edb20 - [tag:Name: "web-server-6"] - would remove demo10 - EC2Volume - vol-8ed468bfab0b42c3bc617479b8f33600 - [tag:Name: "web-server-3"] - would remove demo10 - EC2Volume - vol-94e0370b6ab54f03822095d74b7934b2 - [tag:Name: "web-server-2"] - would remove demo10 - EC2Volume - vol-9ece34dfa7f64dd583ab903a1273340c - [tag:Name: "volume-4ccafc2e"] - would remove demo10 - EC2Volume - vol-a3fb3e8800c94452aff2fcec7f06c26b - [tag:Name: "web-server-0"] - would remove demo10 - EC2Volume - vol-a53954e17cb749a283d030f26bbaf200 - [tag:Name: "volume-5484e330"] - would remove demo10 - EC2Volume - vol-a7afe64f4d0f4965a6703cc0cfab2ba4 - [tag:Name: "Data volume for f1a7c95f"] - would remove demo10 - EC2Volume - vol-d0bc3f2c887f4072a9fda0b8915d94c1 - [tag:Name: "physical_volume_of_39c29f53-eac4-4f02-9781-90512cc7c563"] - would remove demo10 - EC2Volume - vol-d1f066d8dac54ae59d087d7e9947e8a9 - [tag:Name: "Data volume for 4ccafc2e"] - would remove demo10 - EC2Volume - vol-d9adb3f084cd4d588baa08690349b1f9 - [tag:Name: "volume_of_84854c9b-98aa-4f5b-926a-38b3398c3ad2"] - would remove demo10 - EC2Volume - vol-db42e471b19f42b7835442545214bc1a - [tag:Name: "lb-tf-lb-20191126090616258000000002"] - would remove demo10 - EC2Volume - vol-db80932fb47243efa67c9dd34223c647 - [tag:Name: "web-server-5"] - would remove demo10 - EC2Volume - vol-dbea1d1083654d30a43366807a125aed - [tag:Name: "volume-555e9f8a"] - would remove --- truncating long output --- ``` ### Specifying Resource Types to Delete *aws-nuke* deletes a lot of resources and there might be added more at any release. Eventually, every resources should get deleted. You might want to restrict which resources to delete. There are multiple ways to configure this. One way are filters, which already got mentioned. This requires to know the identifier of each resource. It is also possible to prevent whole resource types (eg `S3Bucket`) from getting deleted with two methods. * The `--target` flag limits nuking to the specified resource types. * The `--exclude` flag prevent nuking of the specified resource types. It is also possible to configure the resource types in the config file like in these examples: ``` --- regions: - "eu-west-1" account-blocklist: - 1234567890 resource-types: # only nuke these three resources targets: - S3Object - S3Bucket - IAMRole accounts: 555133742: {} ``` ``` --- regions: - "eu-west-1" account-blocklist: - 1234567890 resource-types: # don't nuke IAM users excludes: - IAMUser accounts: 555133742: {} ``` If targets are specified in multiple places (eg CLI and account specific), then a resource type must be specified in all places. In other words each configuration limits the previous ones. If an exclude is used, then all its resource types will not be deleted. **Hint:** You can see all available resource types with this command: ``` aws-nuke resource-types ``` ### Feature Flags There are some features, which are quite opinionated. To make those work for everyone, *aws-nuke* has flags to manually enable those features. These can be configured on the root-level of the config, like this: ```yaml --- feature-flags: disable-deletion-protection: RDSInstance: true EC2Instance: true CloudformationStack: true force-delete-lightsail-addons: true ``` ### Filtering Resources It is possible to filter this is important for not deleting the current user for example or for resources like S3 Buckets which have a globally shared namespace and might be hard to recreate. Currently the filtering is based on the resource identifier. The identifier will be printed as the first step of *aws-nuke* (eg `i-01b489457a60298dd` for an EC2 instance). **Note: Even with filters you should not run aws-nuke on any AWS account, where you cannot afford to lose all resources. It is easy to make mistakes in the filter configuration. Also, since aws-nuke is in continous development, there is always a possibility to introduce new bugs, no matter how careful we review new code.** The filters are part of the account-specific configuration and are grouped by resource types. This is an example of a config that deletes all resources but the `admin` user with its access permissions and two access keys: ```yaml --- regions: - global - eu-west-1 account-blocklist: - 1234567890 accounts: 0987654321: filters: IAMUser: - "admin" IAMUserPolicyAttachment: - "admin -> AdministratorAccess" IAMUserAccessKey: - "admin -> AKSDAFRETERSDF" - "admin -> AFGDSGRTEWSFEY" ``` Any resource whose resource identifier exactly matches any of the filters in the list will be skipped. These will be marked as "filtered by config" on the *aws-nuke* run. #### Filter Properties Some resources support filtering via properties. When a resource support these properties, they will be listed in the output like in this example: ``` global - IAMUserPolicyAttachment - 'admin -> AdministratorAccess' - [RoleName: "admin", PolicyArn: "arn:aws:iam::aws:policy/AdministratorAccess", PolicyName: "AdministratorAccess"] - would remove ``` To use properties, it is required to specify a object with `properties` and `value` instead of the plain string. These types can be used to simplify the configuration. For example, it is possible to protect all access keys of a single user: ```yaml IAMUserAccessKey: - property: UserName value: "admin" ``` #### Filter Types There are also additional comparision types than an exact match: * `exact` – The identifier must exactly match the given string. This is the default. * `contains` – The identifier must contain the given string. * `glob` – The identifier must match against the given [glob pattern](https://en.wikipedia.org/wiki/Glob_(programming)). This means the string might contains wildcards like `*` and `?`. Note that globbing is designed for file paths, so the wildcards do not match the directory separator (`/`). Details about the glob pattern can be found in the [library documentation](https://godoc.org/github.com/mb0/glob). * `regex` – The identifier must match against the given regular expression. Details about the syntax can be found in the [library documentation](https://golang.org/pkg/regexp/syntax/). * `dateOlderThan` - The identifier is parsed as a timestamp. After the offset is added to it (specified in the `value` field), the resulting timestamp must be AFTER the current time. Details on offset syntax can be found in the [library documentation](https://golang.org/pkg/time/#ParseDuration). Supported date formats are epoch time, `2006-01-02`, `2006/01/02`, `2006-01-02T15:04:05Z`, `2006-01-02T15:04:05.999999999Z07:00`, and `2006-01-02T15:04:05Z07:00`. To use a non-default comparision type, it is required to specify an object with `type` and `value` instead of the plain string. These types can be used to simplify the configuration. For example, it is possible to protect all access keys of a single user by using `glob`: ```yaml IAMUserAccessKey: - type: glob value: "admin -> *" ``` #### Using Them Together It is also possible to use Filter Properties and Filter Types together. For example to protect all Hosted Zone of a specific TLD: ```yaml Route53HostedZone: - property: Name type: glob value: "*.rebuy.cloud." ``` #### Inverting Filter Results Any filter result can be inverted by using `invert: true`, for example: ```yaml CloudFormationStack: - property: Name value: "foo" invert: true ``` In this case *any* CloudFormationStack ***but*** the ones called "foo" will be filtered. Be aware that *aws-nuke* internally takes every resource and applies every filter on it. If a filter matches, it marks the node as filtered. #### Filter Presets It might be the case that some filters are the same across multiple accounts. This especially could happen, if provisioning tools like Terraform are used or if IAM resources follow the same pattern. For this case *aws-nuke* supports presets of filters, that can applied on multiple accounts. A configuration could look like this: ```yaml --- regions: - "global" - "eu-west-1" account-blocklist: - 1234567890 accounts: 555421337: presets: - "common" 555133742: presets: - "common" - "terraform" 555134237: presets: - "common" - "terraform" filters: EC2KeyPair: - "notebook" presets: terraform: filters: S3Bucket: - type: glob value: "my-statebucket-*" DynamoDBTable: - "terraform-lock" common: filters: IAMRole: - "OrganizationAccountAccessRole" ``` ## Install ### Use Released Binaries The easiest way of installing it, is to download the latest [release](https://github.com/rebuy-de/aws-nuke/releases) from GitHub. ### Compile from Source To compile *aws-nuke* from source you need a working [Golang](https://golang.org/doc/install) development environment. The sources must be cloned to `$GOPATH/src/github.com/rebuy-de/aws-nuke`. Also you need to install [Glide](https://glide.sh/), [golint](https://github.com/golang/lint/) and [GNU Make](https://www.gnu.org/software/make/). Then you just need to run `make build` to compile a binary into the project directory or `make install` go install *aws-nuke* into `$GOPATH/bin`. With `make xc` you can cross compile *aws-nuke* for other platforms. ### Docker You can run *aws-nuke* with Docker by using a command like this: ```bash $ docker run \ --rm -it \ -v /full-path/to/nuke-config.yml:/home/aws-nuke/config.yml \ -v /home/user/.aws:/home/aws-nuke/.aws \ quay.io/rebuy/aws-nuke:v2.11.0 \ --profile default \ --config /home/aws-nuke/config.yml ``` To make it work, you need to adjust the paths for the AWS config and the *aws-nuke* config. Also you need to specify the correct AWS profile. Instead of mounting the AWS directory, you can use the `--access-key-id` and `--secret-access-key` flags. Make sure you use the latest version in the image tag. Alternatiely you can use `main` for the latest development version, but be aware that this is more likely to break at any time. ## Testing ### Unit Tests To unit test *aws-nuke*, some tests require [gomock](https://github.com/golang/mock) to run. This will run via `go generate ./...`, but is automatically run via `make test`. To run the unit tests: ```bash make test ``` ## Contact Channels Feel free to create a GitHub Issue for any bug reports or feature requests. Please use our mailing list for questions: aws-nuke@googlegroups.com. You can also search in the mailing list archive, whether someone already had the same problem: https://groups.google.com/d/forum/aws-nuke ## Contribute You can contribute to *aws-nuke* by forking this repository, making your changes and creating a Pull Request against our repository. If you are unsure how to solve a problem or have other questions about a contributions, please create a GitHub issue. aws-nuke-2.16.0/cmd/000077500000000000000000000000001411137415400140765ustar00rootroot00000000000000aws-nuke-2.16.0/cmd/log.go000066400000000000000000000031171411137415400152100ustar00rootroot00000000000000package cmd import ( "fmt" "sort" "strings" "github.com/fatih/color" "github.com/rebuy-de/aws-nuke/resources" ) var ( ReasonSkip = *color.New(color.FgYellow) ReasonError = *color.New(color.FgRed) ReasonRemoveTriggered = *color.New(color.FgGreen) ReasonWaitPending = *color.New(color.FgBlue) ReasonSuccess = *color.New(color.FgGreen) ) var ( ColorRegion = *color.New(color.Bold) ColorResourceType = *color.New() ColorResourceID = *color.New(color.Bold) ColorResourceProperties = *color.New(color.Italic) ) // Format the resource properties in sorted order ready for printing. // This ensures that multiple runs of aws-nuke produce stable output so // that they can be compared with each other. func Sorted(m map[string]string) string { keys := make([]string, 0, len(m)) for k := range m { keys = append(keys, k) } sort.Strings(keys) sorted := make([]string, 0, len(m)) for k := range keys { sorted = append(sorted, fmt.Sprintf("%s: \"%s\"", keys[k], m[keys[k]])) } return fmt.Sprintf("[%s]", strings.Join(sorted, ", ")) } func Log(region *Region, resourceType string, r resources.Resource, c color.Color, msg string) { ColorRegion.Printf("%s", region.Name) fmt.Printf(" - ") ColorResourceType.Print(resourceType) fmt.Printf(" - ") rString, ok := r.(resources.LegacyStringer) if ok { ColorResourceID.Print(rString.String()) fmt.Printf(" - ") } rProp, ok := r.(resources.ResourcePropertyGetter) if ok { ColorResourceProperties.Print(Sorted(rProp.Properties())) fmt.Printf(" - ") } c.Printf("%s\n", msg) } aws-nuke-2.16.0/cmd/nuke.go000066400000000000000000000156521411137415400154000ustar00rootroot00000000000000package cmd import ( "fmt" "time" "github.com/rebuy-de/aws-nuke/pkg/awsutil" "github.com/rebuy-de/aws-nuke/pkg/config" "github.com/rebuy-de/aws-nuke/pkg/types" "github.com/rebuy-de/aws-nuke/resources" "github.com/sirupsen/logrus" ) type Nuke struct { Parameters NukeParameters Account awsutil.Account Config *config.Nuke ResourceTypes types.Collection items Queue } func NewNuke(params NukeParameters, account awsutil.Account) *Nuke { n := Nuke{ Parameters: params, Account: account, } return &n } func (n *Nuke) Run() error { var err error if n.Parameters.ForceSleep < 3 { return fmt.Errorf("Value for --force-sleep cannot be less than 3 seconds. This is for your own protection.") } forceSleep := time.Duration(n.Parameters.ForceSleep) * time.Second fmt.Printf("aws-nuke version %s - %s - %s\n\n", BuildVersion, BuildDate, BuildHash) err = n.Config.ValidateAccount(n.Account.ID(), n.Account.Aliases()) if err != nil { return err } fmt.Printf("Do you really want to nuke the account with "+ "the ID %s and the alias '%s'?\n", n.Account.ID(), n.Account.Alias()) if n.Parameters.Force { fmt.Printf("Waiting %v before continuing.\n", forceSleep) time.Sleep(forceSleep) } else { fmt.Printf("Do you want to continue? Enter account alias to continue.\n") err = Prompt(n.Account.Alias()) if err != nil { return err } } err = n.Scan() if err != nil { return err } if n.items.Count(ItemStateNew) == 0 { fmt.Println("No resource to delete.") return nil } if !n.Parameters.NoDryRun { fmt.Println("The above resources would be deleted with the supplied configuration. Provide --no-dry-run to actually destroy resources.") return nil } fmt.Printf("Do you really want to nuke these resources on the account with "+ "the ID %s and the alias '%s'?\n", n.Account.ID(), n.Account.Alias()) if n.Parameters.Force { fmt.Printf("Waiting %v before continuing.\n", forceSleep) time.Sleep(forceSleep) } else { fmt.Printf("Do you want to continue? Enter account alias to continue.\n") err = Prompt(n.Account.Alias()) if err != nil { return err } } failCount := 0 waitingCount := 0 for { n.HandleQueue() if n.items.Count(ItemStatePending, ItemStateWaiting, ItemStateNew) == 0 && n.items.Count(ItemStateFailed) > 0 { if failCount >= 2 { logrus.Errorf("There are resources in failed state, but none are ready for deletion, anymore.") fmt.Println() for _, item := range n.items { if item.State != ItemStateFailed { continue } item.Print() logrus.Error(item.Reason) } return fmt.Errorf("failed") } failCount = failCount + 1 } else { failCount = 0 } if n.Parameters.MaxWaitRetries != 0 && n.items.Count(ItemStateWaiting, ItemStatePending) > 0 && n.items.Count(ItemStateNew) == 0 { if waitingCount >= n.Parameters.MaxWaitRetries { return fmt.Errorf("Max wait retries of %d exceeded.\n\n", n.Parameters.MaxWaitRetries) } waitingCount = waitingCount + 1 } else { waitingCount = 0 } if n.items.Count(ItemStateNew, ItemStatePending, ItemStateFailed, ItemStateWaiting) == 0 { break } time.Sleep(5 * time.Second) } fmt.Printf("Nuke complete: %d failed, %d skipped, %d finished.\n\n", n.items.Count(ItemStateFailed), n.items.Count(ItemStateFiltered), n.items.Count(ItemStateFinished)) return nil } func (n *Nuke) Scan() error { accountConfig := n.Config.Accounts[n.Account.ID()] resourceTypes := ResolveResourceTypes( resources.GetListerNames(), []types.Collection{ n.Parameters.Targets, n.Config.ResourceTypes.Targets, accountConfig.ResourceTypes.Targets, }, []types.Collection{ n.Parameters.Excludes, n.Config.ResourceTypes.Excludes, accountConfig.ResourceTypes.Excludes, }, ) queue := make(Queue, 0) for _, regionName := range n.Config.Regions { region := NewRegion(regionName, n.Account.ResourceTypeToServiceType, n.Account.NewSession) items := Scan(region, resourceTypes) for item := range items { ffGetter, ok := item.Resource.(resources.FeatureFlagGetter) if ok { ffGetter.FeatureFlags(n.Config.FeatureFlags) } queue = append(queue, item) err := n.Filter(item) if err != nil { return err } if item.State != ItemStateFiltered || !n.Parameters.Quiet { item.Print() } } } fmt.Printf("Scan complete: %d total, %d nukeable, %d filtered.\n\n", queue.CountTotal(), queue.Count(ItemStateNew), queue.Count(ItemStateFiltered)) n.items = queue return nil } func (n *Nuke) Filter(item *Item) error { checker, ok := item.Resource.(resources.Filter) if ok { err := checker.Filter() if err != nil { item.State = ItemStateFiltered item.Reason = err.Error() // Not returning the error, since it could be because of a failed // request to the API. We do not want to block the whole nuking, // because of an issue on AWS side. return nil } } accountFilters, err := n.Config.Filters(n.Account.ID()) if err != nil { return err } itemFilters, ok := accountFilters[item.Type] if !ok { return nil } for _, filter := range itemFilters { prop, err := item.GetProperty(filter.Property) match, err := filter.Match(prop) if err != nil { return err } if IsTrue(filter.Invert) { match = !match } if match { item.State = ItemStateFiltered item.Reason = "filtered by config" return nil } } return nil } func (n *Nuke) HandleQueue() { listCache := make(map[string]map[string][]resources.Resource) for _, item := range n.items { switch item.State { case ItemStateNew: n.HandleRemove(item) item.Print() case ItemStateFailed: n.HandleRemove(item) n.HandleWait(item, listCache) item.Print() case ItemStatePending: n.HandleWait(item, listCache) item.State = ItemStateWaiting item.Print() case ItemStateWaiting: n.HandleWait(item, listCache) item.Print() } } fmt.Println() fmt.Printf("Removal requested: %d waiting, %d failed, %d skipped, %d finished\n\n", n.items.Count(ItemStateWaiting, ItemStatePending), n.items.Count(ItemStateFailed), n.items.Count(ItemStateFiltered), n.items.Count(ItemStateFinished)) } func (n *Nuke) HandleRemove(item *Item) { err := item.Resource.Remove() if err != nil { item.State = ItemStateFailed item.Reason = err.Error() return } item.State = ItemStatePending item.Reason = "" } func (n *Nuke) HandleWait(item *Item, cache map[string]map[string][]resources.Resource) { var err error region := item.Region.Name _, ok := cache[region] if !ok { cache[region] = map[string][]resources.Resource{} } left, ok := cache[region][item.Type] if !ok { left, err = item.List() if err != nil { item.State = ItemStateFailed item.Reason = err.Error() return } cache[region][item.Type] = left } for _, r := range left { if item.Equals(r) { checker, ok := r.(resources.Filter) if ok { err := checker.Filter() if err != nil { break } } return } } item.State = ItemStateFinished item.Reason = "" } aws-nuke-2.16.0/cmd/params.go000066400000000000000000000006101411137415400157050ustar00rootroot00000000000000package cmd import ( "fmt" "strings" ) type NukeParameters struct { ConfigPath string Targets []string Excludes []string NoDryRun bool Force bool ForceSleep int Quiet bool MaxWaitRetries int } func (p *NukeParameters) Validate() error { if strings.TrimSpace(p.ConfigPath) == "" { return fmt.Errorf("You have to specify the --config flag.\n") } return nil } aws-nuke-2.16.0/cmd/queue.go000066400000000000000000000052121411137415400155510ustar00rootroot00000000000000package cmd import ( "fmt" "github.com/rebuy-de/aws-nuke/resources" ) type ItemState int // States of Items based on the latest request to AWS. const ( ItemStateNew ItemState = iota ItemStatePending ItemStateWaiting ItemStateFailed ItemStateFiltered ItemStateFinished ) // An Item describes an actual AWS resource entity with the current state and // some metadata. type Item struct { Resource resources.Resource State ItemState Reason string Region *Region Type string } func (i *Item) Print() { switch i.State { case ItemStateNew: Log(i.Region, i.Type, i.Resource, ReasonWaitPending, "would remove") case ItemStatePending: Log(i.Region, i.Type, i.Resource, ReasonWaitPending, "triggered remove") case ItemStateWaiting: Log(i.Region, i.Type, i.Resource, ReasonWaitPending, "waiting") case ItemStateFailed: Log(i.Region, i.Type, i.Resource, ReasonError, "failed") case ItemStateFiltered: Log(i.Region, i.Type, i.Resource, ReasonSkip, i.Reason) case ItemStateFinished: Log(i.Region, i.Type, i.Resource, ReasonSuccess, "removed") } } // List gets all resource items of the same resource type like the Item. func (i *Item) List() ([]resources.Resource, error) { listers := resources.GetListers() sess, err := i.Region.Session(i.Type) if err != nil { return nil, err } return listers[i.Type](sess) } func (i *Item) GetProperty(key string) (string, error) { if key == "" { stringer, ok := i.Resource.(resources.LegacyStringer) if !ok { return "", fmt.Errorf("%T does not support legacy IDs", i.Resource) } return stringer.String(), nil } getter, ok := i.Resource.(resources.ResourcePropertyGetter) if !ok { return "", fmt.Errorf("%T does not support custom properties", i.Resource) } return getter.Properties().Get(key), nil } func (i *Item) Equals(o resources.Resource) bool { iType := fmt.Sprintf("%T", i.Resource) oType := fmt.Sprintf("%T", o) if iType != oType { return false } iStringer, iOK := i.Resource.(resources.LegacyStringer) oStringer, oOK := o.(resources.LegacyStringer) if iOK != oOK { return false } if iOK && oOK { return iStringer.String() == oStringer.String() } iGetter, iOK := i.Resource.(resources.ResourcePropertyGetter) oGetter, oOK := o.(resources.ResourcePropertyGetter) if iOK != oOK { return false } if iOK && oOK { return iGetter.Properties().Equals(oGetter.Properties()) } return false } type Queue []*Item func (q Queue) CountTotal() int { return len(q) } func (q Queue) Count(states ...ItemState) int { count := 0 for _, item := range q { for _, state := range states { if item.State == state { count = count + 1 break } } } return count } aws-nuke-2.16.0/cmd/region.go000066400000000000000000000030071411137415400157100ustar00rootroot00000000000000package cmd import ( "fmt" "sync" "github.com/aws/aws-sdk-go/aws/session" "github.com/rebuy-de/aws-nuke/pkg/awsutil" ) // SessionFactory support for custom endpoints type SessionFactory func(regionName, svcType string) (*session.Session, error) // ResourceTypeResolver returns the service type from the resourceType type ResourceTypeResolver func(regionName, resourceType string) string type Region struct { Name string NewSession SessionFactory ResTypeResolver ResourceTypeResolver cache map[string]*session.Session lock *sync.RWMutex } func NewRegion(name string, typeResolver ResourceTypeResolver, sessionFactory SessionFactory) *Region { return &Region{ Name: name, NewSession: sessionFactory, ResTypeResolver: typeResolver, lock: &sync.RWMutex{}, cache: make(map[string]*session.Session), } } func (region *Region) Session(resourceType string) (*session.Session, error) { svcType := region.ResTypeResolver(region.Name, resourceType) if svcType == "" { return nil, awsutil.ErrSkipRequest(fmt.Sprintf( "No service available in region '%s' to handle '%s'", region.Name, resourceType)) } // Need to read region.lock.RLock() sess := region.cache[svcType] region.lock.RUnlock() if sess != nil { return sess, nil } // Need to write: region.lock.Lock() sess, err := region.NewSession(region.Name, svcType) if err != nil { region.lock.Unlock() return nil, err } region.cache[svcType] = sess region.lock.Unlock() return sess, nil } aws-nuke-2.16.0/cmd/root.go000066400000000000000000000130271411137415400154130ustar00rootroot00000000000000package cmd import ( "fmt" "os" "sort" "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/rebuy-de/aws-nuke/pkg/awsutil" "github.com/rebuy-de/aws-nuke/pkg/config" "github.com/rebuy-de/aws-nuke/resources" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) func NewRootCommand() *cobra.Command { var ( params NukeParameters creds awsutil.Credentials defaultRegion string verbose bool ) command := &cobra.Command{ Use: "aws-nuke", Short: "aws-nuke removes every resource from AWS", Long: `A tool which removes every resource from an AWS account. Use it with caution, since it cannot distinguish between production and non-production.`, } command.PreRun = func(cmd *cobra.Command, args []string) { log.SetLevel(log.InfoLevel) if verbose { log.SetLevel(log.DebugLevel) } log.SetFormatter(&log.TextFormatter{ EnvironmentOverrideColors: true, }) } command.RunE = func(cmd *cobra.Command, args []string) error { var err error err = params.Validate() if err != nil { return err } if !creds.HasKeys() && !creds.HasProfile() && defaultRegion != "" { creds.AccessKeyID = os.Getenv("AWS_ACCESS_KEY_ID") creds.SecretAccessKey = os.Getenv("AWS_SECRET_ACCESS_KEY") } err = creds.Validate() if err != nil { return err } command.SilenceUsage = true config, err := config.Load(params.ConfigPath) if err != nil { log.Errorf("Failed to parse config file %s", params.ConfigPath) return err } if defaultRegion != "" { awsutil.DefaultRegionID = defaultRegion switch defaultRegion { case endpoints.UsEast1RegionID, endpoints.UsEast2RegionID, endpoints.UsWest1RegionID, endpoints.UsWest2RegionID: awsutil.DefaultAWSPartitionID = endpoints.AwsPartitionID case endpoints.UsGovEast1RegionID, endpoints.UsGovWest1RegionID: awsutil.DefaultAWSPartitionID = endpoints.AwsUsGovPartitionID default: if config.CustomEndpoints.GetRegion(defaultRegion) == nil { err = fmt.Errorf("The custom region '%s' must be specified in the configuration 'endpoints'", defaultRegion) log.Error(err.Error()) return err } } } account, err := awsutil.NewAccount(creds, config.CustomEndpoints) if err != nil { return err } n := NewNuke(params, *account) n.Config = config return n.Run() } command.PersistentFlags().BoolVarP( &verbose, "verbose", "v", false, "Enables debug output.") command.PersistentFlags().StringVarP( ¶ms.ConfigPath, "config", "c", "", "(required) Path to the nuke config file.") command.PersistentFlags().StringVar( &creds.Profile, "profile", "", "Name of the AWS profile name for accessing the AWS API. "+ "Cannot be used together with --access-key-id and --secret-access-key.") command.PersistentFlags().StringVar( &creds.AccessKeyID, "access-key-id", "", "AWS access key ID for accessing the AWS API. "+ "Must be used together with --secret-access-key. "+ "Cannot be used together with --profile.") command.PersistentFlags().StringVar( &creds.SecretAccessKey, "secret-access-key", "", "AWS secret access key for accessing the AWS API. "+ "Must be used together with --access-key-id. "+ "Cannot be used together with --profile.") command.PersistentFlags().StringVar( &creds.SessionToken, "session-token", "", "AWS session token for accessing the AWS API. "+ "Must be used together with --access-key-id and --secret-access-key. "+ "Cannot be used together with --profile.") command.PersistentFlags().StringVar( &creds.AssumeRoleArn, "assume-role-arn", "", "AWS IAM role arn to assume. "+ "The credentials provided via --access-key-id or --profile must "+ "be allowed to assume this role. ") command.PersistentFlags().StringVar( &defaultRegion, "default-region", "", "Custom default region name.") command.PersistentFlags().StringSliceVarP( ¶ms.Targets, "target", "t", []string{}, "Limit nuking to certain resource types (eg IAMServerCertificate). "+ "This flag can be used multiple times.") command.PersistentFlags().StringSliceVarP( ¶ms.Excludes, "exclude", "e", []string{}, "Prevent nuking of certain resource types (eg IAMServerCertificate). "+ "This flag can be used multiple times.") command.PersistentFlags().BoolVar( ¶ms.NoDryRun, "no-dry-run", false, "If specified, it actually deletes found resources. "+ "Otherwise it just lists all candidates.") command.PersistentFlags().BoolVar( ¶ms.Force, "force", false, "Don't ask for confirmation before deleting resources. "+ "Instead it waits 15s before continuing. Set --force-sleep to change the wait time.") command.PersistentFlags().IntVar( ¶ms.ForceSleep, "force-sleep", 15, "If specified and --force is set, wait this many seconds before deleting resources. "+ "Defaults to 15.") command.PersistentFlags().IntVar( ¶ms.MaxWaitRetries, "max-wait-retries", 0, "If specified, the program will exit if resources are stuck in waiting for this many iterations. "+ "0 (default) disables early exit.") command.PersistentFlags().BoolVarP( ¶ms.Quiet, "quiet", "q", false, "Don't show filtered resources.") command.AddCommand(NewVersionCommand()) command.AddCommand(NewResourceTypesCommand()) return command } func NewResourceTypesCommand() *cobra.Command { cmd := &cobra.Command{ Use: "resource-types", Short: "lists all available resource types", Run: func(cmd *cobra.Command, args []string) { names := resources.GetListerNames() sort.Strings(names) for _, resourceType := range names { fmt.Println(resourceType) } }, } return cmd } aws-nuke-2.16.0/cmd/scan.go000066400000000000000000000035711411137415400153570ustar00rootroot00000000000000package cmd import ( "context" "fmt" "runtime/debug" "github.com/rebuy-de/aws-nuke/pkg/awsutil" "github.com/rebuy-de/aws-nuke/pkg/util" "github.com/rebuy-de/aws-nuke/resources" log "github.com/sirupsen/logrus" "golang.org/x/sync/semaphore" ) const ScannerParallelQueries = 16 func Scan(region *Region, resourceTypes []string) <-chan *Item { s := &scanner{ items: make(chan *Item, 100), semaphore: semaphore.NewWeighted(ScannerParallelQueries), } go s.run(region, resourceTypes) return s.items } type scanner struct { items chan *Item semaphore *semaphore.Weighted } func (s *scanner) run(region *Region, resourceTypes []string) { ctx := context.Background() for _, resourceType := range resourceTypes { s.semaphore.Acquire(ctx, 1) go s.list(region, resourceType) } // Wait for all routines to finish. s.semaphore.Acquire(ctx, ScannerParallelQueries) close(s.items) } func (s *scanner) list(region *Region, resourceType string) { defer func() { if r := recover(); r != nil { err := fmt.Errorf("%v\n\n%s", r.(error), string(debug.Stack())) dump := util.Indent(fmt.Sprintf("%v", err), " ") log.Errorf("Listing %s failed:\n%s", resourceType, dump) } }() defer s.semaphore.Release(1) lister := resources.GetLister(resourceType) var rs []resources.Resource sess, err := region.Session(resourceType) if err == nil { rs, err = lister(sess) } if err != nil { _, ok := err.(awsutil.ErrSkipRequest) if ok { log.Debugf("skipping request: %v", err) return } _, ok = err.(awsutil.ErrUnknownEndpoint) if ok { log.Warnf("skipping request: %v", err) return } dump := util.Indent(fmt.Sprintf("%v", err), " ") log.Errorf("Listing %s failed:\n%s", resourceType, dump) return } for _, r := range rs { s.items <- &Item{ Region: region, Resource: r, State: ItemStateNew, Type: resourceType, } } } aws-nuke-2.16.0/cmd/util.go000066400000000000000000000013131411137415400154000ustar00rootroot00000000000000package cmd import ( "bufio" "fmt" "os" "strings" "github.com/rebuy-de/aws-nuke/pkg/types" ) func Prompt(expect string) error { fmt.Print("> ") reader := bufio.NewReader(os.Stdin) text, err := reader.ReadString('\n') if err != nil { return err } if strings.TrimSpace(text) != expect { return fmt.Errorf("aborted") } fmt.Println() return nil } func ResolveResourceTypes(base types.Collection, include, exclude []types.Collection) types.Collection { for _, i := range include { if len(i) > 0 { base = base.Intersect(i) } } for _, e := range exclude { base = base.Remove(e) } return base } func IsTrue(s string) bool { return strings.TrimSpace(strings.ToLower(s)) == "true" } aws-nuke-2.16.0/cmd/util_test.go000066400000000000000000000034731411137415400164500ustar00rootroot00000000000000package cmd import ( "fmt" "sort" "testing" "github.com/rebuy-de/aws-nuke/pkg/types" ) func TestResolveResourceTypes(t *testing.T) { cases := []struct { base types.Collection include []types.Collection exclude []types.Collection result types.Collection }{ { base: types.Collection{"a", "b", "c", "d"}, include: []types.Collection{types.Collection{"a", "b", "c"}}, result: types.Collection{"a", "b", "c"}, }, { base: types.Collection{"a", "b", "c", "d"}, exclude: []types.Collection{types.Collection{"b", "d"}}, result: types.Collection{"a", "c"}, }, { base: types.Collection{"a", "b"}, include: []types.Collection{types.Collection{}}, result: types.Collection{"a", "b"}, }, { base: types.Collection{"c", "b"}, exclude: []types.Collection{types.Collection{}}, result: types.Collection{"c", "b"}, }, { base: types.Collection{"a", "b", "c", "d"}, include: []types.Collection{types.Collection{"a", "b", "c"}}, exclude: []types.Collection{types.Collection{"a"}}, result: types.Collection{"b", "c"}, }, } for i, tc := range cases { t.Run(fmt.Sprint(i), func(t *testing.T) { r := ResolveResourceTypes(tc.base, tc.include, tc.exclude) sort.Strings(r) sort.Strings(tc.result) var ( want = fmt.Sprint(tc.result) have = fmt.Sprint(r) ) if want != have { t.Fatalf("Wrong result. Want: %s. Have: %s", want, have) } }) } } func TestIsTrue(t *testing.T) { falseStrings := []string{"", "false", "treu", "foo"} for _, fs := range falseStrings { if IsTrue(fs) { t.Fatalf("IsTrue falsely returned 'true' for: %s", fs) } } trueStrings := []string{"true", " true", "true ", " TrUe "} for _, ts := range trueStrings { if ! IsTrue(ts) { t.Fatalf("IsTrue falsely returned 'false' for: %s", ts) } } } aws-nuke-2.16.0/cmd/version.go000066400000000000000000000011121411137415400161050ustar00rootroot00000000000000package cmd import ( "fmt" "github.com/spf13/cobra" ) var ( BuildVersion = "unknown" BuildDate = "unknown" BuildHash = "unknown" BuildEnvironment = "unknown" ) func NewVersionCommand() *cobra.Command { cmd := &cobra.Command{ Use: "version", Short: "shows version of this application", Run: func(cmd *cobra.Command, args []string) { fmt.Printf("version: %s\n", BuildVersion) fmt.Printf("build date: %s\n", BuildDate) fmt.Printf("scm hash: %s\n", BuildHash) fmt.Printf("environment: %s\n", BuildEnvironment) }, } return cmd } aws-nuke-2.16.0/config/000077500000000000000000000000001411137415400146005ustar00rootroot00000000000000aws-nuke-2.16.0/config/custom-example.yaml000066400000000000000000000031731411137415400204330ustar00rootroot00000000000000regions: - demo10 # inspired by https://www.terraform.io/docs/providers/aws/guides/custom-service-endpoints.html endpoints: - region: demo10 tls_insecure_skip_verify: true services: - service: ec2 url: https://demo10.cloud.internal/api/v2/aws/ec2 - service: s3 url: https://demo10.cloud.internal:1060 - service: rds url: https://demo10.cloud.internal/api/v2/aws/rds - service: elbv2 url: https://demo10.cloud.internal/api/v2/aws/elbv2 - service: efs url: https://demo10.cloud.internal/api/v2/aws/efs - service: emr url: https://demo10.cloud.internal/api/v2/aws/emr - service: autoscaling url: https://demo10.cloud.internal/api/v2/aws/autoscaling - service: cloudwatch url: https://demo10.cloud.internal/api/v2/aws/cloudwatch - service: sns url: https://demo10.cloud.internal/api/v2/aws/sns - service: iam url: https://demo10.cloud.internal/api/v2/aws/iam - service: acm url: https://demo10.cloud.internal/api/v2/aws/acm account-blocklist: - "account-id-of-custom-region-prod" # production accounts: "account-id-of-custom-region-demo10": presets: - stratoscale presets: stratoscale: filters: EC2VPC: - property: tag:Name type: contains value: "Default VPC" EC2Instance: - property: tag:Name type: contains value: "DNS VM for vpc" EC2Volume: - property: tag:Name type: contains value: "DNS VM for vpc" RDSDBParameterGroup: - type: regex value: "^default-" EC2DHCPOption: - property: tag:Name type: regex value: "^.+$" invert: true aws-nuke-2.16.0/config/example.yaml000066400000000000000000000020151411137415400171150ustar00rootroot00000000000000--- regions: - "global" # This is for all global resource types e.g. IAM - "eu-west-1" account-blocklist: - 1234567890 # optional: restrict nuking to these resources resource-types: targets: - IAMUser - IAMUserPolicyAttachment - IAMUserAccessKey - S3Bucket - S3Object - Route53HostedZone - EC2Instance - CloudFormationStack - MSKCluster accounts: 555133742: filters: IAMUser: - "admin" IAMUserPolicyAttachment: - property: RoleName value: "admin" IAMUserAccessKey: - property: UserName value: "admin" S3Bucket: - "s3://my-bucket" S3Object: - type: "glob" value: "s3://my-bucket/**" Route53HostedZone: - property: Name type: "glob" value: "*.zone.loc." CloudFormationStack: - property: "tag:team" value: "myTeam" EC2Snapshot: - property: "tag:team" type: regex value: ".+" EC2Image: - property: "tag:release" value: "production" aws-nuke-2.16.0/generate_mocks000077500000000000000000000003461411137415400162520ustar00rootroot00000000000000#!/bin/sh go run github.com/golang/mock/mockgen -source $(go list -m -mod=mod -f "{{.Dir}}" "github.com/aws/aws-sdk-go")/service/cloudformation/cloudformationiface/interface.go -destination mocks/mock_cloudformationiface/mock.go aws-nuke-2.16.0/generate_test.go000066400000000000000000000000551411137415400165130ustar00rootroot00000000000000package main //go:generate ./generate_mocks aws-nuke-2.16.0/go.mod000066400000000000000000000006501411137415400144420ustar00rootroot00000000000000module github.com/rebuy-de/aws-nuke go 1.16 require ( github.com/aws/aws-sdk-go v1.38.42 github.com/fatih/color v1.10.0 github.com/golang/mock v1.4.4 github.com/mb0/glob v0.0.0-20160210091149-1eb79d2de6c4 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.7.1 github.com/spf13/cobra v1.1.3 github.com/stretchr/testify v1.6.1 golang.org/x/sync v0.0.0-20201207232520-09787c993a3a gopkg.in/yaml.v2 v2.4.0 ) aws-nuke-2.16.0/go.sum000066400000000000000000001062641411137415400144770ustar00rootroot00000000000000cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/aws/aws-sdk-go v1.34.12 h1:7UbBEYDUa4uW0YmRnOd806MS1yoJMcaodBWDzvBShAI= github.com/aws/aws-sdk-go v1.34.12/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= github.com/aws/aws-sdk-go v1.37.12 h1:rPdjZTlzHn+sbLEO+i535g+WpGf7QBDLYI7rDok+FHo= github.com/aws/aws-sdk-go v1.37.12/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/aws/aws-sdk-go v1.38.42 h1:94blpbGDe2q5e0Xoop7131uzI2CH2qitQoptSMrkJP8= github.com/aws/aws-sdk-go v1.38.42/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 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/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc= github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g= github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 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/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.7.1 h1:rsizeFmZP+GYwyb4V6t6qpG7ZNWzA2bvgW/yC2xHCcg= github.com/sirupsen/logrus v1.7.1/go.mod h1:4GuYW9TZmE769R5STWrRakJc4UqQ3+QQ95fyz7ENv1A= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8= github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M= github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 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/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= 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.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/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-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA= golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/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-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425150028-36563e24a262 h1:qsl9y/CJx34tuA7QCPNp86JNJe4spst6Ff8MjvPUdPg= golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc h1:NCy3Ohtk6Iny5V/reW2Ktypo4zIpWBdRJ1uFMjBxdg8= golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= aws-nuke-2.16.0/golang.mk000066400000000000000000000043461411137415400151420ustar00rootroot00000000000000# Source: https://github.com/rebuy-de/golang-template TARGETS?="." PACKAGE=$(shell GOPATH= go list $(TARGET)) NAME=$(notdir $(PACKAGE)) BUILD_VERSION=$(shell git describe --always --dirty --tags | tr '-' '.' ) BUILD_DATE=$(shell LC_ALL=C date) BUILD_HASH=$(shell git rev-parse HEAD) BUILD_MACHINE=$(shell uname -n) BUILD_USER=$(shell whoami) BUILD_ENVIRONMENT=$(BUILD_USER)@$(BUILD_MACHINE) BUILD_XDST=$(PACKAGE)/cmd BUILD_FLAGS=-ldflags "\ $(ADDITIONAL_LDFLAGS) -s -w \ -X '$(BUILD_XDST).BuildVersion=$(BUILD_VERSION)' \ -X '$(BUILD_XDST).BuildDate=$(BUILD_DATE)' \ -X '$(BUILD_XDST).BuildHash=$(BUILD_HASH)' \ -X '$(BUILD_XDST).BuildEnvironment=$(BUILD_ENVIRONMENT)' \ " GOFILES=$(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*") GOPKGS=$(shell go list ./...) OUTPUT_FILE=$(NAME)-$(BUILD_VERSION)-$(shell go env GOOS)-$(shell go env GOARCH)$(shell go env GOARM)$(shell go env GOEXE) OUTPUT_LINK=$(NAME)$(shell go env GOEXE) WINDOWS_ZIP=$(shell echo $(OUTPUT_FILE) | sed 's/\.exe/\.zip/') default: build vendor: go.mod go.sum go mod vendor touch vendor format: gofmt -s -w $(GOFILES) vet: go_generate vendor go vet $(GOPKGS) lint: $(foreach pkg,$(GOPKGS),golint $(pkg);) go_generate: rm -rvf mocks go generate ./... test_packages: go_generate vendor go test $(GOPKGS) test_format: gofmt -s -l $(GOFILES) test: test_format vet lint test_packages cov: go_generate gocov test -v $(GOPKGS) \ | gocov-html > coverage.html _build: vendor mkdir -p dist $(foreach TARGET,$(TARGETS),go build \ $(BUILD_FLAGS) \ -o dist/$(OUTPUT_FILE) \ $(TARGET);\ ) build: go_generate _build $(foreach TARGET,$(TARGETS),ln -sf $(OUTPUT_FILE) dist/$(OUTPUT_LINK);) compress: _build ifeq ($(GOOS),windows) zip -j dist/$(WINDOWS_ZIP) dist/$(OUTPUT_FILE) else tar czf dist/$(OUTPUT_FILE).tar.gz -C dist $(OUTPUT_FILE) endif rm -f dist/$(OUTPUT_FILE) xc: go_generate GOOS=linux GOARCH=amd64 make compress GOOS=linux GOARCH=arm64 make compress GOOS=linux GOARCH=arm GOARM=7 make compress GOOS=darwin GOARCH=amd64 make compress GOOS=darwin GOARCH=arm64 make compress GOOS=windows GOARCH=amd64 make compress install: test $(foreach TARGET,$(TARGETS),go install \ $(BUILD_FLAGS);) clean: rm dist/ -rvf rm mocks/ -rvf aws-nuke-2.16.0/main.go000066400000000000000000000005631411137415400146120ustar00rootroot00000000000000package main import ( "os" "github.com/rebuy-de/aws-nuke/cmd" ) type NukeParameters struct { ConfigPath string Profile string AccessKeyID string SecretAccessKey string NoDryRun bool Force bool ForceSleep int Quiet bool MaxWaitRetries int } func main() { if err := cmd.NewRootCommand().Execute(); err != nil { os.Exit(-1) } } aws-nuke-2.16.0/pkg/000077500000000000000000000000001411137415400141145ustar00rootroot00000000000000aws-nuke-2.16.0/pkg/awsutil/000077500000000000000000000000001411137415400156045ustar00rootroot00000000000000aws-nuke-2.16.0/pkg/awsutil/account.go000066400000000000000000000043731411137415400175760ustar00rootroot00000000000000package awsutil import ( "strings" "github.com/aws/aws-sdk-go/service/iam" "github.com/aws/aws-sdk-go/service/sts" "github.com/pkg/errors" "github.com/rebuy-de/aws-nuke/pkg/config" ) type Account struct { Credentials id string aliases []string } func NewAccount(creds Credentials, endpoints config.CustomEndpoints) (*Account, error) { creds.CustomEndpoints = endpoints account := Account{ Credentials: creds, } customStackSupportSTSAndIAM := true if endpoints.GetRegion(DefaultRegionID) != nil { if endpoints.GetURL(DefaultRegionID, "sts") == "" { customStackSupportSTSAndIAM = false } else if endpoints.GetURL(DefaultRegionID, "iam") == "" { customStackSupportSTSAndIAM = false } } if !customStackSupportSTSAndIAM { account.id = "account-id-of-custom-region-" + DefaultRegionID account.aliases = []string{account.id} return &account, nil } defaultSession, err := account.NewSession(DefaultRegionID, "") if err != nil { return nil, errors.Wrapf(err, "failed to create default session in %s", DefaultRegionID) } identityOutput, err := sts.New(defaultSession).GetCallerIdentity(nil) if err != nil { return nil, errors.Wrap(err, "failed get caller identity") } globalSession, err := account.NewSession(GlobalRegionID, "") if err != nil { return nil, errors.Wrapf(err, "failed to create global session in %s", GlobalRegionID) } aliasesOutput, err := iam.New(globalSession).ListAccountAliases(nil) if err != nil { return nil, errors.Wrap(err, "failed get account alias") } aliases := []string{} for _, alias := range aliasesOutput.AccountAliases { if alias != nil { aliases = append(aliases, *alias) } } account.id = *identityOutput.Account account.aliases = aliases return &account, nil } func (a *Account) ID() string { return a.id } func (a *Account) Alias() string { return a.aliases[0] } func (a *Account) Aliases() []string { return a.aliases } func (a *Account) ResourceTypeToServiceType(regionName, resourceType string) string { customRegion := a.CustomEndpoints.GetRegion(regionName) if customRegion == nil { return "-" // standard public AWS. } for _, e := range customRegion.Services { if strings.HasPrefix(strings.ToLower(resourceType), e.Service) { return e.Service } } return "" } aws-nuke-2.16.0/pkg/awsutil/errors.go000066400000000000000000000003241411137415400174460ustar00rootroot00000000000000package awsutil type ErrSkipRequest string func (err ErrSkipRequest) Error() string { return string(err) } type ErrUnknownEndpoint string func (err ErrUnknownEndpoint) Error() string { return string(err) } aws-nuke-2.16.0/pkg/awsutil/session.go000066400000000000000000000145601411137415400176240ustar00rootroot00000000000000package awsutil import ( "crypto/tls" "fmt" "net" "net/http" "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/credentials/stscreds" "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/aws/session" "github.com/rebuy-de/aws-nuke/pkg/config" log "github.com/sirupsen/logrus" ) const ( GlobalRegionID = "global" ) var ( // DefaultRegionID The default region. Can be customized for non AWS implementations DefaultRegionID = endpoints.UsEast1RegionID // DefaultAWSPartitionID The default aws partition. Can be customized for non AWS implementations DefaultAWSPartitionID = endpoints.AwsPartitionID ) type Credentials struct { Profile string AccessKeyID string SecretAccessKey string SessionToken string AssumeRoleArn string Credentials *credentials.Credentials CustomEndpoints config.CustomEndpoints session *session.Session } func (c *Credentials) HasProfile() bool { return strings.TrimSpace(c.Profile) != "" } func (c *Credentials) HasAwsCredentials() bool { return c.Credentials != nil } func (c *Credentials) HasKeys() bool { return strings.TrimSpace(c.AccessKeyID) != "" || strings.TrimSpace(c.SecretAccessKey) != "" || strings.TrimSpace(c.SessionToken) != "" } func (c *Credentials) Validate() error { if c.HasProfile() && c.HasKeys() { return fmt.Errorf("You have to specify either the --profile flag or " + "--access-key-id with --secret-access-key and optionally " + "--session-token.\n") } return nil } func (c *Credentials) rootSession() (*session.Session, error) { if c.session == nil { var opts session.Options region := DefaultRegionID log.Debugf("creating new root session in %s", region) switch { case c.HasAwsCredentials(): opts = session.Options{ Config: aws.Config{ Credentials: c.Credentials, }, } case c.HasProfile() && c.HasKeys(): return nil, fmt.Errorf("You have to specify a profile or credentials for at least one region.") case c.HasKeys(): opts = session.Options{ Config: aws.Config{ Credentials: c.awsNewStaticCredentials(), }, } case c.HasProfile(): fallthrough default: opts = session.Options{ SharedConfigState: session.SharedConfigEnable, Profile: c.Profile, AssumeRoleTokenProvider: stscreds.StdinTokenProvider, } } opts.Config.Region = aws.String(region) opts.Config.DisableRestProtocolURICleaning = aws.Bool(true) sess, err := session.NewSessionWithOptions(opts) if err != nil { return nil, err } // if given a role to assume, overwrite the session credentials with assume role credentials if c.AssumeRoleArn != "" { sess.Config.Credentials = stscreds.NewCredentials(sess, c.AssumeRoleArn) } c.session = sess } return c.session, nil } func (c *Credentials) awsNewStaticCredentials() *credentials.Credentials { if !c.HasKeys() { return credentials.NewEnvCredentials() } return credentials.NewStaticCredentials( strings.TrimSpace(c.AccessKeyID), strings.TrimSpace(c.SecretAccessKey), strings.TrimSpace(c.SessionToken), ) } func (c *Credentials) NewSession(region, serviceType string) (*session.Session, error) { log.Debugf("creating new session in %s for %s", region, serviceType) global := false if region == GlobalRegionID { region = DefaultRegionID global = true } var sess *session.Session isCustom := false if customRegion := c.CustomEndpoints.GetRegion(region); customRegion != nil { customService := customRegion.Services.GetService(serviceType) if customService == nil { return nil, ErrSkipRequest(fmt.Sprintf( ".service '%s' is not available in region '%s'", serviceType, region)) } conf := &aws.Config{ Region: ®ion, Endpoint: &customService.URL, Credentials: c.awsNewStaticCredentials(), } if customService.TLSInsecureSkipVerify { conf.HTTPClient = &http.Client{Transport: &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, }} } // ll := aws.LogDebugWithEventStreamBody // conf.LogLevel = &ll var err error sess, err = session.NewSession(conf) if err != nil { return nil, err } isCustom = true } if sess == nil { root, err := c.rootSession() if err != nil { return nil, err } sess = root.Copy(&aws.Config{ Region: ®ion, }) } sess.Handlers.Send.PushFront(func(r *request.Request) { log.Debugf("sending AWS request:\n%s", DumpRequest(r.HTTPRequest)) }) sess.Handlers.ValidateResponse.PushFront(func(r *request.Request) { log.Debugf("received AWS response:\n%s", DumpResponse(r.HTTPResponse)) }) if !isCustom { sess.Handlers.Validate.PushFront(skipMissingServiceInRegionHandler) sess.Handlers.Validate.PushFront(skipGlobalHandler(global)) } return sess, nil } func skipMissingServiceInRegionHandler(r *request.Request) { region := *r.Config.Region service := r.ClientInfo.ServiceName rs, ok := endpoints.RegionsForService(endpoints.DefaultPartitions(), DefaultAWSPartitionID, service) if !ok { // This means that the service does not exist and this shouldn't be handled here. return } if len(rs) == 0 { // Avoid to throw an error on global services. return } _, ok = rs[region] if !ok { r.Error = ErrSkipRequest(fmt.Sprintf( "service '%s' is not available in region '%s'", service, region)) } } func skipGlobalHandler(global bool) func(r *request.Request) { return func(r *request.Request) { service := r.ClientInfo.ServiceName rs, ok := endpoints.RegionsForService(endpoints.DefaultPartitions(), DefaultAWSPartitionID, service) if !ok { // This means that the service does not exist in the endpoints list. if global { r.Error = ErrSkipRequest(fmt.Sprintf("service '%s' is was not found in the endpoint list; assuming it is not global", service)) } else { host := r.HTTPRequest.URL.Hostname() _, err := net.LookupHost(host) if err != nil { log.Debug(err) r.Error = ErrUnknownEndpoint(fmt.Sprintf("DNS lookup failed for %s; assuming it does not exist in this region", host)) } } return } if len(rs) == 0 && !global { r.Error = ErrSkipRequest(fmt.Sprintf("service '%s' is global, but the session is not", service)) return } if len(rs) > 0 && global { r.Error = ErrSkipRequest(fmt.Sprintf("service '%s' is not global, but the session is", service)) return } } } aws-nuke-2.16.0/pkg/awsutil/util.go000066400000000000000000000017231411137415400171130ustar00rootroot00000000000000package awsutil import ( "bytes" "net/http" "net/http/httputil" "regexp" "github.com/rebuy-de/aws-nuke/pkg/util" log "github.com/sirupsen/logrus" ) var ( RESecretHeader = regexp.MustCompile(`(?m:^([^:]*(Auth|Security)[^:]*):.*$)`) ) func HideSecureHeaders(dump []byte) []byte { return RESecretHeader.ReplaceAll(dump, []byte("$1: ")) } func DumpRequest(r *http.Request) string { dump, err := httputil.DumpRequest(r, true) if err != nil { log.WithField("Error", err). Warnf("failed to dump HTTP request") return "" } dump = bytes.TrimSpace(dump) dump = HideSecureHeaders(dump) dump = util.IndentBytes(dump, []byte(" > ")) return string(dump) } func DumpResponse(r *http.Response) string { dump, err := httputil.DumpResponse(r, true) if err != nil { log.WithField("Error", err). Warnf("failed to dump HTTP response") return "" } dump = bytes.TrimSpace(dump) dump = util.IndentBytes(dump, []byte(" < ")) return string(dump) } aws-nuke-2.16.0/pkg/awsutil/util_test.go000066400000000000000000000017051411137415400201520ustar00rootroot00000000000000package awsutil_test import ( "fmt" "testing" "github.com/rebuy-de/aws-nuke/pkg/awsutil" ) func TestSecretRegex(t *testing.T) { cases := []struct{ in, out string }{ { in: "GET / HTTP/1.1\nAuthorization: Never gonna give you up\nHost: bish", out: "GET / HTTP/1.1\nAuthorization: \nHost: bish", }, { in: "GET / HTTP/1.1\nX-Amz-Security-Token: Never gonna let you down\nHost: bash", out: "GET / HTTP/1.1\nX-Amz-Security-Token: \nHost: bash", }, { in: "GET / HTTP/1.1\nX-Amz-Security-Token: Never gonna run around and desert you\nAuthorization: Never gonna make you cry", out: "GET / HTTP/1.1\nX-Amz-Security-Token: \nAuthorization: ", }, } for i, tc := range cases { t.Run(fmt.Sprint(i), func(t *testing.T) { want := tc.out have := string(awsutil.HideSecureHeaders([]byte(tc.in))) if want != have { t.Errorf("Assertion failed. Want: %#v. Have: %#v", want, have) } }) } } aws-nuke-2.16.0/pkg/config/000077500000000000000000000000001411137415400153615ustar00rootroot00000000000000aws-nuke-2.16.0/pkg/config/config.go000066400000000000000000000160551411137415400171640ustar00rootroot00000000000000package config import ( "fmt" "io/ioutil" "strings" "github.com/rebuy-de/aws-nuke/pkg/types" log "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" ) type ResourceTypes struct { Targets types.Collection `yaml:"targets"` Excludes types.Collection `yaml:"excludes"` } type Account struct { Filters Filters `yaml:"filters"` ResourceTypes ResourceTypes `yaml:"resource-types"` Presets []string `yaml:"presets"` } type Nuke struct { // Deprecated: Use AccountBlocklist instead. AccountBlacklist []string `yaml:"account-blacklist"` AccountBlocklist []string `yaml:"account-blocklist"` Regions []string `yaml:"regions"` Accounts map[string]Account `yaml:"accounts"` ResourceTypes ResourceTypes `yaml:"resource-types"` Presets map[string]PresetDefinitions `yaml:"presets"` FeatureFlags FeatureFlags `yaml:"feature-flags"` CustomEndpoints CustomEndpoints `yaml:"endpoints"` } type FeatureFlags struct { DisableDeletionProtection DisableDeletionProtection `yaml:"disable-deletion-protection"` ForceDeleteLightsailAddOns bool `yaml:"force-delete-lightsail-addons"` } type DisableDeletionProtection struct { RDSInstance bool `yaml:"RDSInstance"` EC2Instance bool `yaml:"EC2Instance"` CloudformationStack bool `yaml:"CloudformationStack"` } type PresetDefinitions struct { Filters Filters `yaml:"filters"` } type CustomService struct { Service string `yaml:"service"` URL string `yaml:"url"` TLSInsecureSkipVerify bool `yaml:"tls_insecure_skip_verify"` } type CustomServices []*CustomService type CustomRegion struct { Region string `yaml:"region"` Services CustomServices `yaml:"services"` TLSInsecureSkipVerify bool `yaml:"tls_insecure_skip_verify"` } type CustomEndpoints []*CustomRegion func Load(path string) (*Nuke, error) { var err error raw, err := ioutil.ReadFile(path) if err != nil { return nil, err } config := new(Nuke) err = yaml.UnmarshalStrict(raw, config) if err != nil { return nil, err } if err := config.resolveDeprecations(); err != nil { return nil, err } return config, nil } func (c *Nuke) ResolveBlocklist() []string { if c.AccountBlocklist != nil { return c.AccountBlocklist } log.Warn("deprecated configuration key 'account-blacklist' - please use 'account-blocklist' instead") return c.AccountBlacklist } func (c *Nuke) HasBlocklist() bool { var blocklist = c.ResolveBlocklist() return blocklist != nil && len(blocklist) > 0 } func (c *Nuke) InBlocklist(searchID string) bool { for _, blocklistID := range c.ResolveBlocklist() { if blocklistID == searchID { return true } } return false } func (c *Nuke) ValidateAccount(accountID string, aliases []string) error { if !c.HasBlocklist() { return fmt.Errorf("The config file contains an empty blocklist. " + "For safety reasons you need to specify at least one account ID. " + "This should be your production account.") } if c.InBlocklist(accountID) { return fmt.Errorf("You are trying to nuke the account with the ID %s, "+ "but it is blocklisted. Aborting.", accountID) } if len(aliases) == 0 { return fmt.Errorf("The specified account doesn't have an alias. " + "For safety reasons you need to specify an account alias. " + "Your production account should contain the term 'prod'.") } for _, alias := range aliases { if strings.Contains(strings.ToLower(alias), "prod") { return fmt.Errorf("You are trying to nuke an account with the alias '%s', "+ "but it has the substring 'prod' in it. Aborting.", alias) } } if _, ok := c.Accounts[accountID]; !ok { return fmt.Errorf("Your account ID '%s' isn't listed in the config. "+ "Aborting.", accountID) } return nil } func (c *Nuke) Filters(accountID string) (Filters, error) { account := c.Accounts[accountID] filters := account.Filters if filters == nil { filters = Filters{} } if account.Presets == nil { return filters, nil } for _, presetName := range account.Presets { notFound := fmt.Errorf("Could not find filter preset '%s'", presetName) if c.Presets == nil { return nil, notFound } preset, ok := c.Presets[presetName] if !ok { return nil, notFound } filters.Merge(preset.Filters) } return filters, nil } func (c *Nuke) resolveDeprecations() error { deprecations := map[string]string{ "EC2DhcpOptions": "EC2DHCPOptions", "EC2InternetGatewayAttachement": "EC2InternetGatewayAttachment", "EC2NatGateway": "EC2NATGateway", "EC2Vpc": "EC2VPC", "EC2VpcEndpoint": "EC2VPCEndpoint", "EC2VpnConnection": "EC2VPNConnection", "EC2VpnGateway": "EC2VPNGateway", "EC2VpnGatewayAttachement": "EC2VPNGatewayAttachment", "ECRrepository": "ECRRepository", "IamGroup": "IAMGroup", "IamGroupPolicyAttachement": "IAMGroupPolicyAttachment", "IamInstanceProfile": "IAMInstanceProfile", "IamInstanceProfileRole": "IAMInstanceProfileRole", "IamPolicy": "IAMPolicy", "IamRole": "IAMRole", "IamRolePolicyAttachement": "IAMRolePolicyAttachment", "IamServerCertificate": "IAMServerCertificate", "IamUser": "IAMUser", "IamUserAccessKeys": "IAMUserAccessKey", "IamUserGroupAttachement": "IAMUserGroupAttachment", "IamUserPolicyAttachement": "IAMUserPolicyAttachment", "RDSCluster": "RDSDBCluster", } for _, a := range c.Accounts { for resourceType, resources := range a.Filters { replacement, ok := deprecations[resourceType] if !ok { continue } log.Warnf("deprecated resource type '%s' - converting to '%s'\n", resourceType, replacement) if _, ok := a.Filters[replacement]; ok { return fmt.Errorf("using deprecated resource type and replacement: '%s','%s'", resourceType, replacement) } a.Filters[replacement] = resources delete(a.Filters, resourceType) } } return nil } // GetRegion returns the custom region or nil when no such custom endpoints are defined for this region func (endpoints CustomEndpoints) GetRegion(region string) *CustomRegion { for _, r := range endpoints { if r.Region == region { if r.TLSInsecureSkipVerify { for _, s := range r.Services { s.TLSInsecureSkipVerify = r.TLSInsecureSkipVerify } } return r } } return nil } // GetService returns the custom region or nil when no such custom endpoints are defined for this region func (services CustomServices) GetService(serviceType string) *CustomService { for _, s := range services { if serviceType == s.Service { return s } } return nil } func (endpoints CustomEndpoints) GetURL(region, serviceType string) string { r := endpoints.GetRegion(region) if r == nil { return "" } s := r.Services.GetService(serviceType) if s == nil { return "" } return s.URL } aws-nuke-2.16.0/pkg/config/config_test.go000066400000000000000000000164421411137415400202230ustar00rootroot00000000000000package config import ( "fmt" "reflect" "strings" "testing" "github.com/rebuy-de/aws-nuke/pkg/types" ) func TestConfigBlocklist(t *testing.T) { config := new(Nuke) if config.HasBlocklist() { t.Errorf("HasBlocklist() returned true on a nil backlist.") } if config.InBlocklist("blubber") { t.Errorf("InBlocklist() returned true on a nil backlist.") } config.AccountBlocklist = []string{} if config.HasBlocklist() { t.Errorf("HasBlocklist() returned true on a empty backlist.") } if config.InBlocklist("foobar") { t.Errorf("InBlocklist() returned true on a empty backlist.") } config.AccountBlocklist = append(config.AccountBlocklist, "bim") if !config.HasBlocklist() { t.Errorf("HasBlocklist() returned false on a backlist with one element.") } if !config.InBlocklist("bim") { t.Errorf("InBlocklist() returned false on looking up an existing value.") } if config.InBlocklist("baz") { t.Errorf("InBlocklist() returned true on looking up an non existing value.") } } func TestLoadExampleConfig(t *testing.T) { config, err := Load("test-fixtures/example.yaml") if err != nil { t.Fatal(err) } expect := Nuke{ AccountBlocklist: []string{"1234567890"}, Regions: []string{"eu-west-1", "stratoscale"}, Accounts: map[string]Account{ "555133742": Account{ Presets: []string{"terraform"}, Filters: Filters{ "IAMRole": { NewExactFilter("uber.admin"), }, "IAMRolePolicyAttachment": { NewExactFilter("uber.admin -> AdministratorAccess"), }, }, ResourceTypes: ResourceTypes{ types.Collection{"S3Bucket"}, nil, }, }, }, ResourceTypes: ResourceTypes{ Targets: types.Collection{"DynamoDBTable", "S3Bucket", "S3Object"}, Excludes: types.Collection{"IAMRole"}, }, Presets: map[string]PresetDefinitions{ "terraform": PresetDefinitions{ Filters: Filters{ "S3Bucket": { Filter{ Type: FilterTypeGlob, Value: "my-statebucket-*", }, }, }, }, }, CustomEndpoints: []*CustomRegion{ &CustomRegion{ Region: "stratoscale", TLSInsecureSkipVerify: true, Services: CustomServices{ &CustomService{ Service: "ec2", URL: "https://stratoscale.cloud.internal/api/v2/aws/ec2", }, &CustomService{ Service: "s3", URL: "https://stratoscale.cloud.internal:1060", TLSInsecureSkipVerify: true, }, }, }, }, } if !reflect.DeepEqual(*config, expect) { t.Errorf("Read struct mismatches:") t.Errorf(" Got: %#v", *config) t.Errorf(" Expected: %#v", expect) } } func TestResolveDeprecations(t *testing.T) { config := Nuke{ AccountBlocklist: []string{"1234567890"}, Regions: []string{"eu-west-1"}, Accounts: map[string]Account{ "555133742": { Filters: Filters{ "IamRole": { NewExactFilter("uber.admin"), NewExactFilter("foo.bar"), }, "IAMRolePolicyAttachment": { NewExactFilter("uber.admin -> AdministratorAccess"), }, }, }, "2345678901": { Filters: Filters{ "ECRrepository": { NewExactFilter("foo:bar"), NewExactFilter("bar:foo"), }, "IAMRolePolicyAttachment": { NewExactFilter("uber.admin -> AdministratorAccess"), }, }, }, }, } expect := map[string]Account{ "555133742": { Filters: Filters{ "IAMRole": { NewExactFilter("uber.admin"), NewExactFilter("foo.bar"), }, "IAMRolePolicyAttachment": { NewExactFilter("uber.admin -> AdministratorAccess"), }, }, }, "2345678901": { Filters: Filters{ "ECRRepository": { NewExactFilter("foo:bar"), NewExactFilter("bar:foo"), }, "IAMRolePolicyAttachment": { NewExactFilter("uber.admin -> AdministratorAccess"), }, }, }, } err := config.resolveDeprecations() if err != nil { t.Fatal(err) } if !reflect.DeepEqual(config.Accounts, expect) { t.Errorf("Read struct mismatches:") t.Errorf(" Got: %#v", config.Accounts) t.Errorf(" Expected: %#v", expect) } invalidConfig := Nuke{ AccountBlocklist: []string{"1234567890"}, Regions: []string{"eu-west-1"}, Accounts: map[string]Account{ "555133742": { Filters: Filters{ "IamUserAccessKeys": { NewExactFilter("X")}, "IAMUserAccessKey": { NewExactFilter("Y")}, }, }, }, } err = invalidConfig.resolveDeprecations() if err == nil || !strings.Contains(err.Error(), "using deprecated resource type and replacement") { t.Fatal("invalid config did not cause correct error") } } func TestConfigValidation(t *testing.T) { config, err := Load("test-fixtures/example.yaml") if err != nil { t.Fatal(err) } cases := []struct { ID string Aliases []string ShouldFail bool }{ {ID: "555133742", Aliases: []string{"staging"}, ShouldFail: false}, {ID: "1234567890", Aliases: []string{"staging"}, ShouldFail: true}, {ID: "1111111111", Aliases: []string{"staging"}, ShouldFail: true}, {ID: "555133742", Aliases: []string{"production"}, ShouldFail: true}, {ID: "555133742", Aliases: []string{}, ShouldFail: true}, {ID: "555133742", Aliases: []string{"staging", "prod"}, ShouldFail: true}, } for i, tc := range cases { name := fmt.Sprintf("%d_%s/%v/%t", i, tc.ID, tc.Aliases, tc.ShouldFail) t.Run(name, func(t *testing.T) { err := config.ValidateAccount(tc.ID, tc.Aliases) if tc.ShouldFail && err == nil { t.Fatal("Expected an error but didn't get one.") } if !tc.ShouldFail && err != nil { t.Fatalf("Didn't excpect an error, but got one: %v", err) } }) } } func TestDeprecatedConfigKeys(t *testing.T) { config, err := Load("test-fixtures/deprecated-keys-config.yaml") if err != nil { t.Fatal(err) } if !config.InBlocklist("1234567890") { t.Errorf("Loading the config did not resolve the deprecated key 'account-blacklist' correctly") } } func TestFilterMerge(t *testing.T) { config, err := Load("test-fixtures/example.yaml") if err != nil { t.Fatal(err) } filters, err := config.Filters("555133742") if err != nil { t.Fatal(err) } expect := Filters{ "S3Bucket": []Filter{ Filter{ Type: "glob", Value: "my-statebucket-*", }, }, "IAMRole": []Filter{ Filter{ Type: "exact", Value: "uber.admin", }, }, "IAMRolePolicyAttachment": []Filter{ Filter{ Type: "exact", Value: "uber.admin -> AdministratorAccess", }, }, } if !reflect.DeepEqual(filters, expect) { t.Errorf("Read struct mismatches:") t.Errorf(" Got: %#v", filters) t.Errorf(" Expected: %#v", expect) } } func TestGetCustomRegion(t *testing.T) { config, err := Load("test-fixtures/example.yaml") if err != nil { t.Fatal(err) } stratoscale := config.CustomEndpoints.GetRegion("stratoscale") if stratoscale == nil { t.Fatal("Expected to find a set of custom endpoints for region10") } euWest1 := config.CustomEndpoints.GetRegion("eu-west-1") if euWest1 != nil { t.Fatal("Expected to euWest1 without a set of custom endpoints") } t.Run("TestGetService", func(t *testing.T) { ec2Service := stratoscale.Services.GetService("ec2") if ec2Service == nil { t.Fatal("Expected to find a custom ec2 service for region10") } rdsService := stratoscale.Services.GetService("rds") if rdsService != nil { t.Fatal("Expected to not find a custom rds service for region10") } }) } aws-nuke-2.16.0/pkg/config/filter.go000066400000000000000000000046741411137415400172100ustar00rootroot00000000000000package config import ( "fmt" "regexp" "strconv" "strings" "time" "github.com/mb0/glob" ) type FilterType string const ( FilterTypeEmpty FilterType = "" FilterTypeExact = "exact" FilterTypeGlob = "glob" FilterTypeRegex = "regex" FilterTypeContains = "contains" FilterTypeDateOlderThan = "dateOlderThan" ) type Filters map[string][]Filter func (f Filters) Merge(f2 Filters) { for resourceType, filter := range f2 { f[resourceType] = append(f[resourceType], filter...) } } type Filter struct { Property string Type FilterType Value string Invert string } func (f Filter) Match(o string) (bool, error) { switch f.Type { case FilterTypeEmpty: fallthrough case FilterTypeExact: return f.Value == o, nil case FilterTypeContains: return strings.Contains(o, f.Value), nil case FilterTypeGlob: return glob.Match(f.Value, o) case FilterTypeRegex: re, err := regexp.Compile(f.Value) if err != nil { return false, err } return re.MatchString(o), nil case FilterTypeDateOlderThan: if o == "" { return false, nil } duration, err := time.ParseDuration(f.Value) if err != nil { return false, err } fieldTime, err := parseDate(o) if err != nil { return false, err } fieldTimeWithOffset := fieldTime.Add(duration) return fieldTimeWithOffset.After(time.Now()), nil default: return false, fmt.Errorf("unknown type %s", f.Type) } } func parseDate(input string) (time.Time, error) { if i, err := strconv.ParseInt(input, 10, 64); err == nil { t := time.Unix(i, 0) return t, nil } formats := []string{"2006-01-02", "2006/01/02", "2006-01-02T15:04:05Z", time.RFC3339Nano, // Format of t.MarshalText() and t.MarshalJSON() time.RFC3339, } for _, f := range formats { t, err := time.Parse(f, input) if err == nil { return t, nil } } return time.Now(), fmt.Errorf("unable to parse time %s", input) } func (f *Filter) UnmarshalYAML(unmarshal func(interface{}) error) error { var value string if unmarshal(&value) == nil { f.Type = FilterTypeExact f.Value = value return nil } m := map[string]string{} err := unmarshal(m) if err != nil { return err } f.Type = FilterType(m["type"]) f.Value = m["value"] f.Property = m["property"] f.Invert = m["invert"] return nil } func NewExactFilter(value string) Filter { return Filter{ Type: FilterTypeExact, Value: value, } } aws-nuke-2.16.0/pkg/config/filter_test.go000066400000000000000000000045171411137415400202430ustar00rootroot00000000000000package config_test import ( "strconv" "testing" "time" "github.com/rebuy-de/aws-nuke/pkg/config" yaml "gopkg.in/yaml.v2" ) func TestUnmarshalFilter(t *testing.T) { past := time.Now().UTC().Add(-24 * time.Hour) future := time.Now().UTC().Add(24 * time.Hour) cases := []struct { yaml string match, mismatch []string }{ { yaml: `foo`, match: []string{"foo"}, mismatch: []string{"fo", "fooo", "o", "fo"}, }, { yaml: `{"type":"exact","value":"foo"}`, match: []string{"foo"}, mismatch: []string{"fo", "fooo", "o", "fo"}, }, { yaml: `{"type":"glob","value":"b*sh"}`, match: []string{"bish", "bash", "bosh", "bush", "boooooosh", "bsh"}, mismatch: []string{"woooosh", "fooo", "o", "fo"}, }, { yaml: `{"type":"glob","value":"b?sh"}`, match: []string{"bish", "bash", "bosh", "bush"}, mismatch: []string{"woooosh", "fooo", "o", "fo", "boooooosh", "bsh"}, }, { yaml: `{"type":"regex","value":"b[iao]sh"}`, match: []string{"bish", "bash", "bosh"}, mismatch: []string{"woooosh", "fooo", "o", "fo", "boooooosh", "bsh", "bush"}, }, { yaml: `{"type":"contains","value":"mba"}`, match: []string{"bimbaz", "mba", "bi mba z"}, mismatch: []string{"bim-baz"}, }, { yaml: `{"type":"dateOlderThan","value":"0"}`, match: []string{strconv.Itoa(int(future.Unix())), future.Format("2006-01-02"), future.Format("2006/01/02"), future.Format("2006-01-02T15:04:05Z"), future.Format(time.RFC3339Nano), future.Format(time.RFC3339), }, mismatch: []string{"", strconv.Itoa(int(past.Unix())), past.Format("2006-01-02"), past.Format("2006/01/02"), past.Format("2006-01-02T15:04:05Z"), past.Format(time.RFC3339Nano), past.Format(time.RFC3339), }, }, } for _, tc := range cases { t.Run(tc.yaml, func(t *testing.T) { var filter config.Filter err := yaml.Unmarshal([]byte(tc.yaml), &filter) if err != nil { t.Fatal(err) } for _, o := range tc.match { match, err := filter.Match(o) if err != nil { t.Fatal(err) } if !match { t.Fatalf("'%v' should match", o) } } for _, o := range tc.mismatch { match, err := filter.Match(o) if err != nil { t.Fatal(err) } if match { t.Fatalf("'%v' should not match", o) } } }) } } aws-nuke-2.16.0/pkg/config/test-fixtures/000077500000000000000000000000001411137415400202075ustar00rootroot00000000000000aws-nuke-2.16.0/pkg/config/test-fixtures/deprecated-keys-config.yaml000066400000000000000000000000471411137415400254100ustar00rootroot00000000000000--- account-blacklist: - 1234567890aws-nuke-2.16.0/pkg/config/test-fixtures/example.yaml000066400000000000000000000013711411137415400225300ustar00rootroot00000000000000--- regions: - "eu-west-1" - stratoscale account-blocklist: - 1234567890 endpoints: - region: stratoscale tls_insecure_skip_verify: true services: - service: ec2 url: https://stratoscale.cloud.internal/api/v2/aws/ec2 - service: s3 url: https://stratoscale.cloud.internal:1060 tls_insecure_skip_verify: true resource-types: targets: - DynamoDBTable - S3Bucket - S3Object excludes: - IAMRole accounts: 555133742: presets: - "terraform" resource-types: targets: - S3Bucket filters: IAMRole: - "uber.admin" IAMRolePolicyAttachment: - "uber.admin -> AdministratorAccess" presets: terraform: filters: S3Bucket: - type: glob value: "my-statebucket-*" aws-nuke-2.16.0/pkg/types/000077500000000000000000000000001411137415400152605ustar00rootroot00000000000000aws-nuke-2.16.0/pkg/types/collection.go000066400000000000000000000013511411137415400177420ustar00rootroot00000000000000package types type Collection []string func (c Collection) Intersect(o Collection) Collection { mo := o.toMap() result := Collection{} for _, t := range c { if mo[t] { result = append(result, t) } } return result } func (c Collection) Remove(o Collection) Collection { mo := o.toMap() result := Collection{} for _, t := range c { if !mo[t] { result = append(result, t) } } return result } func (c Collection) Union(o Collection) Collection { ms := c.toMap() result := []string(c) for _, oi := range o { if !ms[oi] { result = append(result, oi) } } return Collection(result) } func (c Collection) toMap() map[string]bool { m := map[string]bool{} for _, t := range c { m[t] = true } return m } aws-nuke-2.16.0/pkg/types/collection_test.go000066400000000000000000000016651411137415400210110ustar00rootroot00000000000000package types_test import ( "fmt" "testing" "github.com/rebuy-de/aws-nuke/pkg/types" ) func TestSetInterset(t *testing.T) { s1 := types.Collection{"a", "b", "c"} s2 := types.Collection{"b", "a", "d"} r := s1.Intersect(s2) want := fmt.Sprint([]string{"a", "b"}) have := fmt.Sprint(r) if want != have { t.Errorf("Wrong result. Want: %s. Have: %s", want, have) } } func TestSetRemove(t *testing.T) { s1 := types.Collection{"a", "b", "c"} s2 := types.Collection{"b", "a", "d"} r := s1.Remove(s2) want := fmt.Sprint([]string{"c"}) have := fmt.Sprint(r) if want != have { t.Errorf("Wrong result. Want: %s. Have: %s", want, have) } } func TestSetUnion(t *testing.T) { s1 := types.Collection{"a", "b", "c"} s2 := types.Collection{"b", "a", "d"} r := s1.Union(s2) want := fmt.Sprint([]string{"a", "b", "c", "d"}) have := fmt.Sprint(r) if want != have { t.Errorf("Wrong result. Want: %s. Have: %s", want, have) } } aws-nuke-2.16.0/pkg/types/properties.go000066400000000000000000000035521411137415400200100ustar00rootroot00000000000000package types import ( "fmt" "strings" ) type Properties map[string]string func NewProperties() Properties { return make(Properties) } func (p Properties) String() string { parts := []string{} for k, v := range p { parts = append(parts, fmt.Sprintf(`%s: "%v"`, k, v)) } return fmt.Sprintf("[%s]", strings.Join(parts, ", ")) } func (p Properties) Set(key string, value interface{}) Properties { if value == nil { return p } switch v := value.(type) { case *string: if v == nil { return p } p[key] = *v case []byte: p[key] = string(v) case *bool: if v == nil { return p } p[key] = fmt.Sprint(*v) case *int64: if v == nil { return p } p[key] = fmt.Sprint(*v) case *int: if v == nil { return p } p[key] = fmt.Sprint(*v) default: // Fallback to Stringer interface. This produces gibberish on pointers, // but is the only way to avoid reflection. p[key] = fmt.Sprint(value) } return p } func (p Properties) SetTag(tagKey *string, tagValue interface{}) Properties { return p.SetTagWithPrefix("", tagKey, tagValue) } func (p Properties) SetTagWithPrefix(prefix string, tagKey *string, tagValue interface{}) Properties { if tagKey == nil { return p } keyStr := strings.TrimSpace(*tagKey) prefix = strings.TrimSpace(prefix) if keyStr == "" { return p } if prefix != "" { keyStr = fmt.Sprintf("%s:%s", prefix, keyStr) } keyStr = fmt.Sprintf("tag:%s", keyStr) return p.Set(keyStr, tagValue) } func (p Properties) Get(key string) string { value, ok := p[key] if !ok { return "" } return value } func (p Properties) Equals(o Properties) bool { if p == nil && o == nil { return true } if p == nil || o == nil { return false } if len(p) != len(o) { return false } for k, pv := range p { ov, ok := o[k] if !ok { return false } if pv != ov { return false } } return true } aws-nuke-2.16.0/pkg/types/properties_test.go000066400000000000000000000062621411137415400210500ustar00rootroot00000000000000package types_test import ( "fmt" "testing" "github.com/aws/aws-sdk-go/aws" "github.com/rebuy-de/aws-nuke/pkg/types" ) func TestPropertiesEquals(t *testing.T) { cases := []struct { p1, p2 types.Properties result bool }{ { p1: nil, p2: nil, result: true, }, { p1: nil, p2: types.NewProperties(), result: false, }, { p1: types.NewProperties(), p2: types.NewProperties(), result: true, }, { p1: types.NewProperties().Set("blub", "blubber"), p2: types.NewProperties().Set("blub", "blubber"), result: true, }, { p1: types.NewProperties().Set("blub", "foo"), p2: types.NewProperties().Set("blub", "bar"), result: false, }, { p1: types.NewProperties().Set("bim", "baz").Set("blub", "blubber"), p2: types.NewProperties().Set("bim", "baz").Set("blub", "blubber"), result: true, }, { p1: types.NewProperties().Set("bim", "baz").Set("blub", "foo"), p2: types.NewProperties().Set("bim", "baz").Set("blub", "bar"), result: false, }, } for i, tc := range cases { t.Run(fmt.Sprint(i), func(t *testing.T) { if tc.p1.Equals(tc.p2) != tc.result { t.Errorf("Test Case failed. Want %t. Got %t.", !tc.result, tc.result) t.Errorf("p1: %s", tc.p1.String()) t.Errorf("p2: %s", tc.p2.String()) } else if tc.p2.Equals(tc.p1) != tc.result { t.Errorf("Test Case reverse check failed. Want %t. Got %t.", !tc.result, tc.result) t.Errorf("p1: %s", tc.p1.String()) t.Errorf("p2: %s", tc.p2.String()) } }) } } func TestPropertiesSetTag(t *testing.T) { cases := []struct { name string key *string value interface{} want string }{ { name: "string", key: aws.String("name"), value: "blubber", want: `[tag:name: "blubber"]`, }, { name: "string_ptr", key: aws.String("name"), value: aws.String("blubber"), want: `[tag:name: "blubber"]`, }, { name: "int", key: aws.String("int"), value: 42, want: `[tag:int: "42"]`, }, { name: "nil", key: aws.String("nothing"), value: nil, want: `[]`, }, { name: "empty_key", key: aws.String(""), value: "empty", want: `[]`, }, { name: "nil_key", key: nil, value: "empty", want: `[]`, }, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { p := types.NewProperties() p.SetTag(tc.key, tc.value) have := p.String() if tc.want != have { t.Errorf("'%s' != '%s'", tc.want, have) } }) } } func TestPropertiesSetTagWithPrefix(t *testing.T) { cases := []struct { name string prefix string key *string value interface{} want string }{ { name: "empty", prefix: "", key: aws.String("name"), value: "blubber", want: `[tag:name: "blubber"]`, }, { name: "nonempty", prefix: "bish", key: aws.String("bash"), value: "bosh", want: `[tag:bish:bash: "bosh"]`, }, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { p := types.NewProperties() p.SetTagWithPrefix(tc.prefix, tc.key, tc.value) have := p.String() if tc.want != have { t.Errorf("'%s' != '%s'", tc.want, have) } }) } } aws-nuke-2.16.0/pkg/util/000077500000000000000000000000001411137415400150715ustar00rootroot00000000000000aws-nuke-2.16.0/pkg/util/indent.go000066400000000000000000000005051411137415400167010ustar00rootroot00000000000000package util func Indent(s, prefix string) string { return string(IndentBytes([]byte(s), []byte(prefix))) } func IndentBytes(b, prefix []byte) []byte { var res []byte bol := true for _, c := range b { if bol && c != '\n' { res = append(res, prefix...) } res = append(res, c) bol = c == '\n' } return res } aws-nuke-2.16.0/resources/000077500000000000000000000000001411137415400153455ustar00rootroot00000000000000aws-nuke-2.16.0/resources/accessanalyzer-analyzers.go000066400000000000000000000030131411137415400227060ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/accessanalyzer" "github.com/rebuy-de/aws-nuke/pkg/types" ) type AccessAnalyzer struct { svc *accessanalyzer.AccessAnalyzer arn string name string status string tags map[string]*string } func init() { register("AccessAnalyzer", ListAccessAnalyzer) } func ListAccessAnalyzer(sess *session.Session) ([]Resource, error) { svc := accessanalyzer.New(sess) params := &accessanalyzer.ListAnalyzersInput{ Type: aws.String("ACCOUNT"), } resources := make([]Resource, 0) err := svc.ListAnalyzersPages(params, func(page *accessanalyzer.ListAnalyzersOutput, lastPage bool) bool { for _, analyzer := range page.Analyzers { resources = append(resources, &AccessAnalyzer{ svc: svc, arn: *analyzer.Arn, name: *analyzer.Name, status: *analyzer.Status, tags: analyzer.Tags, }) } return true }) if err != nil { return nil, err } return resources, nil } func (a *AccessAnalyzer) Remove() error { _, err := a.svc.DeleteAnalyzer(&accessanalyzer.DeleteAnalyzerInput{AnalyzerName: &a.name}) return err } func (a *AccessAnalyzer) Properties() types.Properties { properties := types.NewProperties() properties.Set("ARN", a.arn) properties.Set("Name", a.name) properties.Set("Status", a.status) for k, v := range a.tags { properties.SetTag(&k, v) } return properties } func (a *AccessAnalyzer) String() string { return a.name } aws-nuke-2.16.0/resources/accessanalyzer-archiverules.go000066400000000000000000000031321411137415400233740ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/accessanalyzer" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ArchiveRule struct { svc *accessanalyzer.AccessAnalyzer ruleName string analyzerName string } func init() { register("ArchiveRule", ListArchiveRule) } func ListArchiveRule(sess *session.Session) ([]Resource, error) { svc := accessanalyzer.New(sess) analyzers, err := ListAccessAnalyzer(sess) if err != nil { return nil, err } resources := make([]Resource, 0) for _, analyzer := range analyzers { a, ok := analyzer.(*AccessAnalyzer) if !ok { continue } params := &accessanalyzer.ListArchiveRulesInput{ AnalyzerName: &a.name, } err = svc.ListArchiveRulesPages(params, func(page *accessanalyzer.ListArchiveRulesOutput, lastPage bool) bool { for _, archiveRule := range page.ArchiveRules { resources = append(resources, &ArchiveRule{ svc: svc, ruleName: *archiveRule.RuleName, analyzerName: a.name, }) } return true }) if err != nil { return nil, err } } return resources, nil } func (a *ArchiveRule) Remove() error { _, err := a.svc.DeleteArchiveRule(&accessanalyzer.DeleteArchiveRuleInput{ AnalyzerName: &a.analyzerName, RuleName: &a.ruleName, }) return err } func (a *ArchiveRule) Properties() types.Properties { properties := types.NewProperties() properties.Set("RuleName", a.ruleName) properties.Set("AnalyzerName", a.analyzerName) return properties } func (a *ArchiveRule) String() string { return a.ruleName } aws-nuke-2.16.0/resources/acm-certificates.go000066400000000000000000000041201411137415400210740ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/acm" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ACMCertificate struct { svc *acm.ACM certificateARN *string certificateDetail *acm.CertificateDetail tags []*acm.Tag } func init() { register("ACMCertificate", ListACMCertificates) } func ListACMCertificates(sess *session.Session) ([]Resource, error) { svc := acm.New(sess) resources := []Resource{} params := &acm.ListCertificatesInput{ MaxItems: aws.Int64(100), } for { resp, err := svc.ListCertificates(params) if err != nil { return nil, err } for _, certificate := range resp.CertificateSummaryList { // Unfortunately the ACM API doesn't provide the certificate details when listing, so we // have to describe each certificate separately. certificateDescribe, err := svc.DescribeCertificate(&acm.DescribeCertificateInput{ CertificateArn: certificate.CertificateArn, }) if err != nil { return nil, err } tagParams := &acm.ListTagsForCertificateInput{ CertificateArn: certificate.CertificateArn, } tagResp, tagErr := svc.ListTagsForCertificate(tagParams) if tagErr != nil { return nil, tagErr } resources = append(resources, &ACMCertificate{ svc: svc, certificateARN: certificate.CertificateArn, certificateDetail: certificateDescribe.Certificate, tags: tagResp.Tags, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *ACMCertificate) Remove() error { _, err := f.svc.DeleteCertificate(&acm.DeleteCertificateInput{ CertificateArn: f.certificateARN, }) return err } func (f *ACMCertificate) Properties() types.Properties { properties := types.NewProperties() for _, tag := range f.tags { properties.SetTag(tag.Key, tag.Value) } properties.Set("DomainName", f.certificateDetail.DomainName) return properties } func (f *ACMCertificate) String() string { return *f.certificateARN } aws-nuke-2.16.0/resources/acmpca-certificateauthorities.go000066400000000000000000000042301411137415400236600ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/acmpca" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ACMPCACertificateAuthority struct { svc *acmpca.ACMPCA ARN *string status *string tags []*acmpca.Tag } func init() { register("ACMPCACertificateAuthority", ListACMPCACertificateAuthorities) } func ListACMPCACertificateAuthorities(sess *session.Session) ([]Resource, error) { svc := acmpca.New(sess) resources := []Resource{} tags := []*acmpca.Tag{} params := &acmpca.ListCertificateAuthoritiesInput{ MaxResults: aws.Int64(100), } for { resp, err := svc.ListCertificateAuthorities(params) if err != nil { return nil, err } for _, certificateAuthority := range resp.CertificateAuthorities { tagParams := &acmpca.ListTagsInput{ CertificateAuthorityArn: certificateAuthority.Arn, MaxResults: aws.Int64(100), } for { tagResp, tagErr := svc.ListTags(tagParams) if tagErr != nil { return nil, tagErr } tags = append(tags, tagResp.Tags...) if tagResp.NextToken == nil { break } tagParams.NextToken = tagResp.NextToken } resources = append(resources, &ACMPCACertificateAuthority{ svc: svc, ARN: certificateAuthority.Arn, status: certificateAuthority.Status, tags: tags, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *ACMPCACertificateAuthority) Remove() error { _, err := f.svc.DeleteCertificateAuthority(&acmpca.DeleteCertificateAuthorityInput{ CertificateAuthorityArn: f.ARN, }) return err } func (f *ACMPCACertificateAuthority) String() string { return *f.ARN } func (f *ACMPCACertificateAuthority) Filter() error { if *f.status == "DELETED" { return fmt.Errorf("already deleted") } else { return nil } } func (f *ACMPCACertificateAuthority) Properties() types.Properties { properties := types.NewProperties() for _, tag := range f.tags { properties.SetTag(tag.Key, tag.Value) } properties. Set("ARN", f.ARN). Set("Status", f.status) return properties } aws-nuke-2.16.0/resources/acmpca-certificateauthoritystates.go000066400000000000000000000047131411137415400246020ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/acmpca" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ACMPCACertificateAuthorityState struct { svc *acmpca.ACMPCA ARN *string status *string tags []*acmpca.Tag } func init() { register("ACMPCACertificateAuthorityState", ListACMPCACertificateAuthorityStates) } func ListACMPCACertificateAuthorityStates(sess *session.Session) ([]Resource, error) { svc := acmpca.New(sess) resources := []Resource{} tags := []*acmpca.Tag{} params := &acmpca.ListCertificateAuthoritiesInput{ MaxResults: aws.Int64(100), } for { resp, err := svc.ListCertificateAuthorities(params) if err != nil { return nil, err } for _, certificateAuthority := range resp.CertificateAuthorities { tagParams := &acmpca.ListTagsInput{ CertificateAuthorityArn: certificateAuthority.Arn, MaxResults: aws.Int64(100), } for { tagResp, tagErr := svc.ListTags(tagParams) if tagErr != nil { return nil, tagErr } tags = append(tags, tagResp.Tags...) if tagResp.NextToken == nil { break } tagParams.NextToken = tagResp.NextToken } resources = append(resources, &ACMPCACertificateAuthorityState{ svc: svc, ARN: certificateAuthority.Arn, status: certificateAuthority.Status, tags: tags, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *ACMPCACertificateAuthorityState) Remove() error { _, err := f.svc.UpdateCertificateAuthority(&acmpca.UpdateCertificateAuthorityInput{ CertificateAuthorityArn: f.ARN, Status: aws.String("DISABLED"), }) return err } func (f *ACMPCACertificateAuthorityState) String() string { return *f.ARN } func (f *ACMPCACertificateAuthorityState) Filter() error { switch *f.status { case "CREATING": return fmt.Errorf("available for deletion") case "PENDING_CERTIFICATE": return fmt.Errorf("available for deletion") case "DISABLED": return fmt.Errorf("available for deletion") case "DELETED": return fmt.Errorf("already deleted") default: return nil } } func (f *ACMPCACertificateAuthorityState) Properties() types.Properties { properties := types.NewProperties() for _, tag := range f.tags { properties.SetTag(tag.Key, tag.Value) } properties. Set("ARN", f.ARN). Set("Status", f.status) return properties } aws-nuke-2.16.0/resources/apigateway-apikeys.go000066400000000000000000000020331411137415400214700ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/apigateway" ) type APIGatewayAPIKey struct { svc *apigateway.APIGateway APIKey *string } func init() { register("APIGatewayAPIKey", ListAPIGatewayAPIKeys) } func ListAPIGatewayAPIKeys(sess *session.Session) ([]Resource, error) { svc := apigateway.New(sess) resources := []Resource{} params := &apigateway.GetApiKeysInput{ Limit: aws.Int64(100), } for { output, err := svc.GetApiKeys(params) if err != nil { return nil, err } for _, item := range output.Items { resources = append(resources, &APIGatewayAPIKey{ svc: svc, APIKey: item.Id, }) } if output.Position == nil { break } params.Position = output.Position } return resources, nil } func (f *APIGatewayAPIKey) Remove() error { _, err := f.svc.DeleteApiKey(&apigateway.DeleteApiKeyInput{ ApiKey: f.APIKey, }) return err } func (f *APIGatewayAPIKey) String() string { return *f.APIKey } aws-nuke-2.16.0/resources/apigateway-clientcertificates.go000066400000000000000000000024001411137415400236650ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/apigateway" ) type APIGatewayClientCertificate struct { svc *apigateway.APIGateway clientCertificateID *string } func init() { register("APIGatewayClientCertificate", ListAPIGatewayClientCertificates) } func ListAPIGatewayClientCertificates(sess *session.Session) ([]Resource, error) { svc := apigateway.New(sess) resources := []Resource{} params := &apigateway.GetClientCertificatesInput{ Limit: aws.Int64(100), } for { output, err := svc.GetClientCertificates(params) if err != nil { return nil, err } for _, item := range output.Items { resources = append(resources, &APIGatewayClientCertificate{ svc: svc, clientCertificateID: item.ClientCertificateId, }) } if output.Position == nil { break } params.Position = output.Position } return resources, nil } func (f *APIGatewayClientCertificate) Remove() error { _, err := f.svc.DeleteClientCertificate(&apigateway.DeleteClientCertificateInput{ ClientCertificateId: f.clientCertificateID, }) return err } func (f *APIGatewayClientCertificate) String() string { return *f.clientCertificateID } aws-nuke-2.16.0/resources/apigateway-domainnames.go000066400000000000000000000021531411137415400223210ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/apigateway" ) type APIGatewayDomainName struct { svc *apigateway.APIGateway domainName *string } func init() { register("APIGatewayDomainName", ListAPIGatewayDomainNames) } func ListAPIGatewayDomainNames(sess *session.Session) ([]Resource, error) { svc := apigateway.New(sess) resources := []Resource{} params := &apigateway.GetDomainNamesInput{ Limit: aws.Int64(100), } for { output, err := svc.GetDomainNames(params) if err != nil { return nil, err } for _, item := range output.Items { resources = append(resources, &APIGatewayDomainName{ svc: svc, domainName: item.DomainName, }) } if output.Position == nil { break } params.Position = output.Position } return resources, nil } func (f *APIGatewayDomainName) Remove() error { _, err := f.svc.DeleteDomainName(&apigateway.DeleteDomainNameInput{ DomainName: f.domainName, }) return err } func (f *APIGatewayDomainName) String() string { return *f.domainName } aws-nuke-2.16.0/resources/apigateway-restapis.go000066400000000000000000000030201411137415400216520ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/apigateway" "github.com/rebuy-de/aws-nuke/pkg/types" ) type APIGatewayRestAPI struct { svc *apigateway.APIGateway restAPIID *string name *string version *string tags map[string]*string } func init() { register("APIGatewayRestAPI", ListAPIGatewayRestApis) } func ListAPIGatewayRestApis(sess *session.Session) ([]Resource, error) { svc := apigateway.New(sess) resources := []Resource{} params := &apigateway.GetRestApisInput{ Limit: aws.Int64(100), } for { output, err := svc.GetRestApis(params) if err != nil { return nil, err } for _, item := range output.Items { resources = append(resources, &APIGatewayRestAPI{ svc: svc, restAPIID: item.Id, name: item.Name, version: item.Version, tags: item.Tags, }) } if output.Position == nil { break } params.Position = output.Position } return resources, nil } func (f *APIGatewayRestAPI) Remove() error { _, err := f.svc.DeleteRestApi(&apigateway.DeleteRestApiInput{ RestApiId: f.restAPIID, }) return err } func (f *APIGatewayRestAPI) String() string { return *f.restAPIID } func (f *APIGatewayRestAPI) Properties() types.Properties { properties := types.NewProperties() for key, tag := range f.tags { properties.SetTag(&key, tag) } properties. Set("APIID", f.restAPIID). Set("Name", f.name). Set("Version", f.version) return properties } aws-nuke-2.16.0/resources/apigateway-usageplans.go000066400000000000000000000021371411137415400221720ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/apigateway" ) type APIGatewayUsagePlan struct { svc *apigateway.APIGateway usagePlanID *string } func init() { register("APIGatewayUsagePlan", ListAPIGatewayUsagePlans) } func ListAPIGatewayUsagePlans(sess *session.Session) ([]Resource, error) { svc := apigateway.New(sess) resources := []Resource{} params := &apigateway.GetUsagePlansInput{ Limit: aws.Int64(100), } for { output, err := svc.GetUsagePlans(params) if err != nil { return nil, err } for _, item := range output.Items { resources = append(resources, &APIGatewayUsagePlan{ svc: svc, usagePlanID: item.Id, }) } if output.Position == nil { break } params.Position = output.Position } return resources, nil } func (f *APIGatewayUsagePlan) Remove() error { _, err := f.svc.DeleteUsagePlan(&apigateway.DeleteUsagePlanInput{ UsagePlanId: f.usagePlanID, }) return err } func (f *APIGatewayUsagePlan) String() string { return *f.usagePlanID } aws-nuke-2.16.0/resources/apigateway-vpclinks.go000066400000000000000000000027071411137415400216640ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/apigateway" "github.com/rebuy-de/aws-nuke/pkg/types" ) type APIGatewayVpcLink struct { svc *apigateway.APIGateway vpcLinkID *string name *string tags map[string]*string } func init() { register("APIGatewayVpcLink", ListAPIGatewayVpcLinks) } func ListAPIGatewayVpcLinks(sess *session.Session) ([]Resource, error) { svc := apigateway.New(sess) resources := []Resource{} params := &apigateway.GetVpcLinksInput{ Limit: aws.Int64(100), } for { output, err := svc.GetVpcLinks(params) if err != nil { return nil, err } for _, item := range output.Items { resources = append(resources, &APIGatewayVpcLink{ svc: svc, vpcLinkID: item.Id, name: item.Name, tags: item.Tags, }) } if output.Position == nil { break } params.Position = output.Position } return resources, nil } func (f *APIGatewayVpcLink) Remove() error { _, err := f.svc.DeleteVpcLink(&apigateway.DeleteVpcLinkInput{ VpcLinkId: f.vpcLinkID, }) return err } func (f *APIGatewayVpcLink) String() string { return *f.vpcLinkID } func (f *APIGatewayVpcLink) Properties() types.Properties { properties := types.NewProperties() for key, tag := range f.tags { properties.SetTag(&key, tag) } properties. Set("VPCLinkID", f.vpcLinkID). Set("Name", f.name) return properties } aws-nuke-2.16.0/resources/apigatewayv2-apis.go000066400000000000000000000032001411137415400212240ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/apigatewayv2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type APIGatewayV2API struct { svc *apigatewayv2.ApiGatewayV2 v2APIID *string name *string protocolType *string version *string tags map[string]*string } func init() { register("APIGatewayV2API", ListAPIGatewayV2APIs) } func ListAPIGatewayV2APIs(sess *session.Session) ([]Resource, error) { svc := apigatewayv2.New(sess) resources := []Resource{} params := &apigatewayv2.GetApisInput{ MaxResults: aws.String("100"), } for { output, err := svc.GetApis(params) if err != nil { return nil, err } for _, item := range output.Items { resources = append(resources, &APIGatewayV2API{ svc: svc, v2APIID: item.ApiId, name: item.Name, protocolType: item.ProtocolType, version: item.Version, tags: item.Tags, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *APIGatewayV2API) Remove() error { _, err := f.svc.DeleteApi(&apigatewayv2.DeleteApiInput{ ApiId: f.v2APIID, }) return err } func (f *APIGatewayV2API) String() string { return *f.v2APIID } func (f *APIGatewayV2API) Properties() types.Properties { properties := types.NewProperties() for key, tag := range f.tags { properties.SetTag(&key, tag) } properties. Set("APIID", f.v2APIID). Set("Name", f.name). Set("ProtocolType", f.protocolType). Set("Version", f.version) return properties } aws-nuke-2.16.0/resources/apigatewayv2-vpclinks.go000066400000000000000000000027651411137415400221400ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/apigatewayv2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type APIGatewayV2VpcLink struct { svc *apigatewayv2.ApiGatewayV2 vpcLinkID *string name *string tags map[string]*string } func init() { register("APIGatewayV2VpcLink", ListAPIGatewayV2VpcLinks) } func ListAPIGatewayV2VpcLinks(sess *session.Session) ([]Resource, error) { svc := apigatewayv2.New(sess) resources := []Resource{} params := &apigatewayv2.GetVpcLinksInput{ MaxResults: aws.String("100"), } for { output, err := svc.GetVpcLinks(params) if err != nil { return nil, err } for _, item := range output.Items { resources = append(resources, &APIGatewayV2VpcLink{ svc: svc, vpcLinkID: item.VpcLinkId, name: item.Name, tags: item.Tags, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *APIGatewayV2VpcLink) Remove() error { _, err := f.svc.DeleteVpcLink(&apigatewayv2.DeleteVpcLinkInput{ VpcLinkId: f.vpcLinkID, }) return err } func (f *APIGatewayV2VpcLink) String() string { return *f.vpcLinkID } func (f *APIGatewayV2VpcLink) Properties() types.Properties { properties := types.NewProperties() for key, tag := range f.tags { properties.SetTag(&key, tag) } properties. Set("VPCLinkID", f.vpcLinkID). Set("Name", f.name) return properties } aws-nuke-2.16.0/resources/applicationautoscalingscalabletargets.go000066400000000000000000000037341411137415400255210ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/applicationautoscaling" "github.com/rebuy-de/aws-nuke/pkg/types" ) type AppAutoScaling struct { svc *applicationautoscaling.ApplicationAutoScaling target *applicationautoscaling.ScalableTarget id string roleARN string dimension string namespace string } func init() { register("ApplicationAutoScalingScalableTarget", ListApplicationAutoScalingScalableTargets) } func ListApplicationAutoScalingScalableTargets(sess *session.Session) ([]Resource, error) { svc := applicationautoscaling.New(sess) namespaces := applicationautoscaling.ServiceNamespace_Values() params := &applicationautoscaling.DescribeScalableTargetsInput{} resources := make([]Resource, 0) for _, namespace := range namespaces { for { params.ServiceNamespace = &namespace resp, err := svc.DescribeScalableTargets(params) if err != nil { return nil, err } for _, out := range resp.ScalableTargets { resources = append(resources, &AppAutoScaling{ svc: svc, target: out, id: *out.ResourceId, roleARN: *out.RoleARN, dimension: *out.ScalableDimension, namespace: *out.ServiceNamespace, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } } return resources, nil } func (a *AppAutoScaling) Remove() error { _, err := a.svc.DeregisterScalableTarget(&applicationautoscaling.DeregisterScalableTargetInput{ ResourceId: &a.id, ScalableDimension: &a.dimension, ServiceNamespace: &a.namespace, }) if err != nil { return err } return nil } func (a *AppAutoScaling) Properties() types.Properties { properties := types.NewProperties() properties.Set("ResourceID", a.id) properties.Set("ScalableDimension", a.dimension) properties.Set("ServiceNamespace", a.namespace) return properties } func (a *AppAutoScaling) String() string { return a.id + ": " + a.dimension } aws-nuke-2.16.0/resources/appmesh-mesh.go000066400000000000000000000022031411137415400202600ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/appmesh" "github.com/rebuy-de/aws-nuke/pkg/types" ) type AppMeshMesh struct { svc *appmesh.AppMesh meshName *string } func init() { register("AppMeshMesh", ListAppMeshMeshes) } func ListAppMeshMeshes(sess *session.Session) ([]Resource, error) { svc := appmesh.New(sess) resources := []Resource{} params := &appmesh.ListMeshesInput{ Limit: aws.Int64(100), } for { output, err := svc.ListMeshes(params) if err != nil { return nil, err } for _, item := range output.Meshes { resources = append(resources, &AppMeshMesh{ svc: svc, meshName: item.MeshName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *AppMeshMesh) Remove() error { _, err := f.svc.DeleteMesh(&appmesh.DeleteMeshInput{ MeshName: f.meshName, }) return err } func (f *AppMeshMesh) Properties() types.Properties { properties := types.NewProperties() properties. Set("MeshName", f.meshName) return properties } aws-nuke-2.16.0/resources/appmesh-route.go000066400000000000000000000045711411137415400204740ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/appmesh" "github.com/rebuy-de/aws-nuke/pkg/types" ) type AppMeshRoute struct { svc *appmesh.AppMesh routeName *string meshName *string virtualRouterName *string } func init() { register("AppMeshRoute", ListAppMeshRoutes) } func ListAppMeshRoutes(sess *session.Session) ([]Resource, error) { svc := appmesh.New(sess) resources := []Resource{} // Get Meshes var meshNames []*string err := svc.ListMeshesPages( &appmesh.ListMeshesInput{}, func(page *appmesh.ListMeshesOutput, lastPage bool) bool { for _, mesh := range page.Meshes { meshNames = append(meshNames, mesh.MeshName) } return true }, ) if err != nil { return nil, err } // Get VirtualRouters per mesh var virtualRouters []*appmesh.VirtualRouterRef for _, meshName := range meshNames { err = svc.ListVirtualRoutersPages( &appmesh.ListVirtualRoutersInput{ MeshName: meshName, }, func(page *appmesh.ListVirtualRoutersOutput, lastPage bool) bool { for _, vr := range page.VirtualRouters { virtualRouters = append(virtualRouters, vr) } return lastPage }, ) if err != nil { return nil, err } } // List Routes per Mesh var routes []*appmesh.RouteRef for _, vr := range virtualRouters { err := svc.ListRoutesPages( &appmesh.ListRoutesInput{ MeshName: vr.MeshName, VirtualRouterName: vr.VirtualRouterName, }, func(page *appmesh.ListRoutesOutput, lastPage bool) bool { routes = append(routes, page.Routes...) return lastPage }, ) if err != nil { return nil, err } } // Create the resources for _, r := range routes { resources = append(resources, &AppMeshRoute{ svc: svc, routeName: r.RouteName, meshName: r.MeshName, virtualRouterName: r.VirtualRouterName, }) } return resources, nil } func (f *AppMeshRoute) Remove() error { _, err := f.svc.DeleteRoute(&appmesh.DeleteRouteInput{ MeshName: f.meshName, RouteName: f.routeName, VirtualRouterName: f.virtualRouterName, }) return err } func (f *AppMeshRoute) Properties() types.Properties { properties := types.NewProperties() properties. Set("MeshName", f.meshName). Set("VirtualRouterName", f.virtualRouterName). Set("Name", f.routeName) return properties } aws-nuke-2.16.0/resources/appmesh-virtualgateway.go000066400000000000000000000036151411137415400224040ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/appmesh" "github.com/rebuy-de/aws-nuke/pkg/types" ) type AppMeshVirtualGateway struct { svc *appmesh.AppMesh meshName *string virtualGatewayName *string } func init() { register("AppMeshVirtualGateway", ListAppMeshVirtualGateways) } func ListAppMeshVirtualGateways(sess *session.Session) ([]Resource, error) { svc := appmesh.New(sess) resources := []Resource{} // Get Meshes var meshNames []*string err := svc.ListMeshesPages( &appmesh.ListMeshesInput{}, func(page *appmesh.ListMeshesOutput, lastPage bool) bool { for _, mesh := range page.Meshes { meshNames = append(meshNames, mesh.MeshName) } return true }, ) if err != nil { return nil, err } // List VirtualGateways per Mesh var vgs []*appmesh.VirtualGatewayRef for _, meshName := range meshNames { err = svc.ListVirtualGatewaysPages( &appmesh.ListVirtualGatewaysInput{ MeshName: meshName, }, func(page *appmesh.ListVirtualGatewaysOutput, lastPage bool) bool { for _, vg := range page.VirtualGateways { vgs = append(vgs, vg) } return lastPage }, ) if err != nil { return nil, err } } // Create the resources for _, vg := range vgs { resources = append(resources, &AppMeshVirtualGateway{ svc: svc, meshName: vg.MeshName, virtualGatewayName: vg.VirtualGatewayName, }) } return resources, nil } func (f *AppMeshVirtualGateway) Remove() error { _, err := f.svc.DeleteVirtualGateway(&appmesh.DeleteVirtualGatewayInput{ MeshName: f.meshName, VirtualGatewayName: f.virtualGatewayName, }) return err } func (f *AppMeshVirtualGateway) Properties() types.Properties { properties := types.NewProperties() properties. Set("MeshName", f.meshName). Set("Name", f.virtualGatewayName) return properties } aws-nuke-2.16.0/resources/appmesh-virtualnode.go000066400000000000000000000034771411137415400216760ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/appmesh" "github.com/rebuy-de/aws-nuke/pkg/types" ) type AppMeshVirtualNode struct { svc *appmesh.AppMesh meshName *string virtualNodeName *string } func init() { register("AppMeshVirtualNode", ListAppMeshVirtualNodes) } func ListAppMeshVirtualNodes(sess *session.Session) ([]Resource, error) { svc := appmesh.New(sess) resources := []Resource{} // Get Meshes var meshNames []*string err := svc.ListMeshesPages( &appmesh.ListMeshesInput{}, func(page *appmesh.ListMeshesOutput, lastPage bool) bool { for _, mesh := range page.Meshes { meshNames = append(meshNames, mesh.MeshName) } return true }, ) if err != nil { return nil, err } // List VirtualNodes per Mesh var vns []*appmesh.VirtualNodeRef for _, meshName := range meshNames { err = svc.ListVirtualNodesPages( &appmesh.ListVirtualNodesInput{ MeshName: meshName, }, func(page *appmesh.ListVirtualNodesOutput, lastPage bool) bool { for _, vn := range page.VirtualNodes { vns = append(vns, vn) } return lastPage }, ) if err != nil { return nil, err } } // Create the resources for _, vn := range vns { resources = append(resources, &AppMeshVirtualNode{ svc: svc, meshName: vn.MeshName, virtualNodeName: vn.VirtualNodeName, }) } return resources, nil } func (f *AppMeshVirtualNode) Remove() error { _, err := f.svc.DeleteVirtualNode(&appmesh.DeleteVirtualNodeInput{ MeshName: f.meshName, VirtualNodeName: f.virtualNodeName, }) return err } func (f *AppMeshVirtualNode) Properties() types.Properties { properties := types.NewProperties() properties. Set("MeshName", f.meshName). Set("Name", f.virtualNodeName) return properties } aws-nuke-2.16.0/resources/appmesh-virtualrouter.go000066400000000000000000000035631411137415400222650ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/appmesh" "github.com/rebuy-de/aws-nuke/pkg/types" ) type AppMeshVirtualRouter struct { svc *appmesh.AppMesh meshName *string virtualRouterName *string } func init() { register("AppMeshVirtualRouter", ListAppMeshVirtualRouters) } func ListAppMeshVirtualRouters(sess *session.Session) ([]Resource, error) { svc := appmesh.New(sess) resources := []Resource{} // Get Meshes var meshNames []*string err := svc.ListMeshesPages( &appmesh.ListMeshesInput{}, func(page *appmesh.ListMeshesOutput, lastPage bool) bool { for _, mesh := range page.Meshes { meshNames = append(meshNames, mesh.MeshName) } return true }, ) if err != nil { return nil, err } // List VirtualRouters per Mesh var vrs []*appmesh.VirtualRouterRef for _, meshName := range meshNames { err = svc.ListVirtualRoutersPages( &appmesh.ListVirtualRoutersInput{ MeshName: meshName, }, func(page *appmesh.ListVirtualRoutersOutput, lastPage bool) bool { for _, vr := range page.VirtualRouters { vrs = append(vrs, vr) } return lastPage }, ) if err != nil { return nil, err } } // Create the resources for _, vr := range vrs { resources = append(resources, &AppMeshVirtualRouter{ svc: svc, meshName: vr.MeshName, virtualRouterName: vr.VirtualRouterName, }) } return resources, nil } func (f *AppMeshVirtualRouter) Remove() error { _, err := f.svc.DeleteVirtualRouter(&appmesh.DeleteVirtualRouterInput{ MeshName: f.meshName, VirtualRouterName: f.virtualRouterName, }) return err } func (f *AppMeshVirtualRouter) Properties() types.Properties { properties := types.NewProperties() properties. Set("MeshName", f.meshName). Set("Name", f.virtualRouterName) return properties } aws-nuke-2.16.0/resources/appmesh-virtualservice.go000066400000000000000000000036151411137415400224030ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/appmesh" "github.com/rebuy-de/aws-nuke/pkg/types" ) type AppMeshVirtualService struct { svc *appmesh.AppMesh meshName *string virtualServiceName *string } func init() { register("AppMeshVirtualService", ListAppMeshVirtualServices) } func ListAppMeshVirtualServices(sess *session.Session) ([]Resource, error) { svc := appmesh.New(sess) resources := []Resource{} // Get Meshes var meshNames []*string err := svc.ListMeshesPages( &appmesh.ListMeshesInput{}, func(page *appmesh.ListMeshesOutput, lastPage bool) bool { for _, mesh := range page.Meshes { meshNames = append(meshNames, mesh.MeshName) } return true }, ) if err != nil { return nil, err } // List VirtualServices per Mesh var vss []*appmesh.VirtualServiceRef for _, meshName := range meshNames { err = svc.ListVirtualServicesPages( &appmesh.ListVirtualServicesInput{ MeshName: meshName, }, func(page *appmesh.ListVirtualServicesOutput, lastPage bool) bool { for _, vs := range page.VirtualServices { vss = append(vss, vs) } return lastPage }, ) if err != nil { return nil, err } } // Create the resources for _, vs := range vss { resources = append(resources, &AppMeshVirtualService{ svc: svc, meshName: vs.MeshName, virtualServiceName: vs.VirtualServiceName, }) } return resources, nil } func (f *AppMeshVirtualService) Remove() error { _, err := f.svc.DeleteVirtualService(&appmesh.DeleteVirtualServiceInput{ MeshName: f.meshName, VirtualServiceName: f.virtualServiceName, }) return err } func (f *AppMeshVirtualService) Properties() types.Properties { properties := types.NewProperties() properties. Set("MeshName", f.meshName). Set("Name", f.virtualServiceName) return properties } aws-nuke-2.16.0/resources/appstream-directoryconfigs.go000066400000000000000000000022521411137415400232440ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/appstream" ) type AppStreamDirectoryConfig struct { svc *appstream.AppStream name *string } func init() { register("AppStreamDirectoryConfig", ListAppStreamDirectoryConfigs) } func ListAppStreamDirectoryConfigs(sess *session.Session) ([]Resource, error) { svc := appstream.New(sess) resources := []Resource{} params := &appstream.DescribeDirectoryConfigsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.DescribeDirectoryConfigs(params) if err != nil { return nil, err } for _, directoryConfig := range output.DirectoryConfigs { resources = append(resources, &AppStreamDirectoryConfig{ svc: svc, name: directoryConfig.DirectoryName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *AppStreamDirectoryConfig) Remove() error { _, err := f.svc.DeleteDirectoryConfig(&appstream.DeleteDirectoryConfigInput{ DirectoryName: f.name, }) return err } func (f *AppStreamDirectoryConfig) String() string { return *f.name } aws-nuke-2.16.0/resources/appstream-fleets.go000066400000000000000000000020671411137415400211550ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/appstream" ) type AppStreamFleet struct { svc *appstream.AppStream name *string } func init() { register("AppStreamFleet", ListAppStreamFleets) } func ListAppStreamFleets(sess *session.Session) ([]Resource, error) { svc := appstream.New(sess) resources := []Resource{} params := &appstream.DescribeFleetsInput{} for { output, err := svc.DescribeFleets(params) if err != nil { return nil, err } for _, fleet := range output.Fleets { resources = append(resources, &AppStreamFleet{ svc: svc, name: fleet.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *AppStreamFleet) Remove() error { _, err := f.svc.StopFleet(&appstream.StopFleetInput{ Name: f.name, }) if err != nil { return err } _, err = f.svc.DeleteFleet(&appstream.DeleteFleetInput{ Name: f.name, }) return err } func (f *AppStreamFleet) String() string { return *f.name } aws-nuke-2.16.0/resources/appstream-fleetstates.go000066400000000000000000000023631411137415400222150ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/appstream" ) type AppStreamFleetState struct { svc *appstream.AppStream name *string state *string } func init() { register("AppStreamFleetState", ListAppStreamFleetStates) } func ListAppStreamFleetStates(sess *session.Session) ([]Resource, error) { svc := appstream.New(sess) resources := []Resource{} params := &appstream.DescribeFleetsInput{} for { output, err := svc.DescribeFleets(params) if err != nil { return nil, err } for _, fleet := range output.Fleets { resources = append(resources, &AppStreamFleetState{ svc: svc, name: fleet.Name, state: fleet.State, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *AppStreamFleetState) Remove() error { _, err := f.svc.StopFleet(&appstream.StopFleetInput{ Name: f.name, }) return err } func (f *AppStreamFleetState) String() string { return *f.name } func (f *AppStreamFleetState) Filter() error { if *f.state == "STOPPED" { return fmt.Errorf("already stopped") } else if *f.state == "DELETING" { return fmt.Errorf("already being deleted") } return nil } aws-nuke-2.16.0/resources/appstream-imagebuilders.go000066400000000000000000000021561411137415400225060ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/appstream" ) type AppStreamImageBuilder struct { svc *appstream.AppStream name *string } func init() { register("AppStreamImageBuilder", ListAppStreamImageBuilders) } func ListAppStreamImageBuilders(sess *session.Session) ([]Resource, error) { svc := appstream.New(sess) resources := []Resource{} params := &appstream.DescribeImageBuildersInput{ MaxResults: aws.Int64(100), } for { output, err := svc.DescribeImageBuilders(params) if err != nil { return nil, err } for _, imageBuilder := range output.ImageBuilders { resources = append(resources, &AppStreamImageBuilder{ svc: svc, name: imageBuilder.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *AppStreamImageBuilder) Remove() error { _, err := f.svc.DeleteImageBuilder(&appstream.DeleteImageBuilderInput{ Name: f.name, }) return err } func (f *AppStreamImageBuilder) String() string { return *f.name } aws-nuke-2.16.0/resources/appstream-imagebuilderwaiters.go000066400000000000000000000026351411137415400237240ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/appstream" ) type AppStreamImageBuilderWaiter struct { svc *appstream.AppStream name *string state *string } func init() { register("AppStreamImageBuilderWaiter", ListAppStreamImageBuilderWaiters) } func ListAppStreamImageBuilderWaiters(sess *session.Session) ([]Resource, error) { svc := appstream.New(sess) resources := []Resource{} params := &appstream.DescribeImageBuildersInput{ MaxResults: aws.Int64(100), } for { output, err := svc.DescribeImageBuilders(params) if err != nil { return nil, err } for _, imageBuilder := range output.ImageBuilders { resources = append(resources, &AppStreamImageBuilderWaiter{ svc: svc, name: imageBuilder.Name, state: imageBuilder.State, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *AppStreamImageBuilderWaiter) Remove() error { return nil } func (f *AppStreamImageBuilderWaiter) String() string { return *f.name } func (f *AppStreamImageBuilderWaiter) Filter() error { if *f.state == "STOPPED" { return fmt.Errorf("already stopped") } else if *f.state == "RUNNING" { return fmt.Errorf("already running") } else if *f.state == "DELETING" { return fmt.Errorf("already being deleted") } return nil } aws-nuke-2.16.0/resources/appstream-images.go000066400000000000000000000021471411137415400211370ustar00rootroot00000000000000package resources import ( "fmt" "strings" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/appstream" ) type AppStreamImage struct { svc *appstream.AppStream name *string visibility *string } func init() { register("AppStreamImage", ListAppStreamImages) } func ListAppStreamImages(sess *session.Session) ([]Resource, error) { svc := appstream.New(sess) resources := []Resource{} params := &appstream.DescribeImagesInput{} output, err := svc.DescribeImages(params) if err != nil { return nil, err } for _, image := range output.Images { resources = append(resources, &AppStreamImage{ svc: svc, name: image.Name, visibility: image.Visibility, }) } return resources, nil } func (f *AppStreamImage) Remove() error { _, err := f.svc.DeleteImage(&appstream.DeleteImageInput{ Name: f.name, }) return err } func (f *AppStreamImage) String() string { return *f.name } func (f *AppStreamImage) Filter() error { if strings.ToUpper(*f.visibility) == "PUBLIC" { return fmt.Errorf("cannot delete public AWS images") } return nil } aws-nuke-2.16.0/resources/appstream-stack-fleet-attachments.go000066400000000000000000000030601411137415400244000ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/appstream" ) type AppStreamStackFleetAttachment struct { svc *appstream.AppStream stackName *string fleetName *string } func init() { register("AppStreamStackFleetAttachment", ListAppStreamStackFleetAttachments) } func ListAppStreamStackFleetAttachments(sess *session.Session) ([]Resource, error) { svc := appstream.New(sess) resources := []Resource{} stacks := []*appstream.Stack{} params := &appstream.DescribeStacksInput{} for { output, err := svc.DescribeStacks(params) if err != nil { return nil, err } for _, stack := range output.Stacks { stacks = append(stacks, stack) } if output.NextToken == nil { break } params.NextToken = output.NextToken } stackAssocParams := &appstream.ListAssociatedFleetsInput{} for _, stack := range stacks { stackAssocParams.StackName = stack.Name output, err := svc.ListAssociatedFleets(stackAssocParams) if err != nil { return nil, err } for _, name := range output.Names { resources = append(resources, &AppStreamStackFleetAttachment{ svc: svc, stackName: stack.Name, fleetName: name, }) } } return resources, nil } func (f *AppStreamStackFleetAttachment) Remove() error { _, err := f.svc.DisassociateFleet(&appstream.DisassociateFleetInput{ StackName: f.stackName, FleetName: f.fleetName, }) return err } func (f *AppStreamStackFleetAttachment) String() string { return fmt.Sprintf("%s -> %s", *f.stackName, *f.fleetName) } aws-nuke-2.16.0/resources/appstream-stacks.go000066400000000000000000000017131411137415400211600ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/appstream" ) type AppStreamStack struct { svc *appstream.AppStream name *string } func init() { register("AppStreamStack", ListAppStreamStacks) } func ListAppStreamStacks(sess *session.Session) ([]Resource, error) { svc := appstream.New(sess) resources := []Resource{} params := &appstream.DescribeStacksInput{} for { output, err := svc.DescribeStacks(params) if err != nil { return nil, err } for _, stack := range output.Stacks { resources = append(resources, &AppStreamStack{ svc: svc, name: stack.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *AppStreamStack) Remove() error { _, err := f.svc.DeleteStack(&appstream.DeleteStackInput{ Name: f.name, }) return err } func (f *AppStreamStack) String() string { return *f.name } aws-nuke-2.16.0/resources/appsync-graphqlapis.go000066400000000000000000000032601411137415400216630ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/appsync" "github.com/rebuy-de/aws-nuke/pkg/types" ) // AppSyncGraphqlAPI - An AWS AppSync GraphQL API type AppSyncGraphqlAPI struct { svc *appsync.AppSync apiID *string name *string tags map[string]*string } func init() { register("AppSyncGraphqlAPI", ListAppSyncGraphqlAPIs) } // ListAppSyncGraphqlAPIs - List all AWS AppSync GraphQL APIs in the account func ListAppSyncGraphqlAPIs(sess *session.Session) ([]Resource, error) { svc := appsync.New(sess) resources := []Resource{} params := &appsync.ListGraphqlApisInput{ MaxResults: aws.Int64(25), } for { resp, err := svc.ListGraphqlApis(params) if err != nil { return nil, err } for _, graphqlAPI := range resp.GraphqlApis { resources = append(resources, &AppSyncGraphqlAPI{ svc: svc, apiID: graphqlAPI.ApiId, name: graphqlAPI.Name, tags: graphqlAPI.Tags, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } // Remove - remove an AWS AppSync GraphQL API func (f *AppSyncGraphqlAPI) Remove() error { _, err := f.svc.DeleteGraphqlApi(&appsync.DeleteGraphqlApiInput{ ApiId: f.apiID, }) return err } // Properties - Get the properties of an AWS AppSync GraphQL API func (f *AppSyncGraphqlAPI) Properties() types.Properties { properties := types.NewProperties() for key, value := range f.tags { properties.SetTag(aws.String(key), value) } properties.Set("Name", f.name) properties.Set("APIID", f.apiID) return properties } func (f *AppSyncGraphqlAPI) String() string { return *f.apiID } aws-nuke-2.16.0/resources/athena-named-queries.go000066400000000000000000000032351411137415400216740ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/athena" "github.com/rebuy-de/aws-nuke/pkg/types" ) func init() { register("AthenaNamedQuery", ListAthenaNamedQueries) } type AthenaNamedQuery struct { svc *athena.Athena id *string } func ListAthenaNamedQueries(sess *session.Session) ([]Resource, error) { svc := athena.New(sess) resources := []Resource{} // List WorkGroup var workgroupNames []*string err := svc.ListWorkGroupsPages( &athena.ListWorkGroupsInput{}, func(page *athena.ListWorkGroupsOutput, lastPage bool) bool { for _, workgroup := range page.WorkGroups { workgroupNames = append(workgroupNames, workgroup.Name) } return true }, ) if err != nil { return nil, err } // List NamedQueries or each WorkGroup var namedQueryIDs []*string for _, wgName := range workgroupNames { err := svc.ListNamedQueriesPages( &athena.ListNamedQueriesInput{WorkGroup: wgName}, func(page *athena.ListNamedQueriesOutput, lastPage bool) bool { namedQueryIDs = append(namedQueryIDs, page.NamedQueryIds...) return true }, ) if err != nil { return nil, err } } // Create AthenaNamedQuery resource objects for _, id := range namedQueryIDs { resources = append(resources, &AthenaNamedQuery{ svc: svc, id: id, }) } return resources, err } func (a *AthenaNamedQuery) Remove() error { _, err := a.svc.DeleteNamedQuery(&athena.DeleteNamedQueryInput{ NamedQueryId: a.id, }) return err } func (a *AthenaNamedQuery) Properties() types.Properties { return types.NewProperties(). Set("Id", *a.id) } func (a *AthenaNamedQuery) String() string { return *a.id } aws-nuke-2.16.0/resources/athena-work-groups.go000066400000000000000000000105031411137415400214300ustar00rootroot00000000000000package resources import ( "errors" "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/athena" "github.com/aws/aws-sdk-go/service/sts" "github.com/rebuy-de/aws-nuke/pkg/types" "github.com/sirupsen/logrus" ) func init() { register("AthenaWorkGroup", ListAthenaWorkGroups) } type AthenaWorkGroup struct { svc *athena.Athena name *string arn *string } func ListAthenaWorkGroups(sess *session.Session) ([]Resource, error) { svc := athena.New(sess) resources := []Resource{} // Lookup current account ID stsSvc := sts.New(sess) callerID, err := stsSvc.GetCallerIdentity(&sts.GetCallerIdentityInput{}) if err != nil { return nil, err } accountID := callerID.Account region := svc.Config.Region // List WorkGroup var workgroupNames []*string err = svc.ListWorkGroupsPages( &athena.ListWorkGroupsInput{}, func(page *athena.ListWorkGroupsOutput, lastPage bool) bool { for _, workgroup := range page.WorkGroups { workgroupNames = append(workgroupNames, workgroup.Name) } return true }, ) if err != nil { return nil, err } // Create AthenaWorkGroup resource objects for _, name := range workgroupNames { resources = append(resources, &AthenaWorkGroup{ svc: svc, name: name, // The GetWorkGroup API doesn't return an ARN, // so we need to construct one ourselves arn: aws.String(fmt.Sprintf( "arn:aws:athena:%s:%s:workgroup/%s", *region, *accountID, *name, )), }) } return resources, err } func (a *AthenaWorkGroup) Remove() error { // Primary WorkGroup cannot be deleted, // but we can reset it to a clean state if *a.name == "primary" { logrus.Info("Primary Athena WorkGroup may not be deleted. Resetting configuration only.") // Reset the configuration to its default state _, err := a.svc.UpdateWorkGroup(&athena.UpdateWorkGroupInput{ // See https://docs.aws.amazon.com/athena/latest/APIReference/API_WorkGroupConfigurationUpdates.html // for documented defaults ConfigurationUpdates: &athena.WorkGroupConfigurationUpdates{ EnforceWorkGroupConfiguration: aws.Bool(false), PublishCloudWatchMetricsEnabled: aws.Bool(false), RemoveBytesScannedCutoffPerQuery: aws.Bool(true), RequesterPaysEnabled: aws.Bool(false), ResultConfigurationUpdates: &athena.ResultConfigurationUpdates{ RemoveEncryptionConfiguration: aws.Bool(true), RemoveOutputLocation: aws.Bool(true), }, }, Description: aws.String(""), WorkGroup: a.name, }) // Remove any tags wgTagsRes, err := a.svc.ListTagsForResource(&athena.ListTagsForResourceInput{ ResourceARN: a.arn, }) if err != nil { return err } var tagKeys []*string for _, tag := range wgTagsRes.Tags { tagKeys = append(tagKeys, tag.Key) } _, err = a.svc.UntagResource(&athena.UntagResourceInput{ ResourceARN: a.arn, TagKeys: tagKeys, }) if err != nil { return err } return nil } _, err := a.svc.DeleteWorkGroup(&athena.DeleteWorkGroupInput{ RecursiveDeleteOption: aws.Bool(true), WorkGroup: a.name, }) return err } func (a *AthenaWorkGroup) Filter() error { // If this is the primary work group, // check if it's already had its configuration reset if *a.name == "primary" { // Get workgroup configuration wgConfigRes, err := a.svc.GetWorkGroup(&athena.GetWorkGroupInput{ WorkGroup: a.name, }) if err != nil { return err } // Get workgroup tags wgTagsRes, err := a.svc.ListTagsForResource(&athena.ListTagsForResourceInput{ ResourceARN: a.arn, }) if err != nil { return err } // If the workgroup is already in a "clean" state, then // don't add it to our plan wgConfig := wgConfigRes.WorkGroup.Configuration isCleanConfig := wgConfig.BytesScannedCutoffPerQuery == nil && *wgConfig.EnforceWorkGroupConfiguration == false && *wgConfig.PublishCloudWatchMetricsEnabled == false && *wgConfig.RequesterPaysEnabled == false && *wgConfig.ResultConfiguration == athena.ResultConfiguration{} && len(wgTagsRes.Tags) == 0 if isCleanConfig { return errors.New("cannot delete primary athena work group") } } return nil } func (a *AthenaWorkGroup) Properties() types.Properties { return types.NewProperties(). Set("Name", *a.name). Set("ARN", *a.arn) } func (a *AthenaWorkGroup) String() string { return *a.name } aws-nuke-2.16.0/resources/autoscaling-groups.go000066400000000000000000000023061411137415400215230ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/autoscaling" ) func init() { register("AutoScalingGroup", ListAutoscalingGroups) } func ListAutoscalingGroups(s *session.Session) ([]Resource, error) { svc := autoscaling.New(s) resources := make([]Resource, 0) params := &autoscaling.DescribeAutoScalingGroupsInput{} err := svc.DescribeAutoScalingGroupsPages(params, func(page *autoscaling.DescribeAutoScalingGroupsOutput, lastPage bool) bool { for _, asg := range page.AutoScalingGroups { resources = append(resources, &AutoScalingGroup{ svc: svc, name: asg.AutoScalingGroupName, }) } return !lastPage }) if err != nil { return nil, err } return resources, nil } type AutoScalingGroup struct { svc *autoscaling.AutoScaling name *string } func (asg *AutoScalingGroup) Remove() error { params := &autoscaling.DeleteAutoScalingGroupInput{ AutoScalingGroupName: asg.name, ForceDelete: aws.Bool(true), } _, err := asg.svc.DeleteAutoScalingGroup(params) if err != nil { return err } return nil } func (asg *AutoScalingGroup) String() string { return *asg.name } aws-nuke-2.16.0/resources/autoscaling-launchconfigurations.go000066400000000000000000000024141411137415400244310ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/autoscaling" ) func init() { register("LaunchConfiguration", ListLaunchConfigurations) } func ListLaunchConfigurations(s *session.Session) ([]Resource, error) { resources := make([]Resource, 0) svc := autoscaling.New(s) params := &autoscaling.DescribeLaunchConfigurationsInput{} err := svc.DescribeLaunchConfigurationsPages(params, func(page *autoscaling.DescribeLaunchConfigurationsOutput, lastPage bool) bool { for _, launchconfig := range page.LaunchConfigurations { resources = append(resources, &LaunchConfiguration{ svc: svc, name: launchconfig.LaunchConfigurationName, }) } return !lastPage }) if err != nil { return nil, err } return resources, nil } type LaunchConfiguration struct { svc *autoscaling.AutoScaling name *string } func (launchconfiguration *LaunchConfiguration) Remove() error { params := &autoscaling.DeleteLaunchConfigurationInput{ LaunchConfigurationName: launchconfiguration.name, } _, err := launchconfiguration.svc.DeleteLaunchConfiguration(params) if err != nil { return err } return nil } func (launchconfiguration *LaunchConfiguration) String() string { return *launchconfiguration.name } aws-nuke-2.16.0/resources/autoscaling-lifecyclehooks.go000066400000000000000000000026551411137415400232160ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/autoscaling" ) func init() { register("LifecycleHook", ListLifecycleHooks) } func ListLifecycleHooks(s *session.Session) ([]Resource, error) { svc := autoscaling.New(s) asgResp, err := svc.DescribeAutoScalingGroups(&autoscaling.DescribeAutoScalingGroupsInput{}) if err != nil { return nil, err } resources := make([]Resource, 0) for _, asg := range asgResp.AutoScalingGroups { lchResp, err := svc.DescribeLifecycleHooks(&autoscaling.DescribeLifecycleHooksInput{ AutoScalingGroupName: asg.AutoScalingGroupName, }) if err != nil { return nil, err } for _, lch := range lchResp.LifecycleHooks { resources = append(resources, &LifecycleHook{ svc: svc, lifecycleHookName: lch.LifecycleHookName, autoScalingGroupName: lch.AutoScalingGroupName, }) } } return resources, nil } type LifecycleHook struct { svc *autoscaling.AutoScaling lifecycleHookName *string autoScalingGroupName *string } func (lch *LifecycleHook) Remove() error { params := &autoscaling.DeleteLifecycleHookInput{ AutoScalingGroupName: lch.autoScalingGroupName, LifecycleHookName: lch.lifecycleHookName, } _, err := lch.svc.DeleteLifecycleHook(params) if err != nil { return err } return nil } func (lch *LifecycleHook) String() string { return *lch.lifecycleHookName } aws-nuke-2.16.0/resources/autoscalingplans-scalingplans.go000066400000000000000000000027221411137415400237220ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/autoscalingplans" ) type AutoScalingPlansScalingPlan struct { svc *autoscalingplans.AutoScalingPlans scalingPlanName *string scalingPlanVersion *int64 } func init() { register("AutoScalingPlansScalingPlan", ListAutoScalingPlansScalingPlans) } func ListAutoScalingPlansScalingPlans(sess *session.Session) ([]Resource, error) { svc := autoscalingplans.New(sess) svc.ClientInfo.SigningName = "autoscaling-plans" resources := []Resource{} params := &autoscalingplans.DescribeScalingPlansInput{ MaxResults: aws.Int64(50), } for { output, err := svc.DescribeScalingPlans(params) if err != nil { return nil, err } for _, scalingPlan := range output.ScalingPlans { resources = append(resources, &AutoScalingPlansScalingPlan{ svc: svc, scalingPlanName: scalingPlan.ScalingPlanName, scalingPlanVersion: scalingPlan.ScalingPlanVersion, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *AutoScalingPlansScalingPlan) Remove() error { _, err := f.svc.DeleteScalingPlan(&autoscalingplans.DeleteScalingPlanInput{ ScalingPlanName: f.scalingPlanName, ScalingPlanVersion: f.scalingPlanVersion, }) return err } func (f *AutoScalingPlansScalingPlan) String() string { return *f.scalingPlanName } aws-nuke-2.16.0/resources/backup-plans.go000066400000000000000000000035231411137415400202570ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/backup" "github.com/rebuy-de/aws-nuke/pkg/types" "strings" ) type BackupPlan struct { svc *backup.Backup id string name string arn string tags map[string]*string } func init() { register("AWSBackupPlan", ListBackupPlans) } func ListBackupPlans(sess *session.Session) ([]Resource, error) { svc := backup.New(sess) falseValue := false maxBackupsLen := int64(100) params := &backup.ListBackupPlansInput{ IncludeDeleted: &falseValue, MaxResults: &maxBackupsLen, // aws default limit on number of backup plans per account } resources := make([]Resource, 0) for { output, err := svc.ListBackupPlans(params) if err != nil { return nil, err } for _, plan := range output.BackupPlansList { tagsOutput, _ := svc.ListTags(&backup.ListTagsInput{ResourceArn: plan.BackupPlanArn}) resources = append(resources, &BackupPlan{ svc: svc, id: *plan.BackupPlanId, name: *plan.BackupPlanName, arn: *plan.BackupPlanArn, tags: tagsOutput.Tags, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (b *BackupPlan) Properties() types.Properties { properties := types.NewProperties() properties.Set("ID", b.id) properties.Set("Name", b.name) for tagKey, tagValue := range b.tags { properties.Set(fmt.Sprintf("tag:%v", tagKey), *tagValue) } return properties } func (b *BackupPlan) Remove() error { _, err := b.svc.DeleteBackupPlan(&backup.DeleteBackupPlanInput{ BackupPlanId: &b.id, }) return err } func (b *BackupPlan) String() string { return b.arn } func (b *BackupPlan) Filter() error { if strings.HasPrefix(b.name, "aws/efs/") { return fmt.Errorf("cannot delete EFS automatic backups backup plan") } return nil } aws-nuke-2.16.0/resources/backup-recovery-points.go000066400000000000000000000031751411137415400223150ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/backup" "github.com/rebuy-de/aws-nuke/pkg/types" ) type BackupRecoveryPoint struct { svc *backup.Backup arn string backupVaultName string } func init() { register("AWSBackupRecoveryPoint", ListBackupRecoveryPoints) } func ListBackupRecoveryPoints(sess *session.Session) ([]Resource, error) { svc := backup.New(sess) max_vaults_len := int64(100) params := &backup.ListBackupVaultsInput{ MaxResults: &max_vaults_len, // aws default limit on number of backup vaults per account } resp, err := svc.ListBackupVaults(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.BackupVaultList { recoveryPointsOutput, _ := svc.ListRecoveryPointsByBackupVault(&backup.ListRecoveryPointsByBackupVaultInput{BackupVaultName: out.BackupVaultName}) for _, rp := range recoveryPointsOutput.RecoveryPoints { resources = append(resources, &BackupRecoveryPoint{ svc: svc, arn: *rp.RecoveryPointArn, backupVaultName: *out.BackupVaultName, }) } } return resources, nil } func (b *BackupRecoveryPoint) Properties() types.Properties { properties := types.NewProperties() properties.Set("BackupVault", b.backupVaultName) return properties } func (b *BackupRecoveryPoint) Remove() error { _, err := b.svc.DeleteRecoveryPoint(&backup.DeleteRecoveryPointInput{ BackupVaultName: &b.backupVaultName, RecoveryPointArn: &b.arn, }) return err } func (b *BackupRecoveryPoint) String() string { return fmt.Sprintf("%s", b.arn) } aws-nuke-2.16.0/resources/backup-selections.go000066400000000000000000000041121411137415400213050ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/backup" "github.com/rebuy-de/aws-nuke/pkg/types" "strings" ) type BackupSelection struct { svc *backup.Backup planId string selectionId string selectionName string } func init() { register("AWSBackupSelection", ListBackupSelections) } func ListBackupSelections(sess *session.Session) ([]Resource, error) { svc := backup.New(sess) false_value := false max_backups_len := int64(100) params := &backup.ListBackupPlansInput{ IncludeDeleted: &false_value, MaxResults: &max_backups_len, // aws default limit on number of backup plans per account } resources := make([]Resource, 0) for { output, err := svc.ListBackupPlans(params) if err != nil { return nil, err } for _, plan := range output.BackupPlansList { selectionsOutput, _ := svc.ListBackupSelections(&backup.ListBackupSelectionsInput{BackupPlanId: plan.BackupPlanId}) for _, selection := range selectionsOutput.BackupSelectionsList { resources = append(resources, &BackupSelection{ svc: svc, planId: *selection.BackupPlanId, selectionId: *selection.SelectionId, selectionName: *selection.SelectionName, }) } } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (b *BackupSelection) Properties() types.Properties { properties := types.NewProperties() properties.Set("Name", b.selectionName) properties.Set("ID", b.selectionId) properties.Set("PlanID", b.planId) return properties } func (b *BackupSelection) Remove() error { _, err := b.svc.DeleteBackupSelection(&backup.DeleteBackupSelectionInput{ BackupPlanId: &b.planId, SelectionId: &b.selectionId, }) return err } func (b *BackupSelection) String() string { return fmt.Sprintf("%s (%s)", b.planId, b.selectionId) } func (b *BackupSelection) Filter() error { if strings.HasPrefix(b.selectionName, "aws/efs/") { return fmt.Errorf("cannot delete EFS automatic backups backup selection") } return nil } aws-nuke-2.16.0/resources/backup-vaults-access-policies.go000066400000000000000000000066661411137415400235370ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/backup" ) type BackupVaultAccessPolicy struct { svc *backup.Backup backupVaultName string } func init() { register("AWSBackupVaultAccessPolicy", ListBackupVaultAccessPolicies) } func ListBackupVaultAccessPolicies(sess *session.Session) ([]Resource, error) { svc := backup.New(sess) maxVaultsLen := int64(100) params := &backup.ListBackupVaultsInput{ MaxResults: &maxVaultsLen, // aws default limit on number of backup vaults per account } resp, err := svc.ListBackupVaults(params) if err != nil { return nil, err } // Iterate over backup vaults and add vault policies that exist. resources := make([]Resource, 0) for _, out := range resp.BackupVaultList { // Check if the Backup Vault has an Access Policy set resp, err := svc.GetBackupVaultAccessPolicy(&backup.GetBackupVaultAccessPolicyInput{ BackupVaultName: out.BackupVaultName, }) // Non-existent Access Policies can come from ResourceNotFoundException or // being nil. if err != nil { switch err.(type) { case *backup.ResourceNotFoundException: // Non-existent is OK and we skip over them continue default: return nil, err } } // Only delete policies that exist. if resp.Policy != nil { resources = append(resources, &BackupVaultAccessPolicy{ svc: svc, backupVaultName: *out.BackupVaultName, }) } } return resources, nil } func (b *BackupVaultAccessPolicy) Remove() error { // Set the policy to a policy that allows deletion before removal. // // This is required to delete the policy for the automagically created vaults // such as "aws/efs/automatic-backup-vault" from EFS automatic backups // which by default Deny policy deletion via backup::DeleteBackupVaultAccessPolicy // // Example "aws/efs/automatic-backup-vault" default policy: // // { // "Version": "2012-10-17", // "Statement": [ // { // "Effect": "Deny", // "Principal": { // "AWS": "*" // }, // "Action": [ // "backup:DeleteBackupVault", // "backup:DeleteBackupVaultAccessPolicy", // "backup:DeleteRecoveryPoint", // "backup:StartCopyJob", // "backup:StartRestoreJob", // "backup:UpdateRecoveryPointLifecycle" // ], // "Resource": "*" // } // ] // } // // While deletion is Denied, you can update the policy with one that // doesn't deny and then delete at will. allowDeletionPolicy := `{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "*" }, "Action": "backup:DeleteBackupVaultAccessPolicy", "Resource": "*" } ] }` // Ignore error from if we can't put permissive backup vault policy in for some reason, that's OK. _, _ = b.svc.PutBackupVaultAccessPolicy(&backup.PutBackupVaultAccessPolicyInput{ BackupVaultName: &b.backupVaultName, Policy: &allowDeletionPolicy, }) // In the end, this is the only call we actually really care about for err. _, err := b.svc.DeleteBackupVaultAccessPolicy(&backup.DeleteBackupVaultAccessPolicyInput{ BackupVaultName: &b.backupVaultName, }) return err } func (b *BackupVaultAccessPolicy) String() string { return b.backupVaultName } aws-nuke-2.16.0/resources/backup-vaults.go000066400000000000000000000031541411137415400204600ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/backup" "github.com/rebuy-de/aws-nuke/pkg/types" ) type BackupVault struct { svc *backup.Backup arn string name string tags map[string]*string } func init() { register("AWSBackupVault", ListBackupVaults) } func ListBackupVaults(sess *session.Session) ([]Resource, error) { svc := backup.New(sess) max_vaults_len := int64(100) params := &backup.ListBackupVaultsInput{ MaxResults: &max_vaults_len, // aws default limit on number of backup vaults per account } resp, err := svc.ListBackupVaults(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.BackupVaultList { tagsOutput, _ := svc.ListTags(&backup.ListTagsInput{ResourceArn: out.BackupVaultArn}) resources = append(resources, &BackupVault{ svc: svc, name: *out.BackupVaultName, arn: *out.BackupVaultArn, tags: tagsOutput.Tags, }) } return resources, nil } func (b *BackupVault) Properties() types.Properties { properties := types.NewProperties() properties.Set("Name", b.name) for tagKey, tagValue := range b.tags { properties.Set(fmt.Sprintf("tag:%v", tagKey), *tagValue) } return properties } func (b *BackupVault) Remove() error { _, err := b.svc.DeleteBackupVault(&backup.DeleteBackupVaultInput{ BackupVaultName: &b.name, }) return err } func (b *BackupVault) String() string { return b.arn } func (b *BackupVault) Filter() error { if b.name == "aws/efs/automatic-backup-vault" { return fmt.Errorf("cannot delete EFS automatic backups vault") } return nil } aws-nuke-2.16.0/resources/batch-computeenvironments.go000066400000000000000000000024071411137415400231020ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/batch" ) type BatchComputeEnvironment struct { svc *batch.Batch computeEnvironmentName *string } func init() { register("BatchComputeEnvironment", ListBatchComputeEnvironments) } func ListBatchComputeEnvironments(sess *session.Session) ([]Resource, error) { svc := batch.New(sess) resources := []Resource{} params := &batch.DescribeComputeEnvironmentsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.DescribeComputeEnvironments(params) if err != nil { return nil, err } for _, computeEnvironment := range output.ComputeEnvironments { resources = append(resources, &BatchComputeEnvironment{ svc: svc, computeEnvironmentName: computeEnvironment.ComputeEnvironmentName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *BatchComputeEnvironment) Remove() error { _, err := f.svc.DeleteComputeEnvironment(&batch.DeleteComputeEnvironmentInput{ ComputeEnvironment: f.computeEnvironmentName, }) return err } func (f *BatchComputeEnvironment) String() string { return *f.computeEnvironmentName } aws-nuke-2.16.0/resources/batch-computeenvironmentstates.go000066400000000000000000000031201411137415400241340ustar00rootroot00000000000000package resources import ( "fmt" "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/batch" ) type BatchComputeEnvironmentState struct { svc *batch.Batch computeEnvironmentName *string state *string } func init() { register("BatchComputeEnvironmentState", ListBatchComputeEnvironmentStates) } func ListBatchComputeEnvironmentStates(sess *session.Session) ([]Resource, error) { svc := batch.New(sess) resources := []Resource{} params := &batch.DescribeComputeEnvironmentsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.DescribeComputeEnvironments(params) if err != nil { return nil, err } for _, computeEnvironment := range output.ComputeEnvironments { resources = append(resources, &BatchComputeEnvironmentState{ svc: svc, computeEnvironmentName: computeEnvironment.ComputeEnvironmentName, state: computeEnvironment.State, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *BatchComputeEnvironmentState) Remove() error { _, err := f.svc.UpdateComputeEnvironment(&batch.UpdateComputeEnvironmentInput{ ComputeEnvironment: f.computeEnvironmentName, State: aws.String("DISABLED"), }) return err } func (f *BatchComputeEnvironmentState) String() string { return *f.computeEnvironmentName } func (f *BatchComputeEnvironmentState) Filter() error { if strings.ToLower(*f.state) == "disabled" { return fmt.Errorf("already disabled") } return nil } aws-nuke-2.16.0/resources/batch-jobqueues.go000066400000000000000000000020401411137415400207510ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/batch" ) type BatchJobQueue struct { svc *batch.Batch jobQueue *string } func init() { register("BatchJobQueue", ListBatchJobQueues) } func ListBatchJobQueues(sess *session.Session) ([]Resource, error) { svc := batch.New(sess) resources := []Resource{} params := &batch.DescribeJobQueuesInput{ MaxResults: aws.Int64(100), } for { output, err := svc.DescribeJobQueues(params) if err != nil { return nil, err } for _, queue := range output.JobQueues { resources = append(resources, &BatchJobQueue{ svc: svc, jobQueue: queue.JobQueueName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *BatchJobQueue) Remove() error { _, err := f.svc.DeleteJobQueue(&batch.DeleteJobQueueInput{ JobQueue: f.jobQueue, }) return err } func (f *BatchJobQueue) String() string { return *f.jobQueue } aws-nuke-2.16.0/resources/batch-jobqueuestates.go000066400000000000000000000024751411137415400220260ustar00rootroot00000000000000package resources import ( "fmt" "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/batch" ) type BatchJobQueueState struct { svc *batch.Batch jobQueue *string state *string } func init() { register("BatchJobQueueState", ListBatchJobQueueStates) } func ListBatchJobQueueStates(sess *session.Session) ([]Resource, error) { svc := batch.New(sess) resources := []Resource{} params := &batch.DescribeJobQueuesInput{ MaxResults: aws.Int64(100), } for { output, err := svc.DescribeJobQueues(params) if err != nil { return nil, err } for _, queue := range output.JobQueues { resources = append(resources, &BatchJobQueueState{ svc: svc, jobQueue: queue.JobQueueName, state: queue.State, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *BatchJobQueueState) Remove() error { _, err := f.svc.UpdateJobQueue(&batch.UpdateJobQueueInput{ JobQueue: f.jobQueue, State: aws.String("DISABLED"), }) return err } func (f *BatchJobQueueState) String() string { return *f.jobQueue } func (f *BatchJobQueueState) Filter() error { if strings.ToLower(*f.state) == "disabled" { return fmt.Errorf("already disabled") } return nil } aws-nuke-2.16.0/resources/cloud9-environments.go000066400000000000000000000021501411137415400216160ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloud9" ) type Cloud9Environment struct { svc *cloud9.Cloud9 environmentID *string } func init() { register("Cloud9Environment", ListCloud9Environments) } func ListCloud9Environments(sess *session.Session) ([]Resource, error) { svc := cloud9.New(sess) resources := []Resource{} params := &cloud9.ListEnvironmentsInput{ MaxResults: aws.Int64(25), } for { resp, err := svc.ListEnvironments(params) if err != nil { return nil, err } for _, environmentID := range resp.EnvironmentIds { resources = append(resources, &Cloud9Environment{ svc: svc, environmentID: environmentID, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *Cloud9Environment) Remove() error { _, err := f.svc.DeleteEnvironment(&cloud9.DeleteEnvironmentInput{ EnvironmentId: f.environmentID, }) return err } func (f *Cloud9Environment) String() string { return *f.environmentID } aws-nuke-2.16.0/resources/clouddirectory-directories.go000066400000000000000000000025421411137415400232440ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/clouddirectory" ) type CloudDirectoryDirectory struct { svc *clouddirectory.CloudDirectory directoryARN *string } func init() { register("CloudDirectoryDirectory", ListCloudDirectoryDirectories) } func ListCloudDirectoryDirectories(sess *session.Session) ([]Resource, error) { svc := clouddirectory.New(sess) resources := []Resource{} params := &clouddirectory.ListDirectoriesInput{ MaxResults: aws.Int64(30), State: aws.String("ENABLED"), } for { resp, err := svc.ListDirectories(params) if err != nil { return nil, err } for _, directory := range resp.Directories { resources = append(resources, &CloudDirectoryDirectory{ svc: svc, directoryARN: directory.DirectoryArn, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *CloudDirectoryDirectory) Remove() error { _, err := f.svc.DisableDirectory(&clouddirectory.DisableDirectoryInput{ DirectoryArn: f.directoryARN, }) if err == nil { _, err = f.svc.DeleteDirectory(&clouddirectory.DeleteDirectoryInput{ DirectoryArn: f.directoryARN, }) } return err } func (f *CloudDirectoryDirectory) String() string { return *f.directoryARN } aws-nuke-2.16.0/resources/clouddirectory-schemas.go000066400000000000000000000033451411137415400223550ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/clouddirectory" ) type CloudDirectorySchema struct { svc *clouddirectory.CloudDirectory schemaARN *string } func init() { register("CloudDirectorySchema", ListCloudDirectorySchemas) } func ListCloudDirectorySchemas(sess *session.Session) ([]Resource, error) { svc := clouddirectory.New(sess) resources := []Resource{} developmentParams := &clouddirectory.ListDevelopmentSchemaArnsInput{ MaxResults: aws.Int64(30), } // Get all development schemas for { resp, err := svc.ListDevelopmentSchemaArns(developmentParams) if err != nil { return nil, err } for _, arn := range resp.SchemaArns { resources = append(resources, &CloudDirectorySchema{ svc: svc, schemaARN: arn, }) } if resp.NextToken == nil { break } developmentParams.NextToken = resp.NextToken } // Get all published schemas publishedParams := &clouddirectory.ListPublishedSchemaArnsInput{ MaxResults: aws.Int64(30), } for { resp, err := svc.ListPublishedSchemaArns(publishedParams) if err != nil { return nil, err } for _, arn := range resp.SchemaArns { resources = append(resources, &CloudDirectorySchema{ svc: svc, schemaARN: arn, }) } if resp.NextToken == nil { break } publishedParams.NextToken = resp.NextToken } // Return combined development and production schemas to DeleteSchema return resources, nil } func (f *CloudDirectorySchema) Remove() error { _, err := f.svc.DeleteSchema(&clouddirectory.DeleteSchemaInput{ SchemaArn: f.schemaARN, }) return err } func (f *CloudDirectorySchema) String() string { return *f.schemaARN } aws-nuke-2.16.0/resources/cloudformation-stack.go000066400000000000000000000146301411137415400220300ustar00rootroot00000000000000package resources import ( "errors" "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudformation" "github.com/aws/aws-sdk-go/service/cloudformation/cloudformationiface" "github.com/rebuy-de/aws-nuke/pkg/config" "github.com/rebuy-de/aws-nuke/pkg/types" "github.com/sirupsen/logrus" ) const CLOUDFORMATION_MAX_DELETE_ATTEMPT = 3 func init() { register("CloudFormationStack", ListCloudFormationStacks) } func ListCloudFormationStacks(sess *session.Session) ([]Resource, error) { svc := cloudformation.New(sess) params := &cloudformation.DescribeStacksInput{} resources := make([]Resource, 0) for { resp, err := svc.DescribeStacks(params) if err != nil { return nil, err } for _, stack := range resp.Stacks { resources = append(resources, &CloudFormationStack{ svc: svc, stack: stack, maxDeleteAttempts: CLOUDFORMATION_MAX_DELETE_ATTEMPT, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } type CloudFormationStack struct { svc cloudformationiface.CloudFormationAPI stack *cloudformation.Stack maxDeleteAttempts int featureFlags config.FeatureFlags } func (cfs *CloudFormationStack) FeatureFlags(ff config.FeatureFlags) { cfs.featureFlags = ff } func (cfs *CloudFormationStack) Remove() error { return cfs.removeWithAttempts(0) } func (cfs *CloudFormationStack) removeWithAttempts(attempt int) error { if err := cfs.doRemove(); err != nil { logrus.Errorf("CloudFormationStack stackName=%s attempt=%d maxAttempts=%d delete failed: %s", *cfs.stack.StackName, attempt, cfs.maxDeleteAttempts, err.Error()) awsErr, ok := err.(awserr.Error) if ok && awsErr.Code() == "ValidationError" && awsErr.Message() == "Stack ["+*cfs.stack.StackName+"] cannot be deleted while TerminationProtection is enabled" { if cfs.featureFlags.DisableDeletionProtection.CloudformationStack { logrus.Infof("CloudFormationStack stackName=%s attempt=%d maxAttempts=%d updating termination protection", *cfs.stack.StackName, attempt, cfs.maxDeleteAttempts) _, err = cfs.svc.UpdateTerminationProtection(&cloudformation.UpdateTerminationProtectionInput{ EnableTerminationProtection: aws.Bool(false), StackName: cfs.stack.StackName, }) if err != nil { return err } } else { logrus.Warnf("CloudFormationStack stackName=%s attempt=%d maxAttempts=%d set feature flag to disable deletion protection", *cfs.stack.StackName, attempt, cfs.maxDeleteAttempts) return err } } if attempt >= cfs.maxDeleteAttempts { return errors.New("CFS might not be deleted after this run.") } else { return cfs.removeWithAttempts(attempt + 1) } } else { return nil } } func (cfs *CloudFormationStack) doRemove() error { o, err := cfs.svc.DescribeStacks(&cloudformation.DescribeStacksInput{ StackName: cfs.stack.StackName, }) if err != nil { if awsErr, ok := err.(awserr.Error); ok { if awsErr.Code() == "ValidationFailed" && strings.HasSuffix(awsErr.Message(), " does not exist") { logrus.Infof("CloudFormationStack stackName=%s no longer exists", *cfs.stack.StackName) return nil } } return err } stack := o.Stacks[0] if *stack.StackStatus == cloudformation.StackStatusDeleteComplete { //stack already deleted, no need to re-delete return nil } else if *stack.StackStatus == cloudformation.StackStatusDeleteInProgress { logrus.Infof("CloudFormationStack stackName=%s delete in progress. Waiting", *cfs.stack.StackName) return cfs.svc.WaitUntilStackDeleteComplete(&cloudformation.DescribeStacksInput{ StackName: cfs.stack.StackName, }) } else if *stack.StackStatus == cloudformation.StackStatusDeleteFailed { logrus.Infof("CloudFormationStack stackName=%s delete failed. Attempting to retain and delete stack", *cfs.stack.StackName) // This means the CFS has undeleteable resources. // In order to move on with nuking, we retain them in the deletion. retainableResources, err := cfs.svc.ListStackResources(&cloudformation.ListStackResourcesInput{ StackName: cfs.stack.StackName, }) if err != nil { return err } retain := make([]*string, 0) for _, r := range retainableResources.StackResourceSummaries { if *r.ResourceStatus != cloudformation.ResourceStatusDeleteComplete { retain = append(retain, r.LogicalResourceId) } } _, err = cfs.svc.DeleteStack(&cloudformation.DeleteStackInput{ StackName: cfs.stack.StackName, RetainResources: retain, }) if err != nil { return err } return cfs.svc.WaitUntilStackDeleteComplete(&cloudformation.DescribeStacksInput{ StackName: cfs.stack.StackName, }) } else { if err := cfs.waitForStackToStabilize(*stack.StackStatus); err != nil { return err } else if _, err := cfs.svc.DeleteStack(&cloudformation.DeleteStackInput{ StackName: cfs.stack.StackName, }); err != nil { return err } else if err := cfs.svc.WaitUntilStackDeleteComplete(&cloudformation.DescribeStacksInput{ StackName: cfs.stack.StackName, }); err != nil { return err } else { return nil } } } func (cfs *CloudFormationStack) waitForStackToStabilize(currentStatus string) error { switch currentStatus { case cloudformation.StackStatusUpdateInProgress: fallthrough case cloudformation.StackStatusUpdateRollbackCompleteCleanupInProgress: fallthrough case cloudformation.StackStatusUpdateRollbackInProgress: logrus.Infof("CloudFormationStack stackName=%s update in progress. Waiting to stabalize", *cfs.stack.StackName) return cfs.svc.WaitUntilStackUpdateComplete(&cloudformation.DescribeStacksInput{ StackName: cfs.stack.StackName, }) case cloudformation.StackStatusCreateInProgress: fallthrough case cloudformation.StackStatusRollbackInProgress: logrus.Infof("CloudFormationStack stackName=%s create in progress. Waiting to stabalize", *cfs.stack.StackName) return cfs.svc.WaitUntilStackCreateComplete(&cloudformation.DescribeStacksInput{ StackName: cfs.stack.StackName, }) default: return nil } } func (cfs *CloudFormationStack) Properties() types.Properties { properties := types.NewProperties() properties.Set("Name", cfs.stack.StackName) for _, tagValue := range cfs.stack.Tags { properties.SetTag(tagValue.Key, tagValue.Value) } return properties } func (cfs *CloudFormationStack) String() string { return *cfs.stack.StackName } aws-nuke-2.16.0/resources/cloudformation-stack_test.go000066400000000000000000000211341411137415400230640ustar00rootroot00000000000000package resources import ( "testing" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/cloudformation" "github.com/golang/mock/gomock" "github.com/rebuy-de/aws-nuke/mocks/mock_cloudformationiface" "github.com/stretchr/testify/assert" ) func TestCloudformationStack_Remove_StackAlreadyDeleted(t *testing.T) { a := assert.New(t) ctrl := gomock.NewController(t) defer ctrl.Finish() mockCloudformation := mock_cloudformationiface.NewMockCloudFormationAPI(ctrl) stack := CloudFormationStack{ svc: mockCloudformation, stack: &cloudformation.Stack{ StackName: aws.String("foobar"), }, } mockCloudformation.EXPECT().DescribeStacks(gomock.Eq(&cloudformation.DescribeStacksInput{ StackName: aws.String("foobar"), })).Return(&cloudformation.DescribeStacksOutput{ Stacks: []*cloudformation.Stack{ { StackStatus: aws.String(cloudformation.StackStatusDeleteComplete), }, }, }, nil) err := stack.Remove() a.Nil(err) } func TestCloudformationStack_Remove_StackDoesNotExist(t *testing.T) { a := assert.New(t) ctrl := gomock.NewController(t) defer ctrl.Finish() mockCloudformation := mock_cloudformationiface.NewMockCloudFormationAPI(ctrl) stack := CloudFormationStack{ svc: mockCloudformation, stack: &cloudformation.Stack{ StackName: aws.String("foobar"), }, } mockCloudformation.EXPECT().DescribeStacks(gomock.Eq(&cloudformation.DescribeStacksInput{ StackName: aws.String("foobar"), })).Return(nil, awserr.New("ValidationFailed", "Stack with id foobar does not exist", nil)) err := stack.Remove() a.Nil(err) } func TestCloudformationStack_Remove_DeleteFailed(t *testing.T) { a := assert.New(t) ctrl := gomock.NewController(t) defer ctrl.Finish() mockCloudformation := mock_cloudformationiface.NewMockCloudFormationAPI(ctrl) stack := CloudFormationStack{ svc: mockCloudformation, stack: &cloudformation.Stack{ StackName: aws.String("foobar"), }, } gomock.InOrder( mockCloudformation.EXPECT().DescribeStacks(gomock.Eq(&cloudformation.DescribeStacksInput{ StackName: aws.String("foobar"), })).Return(&cloudformation.DescribeStacksOutput{ Stacks: []*cloudformation.Stack{ { StackStatus: aws.String(cloudformation.StackStatusDeleteFailed), }, }, }, nil), mockCloudformation.EXPECT().ListStackResources(gomock.Eq(&cloudformation.ListStackResourcesInput{ StackName: aws.String("foobar"), })).Return(&cloudformation.ListStackResourcesOutput{ StackResourceSummaries: []*cloudformation.StackResourceSummary{ { ResourceStatus: aws.String(cloudformation.ResourceStatusDeleteComplete), LogicalResourceId: aws.String("fooDeleteComplete"), }, { ResourceStatus: aws.String(cloudformation.ResourceStatusDeleteFailed), LogicalResourceId: aws.String("fooDeleteFailed"), }, }, }, nil), mockCloudformation.EXPECT().DeleteStack(gomock.Eq(&cloudformation.DeleteStackInput{ StackName: aws.String("foobar"), RetainResources: []*string{ aws.String("fooDeleteFailed"), }, })).Return(nil, nil), mockCloudformation.EXPECT().WaitUntilStackDeleteComplete(gomock.Eq(&cloudformation.DescribeStacksInput{ StackName: aws.String("foobar"), })).Return(nil), ) err := stack.Remove() a.Nil(err) } // if the stack is currently in delete in progress func TestCloudformationStack_Remove_DeleteInProgress(t *testing.T) { a := assert.New(t) ctrl := gomock.NewController(t) defer ctrl.Finish() mockCloudformation := mock_cloudformationiface.NewMockCloudFormationAPI(ctrl) stack := CloudFormationStack{ svc: mockCloudformation, stack: &cloudformation.Stack{ StackName: aws.String("foobar"), }, } gomock.InOrder( mockCloudformation.EXPECT().DescribeStacks(gomock.Eq(&cloudformation.DescribeStacksInput{ StackName: aws.String("foobar"), })).Return(&cloudformation.DescribeStacksOutput{ Stacks: []*cloudformation.Stack{ { StackStatus: aws.String(cloudformation.StackStatusDeleteInProgress), }, }, }, nil), mockCloudformation.EXPECT().WaitUntilStackDeleteComplete(gomock.Eq(&cloudformation.DescribeStacksInput{ StackName: aws.String("foobar"), })).Return(nil), ) err := stack.Remove() a.Nil(err) } func TestCloudformationStack_Remove_Stack_InCompletedStatus(t *testing.T) { tests := []string{ cloudformation.StackStatusCreateComplete, cloudformation.StackStatusCreateFailed, cloudformation.StackStatusReviewInProgress, cloudformation.StackStatusRollbackComplete, cloudformation.StackStatusRollbackFailed, cloudformation.StackStatusUpdateComplete, cloudformation.StackStatusUpdateRollbackComplete, cloudformation.StackStatusUpdateRollbackFailed, } for _, stackStatus := range tests { t.Run(stackStatus, func(t *testing.T) { a := assert.New(t) ctrl := gomock.NewController(t) defer ctrl.Finish() mockCloudformation := mock_cloudformationiface.NewMockCloudFormationAPI(ctrl) stack := CloudFormationStack{ svc: mockCloudformation, stack: &cloudformation.Stack{ StackName: aws.String("foobar"), }, } gomock.InOrder( mockCloudformation.EXPECT().DescribeStacks(gomock.Eq(&cloudformation.DescribeStacksInput{ StackName: aws.String("foobar"), })).Return(&cloudformation.DescribeStacksOutput{ Stacks: []*cloudformation.Stack{ { StackStatus: aws.String(stackStatus), }, }, }, nil), mockCloudformation.EXPECT().DeleteStack(gomock.Eq(&cloudformation.DeleteStackInput{ StackName: aws.String("foobar"), })).Return(nil, nil), mockCloudformation.EXPECT().WaitUntilStackDeleteComplete(gomock.Eq(&cloudformation.DescribeStacksInput{ StackName: aws.String("foobar"), })).Return(nil), ) err := stack.Remove() a.Nil(err) }) } } func TestCloudformationStack_Remove_Stack_CreateInProgress(t *testing.T) { tests := []string{ cloudformation.StackStatusCreateInProgress, cloudformation.StackStatusRollbackInProgress, } for _, stackStatus := range tests { t.Run(stackStatus, func(t *testing.T) { a := assert.New(t) ctrl := gomock.NewController(t) defer ctrl.Finish() mockCloudformation := mock_cloudformationiface.NewMockCloudFormationAPI(ctrl) stack := CloudFormationStack{ svc: mockCloudformation, stack: &cloudformation.Stack{ StackName: aws.String("foobar"), }, } gomock.InOrder( mockCloudformation.EXPECT().DescribeStacks(gomock.Eq(&cloudformation.DescribeStacksInput{ StackName: aws.String("foobar"), })).Return(&cloudformation.DescribeStacksOutput{ Stacks: []*cloudformation.Stack{ { StackStatus: aws.String(stackStatus), }, }, }, nil), mockCloudformation.EXPECT().WaitUntilStackCreateComplete(gomock.Eq(&cloudformation.DescribeStacksInput{ StackName: aws.String("foobar"), })).Return(nil), mockCloudformation.EXPECT().DeleteStack(gomock.Eq(&cloudformation.DeleteStackInput{ StackName: aws.String("foobar"), })).Return(nil, nil), mockCloudformation.EXPECT().WaitUntilStackDeleteComplete(gomock.Eq(&cloudformation.DescribeStacksInput{ StackName: aws.String("foobar"), })).Return(nil), ) err := stack.Remove() a.Nil(err) }) } } func TestCloudformationStack_Remove_Stack_UpdateInProgress(t *testing.T) { tests := []string{ cloudformation.StackStatusUpdateInProgress, cloudformation.StackStatusUpdateRollbackCompleteCleanupInProgress, cloudformation.StackStatusUpdateRollbackInProgress, } for _, stackStatus := range tests { t.Run(stackStatus, func(t *testing.T) { a := assert.New(t) ctrl := gomock.NewController(t) defer ctrl.Finish() mockCloudformation := mock_cloudformationiface.NewMockCloudFormationAPI(ctrl) stack := CloudFormationStack{ svc: mockCloudformation, stack: &cloudformation.Stack{ StackName: aws.String("foobar"), }, } gomock.InOrder( mockCloudformation.EXPECT().DescribeStacks(gomock.Eq(&cloudformation.DescribeStacksInput{ StackName: aws.String("foobar"), })).Return(&cloudformation.DescribeStacksOutput{ Stacks: []*cloudformation.Stack{ { StackStatus: aws.String(stackStatus), }, }, }, nil), mockCloudformation.EXPECT().WaitUntilStackUpdateComplete(gomock.Eq(&cloudformation.DescribeStacksInput{ StackName: aws.String("foobar"), })).Return(nil), mockCloudformation.EXPECT().DeleteStack(gomock.Eq(&cloudformation.DeleteStackInput{ StackName: aws.String("foobar"), })).Return(nil, nil), mockCloudformation.EXPECT().WaitUntilStackDeleteComplete(gomock.Eq(&cloudformation.DescribeStacksInput{ StackName: aws.String("foobar"), })).Return(nil), ) err := stack.Remove() a.Nil(err) }) } } aws-nuke-2.16.0/resources/cloudformation-stackset.go000066400000000000000000000114171411137415400225440ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudformation" "github.com/aws/aws-sdk-go/service/cloudformation/cloudformationiface" "github.com/rebuy-de/aws-nuke/pkg/types" "github.com/sirupsen/logrus" "strings" "time" ) func init() { register("CloudFormationStackSet", ListCloudFormationStackSets) } func ListCloudFormationStackSets(sess *session.Session) ([]Resource, error) { svc := cloudformation.New(sess) params := &cloudformation.ListStackSetsInput{ Status: aws.String(cloudformation.StackSetStatusActive), } resources := make([]Resource, 0) for { resp, err := svc.ListStackSets(params) if err != nil { return nil, err } for _, stackSetSummary := range resp.Summaries { resources = append(resources, &CloudFormationStackSet{ svc: svc, stackSetSummary: stackSetSummary, sleepDuration: 10 * time.Second, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } type CloudFormationStackSet struct { svc cloudformationiface.CloudFormationAPI stackSetSummary *cloudformation.StackSetSummary sleepDuration time.Duration } func (cfs *CloudFormationStackSet) findStackInstances() (map[string][]string, error) { accounts := make(map[string][]string) input := &cloudformation.ListStackInstancesInput{ StackSetName: cfs.stackSetSummary.StackSetName, } for { resp, err := cfs.svc.ListStackInstances(input) if err != nil { return nil, err } for _, stackInstanceSummary := range resp.Summaries { if regions, ok := accounts[*stackInstanceSummary.Account]; !ok { accounts[*stackInstanceSummary.Account] = []string{*stackInstanceSummary.Region} } else { accounts[*stackInstanceSummary.Account] = append(regions, *stackInstanceSummary.Region) } } if resp.NextToken == nil { break } input.NextToken = resp.NextToken } return accounts, nil } func (cfs *CloudFormationStackSet) waitForStackSetOperation(operationId string) error { for { result, err := cfs.svc.DescribeStackSetOperation(&cloudformation.DescribeStackSetOperationInput{ StackSetName: cfs.stackSetSummary.StackSetName, OperationId: &operationId, }) if err != nil { return err } logrus.Infof("Got stackInstance operation status on stackSet=%s operationId=%s status=%s", *cfs.stackSetSummary.StackSetName, operationId, *result.StackSetOperation.Status) if *result.StackSetOperation.Status == cloudformation.StackSetOperationResultStatusSucceeded { return nil } else if *result.StackSetOperation.Status == cloudformation.StackSetOperationResultStatusFailed || *result.StackSetOperation.Status == cloudformation.StackSetOperationResultStatusCancelled { return fmt.Errorf("unable to delete stackSet=%s operationId=%s status=%s", *cfs.stackSetSummary.StackSetName, operationId, *result.StackSetOperation.Status) } else { logrus.Infof("Waiting on stackSet=%s operationId=%s status=%s", *cfs.stackSetSummary.StackSetName, operationId, *result.StackSetOperation.Status) time.Sleep(cfs.sleepDuration) } } } func (cfs *CloudFormationStackSet) deleteStackInstances(accountId string, regions []string) error { logrus.Infof("Deleting stack instance accountId=%s regions=%s", accountId, strings.Join(regions, ",")) regionsInput := make([]*string, len(regions)) for i, region := range regions { regionsInput[i] = aws.String(region) fmt.Printf("region=%s i=%d\n", region, i) } result, err := cfs.svc.DeleteStackInstances(&cloudformation.DeleteStackInstancesInput{ StackSetName: cfs.stackSetSummary.StackSetName, Accounts: []*string{&accountId}, Regions: regionsInput, RetainStacks: aws.Bool(true), //this will remove the stack set instance from the stackset, but will leave the stack in the account/region it was deployed to }) fmt.Printf("got result=%v err=%v\n", result, err) if result == nil { return fmt.Errorf("got null result") } if err != nil { return err } return cfs.waitForStackSetOperation(*result.OperationId) } func (cfs *CloudFormationStackSet) Remove() error { accounts, err := cfs.findStackInstances() if err != nil { return err } for accountId, regions := range accounts { err := cfs.deleteStackInstances(accountId, regions) if err != nil { return err } } _, err = cfs.svc.DeleteStackSet(&cloudformation.DeleteStackSetInput{ StackSetName: cfs.stackSetSummary.StackSetName, }) return err } func (cfs *CloudFormationStackSet) Properties() types.Properties { properties := types.NewProperties() properties.Set("Name", cfs.stackSetSummary.StackSetName) properties.Set("StackSetId", cfs.stackSetSummary.StackSetId) return properties } func (cfs *CloudFormationStackSet) String() string { return *cfs.stackSetSummary.StackSetName } aws-nuke-2.16.0/resources/cloudformation-stackset_test.go000066400000000000000000000150331411137415400236010ustar00rootroot00000000000000package resources import ( "testing" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/cloudformation" "github.com/golang/mock/gomock" "github.com/rebuy-de/aws-nuke/mocks/mock_cloudformationiface" "github.com/stretchr/testify/assert" ) func TestCloudformationStackSet_Remove(t *testing.T) { a := assert.New(t) ctrl := gomock.NewController(t) defer ctrl.Finish() mockCloudformation := mock_cloudformationiface.NewMockCloudFormationAPI(ctrl) stackSet := CloudFormationStackSet{ svc: mockCloudformation, stackSetSummary: &cloudformation.StackSetSummary{ StackSetName: aws.String("foobar"), }, } mockCloudformation.EXPECT().ListStackInstances(gomock.Eq(&cloudformation.ListStackInstancesInput{ StackSetName: aws.String("foobar"), })).Return(&cloudformation.ListStackInstancesOutput{ Summaries: []*cloudformation.StackInstanceSummary{ { Account: aws.String("a1"), Region: aws.String("r1"), }, { Account: aws.String("a1"), Region: aws.String("r2"), }, }, }, nil) mockCloudformation.EXPECT().DeleteStackInstances(gomock.Eq(&cloudformation.DeleteStackInstancesInput{ StackSetName: aws.String("foobar"), Accounts: []*string{aws.String("a1")}, Regions: []*string{aws.String("r1"), aws.String("r2")}, RetainStacks: aws.Bool(true), })).Return(&cloudformation.DeleteStackInstancesOutput{ OperationId: aws.String("o1"), }, nil) describeStackSetStatuses := []string{ cloudformation.StackSetOperationResultStatusPending, cloudformation.StackSetOperationResultStatusRunning, cloudformation.StackSetOperationResultStatusSucceeded, } describeStackSetOperationCalls := make([]*gomock.Call, len(describeStackSetStatuses)) for i, status := range describeStackSetStatuses { describeStackSetOperationCalls[i] = mockCloudformation.EXPECT().DescribeStackSetOperation(gomock.Eq(&cloudformation.DescribeStackSetOperationInput{ OperationId: aws.String("o1"), StackSetName: aws.String("foobar"), })).Return(&cloudformation.DescribeStackSetOperationOutput{ StackSetOperation: &cloudformation.StackSetOperation{ Status: aws.String(status), }, }, nil) } gomock.InOrder(describeStackSetOperationCalls...) mockCloudformation.EXPECT().DeleteStackSet(gomock.Eq(&cloudformation.DeleteStackSetInput{ StackSetName: aws.String("foobar"), })).Return(&cloudformation.DeleteStackSetOutput{}, nil) err := stackSet.Remove() a.Nil(err) } func TestCloudformationStackSet_Remove_MultipleAccounts(t *testing.T) { a := assert.New(t) ctrl := gomock.NewController(t) defer ctrl.Finish() mockCloudformation := mock_cloudformationiface.NewMockCloudFormationAPI(ctrl) stackSet := CloudFormationStackSet{ svc: mockCloudformation, stackSetSummary: &cloudformation.StackSetSummary{ StackSetName: aws.String("foobar"), }, } mockCloudformation.EXPECT().ListStackInstances(gomock.Eq(&cloudformation.ListStackInstancesInput{ StackSetName: aws.String("foobar"), })).Return(&cloudformation.ListStackInstancesOutput{ Summaries: []*cloudformation.StackInstanceSummary{ { Account: aws.String("a1"), Region: aws.String("r1"), }, { Account: aws.String("a1"), Region: aws.String("r2"), }, { Account: aws.String("a2"), Region: aws.String("r2"), }, }, }, nil) mockCloudformation.EXPECT().DeleteStackInstances(gomock.Eq(&cloudformation.DeleteStackInstancesInput{ StackSetName: aws.String("foobar"), Accounts: []*string{aws.String("a1")}, Regions: []*string{aws.String("r1"), aws.String("r2")}, RetainStacks: aws.Bool(true), })).Return(&cloudformation.DeleteStackInstancesOutput{ OperationId: aws.String("a1-oId"), }, nil) mockCloudformation.EXPECT().DeleteStackInstances(gomock.Eq(&cloudformation.DeleteStackInstancesInput{ StackSetName: aws.String("foobar"), Accounts: []*string{aws.String("a2")}, Regions: []*string{aws.String("r2")}, RetainStacks: aws.Bool(true), })).Return(&cloudformation.DeleteStackInstancesOutput{ OperationId: aws.String("a2-oId"), }, nil) mockCloudformation.EXPECT().DescribeStackSetOperation(gomock.Eq(&cloudformation.DescribeStackSetOperationInput{ OperationId: aws.String("a1-oId"), StackSetName: aws.String("foobar"), })).Return(&cloudformation.DescribeStackSetOperationOutput{ StackSetOperation: &cloudformation.StackSetOperation{ Status: aws.String(cloudformation.StackSetOperationResultStatusSucceeded), }, }, nil) mockCloudformation.EXPECT().DescribeStackSetOperation(gomock.Eq(&cloudformation.DescribeStackSetOperationInput{ OperationId: aws.String("a2-oId"), StackSetName: aws.String("foobar"), })).Return(&cloudformation.DescribeStackSetOperationOutput{ StackSetOperation: &cloudformation.StackSetOperation{ Status: aws.String(cloudformation.StackSetOperationResultStatusSucceeded), }, }, nil) mockCloudformation.EXPECT().DeleteStackSet(gomock.Eq(&cloudformation.DeleteStackSetInput{ StackSetName: aws.String("foobar"), })).Return(&cloudformation.DeleteStackSetOutput{}, nil) err := stackSet.Remove() a.Nil(err) } func TestCloudformationStackSet_Remove_DeleteStackInstanceFailed(t *testing.T) { a := assert.New(t) ctrl := gomock.NewController(t) defer ctrl.Finish() mockCloudformation := mock_cloudformationiface.NewMockCloudFormationAPI(ctrl) stackSet := CloudFormationStackSet{ svc: mockCloudformation, stackSetSummary: &cloudformation.StackSetSummary{ StackSetName: aws.String("foobar"), }, } mockCloudformation.EXPECT().ListStackInstances(gomock.Eq(&cloudformation.ListStackInstancesInput{ StackSetName: aws.String("foobar"), })).Return(&cloudformation.ListStackInstancesOutput{ Summaries: []*cloudformation.StackInstanceSummary{ { Account: aws.String("a1"), Region: aws.String("r1"), }, }, }, nil) mockCloudformation.EXPECT().DeleteStackInstances(gomock.Eq(&cloudformation.DeleteStackInstancesInput{ StackSetName: aws.String("foobar"), Accounts: []*string{aws.String("a1")}, Regions: []*string{aws.String("r1")}, RetainStacks: aws.Bool(true), })).Return(&cloudformation.DeleteStackInstancesOutput{ OperationId: aws.String("o1"), }, nil) mockCloudformation.EXPECT().DescribeStackSetOperation(gomock.Eq(&cloudformation.DescribeStackSetOperationInput{ OperationId: aws.String("o1"), StackSetName: aws.String("foobar"), })).Return(&cloudformation.DescribeStackSetOperationOutput{ StackSetOperation: &cloudformation.StackSetOperation{ Status: aws.String(cloudformation.StackSetOperationResultStatusFailed), }, }, nil) err := stackSet.Remove() a.EqualError(err, "unable to delete stackSet=foobar operationId=o1 status=FAILED") } aws-nuke-2.16.0/resources/cloudformation-type.go000066400000000000000000000063261411137415400217070ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudformation" "github.com/aws/aws-sdk-go/service/cloudformation/cloudformationiface" "github.com/rebuy-de/aws-nuke/pkg/types" "github.com/sirupsen/logrus" ) func init() { register("CloudFormationType", ListCloudFormationTypes) } func ListCloudFormationTypes(sess *session.Session) ([]Resource, error) { svc := cloudformation.New(sess) params := &cloudformation.ListTypesInput{} resources := make([]Resource, 0) for { resp, err := svc.ListTypes(params) if err != nil { return nil, err } for _, typeSummary := range resp.TypeSummaries { resources = append(resources, &CloudFormationType{ svc: svc, typeSummary: typeSummary, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } type CloudFormationType struct { svc cloudformationiface.CloudFormationAPI typeSummary *cloudformation.TypeSummary } func (cfs *CloudFormationType) findAllVersionSummaries() ([]*cloudformation.TypeVersionSummary, error) { typeVersionSummaries := make([]*cloudformation.TypeVersionSummary, 0) page := 0 params := &cloudformation.ListTypeVersionsInput{ Arn: cfs.typeSummary.TypeArn, } for { logrus.Infof("CloudFormationType loading type versions arn=%s page=%d", *cfs.typeSummary.TypeArn, page) resp, err := cfs.svc.ListTypeVersions(params) if err != nil { return nil, err } typeVersionSummaries = append(typeVersionSummaries, resp.TypeVersionSummaries...) if resp.NextToken == nil { return typeVersionSummaries, nil } params.NextToken = resp.NextToken page = page + 1 } } func (cfs *CloudFormationType) Remove() error { typeVersionSummaries, loadErr := cfs.findAllVersionSummaries() if loadErr != nil { return loadErr } failed := false for _, typeVersionSummary := range typeVersionSummaries { if *typeVersionSummary.IsDefaultVersion { logrus.Infof("CloudFormationType ignoring default version type=%s version=%s", *cfs.typeSummary.TypeArn, *typeVersionSummary.VersionId) } else { logrus.Infof("CloudFormationType removing type=%s version=%s", *cfs.typeSummary.TypeArn, *typeVersionSummary.VersionId) if _, err := cfs.svc.DeregisterType(&cloudformation.DeregisterTypeInput{ VersionId: typeVersionSummary.VersionId, TypeName: typeVersionSummary.TypeName, Type: typeVersionSummary.Type, }); err != nil { logrus.Errorf("CloudFormationType failed removing type=%s version=%s type=%s arn=%s error=%s", *cfs.typeSummary.TypeName, *typeVersionSummary.VersionId, *typeVersionSummary.Type, *cfs.typeSummary.TypeArn, err.Error()) failed = true } } } if failed { return fmt.Errorf("Unable to remove all CloudFormationType versions arn=%s", *cfs.typeSummary.TypeArn) } _, err := cfs.svc.DeregisterType(&cloudformation.DeregisterTypeInput{ Arn: cfs.typeSummary.TypeArn, }) return err } func (cfs *CloudFormationType) Properties() types.Properties { properties := types.NewProperties() properties.Set("Name", cfs.typeSummary.TypeName) properties.Set("Type", cfs.typeSummary.Type) return properties } func (cfs *CloudFormationType) String() string { return *cfs.typeSummary.TypeArn } aws-nuke-2.16.0/resources/cloudformation-type_test.go000066400000000000000000000035401411137415400227410ustar00rootroot00000000000000package resources import ( "testing" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/cloudformation" "github.com/golang/mock/gomock" "github.com/rebuy-de/aws-nuke/mocks/mock_cloudformationiface" "github.com/stretchr/testify/assert" ) func TestCloudformationType_Remove(t *testing.T) { a := assert.New(t) ctrl := gomock.NewController(t) defer ctrl.Finish() mockCloudformation := mock_cloudformationiface.NewMockCloudFormationAPI(ctrl) cfnType := CloudFormationType{ svc: mockCloudformation, typeSummary: &cloudformation.TypeSummary{ TypeArn: aws.String("foobar"), }, } mockCloudformation.EXPECT().ListTypeVersions(gomock.Eq(&cloudformation.ListTypeVersionsInput{ Arn: aws.String("foobar"), })).Return(&cloudformation.ListTypeVersionsOutput{ TypeVersionSummaries: []*cloudformation.TypeVersionSummary{ { IsDefaultVersion: aws.Bool(true), VersionId: aws.String("1"), TypeName: aws.String("t1"), Type: aws.String("RESOURCE"), }, }, NextToken: aws.String("nextToken"), }, nil) mockCloudformation.EXPECT().ListTypeVersions(gomock.Eq(&cloudformation.ListTypeVersionsInput{ Arn: aws.String("foobar"), NextToken: aws.String("nextToken"), })).Return(&cloudformation.ListTypeVersionsOutput{ TypeVersionSummaries: []*cloudformation.TypeVersionSummary{ { IsDefaultVersion: aws.Bool(false), VersionId: aws.String("2"), TypeName: aws.String("t2"), Type: aws.String("RESOURCE"), }, }, }, nil) mockCloudformation.EXPECT().DeregisterType(&cloudformation.DeregisterTypeInput{ VersionId: aws.String("2"), TypeName: aws.String("t2"), Type: aws.String("RESOURCE"), }) mockCloudformation.EXPECT().DeregisterType(&cloudformation.DeregisterTypeInput{ Arn: aws.String("foobar"), }) err := cfnType.Remove() a.Nil(err) } aws-nuke-2.16.0/resources/cloudfront-distributiondeployments.go000066400000000000000000000042661411137415400250640ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudfront" ) type CloudFrontDistributionDeployment struct { svc *cloudfront.CloudFront distributionID *string eTag *string distributionConfig *cloudfront.DistributionConfig status string } func init() { register("CloudFrontDistributionDeployment", ListCloudFrontDistributionDeployments) } func ListCloudFrontDistributionDeployments(sess *session.Session) ([]Resource, error) { svc := cloudfront.New(sess) resources := []Resource{} distributions := []*cloudfront.DistributionSummary{} params := &cloudfront.ListDistributionsInput{ MaxItems: aws.Int64(25), } for { resp, err := svc.ListDistributions(params) if err != nil { return nil, err } for _, item := range resp.DistributionList.Items { distributions = append(distributions, item) } if *resp.DistributionList.IsTruncated == false { break } params.Marker = resp.DistributionList.NextMarker } for _, distribution := range distributions { params := &cloudfront.GetDistributionInput{ Id: distribution.Id, } resp, err := svc.GetDistribution(params) if err != nil { return nil, err } resources = append(resources, &CloudFrontDistributionDeployment{ svc: svc, distributionID: resp.Distribution.Id, eTag: resp.ETag, distributionConfig: resp.Distribution.DistributionConfig, status: UnPtrString(resp.Distribution.Status, "unknown"), }) } return resources, nil } func (f *CloudFrontDistributionDeployment) Remove() error { f.distributionConfig.Enabled = aws.Bool(false) _, err := f.svc.UpdateDistribution(&cloudfront.UpdateDistributionInput{ Id: f.distributionID, DistributionConfig: f.distributionConfig, IfMatch: f.eTag, }) return err } func (f *CloudFrontDistributionDeployment) Filter() error { if *f.distributionConfig.Enabled == false && f.status != "InProgress" { return fmt.Errorf("already disabled") } return nil } func (f *CloudFrontDistributionDeployment) String() string { return *f.distributionID } aws-nuke-2.16.0/resources/cloudfront-distributions.go000066400000000000000000000025431411137415400227570ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudfront" ) type CloudFrontDistribution struct { svc *cloudfront.CloudFront ID *string status *string } func init() { register("CloudFrontDistribution", ListCloudFrontDistributions) } func ListCloudFrontDistributions(sess *session.Session) ([]Resource, error) { svc := cloudfront.New(sess) resources := []Resource{} params := &cloudfront.ListDistributionsInput{ MaxItems: aws.Int64(25), } for { resp, err := svc.ListDistributions(params) if err != nil { return nil, err } for _, item := range resp.DistributionList.Items { resources = append(resources, &CloudFrontDistribution{ svc: svc, ID: item.Id, status: item.Status, }) } if *resp.DistributionList.IsTruncated == false { break } params.Marker = resp.DistributionList.NextMarker } return resources, nil } func (f *CloudFrontDistribution) Remove() error { // Get Existing eTag resp, err := f.svc.GetDistributionConfig(&cloudfront.GetDistributionConfigInput{ Id: f.ID, }) if err != nil { return err } _, err = f.svc.DeleteDistribution(&cloudfront.DeleteDistributionInput{ Id: f.ID, IfMatch: resp.ETag, }) return err } func (f *CloudFrontDistribution) String() string { return *f.ID } aws-nuke-2.16.0/resources/cloudfront-origin-access-identities.go000066400000000000000000000026071411137415400247430ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudfront" "github.com/rebuy-de/aws-nuke/pkg/types" ) type CloudFrontOriginAccessIdentity struct { svc *cloudfront.CloudFront ID *string } func init() { register("CloudFrontOriginAccessIdentity", ListCloudFrontOriginAccessIdentities) } func ListCloudFrontOriginAccessIdentities(sess *session.Session) ([]Resource, error) { svc := cloudfront.New(sess) resources := []Resource{} for { resp, err := svc.ListCloudFrontOriginAccessIdentities(nil) if err != nil { return nil, err } for _, item := range resp.CloudFrontOriginAccessIdentityList.Items { resources = append(resources,&CloudFrontOriginAccessIdentity{ svc: svc, ID: item.Id, }) } return resources, nil } } func (f *CloudFrontOriginAccessIdentity) Remove() error { resp, err := f.svc.GetCloudFrontOriginAccessIdentity(&cloudfront.GetCloudFrontOriginAccessIdentityInput{ Id: f.ID, }) if err != nil { return err } _, err = f.svc.DeleteCloudFrontOriginAccessIdentity(&cloudfront.DeleteCloudFrontOriginAccessIdentityInput{ Id: f.ID, IfMatch: resp.ETag, }) return err } func (f *CloudFrontOriginAccessIdentity) Properties() types.Properties { properties := types.NewProperties() properties.Set("ID", f.ID) return properties } aws-nuke-2.16.0/resources/cloudhsmv2-cluster.go000066400000000000000000000021241411137415400214400ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudhsmv2" ) type CloudHSMV2Cluster struct { svc *cloudhsmv2.CloudHSMV2 clusterID *string } func init() { register("CloudHSMV2Cluster", ListCloudHSMV2Clusters) } func ListCloudHSMV2Clusters(sess *session.Session) ([]Resource, error) { svc := cloudhsmv2.New(sess) resources := []Resource{} params := &cloudhsmv2.DescribeClustersInput{ MaxResults: aws.Int64(25), } for { resp, err := svc.DescribeClusters(params) if err != nil { return nil, err } for _, cluster := range resp.Clusters { resources = append(resources, &CloudHSMV2Cluster{ svc: svc, clusterID: cluster.ClusterId, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *CloudHSMV2Cluster) Remove() error { _, err := f.svc.DeleteCluster(&cloudhsmv2.DeleteClusterInput{ ClusterId: f.clusterID, }) return err } func (f *CloudHSMV2Cluster) String() string { return *f.clusterID } aws-nuke-2.16.0/resources/cloudhsmv2-clusterhsms.go000066400000000000000000000023151411137415400223350ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudhsmv2" ) type CloudHSMV2ClusterHSM struct { svc *cloudhsmv2.CloudHSMV2 clusterID *string hsmID *string } func init() { register("CloudHSMV2ClusterHSM", ListCloudHSMV2ClusterHSMs) } func ListCloudHSMV2ClusterHSMs(sess *session.Session) ([]Resource, error) { svc := cloudhsmv2.New(sess) resources := []Resource{} params := &cloudhsmv2.DescribeClustersInput{ MaxResults: aws.Int64(25), } for { resp, err := svc.DescribeClusters(params) if err != nil { return nil, err } for _, cluster := range resp.Clusters { for _, hsm := range cluster.Hsms { resources = append(resources, &CloudHSMV2ClusterHSM{ svc: svc, clusterID: hsm.ClusterId, hsmID: hsm.HsmId, }) } } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *CloudHSMV2ClusterHSM) Remove() error { _, err := f.svc.DeleteHsm(&cloudhsmv2.DeleteHsmInput{ ClusterId: f.clusterID, HsmId: f.hsmID, }) return err } func (f *CloudHSMV2ClusterHSM) String() string { return *f.hsmID } aws-nuke-2.16.0/resources/cloudsearch-domains.go000066400000000000000000000017061411137415400216240ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudsearch" ) type CloudSearchDomain struct { svc *cloudsearch.CloudSearch domainName *string } func init() { register("CloudSearchDomain", ListCloudSearchDomains) } func ListCloudSearchDomains(sess *session.Session) ([]Resource, error) { svc := cloudsearch.New(sess) params := &cloudsearch.DescribeDomainsInput{} resp, err := svc.DescribeDomains(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, domain := range resp.DomainStatusList { resources = append(resources, &CloudSearchDomain{ svc: svc, domainName: domain.DomainName, }) } return resources, nil } func (f *CloudSearchDomain) Remove() error { _, err := f.svc.DeleteDomain(&cloudsearch.DeleteDomainInput{ DomainName: f.domainName, }) return err } func (f *CloudSearchDomain) String() string { return *f.domainName } aws-nuke-2.16.0/resources/cloudtrail-trails.go000066400000000000000000000015261411137415400213360ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudtrail" ) func init() { register("CloudTrailTrail", ListCloudTrailTrails) } func ListCloudTrailTrails(sess *session.Session) ([]Resource, error) { svc := cloudtrail.New(sess) resp, err := svc.DescribeTrails(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, trail := range resp.TrailList { resources = append(resources, &CloudTrailTrail{ svc: svc, name: trail.Name, }) } return resources, nil } type CloudTrailTrail struct { svc *cloudtrail.CloudTrail name *string } func (trail *CloudTrailTrail) Remove() error { _, err := trail.svc.DeleteTrail(&cloudtrail.DeleteTrailInput{ Name: trail.name, }) return err } func (trail *CloudTrailTrail) String() string { return *trail.name } aws-nuke-2.16.0/resources/cloudwatch-alarms.go000066400000000000000000000021411411137415400213040ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudwatch" ) type CloudWatchAlarm struct { svc *cloudwatch.CloudWatch alarmName *string } func init() { register("CloudWatchAlarm", ListCloudWatchAlarms) } func ListCloudWatchAlarms(sess *session.Session) ([]Resource, error) { svc := cloudwatch.New(sess) resources := []Resource{} params := &cloudwatch.DescribeAlarmsInput{ MaxRecords: aws.Int64(100), } for { output, err := svc.DescribeAlarms(params) if err != nil { return nil, err } for _, metricAlarm := range output.MetricAlarms { resources = append(resources, &CloudWatchAlarm{ svc: svc, alarmName: metricAlarm.AlarmName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *CloudWatchAlarm) Remove() error { _, err := f.svc.DeleteAlarms(&cloudwatch.DeleteAlarmsInput{ AlarmNames: []*string{f.alarmName}, }) return err } func (f *CloudWatchAlarm) String() string { return *f.alarmName } aws-nuke-2.16.0/resources/cloudwatch-dashboards.go000066400000000000000000000021561411137415400221450ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudwatch" ) type CloudWatchDashboard struct { svc *cloudwatch.CloudWatch dashboardName *string } func init() { register("CloudWatchDashboard", ListCloudWatchDashboards) } func ListCloudWatchDashboards(sess *session.Session) ([]Resource, error) { svc := cloudwatch.New(sess) resources := []Resource{} params := &cloudwatch.ListDashboardsInput{} for { output, err := svc.ListDashboards(params) if err != nil { return nil, err } for _, dashboardEntry := range output.DashboardEntries { resources = append(resources, &CloudWatchDashboard{ svc: svc, dashboardName: dashboardEntry.DashboardName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *CloudWatchDashboard) Remove() error { _, err := f.svc.DeleteDashboards(&cloudwatch.DeleteDashboardsInput{ DashboardNames: []*string{f.dashboardName}, }) return err } func (f *CloudWatchDashboard) String() string { return *f.dashboardName } aws-nuke-2.16.0/resources/cloudwatchevents-rules.go000066400000000000000000000017401411137415400224100ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudwatchevents" ) func init() { register("CloudWatchEventsRule", ListCloudWatchEventsRules) } func ListCloudWatchEventsRules(sess *session.Session) ([]Resource, error) { svc := cloudwatchevents.New(sess) resp, err := svc.ListRules(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, rule := range resp.Rules { resources = append(resources, &CloudWatchEventsRule{ svc: svc, name: rule.Name, }) } return resources, nil } type CloudWatchEventsRule struct { svc *cloudwatchevents.CloudWatchEvents name *string } func (rule *CloudWatchEventsRule) Remove() error { _, err := rule.svc.DeleteRule(&cloudwatchevents.DeleteRuleInput{ Name: rule.name, Force: aws.Bool(true), }) return err } func (rule *CloudWatchEventsRule) String() string { return fmt.Sprintf("Rule: %s", *rule.name) } aws-nuke-2.16.0/resources/cloudwatchevents-targets.go000066400000000000000000000025401411137415400227260ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudwatchevents" ) func init() { register("CloudWatchEventsTarget", ListCloudWatchEventsTargets) } func ListCloudWatchEventsTargets(sess *session.Session) ([]Resource, error) { svc := cloudwatchevents.New(sess) resp, err := svc.ListRules(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, rule := range resp.Rules { targetResp, err := svc.ListTargetsByRule(&cloudwatchevents.ListTargetsByRuleInput{ Rule: rule.Name, }) if err != nil { return nil, err } for _, target := range targetResp.Targets { resources = append(resources, &CloudWatchEventsTarget{ svc: svc, ruleName: rule.Name, targetId: target.Id, }) } } return resources, nil } type CloudWatchEventsTarget struct { svc *cloudwatchevents.CloudWatchEvents targetId *string ruleName *string } func (target *CloudWatchEventsTarget) Remove() error { ids := []*string{target.targetId} _, err := target.svc.RemoveTargets(&cloudwatchevents.RemoveTargetsInput{ Ids: ids, Rule: target.ruleName, Force: aws.Bool(true), }) return err } func (target *CloudWatchEventsTarget) String() string { return fmt.Sprintf("Rule: %s Target ID: %s", *target.ruleName, *target.targetId) } aws-nuke-2.16.0/resources/cloudwatchlogs-destinations.go000066400000000000000000000023631411137415400234240ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudwatchlogs" ) type CloudWatchLogsDestination struct { svc *cloudwatchlogs.CloudWatchLogs destinationName *string } func init() { register("CloudWatchLogsDestination", ListCloudWatchLogsDestinations) } func ListCloudWatchLogsDestinations(sess *session.Session) ([]Resource, error) { svc := cloudwatchlogs.New(sess) resources := []Resource{} params := &cloudwatchlogs.DescribeDestinationsInput{ Limit: aws.Int64(50), } for { output, err := svc.DescribeDestinations(params) if err != nil { return nil, err } for _, destination := range output.Destinations { resources = append(resources, &CloudWatchLogsDestination{ svc: svc, destinationName: destination.DestinationName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *CloudWatchLogsDestination) Remove() error { _, err := f.svc.DeleteDestination(&cloudwatchlogs.DeleteDestinationInput{ DestinationName: f.destinationName, }) return err } func (f *CloudWatchLogsDestination) String() string { return *f.destinationName } aws-nuke-2.16.0/resources/cloudwatchlogs-loggroups.go000066400000000000000000000022611411137415400227360ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudwatchlogs" ) type CloudWatchLogsLogGroup struct { svc *cloudwatchlogs.CloudWatchLogs logGroupName *string } func init() { register("CloudWatchLogsLogGroup", ListCloudWatchLogsLogGroups) } func ListCloudWatchLogsLogGroups(sess *session.Session) ([]Resource, error) { svc := cloudwatchlogs.New(sess) resources := []Resource{} params := &cloudwatchlogs.DescribeLogGroupsInput{ Limit: aws.Int64(50), } for { output, err := svc.DescribeLogGroups(params) if err != nil { return nil, err } for _, logGroup := range output.LogGroups { resources = append(resources, &CloudWatchLogsLogGroup{ svc: svc, logGroupName: logGroup.LogGroupName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *CloudWatchLogsLogGroup) Remove() error { _, err := f.svc.DeleteLogGroup(&cloudwatchlogs.DeleteLogGroupInput{ LogGroupName: f.logGroupName, }) return err } func (f *CloudWatchLogsLogGroup) String() string { return *f.logGroupName } aws-nuke-2.16.0/resources/cloudwatchlogs-resourcepolicy.go000066400000000000000000000027071411137415400237710ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudwatchlogs" "github.com/rebuy-de/aws-nuke/pkg/types" ) type CloudWatchLogsResourcePolicy struct { svc *cloudwatchlogs.CloudWatchLogs policyName *string } func init() { register("CloudWatchLogsResourcePolicy", ListCloudWatchLogsResourcePolicies) } func ListCloudWatchLogsResourcePolicies(sess *session.Session) ([]Resource, error) { svc := cloudwatchlogs.New(sess) resources := []Resource{} params := &cloudwatchlogs.DescribeResourcePoliciesInput{ Limit: aws.Int64(50), } for { output, err := svc.DescribeResourcePolicies(params) if err != nil { return nil, err } for _, destination := range output.ResourcePolicies { resources = append(resources, &CloudWatchLogsResourcePolicy{ svc: svc, policyName: destination.PolicyName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (p *CloudWatchLogsResourcePolicy) Remove() error { _, err := p.svc.DeleteResourcePolicy(&cloudwatchlogs.DeleteResourcePolicyInput{ PolicyName: p.policyName, }) return err } func (p *CloudWatchLogsResourcePolicy) Properties() types.Properties { properties := types.NewProperties() properties.Set("Name", p.policyName) return properties } func (p *CloudWatchLogsResourcePolicy) String() string { return *p.policyName } aws-nuke-2.16.0/resources/codebuild-projects.go000066400000000000000000000033451411137415400214620ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/codebuild" "github.com/rebuy-de/aws-nuke/pkg/types" ) type CodeBuildProject struct { svc *codebuild.CodeBuild projectName *string tags map[string]*string } func init() { register("CodeBuildProject", ListCodeBuildProjects) } func GetTags(svc *codebuild.CodeBuild, project *string) map[string]*string { tags := make(map[string]*string) batchResult, _ := svc.BatchGetProjects(&codebuild.BatchGetProjectsInput{Names: []*string{project}}) for _, project := range batchResult.Projects { if len(project.Tags) > 0 { for _, v := range project.Tags { tags[*v.Key] = v.Value } return tags } } return nil } func ListCodeBuildProjects(sess *session.Session) ([]Resource, error) { svc := codebuild.New(sess) resources := []Resource{} params := &codebuild.ListProjectsInput{} for { resp, err := svc.ListProjects(params) if err != nil { return nil, err } for _, project := range resp.Projects { resources = append(resources, &CodeBuildProject{ svc: svc, projectName: project, tags: GetTags(svc, project), }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *CodeBuildProject) Remove() error { _, err := f.svc.DeleteProject(&codebuild.DeleteProjectInput{ Name: f.projectName, }) return err } func (f *CodeBuildProject) String() string { return *f.projectName } func (f *CodeBuildProject) Properties() types.Properties { properties := types.NewProperties() for key, tag := range f.tags { properties.SetTag(&key, tag) } properties. Set("ProjectName", f.projectName) return properties } aws-nuke-2.16.0/resources/codecommit-repositories.go000066400000000000000000000021431411137415400225440ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/codecommit" ) type CodeCommitRepository struct { svc *codecommit.CodeCommit repositoryName *string } func init() { register("CodeCommitRepository", ListCodeCommitRepositories) } func ListCodeCommitRepositories(sess *session.Session) ([]Resource, error) { svc := codecommit.New(sess) resources := []Resource{} params := &codecommit.ListRepositoriesInput{} for { resp, err := svc.ListRepositories(params) if err != nil { return nil, err } for _, repository := range resp.Repositories { resources = append(resources, &CodeCommitRepository{ svc: svc, repositoryName: repository.RepositoryName, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *CodeCommitRepository) Remove() error { _, err := f.svc.DeleteRepository(&codecommit.DeleteRepositoryInput{ RepositoryName: f.repositoryName, }) return err } func (f *CodeCommitRepository) String() string { return *f.repositoryName } aws-nuke-2.16.0/resources/codedeploy-applications.go000066400000000000000000000021441411137415400225100ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/codedeploy" ) type CodeDeployApplication struct { svc *codedeploy.CodeDeploy applicationName *string } func init() { register("CodeDeployApplication", ListCodeDeployApplications) } func ListCodeDeployApplications(sess *session.Session) ([]Resource, error) { svc := codedeploy.New(sess) resources := []Resource{} params := &codedeploy.ListApplicationsInput{} for { resp, err := svc.ListApplications(params) if err != nil { return nil, err } for _, application := range resp.Applications { resources = append(resources, &CodeDeployApplication{ svc: svc, applicationName: application, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *CodeDeployApplication) Remove() error { _, err := f.svc.DeleteApplication(&codedeploy.DeleteApplicationInput{ ApplicationName: f.applicationName, }) return err } func (f *CodeDeployApplication) String() string { return *f.applicationName } aws-nuke-2.16.0/resources/codepipeline-pipelines.go000066400000000000000000000020741411137415400223250ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/codepipeline" ) type CodePipelinePipeline struct { svc *codepipeline.CodePipeline pipelineName *string } func init() { register("CodePipelinePipeline", ListCodePipelinePipelines) } func ListCodePipelinePipelines(sess *session.Session) ([]Resource, error) { svc := codepipeline.New(sess) resources := []Resource{} params := &codepipeline.ListPipelinesInput{} for { resp, err := svc.ListPipelines(params) if err != nil { return nil, err } for _, pipeline := range resp.Pipelines { resources = append(resources, &CodePipelinePipeline{ svc: svc, pipelineName: pipeline.Name, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *CodePipelinePipeline) Remove() error { _, err := f.svc.DeletePipeline(&codepipeline.DeletePipelineInput{ Name: f.pipelineName, }) return err } func (f *CodePipelinePipeline) String() string { return *f.pipelineName } aws-nuke-2.16.0/resources/codestar-connections.go000066400000000000000000000031371411137415400220240ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/codestarconnections" "github.com/rebuy-de/aws-nuke/pkg/types" ) type CodeStarConnection struct { svc *codestarconnections.CodeStarConnections connectionARN *string connectionName *string providerType *string } func init() { register("CodeStarConnection", ListCodeStarConnections) } func ListCodeStarConnections(sess *session.Session) ([]Resource, error) { svc := codestarconnections.New(sess) resources := []Resource{} params := &codestarconnections.ListConnectionsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListConnections(params) if err != nil { return nil, err } for _, connection := range output.Connections { resources = append(resources, &CodeStarConnection{ svc: svc, connectionARN: connection.ConnectionArn, connectionName: connection.ConnectionName, providerType: connection.ProviderType, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *CodeStarConnection) Remove() error { _, err := f.svc.DeleteConnection(&codestarconnections.DeleteConnectionInput{ ConnectionArn: f.connectionARN, }) return err } func (f *CodeStarConnection) Properties() types.Properties { properties := types.NewProperties() properties. Set("Name", f.connectionName). Set("ProviderType", f.providerType) return properties } func (f *CodeStarConnection) String() string { return *f.connectionName } aws-nuke-2.16.0/resources/codestar-notifications.go000066400000000000000000000035421411137415400223530ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/codestarnotifications" "github.com/rebuy-de/aws-nuke/pkg/types" ) type CodeStarNotificationRule struct { svc *codestarnotifications.CodeStarNotifications id *string name *string arn *string tags map[string]*string } func init() { register("CodeStarNotificationRule", ListCodeStarNotificationRules) } func ListCodeStarNotificationRules(sess *session.Session) ([]Resource, error) { svc := codestarnotifications.New(sess) resources := []Resource{} params := &codestarnotifications.ListNotificationRulesInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListNotificationRules(params) if err != nil { return nil, err } for _, notification := range output.NotificationRules { descOutput, err := svc.DescribeNotificationRule(&codestarnotifications.DescribeNotificationRuleInput{ Arn: notification.Arn, }) if err != nil { return nil, err } resources = append(resources, &CodeStarNotificationRule{ svc: svc, id: notification.Id, name: descOutput.Name, arn: notification.Arn, tags: descOutput.Tags, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (cn *CodeStarNotificationRule) Remove() error { _, err := cn.svc.DeleteNotificationRule(&codestarnotifications.DeleteNotificationRuleInput{ Arn: cn.arn, }) return err } func (cn *CodeStarNotificationRule) String() string { return fmt.Sprintf("%s (%s)", *cn.id, *cn.name) } func (cn *CodeStarNotificationRule) Properties() types.Properties { properties := types.NewProperties() for key, tag := range cn.tags { properties.SetTag(&key, tag) } properties. Set("Name", cn.name). Set("ID", cn.id) return properties } aws-nuke-2.16.0/resources/codestar-projects.go000066400000000000000000000020161411137415400213260ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/codestar" ) type CodeStarProject struct { svc *codestar.CodeStar id *string } func init() { register("CodeStarProject", ListCodeStarProjects) } func ListCodeStarProjects(sess *session.Session) ([]Resource, error) { svc := codestar.New(sess) resources := []Resource{} params := &codestar.ListProjectsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListProjects(params) if err != nil { return nil, err } for _, project := range output.Projects { resources = append(resources, &CodeStarProject{ svc: svc, id: project.ProjectId, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *CodeStarProject) Remove() error { _, err := f.svc.DeleteProject(&codestar.DeleteProjectInput{ Id: f.id, }) return err } func (f *CodeStarProject) String() string { return *f.id } aws-nuke-2.16.0/resources/cognito-identity-providers.go000066400000000000000000000041621411137415400232030ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cognitoidentityprovider" "github.com/rebuy-de/aws-nuke/pkg/types" "github.com/sirupsen/logrus" ) type CognitoIdentityProvider struct { svc *cognitoidentityprovider.CognitoIdentityProvider name *string providerType *string userPoolName *string userPoolId *string } func init() { register("CognitoIdentityProvider", ListCognitoIdentityProviders) } func ListCognitoIdentityProviders(sess *session.Session) ([]Resource, error) { svc := cognitoidentityprovider.New(sess) userPools, poolErr := ListCognitoUserPools(sess) if poolErr != nil { return nil, poolErr } resources := []Resource{} for _, userPoolResource := range userPools { userPool, ok := userPoolResource.(*CognitoUserPool) if !ok { logrus.Errorf("Unable to case CognitoUserPool") continue } listParams := &cognitoidentityprovider.ListIdentityProvidersInput{ UserPoolId: userPool.id, MaxResults: aws.Int64(50), } for { output, err := svc.ListIdentityProviders(listParams) if err != nil { return nil, err } for _, provider := range output.Providers { resources = append(resources, &CognitoIdentityProvider{ svc: svc, name: provider.ProviderName, providerType: provider.ProviderType, userPoolName: userPool.name, userPoolId: userPool.id, }) } if output.NextToken == nil { break } listParams.NextToken = output.NextToken } } return resources, nil } func (p *CognitoIdentityProvider) Remove() error { _, err := p.svc.DeleteIdentityProvider(&cognitoidentityprovider.DeleteIdentityProviderInput{ UserPoolId: p.userPoolId, ProviderName: p.name, }) return err } func (p *CognitoIdentityProvider) Properties() types.Properties { properties := types.NewProperties() properties.Set("Type", p.providerType) properties.Set("UserPoolName", p.userPoolName) properties.Set("Name", p.name) return properties } func (p *CognitoIdentityProvider) String() string { return *p.userPoolName + " -> " + *p.name } aws-nuke-2.16.0/resources/cognito-identitypools.go000066400000000000000000000022541411137415400222450ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cognitoidentity" ) type CognitoIdentityPool struct { svc *cognitoidentity.CognitoIdentity name *string id *string } func init() { register("CognitoIdentityPool", ListCognitoIdentityPools) } func ListCognitoIdentityPools(sess *session.Session) ([]Resource, error) { svc := cognitoidentity.New(sess) resources := []Resource{} params := &cognitoidentity.ListIdentityPoolsInput{ MaxResults: aws.Int64(50), } for { output, err := svc.ListIdentityPools(params) if err != nil { return nil, err } for _, pool := range output.IdentityPools { resources = append(resources, &CognitoIdentityPool{ svc: svc, name: pool.IdentityPoolName, id: pool.IdentityPoolId, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *CognitoIdentityPool) Remove() error { _, err := f.svc.DeleteIdentityPool(&cognitoidentity.DeleteIdentityPoolInput{ IdentityPoolId: f.id, }) return err } func (f *CognitoIdentityPool) String() string { return *f.name } aws-nuke-2.16.0/resources/cognito-userpool-clients.go000066400000000000000000000041021411137415400226400ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cognitoidentityprovider" "github.com/rebuy-de/aws-nuke/pkg/types" "github.com/sirupsen/logrus" ) type CognitoUserPoolClient struct { svc *cognitoidentityprovider.CognitoIdentityProvider name *string id *string userPoolName *string userPoolId *string } func init() { register("CognitoUserPoolClient", ListCognitoUserPoolClients) } func ListCognitoUserPoolClients(sess *session.Session) ([]Resource, error) { svc := cognitoidentityprovider.New(sess) userPools, poolErr := ListCognitoUserPools(sess) if poolErr != nil { return nil, poolErr } resources := []Resource{} for _, userPoolResource := range userPools { userPool, ok := userPoolResource.(*CognitoUserPool) if !ok { logrus.Errorf("Unable to case CognitoUserPool") continue } listParams := &cognitoidentityprovider.ListUserPoolClientsInput{ UserPoolId: userPool.id, MaxResults: aws.Int64(50), } for { output, err := svc.ListUserPoolClients(listParams) if err != nil { return nil, err } for _, client := range output.UserPoolClients { resources = append(resources, &CognitoUserPoolClient{ svc: svc, id: client.ClientId, name: client.ClientName, userPoolName: userPool.name, userPoolId: userPool.id, }) } if output.NextToken == nil { break } listParams.NextToken = output.NextToken } } return resources, nil } func (p *CognitoUserPoolClient) Remove() error { _, err := p.svc.DeleteUserPoolClient(&cognitoidentityprovider.DeleteUserPoolClientInput{ ClientId: p.id, UserPoolId: p.userPoolId, }) return err } func (p *CognitoUserPoolClient) Properties() types.Properties { properties := types.NewProperties() properties.Set("ID", p.id) properties.Set("Name", p.name) properties.Set("UserPoolName", p.userPoolName) return properties } func (p *CognitoUserPoolClient) String() string { return *p.userPoolName + " -> " + *p.name } aws-nuke-2.16.0/resources/cognito-userpool-domains.go000066400000000000000000000032411411137415400226340ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cognitoidentityprovider" "github.com/sirupsen/logrus" ) type CognitoUserPoolDomain struct { svc *cognitoidentityprovider.CognitoIdentityProvider name *string userPoolName *string userPoolId *string } func init() { register("CognitoUserPoolDomain", ListCognitoUserPoolDomains) } func ListCognitoUserPoolDomains(sess *session.Session) ([]Resource, error) { svc := cognitoidentityprovider.New(sess) userPools, poolErr := ListCognitoUserPools(sess) if poolErr != nil { return nil, poolErr } resources := make([]Resource, 0) for _, userPoolResource := range userPools { userPool, ok := userPoolResource.(*CognitoUserPool) if !ok { logrus.Errorf("Unable to case CognitoUserPool") continue } describeParams := &cognitoidentityprovider.DescribeUserPoolInput{ UserPoolId: userPool.id, } userPoolDetails, err := svc.DescribeUserPool(describeParams) if err != nil { return nil, err } if userPoolDetails.UserPool.Domain == nil { // No domain on this user pool so skip continue } resources = append(resources, &CognitoUserPoolDomain{ svc: svc, name: userPoolDetails.UserPool.Domain, userPoolName: userPool.name, userPoolId: userPool.id, }) } return resources, nil } func (f *CognitoUserPoolDomain) Remove() error { params := &cognitoidentityprovider.DeleteUserPoolDomainInput{ Domain: f.name, UserPoolId: f.userPoolId, } _, err := f.svc.DeleteUserPoolDomain(params) return err } func (f *CognitoUserPoolDomain) String() string { return *f.userPoolName + " -> " + *f.name } aws-nuke-2.16.0/resources/cognito-userpools.go000066400000000000000000000022201411137415400213630ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cognitoidentityprovider" ) type CognitoUserPool struct { svc *cognitoidentityprovider.CognitoIdentityProvider name *string id *string } func init() { register("CognitoUserPool", ListCognitoUserPools) } func ListCognitoUserPools(sess *session.Session) ([]Resource, error) { svc := cognitoidentityprovider.New(sess) resources := []Resource{} params := &cognitoidentityprovider.ListUserPoolsInput{ MaxResults: aws.Int64(50), } for { output, err := svc.ListUserPools(params) if err != nil { return nil, err } for _, pool := range output.UserPools { resources = append(resources, &CognitoUserPool{ svc: svc, name: pool.Name, id: pool.Id, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *CognitoUserPool) Remove() error { _, err := f.svc.DeleteUserPool(&cognitoidentityprovider.DeleteUserPoolInput{ UserPoolId: f.id, }) return err } func (f *CognitoUserPool) String() string { return *f.name } aws-nuke-2.16.0/resources/comprehend_document_classifier.go000066400000000000000000000050411411137415400241220ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/comprehend" "github.com/rebuy-de/aws-nuke/pkg/types" "github.com/sirupsen/logrus" ) func init() { register("ComprehendDocumentClassifier", ListComprehendDocumentClassifiers) } func ListComprehendDocumentClassifiers(sess *session.Session) ([]Resource, error) { svc := comprehend.New(sess) params := &comprehend.ListDocumentClassifiersInput{} resources := make([]Resource, 0) for { resp, err := svc.ListDocumentClassifiers(params) if err != nil { return nil, err } for _, documentClassifier := range resp.DocumentClassifierPropertiesList { resources = append(resources, &ComprehendDocumentClassifier{ svc: svc, documentClassifier: documentClassifier, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } type ComprehendDocumentClassifier struct { svc *comprehend.Comprehend documentClassifier *comprehend.DocumentClassifierProperties } func (ce *ComprehendDocumentClassifier) Remove() error { switch *ce.documentClassifier.Status { case "IN_ERROR": fallthrough case "TRAINED": { logrus.Infof("ComprehendDocumentClassifier deleteDocumentClassifier arn=%s status=%s", *ce.documentClassifier.DocumentClassifierArn, *ce.documentClassifier.Status) _, err := ce.svc.DeleteDocumentClassifier(&comprehend.DeleteDocumentClassifierInput{ DocumentClassifierArn: ce.documentClassifier.DocumentClassifierArn, }) return err } case "SUBMITTED": fallthrough case "TRAINING": { logrus.Infof("ComprehendDocumentClassifier stopTrainingDocumentClassifier arn=%s status=%s", *ce.documentClassifier.DocumentClassifierArn, *ce.documentClassifier.Status) _, err := ce.svc.StopTrainingDocumentClassifier(&comprehend.StopTrainingDocumentClassifierInput{ DocumentClassifierArn: ce.documentClassifier.DocumentClassifierArn, }) return err } default: { logrus.Infof("ComprehendDocumentClassifier already deleting arn=%s status=%s", *ce.documentClassifier.DocumentClassifierArn, *ce.documentClassifier.Status) return nil } } } func (ce *ComprehendDocumentClassifier) Properties() types.Properties { properties := types.NewProperties() properties.Set("LanguageCode", ce.documentClassifier.LanguageCode) properties.Set("DocumentClassifierArn", ce.documentClassifier.DocumentClassifierArn) return properties } func (ce *ComprehendDocumentClassifier) String() string { return *ce.documentClassifier.DocumentClassifierArn } aws-nuke-2.16.0/resources/comprehend_dominant_language_detection_job.go000066400000000000000000000034351411137415400264510ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/comprehend" "github.com/rebuy-de/aws-nuke/pkg/types" ) func init() { register("ComprehendDominantLanguageDetectionJob", ListComprehendDominantLanguageDetectionJobs) } func ListComprehendDominantLanguageDetectionJobs(sess *session.Session) ([]Resource, error) { svc := comprehend.New(sess) params := &comprehend.ListDominantLanguageDetectionJobsInput{} resources := make([]Resource, 0) for { resp, err := svc.ListDominantLanguageDetectionJobs(params) if err != nil { return nil, err } for _, dominantLanguageDetectionJob := range resp.DominantLanguageDetectionJobPropertiesList { resources = append(resources, &ComprehendDominantLanguageDetectionJob{ svc: svc, dominantLanguageDetectionJob: dominantLanguageDetectionJob, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } type ComprehendDominantLanguageDetectionJob struct { svc *comprehend.Comprehend dominantLanguageDetectionJob *comprehend.DominantLanguageDetectionJobProperties } func (ce *ComprehendDominantLanguageDetectionJob) Remove() error { _, err := ce.svc.StopDominantLanguageDetectionJob(&comprehend.StopDominantLanguageDetectionJobInput{ JobId: ce.dominantLanguageDetectionJob.JobId, }) return err } func (ce *ComprehendDominantLanguageDetectionJob) Properties() types.Properties { properties := types.NewProperties() properties.Set("JobName", ce.dominantLanguageDetectionJob.JobName) properties.Set("JobId", ce.dominantLanguageDetectionJob.JobId) return properties } func (ce *ComprehendDominantLanguageDetectionJob) String() string { return *ce.dominantLanguageDetectionJob.JobName } aws-nuke-2.16.0/resources/comprehend_endpoint.go000066400000000000000000000025371411137415400217270ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/comprehend" "github.com/rebuy-de/aws-nuke/pkg/types" ) func init() { register("ComprehendEndpoint", ListComprehendEndpoints) } func ListComprehendEndpoints(sess *session.Session) ([]Resource, error) { svc := comprehend.New(sess) params := &comprehend.ListEndpointsInput{} resources := make([]Resource, 0) for { resp, err := svc.ListEndpoints(params) if err != nil { return nil, err } for _, endpoint := range resp.EndpointPropertiesList { resources = append(resources, &ComprehendEndpoint{ svc: svc, endpoint: endpoint, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } type ComprehendEndpoint struct { svc *comprehend.Comprehend endpoint *comprehend.EndpointProperties } func (ce *ComprehendEndpoint) Remove() error { _, err := ce.svc.DeleteEndpoint(&comprehend.DeleteEndpointInput{ EndpointArn: ce.endpoint.EndpointArn, }) return err } func (ce *ComprehendEndpoint) Properties() types.Properties { properties := types.NewProperties() properties.Set("EndpointArn", ce.endpoint.EndpointArn) properties.Set("ModelArn", ce.endpoint.ModelArn) return properties } func (ce *ComprehendEndpoint) String() string { return *ce.endpoint.EndpointArn } aws-nuke-2.16.0/resources/comprehend_entities_detection_job.go000066400000000000000000000033561411137415400246230ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/comprehend" "github.com/rebuy-de/aws-nuke/pkg/types" ) func init() { register("ComprehendEntitiesDetectionJob", ListComprehendEntitiesDetectionJobs) } func ListComprehendEntitiesDetectionJobs(sess *session.Session) ([]Resource, error) { svc := comprehend.New(sess) params := &comprehend.ListEntitiesDetectionJobsInput{} resources := make([]Resource, 0) for { resp, err := svc.ListEntitiesDetectionJobs(params) if err != nil { return nil, err } for _, entitiesDetectionJob := range resp.EntitiesDetectionJobPropertiesList { if *entitiesDetectionJob.JobStatus == "STOPPED" { // if the job has already been stopped, do not try to delete it again continue } resources = append(resources, &ComprehendEntitiesDetectionJob{ svc: svc, entitiesDetectionJob: entitiesDetectionJob, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } type ComprehendEntitiesDetectionJob struct { svc *comprehend.Comprehend entitiesDetectionJob *comprehend.EntitiesDetectionJobProperties } func (ce *ComprehendEntitiesDetectionJob) Remove() error { _, err := ce.svc.StopEntitiesDetectionJob(&comprehend.StopEntitiesDetectionJobInput{ JobId: ce.entitiesDetectionJob.JobId, }) return err } func (ce *ComprehendEntitiesDetectionJob) Properties() types.Properties { properties := types.NewProperties() properties.Set("JobName", ce.entitiesDetectionJob.JobName) properties.Set("JobId", ce.entitiesDetectionJob.JobId) return properties } func (ce *ComprehendEntitiesDetectionJob) String() string { return *ce.entitiesDetectionJob.JobName } aws-nuke-2.16.0/resources/comprehend_entity_recognizer.go000066400000000000000000000046771411137415400236610ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/comprehend" "github.com/rebuy-de/aws-nuke/pkg/types" "github.com/sirupsen/logrus" ) func init() { register("ComprehendEntityRecognizer", ListComprehendEntityRecognizers) } func ListComprehendEntityRecognizers(sess *session.Session) ([]Resource, error) { svc := comprehend.New(sess) params := &comprehend.ListEntityRecognizersInput{} resources := make([]Resource, 0) for { resp, err := svc.ListEntityRecognizers(params) if err != nil { return nil, err } for _, entityRecognizer := range resp.EntityRecognizerPropertiesList { resources = append(resources, &ComprehendEntityRecognizer{ svc: svc, entityRecognizer: entityRecognizer, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } type ComprehendEntityRecognizer struct { svc *comprehend.Comprehend entityRecognizer *comprehend.EntityRecognizerProperties } func (ce *ComprehendEntityRecognizer) Remove() error { switch *ce.entityRecognizer.Status { case "IN_ERROR": fallthrough case "TRAINED": { logrus.Infof("ComprehendEntityRecognizer deleteEntityRecognizer arn=%s status=%s", *ce.entityRecognizer.EntityRecognizerArn, *ce.entityRecognizer.Status) _, err := ce.svc.DeleteEntityRecognizer(&comprehend.DeleteEntityRecognizerInput{ EntityRecognizerArn: ce.entityRecognizer.EntityRecognizerArn, }) return err } case "SUBMITTED": fallthrough case "TRAINING": { logrus.Infof("ComprehendEntityRecognizer stopTrainingEntityRecognizer arn=%s status=%s", *ce.entityRecognizer.EntityRecognizerArn, *ce.entityRecognizer.Status) _, err := ce.svc.StopTrainingEntityRecognizer(&comprehend.StopTrainingEntityRecognizerInput{ EntityRecognizerArn: ce.entityRecognizer.EntityRecognizerArn, }) return err } default: { logrus.Infof("ComprehendEntityRecognizer already deleting arn=%s status=%s", *ce.entityRecognizer.EntityRecognizerArn, *ce.entityRecognizer.Status) return nil } } } func (ce *ComprehendEntityRecognizer) Properties() types.Properties { properties := types.NewProperties() properties.Set("LanguageCode", ce.entityRecognizer.LanguageCode) properties.Set("EntityRecognizerArn", ce.entityRecognizer.EntityRecognizerArn) return properties } func (ce *ComprehendEntityRecognizer) String() string { return *ce.entityRecognizer.EntityRecognizerArn } aws-nuke-2.16.0/resources/comprehend_key_phrases_detection_job.go000066400000000000000000000032151411137415400253060ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/comprehend" "github.com/rebuy-de/aws-nuke/pkg/types" ) func init() { register("ComprehendKeyPhrasesDetectionJob", ListComprehendKeyPhrasesDetectionJobs) } func ListComprehendKeyPhrasesDetectionJobs(sess *session.Session) ([]Resource, error) { svc := comprehend.New(sess) params := &comprehend.ListKeyPhrasesDetectionJobsInput{} resources := make([]Resource, 0) for { resp, err := svc.ListKeyPhrasesDetectionJobs(params) if err != nil { return nil, err } for _, keyPhrasesDetectionJob := range resp.KeyPhrasesDetectionJobPropertiesList { resources = append(resources, &ComprehendKeyPhrasesDetectionJob{ svc: svc, keyPhrasesDetectionJob: keyPhrasesDetectionJob, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } type ComprehendKeyPhrasesDetectionJob struct { svc *comprehend.Comprehend keyPhrasesDetectionJob *comprehend.KeyPhrasesDetectionJobProperties } func (ce *ComprehendKeyPhrasesDetectionJob) Remove() error { _, err := ce.svc.StopKeyPhrasesDetectionJob(&comprehend.StopKeyPhrasesDetectionJobInput{ JobId: ce.keyPhrasesDetectionJob.JobId, }) return err } func (ce *ComprehendKeyPhrasesDetectionJob) Properties() types.Properties { properties := types.NewProperties() properties.Set("JobName", ce.keyPhrasesDetectionJob.JobName) properties.Set("JobId", ce.keyPhrasesDetectionJob.JobId) return properties } func (ce *ComprehendKeyPhrasesDetectionJob) String() string { return *ce.keyPhrasesDetectionJob.JobName } aws-nuke-2.16.0/resources/comprehend_sentiment_detection_job.go000066400000000000000000000031651411137415400250030ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/comprehend" "github.com/rebuy-de/aws-nuke/pkg/types" ) func init() { register("ComprehendSentimentDetectionJob", ListComprehendSentimentDetectionJobs) } func ListComprehendSentimentDetectionJobs(sess *session.Session) ([]Resource, error) { svc := comprehend.New(sess) params := &comprehend.ListSentimentDetectionJobsInput{} resources := make([]Resource, 0) for { resp, err := svc.ListSentimentDetectionJobs(params) if err != nil { return nil, err } for _, sentimentDetectionJob := range resp.SentimentDetectionJobPropertiesList { resources = append(resources, &ComprehendSentimentDetectionJob{ svc: svc, sentimentDetectionJob: sentimentDetectionJob, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } type ComprehendSentimentDetectionJob struct { svc *comprehend.Comprehend sentimentDetectionJob *comprehend.SentimentDetectionJobProperties } func (ce *ComprehendSentimentDetectionJob) Remove() error { _, err := ce.svc.StopSentimentDetectionJob(&comprehend.StopSentimentDetectionJobInput{ JobId: ce.sentimentDetectionJob.JobId, }) return err } func (ce *ComprehendSentimentDetectionJob) Properties() types.Properties { properties := types.NewProperties() properties.Set("JobName", ce.sentimentDetectionJob.JobName) properties.Set("JobId", ce.sentimentDetectionJob.JobId) return properties } func (ce *ComprehendSentimentDetectionJob) String() string { return *ce.sentimentDetectionJob.JobName } aws-nuke-2.16.0/resources/configservice-configrules.go000066400000000000000000000022251411137415400230410ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/configservice" ) type ConfigServiceConfigRule struct { svc *configservice.ConfigService configRuleName *string } func init() { register("ConfigServiceConfigRule", ListConfigServiceConfigRules) } func ListConfigServiceConfigRules(sess *session.Session) ([]Resource, error) { svc := configservice.New(sess) resources := []Resource{} params := &configservice.DescribeConfigRulesInput{} for { output, err := svc.DescribeConfigRules(params) if err != nil { return nil, err } for _, configRule := range output.ConfigRules { resources = append(resources, &ConfigServiceConfigRule{ svc: svc, configRuleName: configRule.ConfigRuleName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *ConfigServiceConfigRule) Remove() error { _, err := f.svc.DeleteConfigRule(&configservice.DeleteConfigRuleInput{ ConfigRuleName: f.configRuleName, }) return err } func (f *ConfigServiceConfigRule) String() string { return *f.configRuleName } aws-nuke-2.16.0/resources/configservice-configurationrecorders.go000066400000000000000000000023661411137415400253070ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/configservice" ) type ConfigServiceConfigurationRecorder struct { svc *configservice.ConfigService configurationRecorderName *string } func init() { register("ConfigServiceConfigurationRecorder", ListConfigServiceConfigurationRecorders) } func ListConfigServiceConfigurationRecorders(sess *session.Session) ([]Resource, error) { svc := configservice.New(sess) params := &configservice.DescribeConfigurationRecordersInput{} resp, err := svc.DescribeConfigurationRecorders(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, configurationRecorder := range resp.ConfigurationRecorders { resources = append(resources, &ConfigServiceConfigurationRecorder{ svc: svc, configurationRecorderName: configurationRecorder.Name, }) } return resources, nil } func (f *ConfigServiceConfigurationRecorder) Remove() error { _, err := f.svc.DeleteConfigurationRecorder(&configservice.DeleteConfigurationRecorderInput{ ConfigurationRecorderName: f.configurationRecorderName, }) return err } func (f *ConfigServiceConfigurationRecorder) String() string { return *f.configurationRecorderName } aws-nuke-2.16.0/resources/configservice-deliverychannels.go000066400000000000000000000022161411137415400240600ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/configservice" ) type ConfigServiceDeliveryChannel struct { svc *configservice.ConfigService deliveryChannelName *string } func init() { register("ConfigServiceDeliveryChannel", ListConfigServiceDeliveryChannels) } func ListConfigServiceDeliveryChannels(sess *session.Session) ([]Resource, error) { svc := configservice.New(sess) params := &configservice.DescribeDeliveryChannelsInput{} resp, err := svc.DescribeDeliveryChannels(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, deliveryChannel := range resp.DeliveryChannels { resources = append(resources, &ConfigServiceDeliveryChannel{ svc: svc, deliveryChannelName: deliveryChannel.Name, }) } return resources, nil } func (f *ConfigServiceDeliveryChannel) Remove() error { _, err := f.svc.DeleteDeliveryChannel(&configservice.DeleteDeliveryChannelInput{ DeliveryChannelName: f.deliveryChannelName, }) return err } func (f *ConfigServiceDeliveryChannel) String() string { return *f.deliveryChannelName } aws-nuke-2.16.0/resources/databasemigrationservice-certificates.go000066400000000000000000000024371411137415400254040ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/databasemigrationservice" ) type DatabaseMigrationServiceCertificate struct { svc *databasemigrationservice.DatabaseMigrationService ARN *string } func init() { register("DatabaseMigrationServiceCertificate", ListDatabaseMigrationServiceCertificates) } func ListDatabaseMigrationServiceCertificates(sess *session.Session) ([]Resource, error) { svc := databasemigrationservice.New(sess) resources := []Resource{} params := &databasemigrationservice.DescribeCertificatesInput{ MaxRecords: aws.Int64(100), } for { output, err := svc.DescribeCertificates(params) if err != nil { return nil, err } for _, certificate := range output.Certificates { resources = append(resources, &DatabaseMigrationServiceCertificate{ svc: svc, ARN: certificate.CertificateArn, }) } if output.Marker == nil { break } params.Marker = output.Marker } return resources, nil } func (f *DatabaseMigrationServiceCertificate) Remove() error { _, err := f.svc.DeleteEndpoint(&databasemigrationservice.DeleteEndpointInput{ EndpointArn: f.ARN, }) return err } func (f *DatabaseMigrationServiceCertificate) String() string { return *f.ARN } aws-nuke-2.16.0/resources/databasemigrationservice-endpoints.go000066400000000000000000000023701411137415400247360ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/databasemigrationservice" ) type DatabaseMigrationServiceEndpoint struct { svc *databasemigrationservice.DatabaseMigrationService ARN *string } func init() { register("DatabaseMigrationServiceEndpoint", ListDatabaseMigrationServiceEndpoints) } func ListDatabaseMigrationServiceEndpoints(sess *session.Session) ([]Resource, error) { svc := databasemigrationservice.New(sess) resources := []Resource{} params := &databasemigrationservice.DescribeEndpointsInput{ MaxRecords: aws.Int64(100), } for { output, err := svc.DescribeEndpoints(params) if err != nil { return nil, err } for _, endpoint := range output.Endpoints { resources = append(resources, &DatabaseMigrationServiceEndpoint{ svc: svc, ARN: endpoint.EndpointArn, }) } if output.Marker == nil { break } params.Marker = output.Marker } return resources, nil } func (f *DatabaseMigrationServiceEndpoint) Remove() error { _, err := f.svc.DeleteEndpoint(&databasemigrationservice.DeleteEndpointInput{ EndpointArn: f.ARN, }) return err } func (f *DatabaseMigrationServiceEndpoint) String() string { return *f.ARN } aws-nuke-2.16.0/resources/databasemigrationservice-eventsubscriptions.go000066400000000000000000000027241411137415400267070ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/databasemigrationservice" ) type DatabaseMigrationServiceEventSubscription struct { svc *databasemigrationservice.DatabaseMigrationService subscriptionName *string } func init() { register("DatabaseMigrationServiceEventSubscription", ListDatabaseMigrationServiceEventSubscriptions) } func ListDatabaseMigrationServiceEventSubscriptions(sess *session.Session) ([]Resource, error) { svc := databasemigrationservice.New(sess) resources := []Resource{} params := &databasemigrationservice.DescribeEventSubscriptionsInput{ MaxRecords: aws.Int64(100), } for { output, err := svc.DescribeEventSubscriptions(params) if err != nil { return nil, err } for _, eventSubscription := range output.EventSubscriptionsList { resources = append(resources, &DatabaseMigrationServiceEventSubscription{ svc: svc, subscriptionName: eventSubscription.CustSubscriptionId, }) } if output.Marker == nil { break } params.Marker = output.Marker } return resources, nil } func (f *DatabaseMigrationServiceEventSubscription) Remove() error { _, err := f.svc.DeleteEventSubscription(&databasemigrationservice.DeleteEventSubscriptionInput{ SubscriptionName: f.subscriptionName, }) return err } func (f *DatabaseMigrationServiceEventSubscription) String() string { return *f.subscriptionName } aws-nuke-2.16.0/resources/databasemigrationservice-replicationinstances.go000066400000000000000000000026501411137415400271550ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/databasemigrationservice" ) type DatabaseMigrationServiceReplicationInstance struct { svc *databasemigrationservice.DatabaseMigrationService ARN *string } func init() { register("DatabaseMigrationServiceReplicationInstance", ListDatabaseMigrationServiceReplicationInstances) } func ListDatabaseMigrationServiceReplicationInstances(sess *session.Session) ([]Resource, error) { svc := databasemigrationservice.New(sess) resources := []Resource{} params := &databasemigrationservice.DescribeReplicationInstancesInput{ MaxRecords: aws.Int64(100), } for { output, err := svc.DescribeReplicationInstances(params) if err != nil { return nil, err } for _, replicationInstance := range output.ReplicationInstances { resources = append(resources, &DatabaseMigrationServiceReplicationInstance{ svc: svc, ARN: replicationInstance.ReplicationInstanceArn, }) } if output.Marker == nil { break } params.Marker = output.Marker } return resources, nil } func (f *DatabaseMigrationServiceReplicationInstance) Remove() error { _, err := f.svc.DeleteReplicationInstance(&databasemigrationservice.DeleteReplicationInstanceInput{ ReplicationInstanceArn: f.ARN, }) return err } func (f *DatabaseMigrationServiceReplicationInstance) String() string { return *f.ARN } aws-nuke-2.16.0/resources/databasemigrationservice-replicationtasks.go000066400000000000000000000025501411137415400263120ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/databasemigrationservice" ) type DatabaseMigrationServiceReplicationTask struct { svc *databasemigrationservice.DatabaseMigrationService ARN *string } func init() { register("DatabaseMigrationServiceReplicationTask", ListDatabaseMigrationServiceReplicationTasks) } func ListDatabaseMigrationServiceReplicationTasks(sess *session.Session) ([]Resource, error) { svc := databasemigrationservice.New(sess) resources := []Resource{} params := &databasemigrationservice.DescribeReplicationTasksInput{ MaxRecords: aws.Int64(100), } for { output, err := svc.DescribeReplicationTasks(params) if err != nil { return nil, err } for _, replicationTask := range output.ReplicationTasks { resources = append(resources, &DatabaseMigrationServiceReplicationTask{ svc: svc, ARN: replicationTask.ReplicationTaskArn, }) } if output.Marker == nil { break } params.Marker = output.Marker } return resources, nil } func (f *DatabaseMigrationServiceReplicationTask) Remove() error { _, err := f.svc.DeleteReplicationTask(&databasemigrationservice.DeleteReplicationTaskInput{ ReplicationTaskArn: f.ARN, }) return err } func (f *DatabaseMigrationServiceReplicationTask) String() string { return *f.ARN } aws-nuke-2.16.0/resources/databasemigrationservice-subnetgroups.go000066400000000000000000000026271411137415400255000ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/databasemigrationservice" ) type DatabaseMigrationServiceSubnetGroup struct { svc *databasemigrationservice.DatabaseMigrationService ID *string } func init() { register("DatabaseMigrationServiceSubnetGroup", ListDatabaseMigrationServiceSubnetGroups) } func ListDatabaseMigrationServiceSubnetGroups(sess *session.Session) ([]Resource, error) { svc := databasemigrationservice.New(sess) resources := []Resource{} params := &databasemigrationservice.DescribeReplicationSubnetGroupsInput{ MaxRecords: aws.Int64(100), } for { output, err := svc.DescribeReplicationSubnetGroups(params) if err != nil { return nil, err } for _, replicationSubnetGroup := range output.ReplicationSubnetGroups { resources = append(resources, &DatabaseMigrationServiceSubnetGroup{ svc: svc, ID: replicationSubnetGroup.ReplicationSubnetGroupIdentifier, }) } if output.Marker == nil { break } params.Marker = output.Marker } return resources, nil } func (f *DatabaseMigrationServiceSubnetGroup) Remove() error { _, err := f.svc.DeleteReplicationSubnetGroup(&databasemigrationservice.DeleteReplicationSubnetGroupInput{ ReplicationSubnetGroupIdentifier: f.ID, }) return err } func (f *DatabaseMigrationServiceSubnetGroup) String() string { return *f.ID } aws-nuke-2.16.0/resources/datapipeline-pipelines.go000066400000000000000000000020601411137415400223170ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/datapipeline" ) type DataPipelinePipeline struct { svc *datapipeline.DataPipeline pipelineID *string } func init() { register("DataPipelinePipeline", ListDataPipelinePipelines) } func ListDataPipelinePipelines(sess *session.Session) ([]Resource, error) { svc := datapipeline.New(sess) resources := []Resource{} params := &datapipeline.ListPipelinesInput{} for { resp, err := svc.ListPipelines(params) if err != nil { return nil, err } for _, pipeline := range resp.PipelineIdList { resources = append(resources, &DataPipelinePipeline{ svc: svc, pipelineID: pipeline.Id, }) } if resp.Marker == nil { break } params.Marker = resp.Marker } return resources, nil } func (f *DataPipelinePipeline) Remove() error { _, err := f.svc.DeletePipeline(&datapipeline.DeletePipelineInput{ PipelineId: f.pipelineID, }) return err } func (f *DataPipelinePipeline) String() string { return *f.pipelineID } aws-nuke-2.16.0/resources/dax-clusters.go000066400000000000000000000020221411137415400203060ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/dax" ) type DAXCluster struct { svc *dax.DAX clusterName *string } func init() { register("DAXCluster", ListDAXClusters) } func ListDAXClusters(sess *session.Session) ([]Resource, error) { svc := dax.New(sess) resources := []Resource{} params := &dax.DescribeClustersInput{ MaxResults: aws.Int64(100), } for { output, err := svc.DescribeClusters(params) if err != nil { return nil, err } for _, cluster := range output.Clusters { resources = append(resources, &DAXCluster{ svc: svc, clusterName: cluster.ClusterName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *DAXCluster) Remove() error { _, err := f.svc.DeleteCluster(&dax.DeleteClusterInput{ ClusterName: f.clusterName, }) return err } func (f *DAXCluster) String() string { return *f.clusterName } aws-nuke-2.16.0/resources/dax-parametergroups.go000066400000000000000000000024551411137415400216740ustar00rootroot00000000000000package resources import ( "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/dax" ) type DAXParameterGroup struct { svc *dax.DAX parameterGroupName *string } func init() { register("DAXParameterGroup", ListDAXParameterGroups) } func ListDAXParameterGroups(sess *session.Session) ([]Resource, error) { svc := dax.New(sess) resources := []Resource{} params := &dax.DescribeParameterGroupsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.DescribeParameterGroups(params) if err != nil { return nil, err } for _, parameterGroup := range output.ParameterGroups { //Ensure default is not deleted if !strings.Contains(*parameterGroup.ParameterGroupName, "default") { resources = append(resources, &DAXParameterGroup{ svc: svc, parameterGroupName: parameterGroup.ParameterGroupName, }) } } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *DAXParameterGroup) Remove() error { _, err := f.svc.DeleteParameterGroup(&dax.DeleteParameterGroupInput{ ParameterGroupName: f.parameterGroupName, }) return err } func (f *DAXParameterGroup) String() string { return *f.parameterGroupName } aws-nuke-2.16.0/resources/dax-subnetgroups.go000066400000000000000000000024071411137415400212110ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/dax" "fmt" ) type DAXSubnetGroup struct { svc *dax.DAX subnetGroupName *string } func init() { register("DAXSubnetGroup", ListDAXSubnetGroups) } func ListDAXSubnetGroups(sess *session.Session) ([]Resource, error) { svc := dax.New(sess) resources := []Resource{} params := &dax.DescribeSubnetGroupsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.DescribeSubnetGroups(params) if err != nil { return nil, err } for _, subnet := range output.SubnetGroups { resources = append(resources, &DAXSubnetGroup{ svc: svc, subnetGroupName: subnet.SubnetGroupName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *DAXSubnetGroup) Filter() error { if *f.subnetGroupName == "default" { return fmt.Errorf("Cannot delete default DAX Subnet group") } return nil } func (f *DAXSubnetGroup) Remove() error { _, err := f.svc.DeleteSubnetGroup(&dax.DeleteSubnetGroupInput{ SubnetGroupName: f.subnetGroupName, }) return err } func (f *DAXSubnetGroup) String() string { return *f.subnetGroupName } aws-nuke-2.16.0/resources/devicefarm-projects.go000066400000000000000000000017441411137415400216360ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/devicefarm" ) type DeviceFarmProject struct { svc *devicefarm.DeviceFarm ARN *string } func init() { register("DeviceFarmProject", ListDeviceFarmProjects) } func ListDeviceFarmProjects(sess *session.Session) ([]Resource, error) { svc := devicefarm.New(sess) resources := []Resource{} params := &devicefarm.ListProjectsInput{} for { output, err := svc.ListProjects(params) if err != nil { return nil, err } for _, project := range output.Projects { resources = append(resources, &DeviceFarmProject{ svc: svc, ARN: project.Arn, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *DeviceFarmProject) Remove() error { _, err := f.svc.DeleteProject(&devicefarm.DeleteProjectInput{ Arn: f.ARN, }) return err } func (f *DeviceFarmProject) String() string { return *f.ARN } aws-nuke-2.16.0/resources/directoryservice-directories.go000066400000000000000000000023311411137415400235720ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/directoryservice" ) type DirectoryServiceDirectory struct { svc *directoryservice.DirectoryService directoryID *string } func init() { register("DirectoryServiceDirectory", ListDirectoryServiceDirectories) } func ListDirectoryServiceDirectories(sess *session.Session) ([]Resource, error) { svc := directoryservice.New(sess) resources := []Resource{} params := &directoryservice.DescribeDirectoriesInput{ Limit: aws.Int64(100), } for { resp, err := svc.DescribeDirectories(params) if err != nil { return nil, err } for _, directory := range resp.DirectoryDescriptions { resources = append(resources, &DirectoryServiceDirectory{ svc: svc, directoryID: directory.DirectoryId, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *DirectoryServiceDirectory) Remove() error { _, err := f.svc.DeleteDirectory(&directoryservice.DeleteDirectoryInput{ DirectoryId: f.directoryID, }) return err } func (f *DirectoryServiceDirectory) String() string { return *f.directoryID } aws-nuke-2.16.0/resources/dynamodb-items.go000066400000000000000000000046161411137415400206170ustar00rootroot00000000000000package resources import ( "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/dynamodb" "github.com/rebuy-de/aws-nuke/pkg/types" "github.com/sirupsen/logrus" ) type DynamoDBTableItem struct { svc *dynamodb.DynamoDB id map[string]*dynamodb.AttributeValue table *DynamoDBTable keyName string keyValue string } func init() { register("DynamoDBTableItem", ListDynamoDBItems) } func ListDynamoDBItems(sess *session.Session) ([]Resource, error) { svc := dynamodb.New(sess) tables, tablesErr := ListDynamoDBTables(sess) if tablesErr != nil { return nil, tablesErr } resources := make([]Resource, 0) for _, dynamoTableResource := range tables { dynamoTable, ok := dynamoTableResource.(*DynamoDBTable) if !ok { // This should never happen (tm). logrus.Errorf("Unable to cast DynamoDBTable.") continue } describeParams := &dynamodb.DescribeTableInput{ TableName: &dynamoTable.id, } descResp, descErr := svc.DescribeTable(describeParams) if descErr != nil { return nil, descErr } keyName := descResp.Table.KeySchema[0].AttributeName params := &dynamodb.ScanInput{ TableName: &dynamoTable.id, ProjectionExpression: aws.String("#key"), ExpressionAttributeNames: map[string]*string{ "#key": keyName, }, } scanResp, scanErr := svc.Scan(params) if scanErr != nil { return nil, scanErr } for _, itemMap := range scanResp.Items { var keyValue string for _, value := range itemMap { value := strings.TrimSpace(value.String()) keyValue = string([]rune(value)[8:(len([]rune(value)) - 3)]) } resources = append(resources, &DynamoDBTableItem{ svc: svc, id: itemMap, table: dynamoTable, keyName: aws.StringValue(keyName), keyValue: keyValue, }) } } return resources, nil } func (i *DynamoDBTableItem) Remove() error { params := &dynamodb.DeleteItemInput{ Key: i.id, TableName: &i.table.id, } _, err := i.svc.DeleteItem(params) if err != nil { return err } return nil } func (i *DynamoDBTableItem) Properties() types.Properties { properties := types.NewProperties() properties.Set("Table", i.table) properties.Set("KeyName", i.keyName) properties.Set("KeyValue", i.keyValue) return properties } func (i *DynamoDBTableItem) String() string { return i.table.String() + " -> " + i.keyValue } aws-nuke-2.16.0/resources/dynamodb-tables.go000066400000000000000000000034361411137415400207470ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/dynamodb" "github.com/rebuy-de/aws-nuke/pkg/types" ) type DynamoDBTable struct { svc *dynamodb.DynamoDB id string tags []*dynamodb.Tag } func init() { register("DynamoDBTable", ListDynamoDBTables) } func ListDynamoDBTables(sess *session.Session) ([]Resource, error) { svc := dynamodb.New(sess) resp, err := svc.ListTables(&dynamodb.ListTablesInput{}) if err != nil { return nil, err } resources := make([]Resource, 0) for _, tableName := range resp.TableNames { tags, err := GetTableTags(svc, tableName) if err != nil { continue } resources = append(resources, &DynamoDBTable{ svc: svc, id: *tableName, tags: tags, }) } return resources, nil } func (i *DynamoDBTable) Remove() error { params := &dynamodb.DeleteTableInput{ TableName: aws.String(i.id), } _, err := i.svc.DeleteTable(params) if err != nil { return err } return nil } func GetTableTags(svc *dynamodb.DynamoDB, tableName *string) ([]*dynamodb.Tag, error) { result, err := svc.DescribeTable(&dynamodb.DescribeTableInput{ TableName: aws.String(*tableName), }) if err != nil { return make([]*dynamodb.Tag, 0), err } tags, err := svc.ListTagsOfResource(&dynamodb.ListTagsOfResourceInput{ ResourceArn: result.Table.TableArn, }) if err != nil { return make([]*dynamodb.Tag, 0), err } return tags.Tags, nil } func (i *DynamoDBTable) Properties() types.Properties { properties := types.NewProperties() properties.Set("Identifier", i.id) for _, tag := range i.tags { properties.SetTag(tag.Key, tag.Value) } return properties } func (i *DynamoDBTable) String() string { return i.id } aws-nuke-2.16.0/resources/ec2-client-vpn-endpoint-attachments.go000066400000000000000000000037711411137415400245610ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" ) type EC2ClientVpnEndpointAttachments struct { svc *ec2.EC2 associationId *string clientVpnEndpointId *string vpcId *string } func init() { register("EC2ClientVpnEndpointAttachment", ListEC2ClientVpnEndpointAttachments) } func ListEC2ClientVpnEndpointAttachments(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) endpoints := make([]*string, 0) params := &ec2.DescribeClientVpnEndpointsInput{} err := svc.DescribeClientVpnEndpointsPages(params, func(page *ec2.DescribeClientVpnEndpointsOutput, lastPage bool) bool { for _, out := range page.ClientVpnEndpoints { endpoints = append(endpoints, out.ClientVpnEndpointId) } return true }) if err != nil { return nil, err } resources := make([]Resource, 0) for _, clientVpnEndpointId := range endpoints { params := &ec2.DescribeClientVpnTargetNetworksInput{ ClientVpnEndpointId: clientVpnEndpointId, } err := svc.DescribeClientVpnTargetNetworksPages(params, func(page *ec2.DescribeClientVpnTargetNetworksOutput, lastPage bool) bool { for _, out := range page.ClientVpnTargetNetworks { resources = append(resources, &EC2ClientVpnEndpointAttachments{ svc: svc, associationId: out.AssociationId, clientVpnEndpointId: out.ClientVpnEndpointId, vpcId: out.VpcId, }) } return true }) if err != nil { return nil, err } } return resources, nil } func (e *EC2ClientVpnEndpointAttachments) Remove() error { params := &ec2.DisassociateClientVpnTargetNetworkInput{ AssociationId: e.associationId, ClientVpnEndpointId: e.clientVpnEndpointId, } _, err := e.svc.DisassociateClientVpnTargetNetwork(params) if err != nil { return err } return nil } func (e *EC2ClientVpnEndpointAttachments) String() string { return fmt.Sprintf("%s -> %s", *e.clientVpnEndpointId, *e.vpcId) } aws-nuke-2.16.0/resources/ec2-client-vpn-endpoint.go000066400000000000000000000025741411137415400222500ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2ClientVpnEndpoint struct { svc *ec2.EC2 id string cveTags []*ec2.Tag } func init() { register("EC2ClientVpnEndpoint", ListEC2ClientVpnEndoint) } func ListEC2ClientVpnEndoint(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resources := make([]Resource, 0) params := &ec2.DescribeClientVpnEndpointsInput{} err := svc.DescribeClientVpnEndpointsPages(params, func(page *ec2.DescribeClientVpnEndpointsOutput, lastPage bool) bool { for _, out := range page.ClientVpnEndpoints { resources = append(resources, &EC2ClientVpnEndpoint{ svc: svc, id: *out.ClientVpnEndpointId, }) } return true }) if err != nil { return nil, err } return resources, nil } func (c *EC2ClientVpnEndpoint) Remove() error { params := &ec2.DeleteClientVpnEndpointInput{ ClientVpnEndpointId: &c.id, } _, err := c.svc.DeleteClientVpnEndpoint(params) if err != nil { return err } return nil } func (e *EC2ClientVpnEndpoint) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range e.cveTags { properties.SetTagWithPrefix("cve", tagValue.Key, tagValue.Value) } return properties } func (c *EC2ClientVpnEndpoint) String() string { return c.id } aws-nuke-2.16.0/resources/ec2-customer-gateways.go000066400000000000000000000022061411137415400220260ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" ) type EC2CustomerGateway struct { svc *ec2.EC2 id string state string } func init() { register("EC2CustomerGateway", ListEC2CustomerGateways) } func ListEC2CustomerGateways(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) params := &ec2.DescribeCustomerGatewaysInput{} resp, err := svc.DescribeCustomerGateways(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.CustomerGateways { resources = append(resources, &EC2CustomerGateway{ svc: svc, id: *out.CustomerGatewayId, state: *out.State, }) } return resources, nil } func (c *EC2CustomerGateway) Filter() error { if c.state == "deleted" { return fmt.Errorf("already deleted") } return nil } func (c *EC2CustomerGateway) Remove() error { params := &ec2.DeleteCustomerGatewayInput{ CustomerGatewayId: &c.id, } _, err := c.svc.DeleteCustomerGateway(params) if err != nil { return err } return nil } func (c *EC2CustomerGateway) String() string { return c.id } aws-nuke-2.16.0/resources/ec2-dhcp-options.go000066400000000000000000000021761411137415400207600ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2DHCPOption struct { svc *ec2.EC2 id *string tags []*ec2.Tag } func init() { register("EC2DHCPOption", ListEC2DHCPOptions) } func ListEC2DHCPOptions(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resp, err := svc.DescribeDhcpOptions(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.DhcpOptions { resources = append(resources, &EC2DHCPOption{ svc: svc, id: out.DhcpOptionsId, tags: out.Tags, }) } return resources, nil } func (e *EC2DHCPOption) Remove() error { params := &ec2.DeleteDhcpOptionsInput{ DhcpOptionsId: e.id, } _, err := e.svc.DeleteDhcpOptions(params) if err != nil { return err } return nil } func (e *EC2DHCPOption) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range e.tags { properties.SetTag(tagValue.Key, tagValue.Value) } return properties } func (e *EC2DHCPOption) String() string { return *e.id } aws-nuke-2.16.0/resources/ec2-egress-only-internet-gateways.go000066400000000000000000000031261411137415400242640ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2EgressOnlyInternetGateway struct { svc *ec2.EC2 igw *ec2.EgressOnlyInternetGateway } func init() { register("EC2EgressOnlyInternetGateway", ListEC2EgressOnlyInternetGateways) } func ListEC2EgressOnlyInternetGateways(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resources := make([]Resource, 0) igwInputParams := &ec2.DescribeEgressOnlyInternetGatewaysInput{ MaxResults: aws.Int64(255), } for { resp, err := svc.DescribeEgressOnlyInternetGateways(igwInputParams) if err != nil { return nil, err } for _, igw := range resp.EgressOnlyInternetGateways { resources = append(resources, &EC2EgressOnlyInternetGateway{ svc: svc, igw: igw, }) } if resp.NextToken == nil { break } igwInputParams.NextToken = resp.NextToken } return resources, nil } func (e *EC2EgressOnlyInternetGateway) Remove() error { params := &ec2.DeleteEgressOnlyInternetGatewayInput{ EgressOnlyInternetGatewayId: e.igw.EgressOnlyInternetGatewayId, } _, err := e.svc.DeleteEgressOnlyInternetGateway(params) if err != nil { return err } return nil } func (e *EC2EgressOnlyInternetGateway) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range e.igw.Tags { properties.SetTag(tagValue.Key, tagValue.Value) } return properties } func (e *EC2EgressOnlyInternetGateway) String() string { return *e.igw.EgressOnlyInternetGatewayId } aws-nuke-2.16.0/resources/ec2-eip.go000066400000000000000000000022701411137415400171210ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2Address struct { svc *ec2.EC2 eip *ec2.Address id string ip string } func init() { register("EC2Address", ListEC2Addresses) } func ListEC2Addresses(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) params := &ec2.DescribeAddressesInput{} resp, err := svc.DescribeAddresses(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.Addresses { resources = append(resources, &EC2Address{ svc: svc, eip: out, id: *out.AllocationId, ip: *out.PublicIp, }) } return resources, nil } func (e *EC2Address) Remove() error { _, err := e.svc.ReleaseAddress(&ec2.ReleaseAddressInput{ AllocationId: &e.id, }) if err != nil { return err } return nil } func (e *EC2Address) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range e.eip.Tags { properties.SetTag(tagValue.Key, tagValue.Value) } properties.Set("AllocationID", e.id) return properties } func (e *EC2Address) String() string { return e.ip } aws-nuke-2.16.0/resources/ec2-images.go000066400000000000000000000022021411137415400176040ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2Image struct { svc *ec2.EC2 id string tags []*ec2.Tag } func init() { register("EC2Image", ListEC2Images) } func ListEC2Images(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) params := &ec2.DescribeImagesInput{ Owners: []*string{ aws.String("self"), }, } resp, err := svc.DescribeImages(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.Images { resources = append(resources, &EC2Image{ svc: svc, id: *out.ImageId, tags: out.Tags, }) } return resources, nil } func (e *EC2Image) Remove() error { _, err := e.svc.DeregisterImage(&ec2.DeregisterImageInput{ ImageId: &e.id, }) return err } func (e *EC2Image) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range e.tags { properties.SetTag(tagValue.Key, tagValue.Value) } return properties } func (e *EC2Image) String() string { return e.id } aws-nuke-2.16.0/resources/ec2-instances.go000066400000000000000000000055651411137415400203450ustar00rootroot00000000000000package resources import ( "fmt" "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/config" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2Instance struct { svc *ec2.EC2 instance *ec2.Instance featureFlags config.FeatureFlags } func init() { register("EC2Instance", ListEC2Instances) } func ListEC2Instances(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) params := &ec2.DescribeInstancesInput{} resources := make([]Resource, 0) for { resp, err := svc.DescribeInstances(params) if err != nil { return nil, err } for _, reservation := range resp.Reservations { for _, instance := range reservation.Instances { resources = append(resources, &EC2Instance{ svc: svc, instance: instance, }) } } if resp.NextToken == nil { break } params = &ec2.DescribeInstancesInput{ NextToken: resp.NextToken, } } return resources, nil } func (i *EC2Instance) FeatureFlags(ff config.FeatureFlags) { i.featureFlags = ff } func (i *EC2Instance) Filter() error { if *i.instance.State.Name == "terminated" { return fmt.Errorf("already terminated") } return nil } func (i *EC2Instance) Remove() error { params := &ec2.TerminateInstancesInput{ InstanceIds: []*string{i.instance.InstanceId}, } _, err := i.svc.TerminateInstances(params) if err != nil { if i.featureFlags.DisableDeletionProtection.EC2Instance { awsErr, ok := err.(awserr.Error) if ok && awsErr.Code() == "OperationNotPermitted" && awsErr.Message() == "The instance '"+*i.instance.InstanceId+"' may not be terminated. "+ "Modify its 'disableApiTermination' instance attribute and try again." { err = i.DisableProtection() if err != nil { return err } _, err := i.svc.TerminateInstances(params) if err != nil { return err } return nil } } return err } return nil } func (i *EC2Instance) DisableProtection() error { params := &ec2.ModifyInstanceAttributeInput{ InstanceId: i.instance.InstanceId, DisableApiTermination: &ec2.AttributeBooleanValue{ Value: aws.Bool(false), }, } _, err := i.svc.ModifyInstanceAttribute(params) if err != nil { return err } return nil } func (i *EC2Instance) Properties() types.Properties { properties := types.NewProperties() properties.Set("Identifier", i.instance.InstanceId) properties.Set("ImageIdentifier", i.instance.ImageId) properties.Set("InstanceState", i.instance.State.Name) properties.Set("InstanceType", i.instance.InstanceType) properties.Set("LaunchTime", i.instance.LaunchTime.Format(time.RFC3339)) for _, tagValue := range i.instance.Tags { properties.SetTag(tagValue.Key, tagValue.Value) } return properties } func (i *EC2Instance) String() string { return *i.instance.InstanceId } aws-nuke-2.16.0/resources/ec2-internet-gateway-attachments.go000066400000000000000000000036261411137415400241520ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2InternetGatewayAttachment struct { svc *ec2.EC2 vpcId *string vpcTags []*ec2.Tag igwId *string igwTags []*ec2.Tag } func init() { register("EC2InternetGatewayAttachment", ListEC2InternetGatewayAttachments) } func ListEC2InternetGatewayAttachments(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resp, err := svc.DescribeVpcs(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, vpc := range resp.Vpcs { params := &ec2.DescribeInternetGatewaysInput{ Filters: []*ec2.Filter{ { Name: aws.String("attachment.vpc-id"), Values: []*string{vpc.VpcId}, }, }, } resp, err := svc.DescribeInternetGateways(params) if err != nil { return nil, err } for _, igw := range resp.InternetGateways { resources = append(resources, &EC2InternetGatewayAttachment{ svc: svc, vpcId: vpc.VpcId, vpcTags: vpc.Tags, igwId: igw.InternetGatewayId, igwTags: igw.Tags, }) } } return resources, nil } func (e *EC2InternetGatewayAttachment) Remove() error { params := &ec2.DetachInternetGatewayInput{ VpcId: e.vpcId, InternetGatewayId: e.igwId, } _, err := e.svc.DetachInternetGateway(params) if err != nil { return err } return nil } func (e *EC2InternetGatewayAttachment) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range e.igwTags { properties.SetTagWithPrefix("igw", tagValue.Key, tagValue.Value) } for _, tagValue := range e.vpcTags { properties.SetTagWithPrefix("vpc", tagValue.Key, tagValue.Value) } return properties } func (e *EC2InternetGatewayAttachment) String() string { return fmt.Sprintf("%s -> %s", *e.igwId, *e.vpcId) } aws-nuke-2.16.0/resources/ec2-internet-gateways.go000066400000000000000000000022741411137415400220220ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2InternetGateway struct { svc *ec2.EC2 igw *ec2.InternetGateway } func init() { register("EC2InternetGateway", ListEC2InternetGateways) } func ListEC2InternetGateways(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resp, err := svc.DescribeInternetGateways(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, igw := range resp.InternetGateways { resources = append(resources, &EC2InternetGateway{ svc: svc, igw: igw, }) } return resources, nil } func (e *EC2InternetGateway) Remove() error { params := &ec2.DeleteInternetGatewayInput{ InternetGatewayId: e.igw.InternetGatewayId, } _, err := e.svc.DeleteInternetGateway(params) if err != nil { return err } return nil } func (e *EC2InternetGateway) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range e.igw.Tags { properties.SetTag(tagValue.Key, tagValue.Value) } return properties } func (e *EC2InternetGateway) String() string { return *e.igw.InternetGatewayId } aws-nuke-2.16.0/resources/ec2-key-pairs.go000066400000000000000000000014711411137415400202520ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" ) type EC2KeyPair struct { svc *ec2.EC2 name string } func init() { register("EC2KeyPair", ListEC2KeyPairs) } func ListEC2KeyPairs(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resp, err := svc.DescribeKeyPairs(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.KeyPairs { resources = append(resources, &EC2KeyPair{ svc: svc, name: *out.KeyName, }) } return resources, nil } func (e *EC2KeyPair) Remove() error { params := &ec2.DeleteKeyPairInput{ KeyName: &e.name, } _, err := e.svc.DeleteKeyPair(params) if err != nil { return err } return nil } func (e *EC2KeyPair) String() string { return e.name } aws-nuke-2.16.0/resources/ec2-launch-templates.go000066400000000000000000000017601411137415400216150ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" ) type EC2LaunchTemplate struct { svc *ec2.EC2 name *string } func init() { register("EC2LaunchTemplate", ListEC2LaunchTemplates) } func ListEC2LaunchTemplates(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resp, err := svc.DescribeLaunchTemplates(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, template := range resp.LaunchTemplates { resources = append(resources, &EC2LaunchTemplate{ svc: svc, name: template.LaunchTemplateName, }) } return resources, nil } func (template *EC2LaunchTemplate) Remove() error { _, err := template.svc.DeleteLaunchTemplate(&ec2.DeleteLaunchTemplateInput{ LaunchTemplateName: template.name, }) return err } func (template *EC2LaunchTemplate) String() string { return *template.name } aws-nuke-2.16.0/resources/ec2-nat-gateways.go000066400000000000000000000024701411137415400207520ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2NATGateway struct { svc *ec2.EC2 natgw *ec2.NatGateway } func init() { register("EC2NATGateway", ListEC2NATGateways) } func ListEC2NATGateways(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) params := &ec2.DescribeNatGatewaysInput{} resp, err := svc.DescribeNatGateways(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, natgw := range resp.NatGateways { resources = append(resources, &EC2NATGateway{ svc: svc, natgw: natgw, }) } return resources, nil } func (n *EC2NATGateway) Filter() error { if *n.natgw.State == "deleted" { return fmt.Errorf("already deleted") } return nil } func (n *EC2NATGateway) Remove() error { params := &ec2.DeleteNatGatewayInput{ NatGatewayId: n.natgw.NatGatewayId, } _, err := n.svc.DeleteNatGateway(params) if err != nil { return err } return nil } func (n *EC2NATGateway) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range n.natgw.Tags { properties.SetTag(tagValue.Key, tagValue.Value) } return properties } func (n *EC2NATGateway) String() string { return *n.natgw.NatGatewayId } aws-nuke-2.16.0/resources/ec2-network-acls.go000066400000000000000000000025331411137415400207570ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2NetworkACL struct { svc *ec2.EC2 id *string isDefault *bool tags []*ec2.Tag } func init() { register("EC2NetworkACL", ListEC2NetworkACLs) } func ListEC2NetworkACLs(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resp, err := svc.DescribeNetworkAcls(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.NetworkAcls { resources = append(resources, &EC2NetworkACL{ svc: svc, id: out.NetworkAclId, isDefault: out.IsDefault, tags: out.Tags, }) } return resources, nil } func (e *EC2NetworkACL) Filter() error { if *e.isDefault { return fmt.Errorf("cannot delete default VPC") } return nil } func (e *EC2NetworkACL) Remove() error { params := &ec2.DeleteNetworkAclInput{ NetworkAclId: e.id, } _, err := e.svc.DeleteNetworkAcl(params) if err != nil { return err } return nil } func (f *EC2NetworkACL) Properties() types.Properties { properties := types.NewProperties() for _, tag := range f.tags { properties.SetTag(tag.Key, tag.Value) } properties.Set("ID", f.id) return properties } func (e *EC2NetworkACL) String() string { return *e.id } aws-nuke-2.16.0/resources/ec2-network-interfaces.go000066400000000000000000000031511411137415400221550ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2NetworkInterface struct { svc *ec2.EC2 eni *ec2.NetworkInterface } func init() { register("EC2NetworkInterface", ListEC2NetworkInterfaces) } func ListEC2NetworkInterfaces(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resp, err := svc.DescribeNetworkInterfaces(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.NetworkInterfaces { resources = append(resources, &EC2NetworkInterface{ svc: svc, eni: out, }) } return resources, nil } func (e *EC2NetworkInterface) Remove() error { if e.eni.Attachment != nil { _, err := e.svc.DetachNetworkInterface(&ec2.DetachNetworkInterfaceInput{ AttachmentId: e.eni.Attachment.AttachmentId, Force: aws.Bool(true), }) if err != nil { return err } } params := &ec2.DeleteNetworkInterfaceInput{ NetworkInterfaceId: e.eni.NetworkInterfaceId, } _, err := e.svc.DeleteNetworkInterface(params) if err != nil { return err } return nil } func (r *EC2NetworkInterface) Properties() types.Properties { properties := types.NewProperties() for _, tag := range r.eni.TagSet { properties.SetTag(tag.Key, tag.Value) } properties. Set("ID", r.eni.NetworkInterfaceId). Set("VPC", r.eni.VpcId). Set("AvailabilityZone", r.eni.AvailabilityZone). Set("PrivateIPAddress", r.eni.PrivateIpAddress). Set("SubnetID", r.eni.SubnetId). Set("Status", r.eni.Status) return properties } aws-nuke-2.16.0/resources/ec2-placement-groups.go000066400000000000000000000021551411137415400216330ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" ) type EC2PlacementGroup struct { svc *ec2.EC2 name string state string } func init() { register("EC2PlacementGroup", ListEC2PlacementGroups) } func ListEC2PlacementGroups(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) params := &ec2.DescribePlacementGroupsInput{} resp, err := svc.DescribePlacementGroups(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.PlacementGroups { resources = append(resources, &EC2PlacementGroup{ svc: svc, name: *out.GroupName, state: *out.State, }) } return resources, nil } func (p *EC2PlacementGroup) Filter() error { if p.state == "deleted" { return fmt.Errorf("already deleted") } return nil } func (p *EC2PlacementGroup) Remove() error { params := &ec2.DeletePlacementGroupInput{ GroupName: &p.name, } _, err := p.svc.DeletePlacementGroup(params) if err != nil { return err } return nil } func (p *EC2PlacementGroup) String() string { return p.name } aws-nuke-2.16.0/resources/ec2-route-tables.go000066400000000000000000000022351411137415400207530ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2RouteTable struct { svc *ec2.EC2 routeTable *ec2.RouteTable } func init() { register("EC2RouteTable", ListEC2RouteTables) } func ListEC2RouteTables(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resp, err := svc.DescribeRouteTables(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.RouteTables { resources = append(resources, &EC2RouteTable{ svc: svc, routeTable: out, }) } return resources, nil } func (e *EC2RouteTable) Remove() error { params := &ec2.DeleteRouteTableInput{ RouteTableId: e.routeTable.RouteTableId, } _, err := e.svc.DeleteRouteTable(params) if err != nil { return err } return nil } func (e *EC2RouteTable) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range e.routeTable.Tags { properties.SetTag(tagValue.Key, tagValue.Value) } return properties } func (e *EC2RouteTable) String() string { return *e.routeTable.RouteTableId } aws-nuke-2.16.0/resources/ec2-security-groups.go000066400000000000000000000041331411137415400215300ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2SecurityGroup struct { svc *ec2.EC2 group *ec2.SecurityGroup id *string name *string ingress []*ec2.IpPermission egress []*ec2.IpPermission } func init() { register("EC2SecurityGroup", ListEC2SecurityGroups) } func ListEC2SecurityGroups(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resources := make([]Resource, 0) params := &ec2.DescribeSecurityGroupsInput{} err := svc.DescribeSecurityGroupsPages(params, func(page *ec2.DescribeSecurityGroupsOutput, lastPage bool) bool { for _, group := range page.SecurityGroups { resources = append(resources, &EC2SecurityGroup{ svc: svc, group: group, id: group.GroupId, name: group.GroupName, ingress: group.IpPermissions, egress: group.IpPermissionsEgress, }) } return !lastPage }) if err != nil { return nil, err } return resources, nil } func (sg *EC2SecurityGroup) Filter() error { if *sg.name == "default" { return fmt.Errorf("cannot delete group 'default'") } return nil } func (sg *EC2SecurityGroup) Remove() error { if len(sg.egress) > 0 { egressParams := &ec2.RevokeSecurityGroupEgressInput{ GroupId: sg.id, IpPermissions: sg.egress, } _, _ = sg.svc.RevokeSecurityGroupEgress(egressParams) } if len(sg.ingress) > 0 { ingressParams := &ec2.RevokeSecurityGroupIngressInput{ GroupId: sg.id, IpPermissions: sg.ingress, } _, _ = sg.svc.RevokeSecurityGroupIngress(ingressParams) } params := &ec2.DeleteSecurityGroupInput{ GroupId: sg.id, } _, err := sg.svc.DeleteSecurityGroup(params) if err != nil { return err } return nil } func (sg *EC2SecurityGroup) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range sg.group.Tags { properties.SetTag(tagValue.Key, tagValue.Value) } properties.Set("Name", sg.name) return properties } func (sg *EC2SecurityGroup) String() string { return *sg.id } aws-nuke-2.16.0/resources/ec2-snapshots.go000066400000000000000000000023051411137415400203650ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2Snapshot struct { svc *ec2.EC2 id string tags []*ec2.Tag } func init() { register("EC2Snapshot", ListEC2Snapshots) } func ListEC2Snapshots(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) params := &ec2.DescribeSnapshotsInput{ OwnerIds: []*string{ aws.String("self"), }, } resp, err := svc.DescribeSnapshots(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.Snapshots { resources = append(resources, &EC2Snapshot{ svc: svc, id: *out.SnapshotId, tags: out.Tags, }) } return resources, nil } func (e *EC2Snapshot) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range e.tags { properties.Set(fmt.Sprintf("tag:%v", *tagValue.Key), tagValue.Value) } return properties } func (e *EC2Snapshot) Remove() error { _, err := e.svc.DeleteSnapshot(&ec2.DeleteSnapshotInput{ SnapshotId: &e.id, }) return err } func (e *EC2Snapshot) String() string { return e.id } aws-nuke-2.16.0/resources/ec2-spot-fleet-requests.go000066400000000000000000000023411411137415400222760ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" ) type EC2SpotFleetRequest struct { svc *ec2.EC2 id string state string } func init() { register("EC2SpotFleetRequest", ListEC2SpotFleetRequests) } func ListEC2SpotFleetRequests(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resp, err := svc.DescribeSpotFleetRequests(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, config := range resp.SpotFleetRequestConfigs { resources = append(resources, &EC2SpotFleetRequest{ svc: svc, id: *config.SpotFleetRequestId, state: *config.SpotFleetRequestState, }) } return resources, nil } func (i *EC2SpotFleetRequest) Filter() error { if i.state == "cancelled" { return fmt.Errorf("already cancelled") } return nil } func (i *EC2SpotFleetRequest) Remove() error { params := &ec2.CancelSpotFleetRequestsInput{ TerminateInstances: aws.Bool(true), SpotFleetRequestIds: []*string{ &i.id, }, } _, err := i.svc.CancelSpotFleetRequests(params) if err != nil { return err } return nil } func (i *EC2SpotFleetRequest) String() string { return i.id } aws-nuke-2.16.0/resources/ec2-subnets.go000066400000000000000000000022421411137415400200260ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2Subnet struct { svc *ec2.EC2 subnet *ec2.Subnet } func init() { register("EC2Subnet", ListEC2Subnets) } func ListEC2Subnets(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) params := &ec2.DescribeSubnetsInput{} resp, err := svc.DescribeSubnets(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.Subnets { resources = append(resources, &EC2Subnet{ svc: svc, subnet: out, }) } return resources, nil } func (e *EC2Subnet) Remove() error { params := &ec2.DeleteSubnetInput{ SubnetId: e.subnet.SubnetId, } _, err := e.svc.DeleteSubnet(params) if err != nil { return err } return nil } func (e *EC2Subnet) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range e.subnet.Tags { properties.SetTag(tagValue.Key, tagValue.Value) } properties.Set("DefaultForAz", e.subnet.DefaultForAz) return properties } func (e *EC2Subnet) String() string { return *e.subnet.SubnetId } aws-nuke-2.16.0/resources/ec2-tgw-attachments.go000066400000000000000000000036211411137415400214570ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2TGWAttachment struct { svc *ec2.EC2 tgwa *ec2.TransitGatewayAttachment } func init() { register("EC2TGWAttachment", ListEC2TGWAttachments) } func ListEC2TGWAttachments(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) params := &ec2.DescribeTransitGatewayAttachmentsInput{} resources := make([]Resource, 0) for { resp, err := svc.DescribeTransitGatewayAttachments(params) if err != nil { return nil, err } for _, tgwa := range resp.TransitGatewayAttachments { resources = append(resources, &EC2TGWAttachment{ svc: svc, tgwa: tgwa, }) } if resp.NextToken == nil { break } params = &ec2.DescribeTransitGatewayAttachmentsInput{ NextToken: resp.NextToken, } } return resources, nil } func (e *EC2TGWAttachment) Remove() error { if *e.tgwa.ResourceType == "VPN" { // This will get deleted as part of EC2VPNConnection, there is no API // as part of TGW to delete VPN attachments. return fmt.Errorf("VPN attachment") } params := &ec2.DeleteTransitGatewayVpcAttachmentInput{ TransitGatewayAttachmentId: e.tgwa.TransitGatewayAttachmentId, } _, err := e.svc.DeleteTransitGatewayVpcAttachment(params) if err != nil { return err } return nil } func (e *EC2TGWAttachment) Filter() error { if *e.tgwa.State == "deleted" { return fmt.Errorf("already deleted") } return nil } func (e *EC2TGWAttachment) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range e.tgwa.Tags { properties.SetTag(tagValue.Key, tagValue.Value) } properties.Set("ID", e.tgwa.TransitGatewayAttachmentId) return properties } func (e *EC2TGWAttachment) String() string { return fmt.Sprintf("%s(%s)", *e.tgwa.TransitGatewayAttachmentId, *e.tgwa.ResourceType) } aws-nuke-2.16.0/resources/ec2-tgw.go000066400000000000000000000027541411137415400171540ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2TGW struct { svc *ec2.EC2 tgw *ec2.TransitGateway } func init() { register("EC2TGW", ListEC2TGWs) } func ListEC2TGWs(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) params := &ec2.DescribeTransitGatewaysInput{} resources := make([]Resource, 0) for { resp, err := svc.DescribeTransitGateways(params) if err != nil { return nil, err } for _, tgw := range resp.TransitGateways { resources = append(resources, &EC2TGW{ svc: svc, tgw: tgw, }) } if resp.NextToken == nil { break } params = &ec2.DescribeTransitGatewaysInput{ NextToken: resp.NextToken, } } return resources, nil } func (e *EC2TGW) Remove() error { params := &ec2.DeleteTransitGatewayInput{ TransitGatewayId: e.tgw.TransitGatewayId, } _, err := e.svc.DeleteTransitGateway(params) if err != nil { return err } return nil } func (e *EC2TGW) Filter() error { if *e.tgw.State == "deleted" { return fmt.Errorf("already deleted") } return nil } func (e *EC2TGW) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range e.tgw.Tags { properties.SetTag(tagValue.Key, tagValue.Value) } properties. Set("ID", e.tgw.TransitGatewayId). Set("OwnerId", e.tgw.OwnerId) return properties } func (e *EC2TGW) String() string { return *e.tgw.TransitGatewayId } aws-nuke-2.16.0/resources/ec2-volume.go000066400000000000000000000020651411137415400176550ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2Volume struct { svc *ec2.EC2 volume *ec2.Volume } func init() { register("EC2Volume", ListEC2Volumes) } func ListEC2Volumes(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resp, err := svc.DescribeVolumes(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.Volumes { resources = append(resources, &EC2Volume{ svc: svc, volume: out, }) } return resources, nil } func (e *EC2Volume) Remove() error { _, err := e.svc.DeleteVolume(&ec2.DeleteVolumeInput{ VolumeId: e.volume.VolumeId, }) return err } func (e *EC2Volume) Properties() types.Properties { properties := types.NewProperties() properties.Set("State", e.volume.State) for _, tagValue := range e.volume.Tags { properties.SetTag(tagValue.Key, tagValue.Value) } return properties } func (e *EC2Volume) String() string { return *e.volume.VolumeId } aws-nuke-2.16.0/resources/ec2-vpc-endpoint-service-configurations.go000066400000000000000000000031051411137415400254360ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2VPCEndpointServiceConfiguration struct { svc *ec2.EC2 id *string name *string } func init() { register("EC2VPCEndpointServiceConfiguration", ListEC2VPCEndpointServiceConfigurations) } func ListEC2VPCEndpointServiceConfigurations(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resources := make([]Resource, 0) params := &ec2.DescribeVpcEndpointServiceConfigurationsInput{ MaxResults: aws.Int64(100), } for { resp, err := svc.DescribeVpcEndpointServiceConfigurations(params) if err != nil { return nil, err } for _, serviceConfig := range resp.ServiceConfigurations { resources = append(resources, &EC2VPCEndpointServiceConfiguration{ svc: svc, id: serviceConfig.ServiceId, name: serviceConfig.ServiceName, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (e *EC2VPCEndpointServiceConfiguration) Remove() error { params := &ec2.DeleteVpcEndpointServiceConfigurationsInput{ ServiceIds: []*string{e.id}, } _, err := e.svc.DeleteVpcEndpointServiceConfigurations(params) if err != nil { return err } return nil } func (e *EC2VPCEndpointServiceConfiguration) Properties() types.Properties { properties := types.NewProperties() properties.Set("Name", e.name) return properties } func (e *EC2VPCEndpointServiceConfiguration) String() string { return *e.id } aws-nuke-2.16.0/resources/ec2-vpc-peering-connections.go000066400000000000000000000025301411137415400231020ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" ) type EC2VPCPeeringConnection struct { svc *ec2.EC2 id *string status *string } func init() { register("EC2VPCPeeringConnection", ListEC2VPCPeeringConnections) } func ListEC2VPCPeeringConnections(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resources := make([]Resource, 0) // filter should be set as deleted vpc connetions are returned params := &ec2.DescribeVpcPeeringConnectionsInput{} resp, err := svc.DescribeVpcPeeringConnections(params) if err != nil { return nil, err } for _, peeringConfig := range resp.VpcPeeringConnections { resources = append(resources, &EC2VPCPeeringConnection{ svc: svc, id: peeringConfig.VpcPeeringConnectionId, status: peeringConfig.Status.Code, }) } return resources, nil } func (p *EC2VPCPeeringConnection) Filter() error { if *p.status == "deleting" || *p.status == "deleted" { return fmt.Errorf("already deleted") } return nil } func (p *EC2VPCPeeringConnection) Remove() error { params := &ec2.DeleteVpcPeeringConnectionInput{ VpcPeeringConnectionId: p.id, } _, err := p.svc.DeleteVpcPeeringConnection(params) if err != nil { return err } return nil } func (p *EC2VPCPeeringConnection) String() string { return *p.id } aws-nuke-2.16.0/resources/ec2-vpc.go000066400000000000000000000021451411137415400171350ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2VPC struct { svc *ec2.EC2 vpc *ec2.Vpc } func init() { register("EC2VPC", ListEC2VPCs) } func ListEC2VPCs(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resp, err := svc.DescribeVpcs(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, vpc := range resp.Vpcs { resources = append(resources, &EC2VPC{ svc: svc, vpc: vpc, }) } return resources, nil } func (e *EC2VPC) Remove() error { params := &ec2.DeleteVpcInput{ VpcId: e.vpc.VpcId, } _, err := e.svc.DeleteVpc(params) if err != nil { return err } return nil } func (e *EC2VPC) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range e.vpc.Tags { properties.SetTag(tagValue.Key, tagValue.Value) } properties.Set("ID", e.vpc.VpcId) properties.Set("IsDefault", e.vpc.IsDefault) return properties } func (e *EC2VPC) String() string { return *e.vpc.VpcId } aws-nuke-2.16.0/resources/ec2-vpcEndpoint.go000066400000000000000000000030321411137415400206320ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" "github.com/aws/aws-sdk-go/aws" ) type EC2VPCEndpoint struct { svc *ec2.EC2 id *string vpcTags []*ec2.Tag } func init() { register("EC2VPCEndpoint", ListEC2VPCEndpoints) } func ListEC2VPCEndpoints(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resp, err := svc.DescribeVpcs(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, vpc := range resp.Vpcs { params := &ec2.DescribeVpcEndpointsInput{ Filters: []*ec2.Filter{ { Name: aws.String("vpc-id"), Values: []*string{vpc.VpcId}, }, }, } resp, err := svc.DescribeVpcEndpoints(params) if err != nil { return nil, err } for _, vpcEndpoint := range resp.VpcEndpoints { resources = append(resources, &EC2VPCEndpoint{ svc: svc, id: vpcEndpoint.VpcEndpointId, vpcTags: vpc.Tags, }) } } return resources, nil } func (endpoint *EC2VPCEndpoint) Remove() error { params := &ec2.DeleteVpcEndpointsInput{ VpcEndpointIds: []*string{endpoint.id}, } _, err := endpoint.svc.DeleteVpcEndpoints(params) if err != nil { return err } return nil } func (e *EC2VPCEndpoint) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range e.vpcTags { properties.SetTag(tagValue.Key, tagValue.Value) } return properties } func (endpoint *EC2VPCEndpoint) String() string { return *endpoint.id } aws-nuke-2.16.0/resources/ec2-vpn-connections.go000066400000000000000000000025461411137415400214750ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2VPNConnection struct { svc *ec2.EC2 conn *ec2.VpnConnection } func init() { register("EC2VPNConnection", ListEC2VPNConnections) } func ListEC2VPNConnections(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) params := &ec2.DescribeVpnConnectionsInput{} resp, err := svc.DescribeVpnConnections(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.VpnConnections { resources = append(resources, &EC2VPNConnection{ svc: svc, conn: out, }) } return resources, nil } func (v *EC2VPNConnection) Filter() error { if *v.conn.State == "deleted" { return fmt.Errorf("already deleted") } return nil } func (v *EC2VPNConnection) Remove() error { params := &ec2.DeleteVpnConnectionInput{ VpnConnectionId: v.conn.VpnConnectionId, } _, err := v.svc.DeleteVpnConnection(params) if err != nil { return err } return nil } func (v *EC2VPNConnection) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range v.conn.Tags { properties.SetTag(tagValue.Key, tagValue.Value) } return properties } func (v *EC2VPNConnection) String() string { return *v.conn.VpnConnectionId } aws-nuke-2.16.0/resources/ec2-vpn-gateway-attachments.go000066400000000000000000000037371411137415400231300ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EC2VPNGatewayAttachment struct { svc *ec2.EC2 vpcId string vpnId string state string vpcTags []*ec2.Tag vgwTags []*ec2.Tag } func init() { register("EC2VPNGatewayAttachment", ListEC2VPNGatewayAttachments) } func ListEC2VPNGatewayAttachments(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) resp, err := svc.DescribeVpcs(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, vpc := range resp.Vpcs { params := &ec2.DescribeVpnGatewaysInput{ Filters: []*ec2.Filter{ { Name: aws.String("attachment.vpc-id"), Values: []*string{vpc.VpcId}, }, }, } resp, err := svc.DescribeVpnGateways(params) if err != nil { return nil, err } for _, vgw := range resp.VpnGateways { resources = append(resources, &EC2VPNGatewayAttachment{ svc: svc, vpcId: *vpc.VpcId, vpnId: *vgw.VpnGatewayId, vpcTags: vpc.Tags, vgwTags: vgw.Tags, }) } } return resources, nil } func (v *EC2VPNGatewayAttachment) Filter() error { if v.state == "detached" { return fmt.Errorf("already detached") } return nil } func (v *EC2VPNGatewayAttachment) Remove() error { params := &ec2.DetachVpnGatewayInput{ VpcId: &v.vpcId, VpnGatewayId: &v.vpnId, } _, err := v.svc.DetachVpnGateway(params) if err != nil { return err } return nil } func (v *EC2VPNGatewayAttachment) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range v.vgwTags { properties.SetTagWithPrefix("vgw", tagValue.Key, tagValue.Value) } for _, tagValue := range v.vpcTags { properties.SetTagWithPrefix("vpc", tagValue.Key, tagValue.Value) } return properties } func (v *EC2VPNGatewayAttachment) String() string { return fmt.Sprintf("%s -> %s", v.vpnId, v.vpcId) } aws-nuke-2.16.0/resources/ec2-vpn-gateways.go000066400000000000000000000020731411137415400207720ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" ) type EC2VPNGateway struct { svc *ec2.EC2 id string state string } func init() { register("EC2VPNGateway", ListEC2VPNGateways) } func ListEC2VPNGateways(sess *session.Session) ([]Resource, error) { svc := ec2.New(sess) params := &ec2.DescribeVpnGatewaysInput{} resp, err := svc.DescribeVpnGateways(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.VpnGateways { resources = append(resources, &EC2VPNGateway{ svc: svc, id: *out.VpnGatewayId, state: *out.State, }) } return resources, nil } func (v *EC2VPNGateway) Filter() error { if v.state == "deleted" { return fmt.Errorf("already deleted") } return nil } func (v *EC2VPNGateway) Remove() error { params := &ec2.DeleteVpnGatewayInput{ VpnGatewayId: &v.id, } _, err := v.svc.DeleteVpnGateway(params) if err != nil { return err } return nil } func (v *EC2VPNGateway) String() string { return v.id } aws-nuke-2.16.0/resources/ecr-repository.go000066400000000000000000000022531411137415400206640ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ecr" ) type ECRRepository struct { svc *ecr.ECR name *string } func init() { register("ECRRepository", ListECRRepositories) } func ListECRRepositories(sess *session.Session) ([]Resource, error) { svc := ecr.New(sess) resources := []Resource{} input := &ecr.DescribeRepositoriesInput{ MaxResults: aws.Int64(100), } for { output, err := svc.DescribeRepositories(input) if err != nil { return nil, err } for _, repository := range output.Repositories { resources = append(resources, &ECRRepository{ svc: svc, name: repository.RepositoryName, }) } if output.NextToken == nil { break } input.NextToken = output.NextToken } return resources, nil } func (r *ECRRepository) Filter() error { return nil } func (r *ECRRepository) Remove() error { params := &ecr.DeleteRepositoryInput{ RepositoryName: r.name, Force: aws.Bool(true), } _, err := r.svc.DeleteRepository(params) return err } func (r *ECRRepository) String() string { return fmt.Sprintf("Repository: %s", *r.name) } aws-nuke-2.16.0/resources/ecs-clusterinstances.go000066400000000000000000000037071411137415400220440ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ecs" ) type ECSClusterInstance struct { svc *ecs.ECS instanceARN *string clusterARN *string } func init() { register("ECSClusterInstance", ListECSClusterInstances) } func ListECSClusterInstances(sess *session.Session) ([]Resource, error) { svc := ecs.New(sess) resources := []Resource{} clusters := []*string{} clusterParams := &ecs.ListClustersInput{ MaxResults: aws.Int64(100), } // Iterate over clusters to ensure we dont presume its always default associations for { output, err := svc.ListClusters(clusterParams) if err != nil { return nil, err } for _, clusterArn := range output.ClusterArns { clusters = append(clusters, clusterArn) } if output.NextToken == nil { break } clusterParams.NextToken = output.NextToken } // Iterate over known clusters and discover their instances // to prevent assuming default is always used for _, clusterArn := range clusters { instanceParams := &ecs.ListContainerInstancesInput{ Cluster: clusterArn, MaxResults: aws.Int64(100), } output, err := svc.ListContainerInstances(instanceParams) if err != nil { return nil, err } for _, instanceArn := range output.ContainerInstanceArns { resources = append(resources, &ECSClusterInstance{ svc: svc, instanceARN: instanceArn, clusterARN: clusterArn, }) } if output.NextToken == nil { break } instanceParams.NextToken = output.NextToken } return resources, nil } func (f *ECSClusterInstance) Remove() error { _, err := f.svc.DeregisterContainerInstance(&ecs.DeregisterContainerInstanceInput{ Cluster: f.clusterARN, ContainerInstance: f.instanceARN, Force: aws.Bool(true), }) return err } func (f *ECSClusterInstance) String() string { return fmt.Sprintf("%s -> %s", *f.instanceARN, *f.clusterARN) } aws-nuke-2.16.0/resources/ecs-clusters.go000066400000000000000000000017231411137415400203130ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ecs" ) type ECSCluster struct { svc *ecs.ECS ARN *string } func init() { register("ECSCluster", ListECSClusters) } func ListECSClusters(sess *session.Session) ([]Resource, error) { svc := ecs.New(sess) resources := []Resource{} params := &ecs.ListClustersInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListClusters(params) if err != nil { return nil, err } for _, clusterArn := range output.ClusterArns { resources = append(resources, &ECSCluster{ svc: svc, ARN: clusterArn, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *ECSCluster) Remove() error { _, err := f.svc.DeleteCluster(&ecs.DeleteClusterInput{ Cluster: f.ARN, }) return err } func (f *ECSCluster) String() string { return *f.ARN } aws-nuke-2.16.0/resources/ecs-services.go000066400000000000000000000034541411137415400202750ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ecs" ) type ECSService struct { svc *ecs.ECS serviceARN *string clusterARN *string } func init() { register("ECSService", ListECSServices) } func ListECSServices(sess *session.Session) ([]Resource, error) { svc := ecs.New(sess) resources := []Resource{} clusters := []*string{} clusterParams := &ecs.ListClustersInput{ MaxResults: aws.Int64(100), } // Iterate over clusters to ensure we dont presume its always default associations for { output, err := svc.ListClusters(clusterParams) if err != nil { return nil, err } for _, clusterArn := range output.ClusterArns { clusters = append(clusters, clusterArn) } if output.NextToken == nil { break } clusterParams.NextToken = output.NextToken } // Iterate over known clusters and discover their instances // to prevent assuming default is always used for _, clusterArn := range clusters { serviceParams := &ecs.ListServicesInput{ Cluster: clusterArn, MaxResults: aws.Int64(10), } output, err := svc.ListServices(serviceParams) if err != nil { return nil, err } for _, serviceArn := range output.ServiceArns { resources = append(resources, &ECSService{ svc: svc, serviceARN: serviceArn, clusterARN: clusterArn, }) } if output.NextToken == nil { continue } serviceParams.NextToken = output.NextToken } return resources, nil } func (f *ECSService) Remove() error { _, err := f.svc.DeleteService(&ecs.DeleteServiceInput{ Cluster: f.clusterARN, Service: f.serviceARN, Force: aws.Bool(true), }) return err } func (f *ECSService) String() string { return fmt.Sprintf("%s -> %s", *f.serviceARN, *f.clusterARN) } aws-nuke-2.16.0/resources/ecs-taskdefinitions.go000066400000000000000000000021041411137415400216370ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ecs" ) type ECSTaskDefinition struct { svc *ecs.ECS ARN *string } func init() { register("ECSTaskDefinition", ListECSTaskDefinitions) } func ListECSTaskDefinitions(sess *session.Session) ([]Resource, error) { svc := ecs.New(sess) resources := []Resource{} params := &ecs.ListTaskDefinitionsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListTaskDefinitions(params) if err != nil { return nil, err } for _, taskDefinitionARN := range output.TaskDefinitionArns { resources = append(resources, &ECSTaskDefinition{ svc: svc, ARN: taskDefinitionARN, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *ECSTaskDefinition) Remove() error { _, err := f.svc.DeregisterTaskDefinition(&ecs.DeregisterTaskDefinitionInput{ TaskDefinition: f.ARN, }) return err } func (f *ECSTaskDefinition) String() string { return *f.ARN } aws-nuke-2.16.0/resources/efs-filesystem.go000066400000000000000000000015261411137415400206370ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/efs" ) type EFSFileSystem struct { svc *efs.EFS id string name string } func init() { register("EFSFileSystem", ListEFSFileSystems) } func ListEFSFileSystems(sess *session.Session) ([]Resource, error) { svc := efs.New(sess) resp, err := svc.DescribeFileSystems(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, fs := range resp.FileSystems { resources = append(resources, &EFSFileSystem{ svc: svc, id: *fs.FileSystemId, name: *fs.CreationToken, }) } return resources, nil } func (e *EFSFileSystem) Remove() error { _, err := e.svc.DeleteFileSystem(&efs.DeleteFileSystemInput{ FileSystemId: &e.id, }) return err } func (e *EFSFileSystem) String() string { return e.name } aws-nuke-2.16.0/resources/efs-mount-targets.go000066400000000000000000000021111411137415400212530ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/efs" ) type EFSMountTarget struct { svc *efs.EFS id string fsid string } func init() { register("EFSMountTarget", ListEFSMountTargets) } func ListEFSMountTargets(sess *session.Session) ([]Resource, error) { svc := efs.New(sess) resp, err := svc.DescribeFileSystems(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, fs := range resp.FileSystems { mt, err := svc.DescribeMountTargets(&efs.DescribeMountTargetsInput{ FileSystemId: fs.FileSystemId, }) if err != nil { return nil, err } for _, t := range mt.MountTargets { resources = append(resources, &EFSMountTarget{ svc: svc, id: *t.MountTargetId, fsid: *t.FileSystemId, }) } } return resources, nil } func (e *EFSMountTarget) Remove() error { _, err := e.svc.DeleteMountTarget(&efs.DeleteMountTargetInput{ MountTargetId: &e.id, }) return err } func (e *EFSMountTarget) String() string { return fmt.Sprintf("%s:%s", e.fsid, e.id) } aws-nuke-2.16.0/resources/eks-clusters.go000066400000000000000000000017031411137415400203210ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/eks" ) type EKSCluster struct { svc *eks.EKS name *string } func init() { register("EKSCluster", ListEKSClusters) } func ListEKSClusters(sess *session.Session) ([]Resource, error) { svc := eks.New(sess) resources := []Resource{} params := &eks.ListClustersInput{ MaxResults: aws.Int64(100), } for { resp, err := svc.ListClusters(params) if err != nil { return nil, err } for _, cluster := range resp.Clusters { resources = append(resources, &EKSCluster{ svc: svc, name: cluster, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *EKSCluster) Remove() error { _, err := f.svc.DeleteCluster(&eks.DeleteClusterInput{ Name: f.name, }) return err } func (f *EKSCluster) String() string { return *f.name } aws-nuke-2.16.0/resources/eks-fargate.go000066400000000000000000000040071411137415400200660ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/eks" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EKSFargateProfile struct { svc *eks.EKS cluster *string name *string } func init() { register("EKSFargateProfiles", ListEKSFargateProfiles) } func ListEKSFargateProfiles(sess *session.Session) ([]Resource, error) { svc := eks.New(sess) clusterNames := []*string{} resources := []Resource{} clusterInputParams := &eks.ListClustersInput{ MaxResults: aws.Int64(100), } // fetch all cluster names for { resp, err := svc.ListClusters(clusterInputParams) if err != nil { return nil, err } for _, cluster := range resp.Clusters { clusterNames = append(clusterNames, cluster) } if resp.NextToken == nil { break } clusterInputParams.NextToken = resp.NextToken } fargateInputParams := &eks.ListFargateProfilesInput{ MaxResults: aws.Int64(100), } // fetch the associated eks fargate profiles for _, clusterName := range clusterNames { fargateInputParams.ClusterName = clusterName for { resp, err := svc.ListFargateProfiles(fargateInputParams) if err != nil { return nil, err } for _, name := range resp.FargateProfileNames { resources = append(resources, &EKSFargateProfile{ svc: svc, name: name, cluster: clusterName, }) } if resp.NextToken == nil { fargateInputParams.NextToken = nil break } fargateInputParams.NextToken = resp.NextToken } } return resources, nil } func (fp *EKSFargateProfile) Remove() error { _, err := fp.svc.DeleteFargateProfile(&eks.DeleteFargateProfileInput{ ClusterName: fp.cluster, FargateProfileName: fp.name, }) return err } func (fp *EKSFargateProfile) Properties() types.Properties { return types.NewProperties(). Set("Cluster", *fp.cluster). Set("Profile", *fp.name) } func (fp *EKSFargateProfile) String() string { return fmt.Sprintf("%s:%s", *fp.cluster, *fp.name) } aws-nuke-2.16.0/resources/eks-nodegroups.go000066400000000000000000000036751411137415400206540ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/eks" "github.com/rebuy-de/aws-nuke/pkg/types" ) type EKSNodegroup struct { svc *eks.EKS cluster *string name *string } func init() { register("EKSNodegroups", ListEKSNodegroups) } func ListEKSNodegroups(sess *session.Session) ([]Resource, error) { svc := eks.New(sess) clusterNames := []*string{} resources := []Resource{} clusterInputParams := &eks.ListClustersInput{ MaxResults: aws.Int64(100), } // fetch all cluster names for { resp, err := svc.ListClusters(clusterInputParams) if err != nil { return nil, err } for _, cluster := range resp.Clusters { clusterNames = append(clusterNames, cluster) } if resp.NextToken == nil { break } clusterInputParams.NextToken = resp.NextToken } nodegroupsInputParams := &eks.ListNodegroupsInput{ MaxResults: aws.Int64(100), } // fetch the associated node groups for _, clusterName := range clusterNames { nodegroupsInputParams.ClusterName = clusterName for { resp, err := svc.ListNodegroups(nodegroupsInputParams) if err != nil { return nil, err } for _, name := range resp.Nodegroups { resources = append(resources, &EKSNodegroup{ svc: svc, name: name, cluster: clusterName, }) } if resp.NextToken == nil { nodegroupsInputParams.NextToken = nil break } nodegroupsInputParams.NextToken = resp.NextToken } } return resources, nil } func (ng *EKSNodegroup) Remove() error { _, err := ng.svc.DeleteNodegroup(&eks.DeleteNodegroupInput{ ClusterName: ng.cluster, NodegroupName: ng.name, }) return err } func (ng *EKSNodegroup) Properties() types.Properties { return types.NewProperties(). Set("Cluster", *ng.cluster). Set("Profile", *ng.name) } func (ng *EKSNodegroup) String() string { return fmt.Sprintf("%s:%s", *ng.cluster, *ng.name) } aws-nuke-2.16.0/resources/elasticache-cacheparametergroups.go000066400000000000000000000035721411137415400243520ustar00rootroot00000000000000package resources import ( "fmt" "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/elasticache" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ElasticacheCacheParameterGroup struct { svc *elasticache.ElastiCache groupName *string groupFamily *string } func init() { register("ElasticacheCacheParameterGroup", ListElasticacheCacheParameterGroups) } func ListElasticacheCacheParameterGroups(sess *session.Session) ([]Resource, error) { svc := elasticache.New(sess) var resources []Resource params := &elasticache.DescribeCacheParameterGroupsInput{MaxRecords: aws.Int64(100)} for { resp, err := svc.DescribeCacheParameterGroups(params) if err != nil { return nil, err } for _, cacheParameterGroup := range resp.CacheParameterGroups { resources = append(resources, &ElasticacheCacheParameterGroup{ svc: svc, groupName: cacheParameterGroup.CacheParameterGroupName, groupFamily: cacheParameterGroup.CacheParameterGroupFamily, }) } if resp.Marker == nil { break } params.Marker = resp.Marker } return resources, nil } func (i *ElasticacheCacheParameterGroup) Filter() error { if strings.HasPrefix(*i.groupName, "default.") { return fmt.Errorf("Cannot delete default cache parameter group") } return nil } func (i *ElasticacheCacheParameterGroup) Remove() error { params := &elasticache.DeleteCacheParameterGroupInput{ CacheParameterGroupName: i.groupName, } _, err := i.svc.DeleteCacheParameterGroup(params) if err != nil { return err } return nil } func (i *ElasticacheCacheParameterGroup) String() string { return *i.groupName } func (i *ElasticacheCacheParameterGroup) Properties() types.Properties { properties := types.NewProperties() properties. Set("GroupName", i.groupName). Set("GroupFamily", i.groupFamily) return properties } aws-nuke-2.16.0/resources/elasticache-memcachecluster.go000066400000000000000000000022711411137415400233050ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/elasticache" ) type ElasticacheCacheCluster struct { svc *elasticache.ElastiCache clusterID *string status *string } func init() { register("ElasticacheCacheCluster", ListElasticacheCacheClusters) } func ListElasticacheCacheClusters(sess *session.Session) ([]Resource, error) { svc := elasticache.New(sess) params := &elasticache.DescribeCacheClustersInput{MaxRecords: aws.Int64(100)} resp, err := svc.DescribeCacheClusters(params) if err != nil { return nil, err } var resources []Resource for _, cacheCluster := range resp.CacheClusters { resources = append(resources, &ElasticacheCacheCluster{ svc: svc, clusterID: cacheCluster.CacheClusterId, status: cacheCluster.CacheClusterStatus, }) } return resources, nil } func (i *ElasticacheCacheCluster) Remove() error { params := &elasticache.DeleteCacheClusterInput{ CacheClusterId: i.clusterID, } _, err := i.svc.DeleteCacheCluster(params) if err != nil { return err } return nil } func (i *ElasticacheCacheCluster) String() string { return *i.clusterID } aws-nuke-2.16.0/resources/elasticache-replicationgroups.go000066400000000000000000000024111411137415400237060ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/elasticache" ) type ElasticacheReplicationGroup struct { svc *elasticache.ElastiCache groupID *string } func init() { register("ElasticacheReplicationGroup", ListElasticacheReplicationGroups) } func ListElasticacheReplicationGroups(sess *session.Session) ([]Resource, error) { svc := elasticache.New(sess) var resources []Resource params := &elasticache.DescribeReplicationGroupsInput{MaxRecords: aws.Int64(100)} for { resp, err := svc.DescribeReplicationGroups(params) if err != nil { return nil, err } for _, replicationGroup := range resp.ReplicationGroups { resources = append(resources, &ElasticacheReplicationGroup{ svc: svc, groupID: replicationGroup.ReplicationGroupId, }) } if resp.Marker == nil { break } params.Marker = resp.Marker } return resources, nil } func (i *ElasticacheReplicationGroup) Remove() error { params := &elasticache.DeleteReplicationGroupInput{ ReplicationGroupId: i.groupID, } _, err := i.svc.DeleteReplicationGroup(params) if err != nil { return err } return nil } func (i *ElasticacheReplicationGroup) String() string { return *i.groupID } aws-nuke-2.16.0/resources/elasticache-subnetgroups.go000066400000000000000000000021621411137415400227000ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/elasticache" ) type ElasticacheSubnetGroup struct { svc *elasticache.ElastiCache name *string } func init() { register("ElasticacheSubnetGroup", ListElasticacheSubnetGroups) } func ListElasticacheSubnetGroups(sess *session.Session) ([]Resource, error) { svc := elasticache.New(sess) params := &elasticache.DescribeCacheSubnetGroupsInput{MaxRecords: aws.Int64(100)} resp, err := svc.DescribeCacheSubnetGroups(params) if err != nil { return nil, err } var resources []Resource for _, subnetGroup := range resp.CacheSubnetGroups { resources = append(resources, &ElasticacheSubnetGroup{ svc: svc, name: subnetGroup.CacheSubnetGroupName, }) } return resources, nil } func (i *ElasticacheSubnetGroup) Remove() error { params := &elasticache.DeleteCacheSubnetGroupInput{ CacheSubnetGroupName: i.name, } _, err := i.svc.DeleteCacheSubnetGroup(params) if err != nil { return err } return nil } func (i *ElasticacheSubnetGroup) String() string { return *i.name } aws-nuke-2.16.0/resources/elasticbeanstalk-applications.go000066400000000000000000000020501411137415400236660ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/elasticbeanstalk" ) type ElasticBeanstalkApplication struct { svc *elasticbeanstalk.ElasticBeanstalk name *string } func init() { register("ElasticBeanstalkApplication", ListElasticBeanstalkApplications) } func ListElasticBeanstalkApplications(sess *session.Session) ([]Resource, error) { svc := elasticbeanstalk.New(sess) resources := []Resource{} params := &elasticbeanstalk.DescribeApplicationsInput{} output, err := svc.DescribeApplications(params) if err != nil { return nil, err } for _, application := range output.Applications { resources = append(resources, &ElasticBeanstalkApplication{ svc: svc, name: application.ApplicationName, }) } return resources, nil } func (f *ElasticBeanstalkApplication) Remove() error { _, err := f.svc.DeleteApplication(&elasticbeanstalk.DeleteApplicationInput{ ApplicationName: f.name, }) return err } func (f *ElasticBeanstalkApplication) String() string { return *f.name } aws-nuke-2.16.0/resources/elasticbeanstalk-environments.go000066400000000000000000000030441411137415400237330ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/elasticbeanstalk" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ElasticBeanstalkEnvironment struct { svc *elasticbeanstalk.ElasticBeanstalk ID *string name *string } func init() { register("ElasticBeanstalkEnvironment", ListElasticBeanstalkEnvironments) } func ListElasticBeanstalkEnvironments(sess *session.Session) ([]Resource, error) { svc := elasticbeanstalk.New(sess) resources := []Resource{} params := &elasticbeanstalk.DescribeEnvironmentsInput{ MaxRecords: aws.Int64(100), IncludeDeleted: aws.Bool(false), } for { output, err := svc.DescribeEnvironments(params) if err != nil { return nil, err } for _, environment := range output.Environments { resources = append(resources, &ElasticBeanstalkEnvironment{ svc: svc, ID: environment.EnvironmentId, name: environment.EnvironmentName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *ElasticBeanstalkEnvironment) Remove() error { _, err := f.svc.TerminateEnvironment(&elasticbeanstalk.TerminateEnvironmentInput{ EnvironmentId: f.ID, ForceTerminate: aws.Bool(true), TerminateResources: aws.Bool(true), }) return err } func (e *ElasticBeanstalkEnvironment) Properties() types.Properties { return types.NewProperties(). Set("Name", e.name) } func (f *ElasticBeanstalkEnvironment) String() string { return *f.ID } aws-nuke-2.16.0/resources/elasticsearchservice-domain.go000066400000000000000000000017221411137415400233360ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/elasticsearchservice" ) type ESDomain struct { svc *elasticsearchservice.ElasticsearchService domainName *string } func init() { register("ESDomain", ListESDomains) } func ListESDomains(sess *session.Session) ([]Resource, error) { svc := elasticsearchservice.New(sess) params := &elasticsearchservice.ListDomainNamesInput{} resp, err := svc.ListDomainNames(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, domain := range resp.DomainNames { resources = append(resources, &ESDomain{ svc: svc, domainName: domain.DomainName, }) } return resources, nil } func (f *ESDomain) Remove() error { _, err := f.svc.DeleteElasticsearchDomain(&elasticsearchservice.DeleteElasticsearchDomainInput{ DomainName: f.domainName, }) return err } func (f *ESDomain) String() string { return *f.domainName } aws-nuke-2.16.0/resources/elastictranscoder-pipelines.go000066400000000000000000000021651411137415400233770ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/elastictranscoder" ) type ElasticTranscoderPipeline struct { svc *elastictranscoder.ElasticTranscoder pipelineID *string } func init() { register("ElasticTranscoderPipeline", ListElasticTranscoderPipelines) } func ListElasticTranscoderPipelines(sess *session.Session) ([]Resource, error) { svc := elastictranscoder.New(sess) resources := []Resource{} params := &elastictranscoder.ListPipelinesInput{} for { resp, err := svc.ListPipelines(params) if err != nil { return nil, err } for _, pipeline := range resp.Pipelines { resources = append(resources, &ElasticTranscoderPipeline{ svc: svc, pipelineID: pipeline.Id, }) } if resp.NextPageToken == nil { break } params.PageToken = resp.NextPageToken } return resources, nil } func (f *ElasticTranscoderPipeline) Remove() error { _, err := f.svc.DeletePipeline(&elastictranscoder.DeletePipelineInput{ Id: f.pipelineID, }) return err } func (f *ElasticTranscoderPipeline) String() string { return *f.pipelineID } aws-nuke-2.16.0/resources/elb-elb.go000066400000000000000000000034121411137415400171760ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/elb" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ELBLoadBalancer struct { svc *elb.ELB name *string tags []*elb.Tag } func init() { register("ELB", ListELBLoadBalancers) } func ListELBLoadBalancers(sess *session.Session) ([]Resource, error) { resources := make([]Resource, 0) elbNames := make([]*string, 0) svc := elb.New(sess) err := svc.DescribeLoadBalancersPages(nil, func(page *elb.DescribeLoadBalancersOutput, lastPage bool) bool { for _, desc := range page.LoadBalancerDescriptions { elbNames = append(elbNames, desc.LoadBalancerName) } return !lastPage }) if err != nil { return nil, err } for len(elbNames) > 0 { requestElements := len(elbNames) if requestElements > 20 { requestElements = 20 } tagResp, err := svc.DescribeTags(&elb.DescribeTagsInput{ LoadBalancerNames: elbNames[:requestElements], }) if err != nil { return nil, err } for _, elbTagInfo := range tagResp.TagDescriptions { resources = append(resources, &ELBLoadBalancer{ svc: svc, name: elbTagInfo.LoadBalancerName, tags: elbTagInfo.Tags, }) } // Remove the elements that were queried elbNames = elbNames[requestElements:] } return resources, nil } func (e *ELBLoadBalancer) Remove() error { params := &elb.DeleteLoadBalancerInput{ LoadBalancerName: e.name, } _, err := e.svc.DeleteLoadBalancer(params) if err != nil { return err } return nil } func (e *ELBLoadBalancer) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range e.tags { properties.SetTag(tagValue.Key, tagValue.Value) } return properties } func (e *ELBLoadBalancer) String() string { return *e.name } aws-nuke-2.16.0/resources/elbv2-alb.go000066400000000000000000000043241411137415400174450ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/elbv2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ELBv2LoadBalancer struct { svc *elbv2.ELBV2 name *string arn *string tags []*elbv2.Tag } func init() { register("ELBv2", ListELBv2LoadBalancers) } func ListELBv2LoadBalancers(sess *session.Session) ([]Resource, error) { svc := elbv2.New(sess) var tagReqELBv2ARNs []*string ELBv2ArnToName := make(map[string]*string) err := svc.DescribeLoadBalancersPages(nil, func(page *elbv2.DescribeLoadBalancersOutput, lastPage bool) bool { for _, elbv2 := range page.LoadBalancers { tagReqELBv2ARNs = append(tagReqELBv2ARNs, elbv2.LoadBalancerArn) ELBv2ArnToName[*elbv2.LoadBalancerArn] = elbv2.LoadBalancerName } return !lastPage }) if err != nil { return nil, err } // Tags for ELBv2s 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 resources := make([]Resource, 0) for len(tagReqELBv2ARNs) > 0 { requestElements := len(tagReqELBv2ARNs) if requestElements > 20 { requestElements = 20 } tagResp, err := svc.DescribeTags(&elbv2.DescribeTagsInput{ ResourceArns: tagReqELBv2ARNs[:requestElements], }) if err != nil { return nil, err } for _, elbv2TagInfo := range tagResp.TagDescriptions { resources = append(resources, &ELBv2LoadBalancer{ svc: svc, name: ELBv2ArnToName[*elbv2TagInfo.ResourceArn], arn: elbv2TagInfo.ResourceArn, tags: elbv2TagInfo.Tags, }) } // Remove the elements that were queried tagReqELBv2ARNs = tagReqELBv2ARNs[requestElements:] } return resources, nil } func (e *ELBv2LoadBalancer) Remove() error { params := &elbv2.DeleteLoadBalancerInput{ LoadBalancerArn: e.arn, } _, err := e.svc.DeleteLoadBalancer(params) if err != nil { return err } return nil } func (e *ELBv2LoadBalancer) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range e.tags { properties.SetTag(tagValue.Key, tagValue.Value) } return properties } func (e *ELBv2LoadBalancer) String() string { return *e.name } aws-nuke-2.16.0/resources/elbv2-targetgroup.go000066400000000000000000000044671411137415400212620ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/elbv2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ELBv2TargetGroup struct { svc *elbv2.ELBV2 name *string arn *string tags []*elbv2.Tag } func init() { register("ELBv2TargetGroup", ListELBv2TargetGroups) } func ListELBv2TargetGroups(sess *session.Session) ([]Resource, error) { svc := elbv2.New(sess) var tagReqELBv2TargetGroupARNs []*string targetGroupArnToName := make(map[string]*string) err := svc.DescribeTargetGroupsPages(nil, func(page *elbv2.DescribeTargetGroupsOutput, lastPage bool) bool { for _, targetGroup := range page.TargetGroups { tagReqELBv2TargetGroupARNs = append(tagReqELBv2TargetGroupARNs, targetGroup.TargetGroupArn) targetGroupArnToName[*targetGroup.TargetGroupArn] = targetGroup.TargetGroupName } return !lastPage }) if err != nil { return nil, err } // Tags for ELBv2 target groups 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 resources := make([]Resource, 0) for len(tagReqELBv2TargetGroupARNs) > 0 { requestElements := len(tagReqELBv2TargetGroupARNs) if requestElements > 20 { requestElements = 20 } tagResp, err := svc.DescribeTags(&elbv2.DescribeTagsInput{ ResourceArns: tagReqELBv2TargetGroupARNs[:requestElements], }) if err != nil { return nil, err } for _, tagInfo := range tagResp.TagDescriptions { resources = append(resources, &ELBv2TargetGroup{ svc: svc, name: targetGroupArnToName[*tagInfo.ResourceArn], arn: tagInfo.ResourceArn, tags: tagInfo.Tags, }) } // Remove the elements that were queried tagReqELBv2TargetGroupARNs = tagReqELBv2TargetGroupARNs[requestElements:] } return resources, nil } func (e *ELBv2TargetGroup) Remove() error { _, err := e.svc.DeleteTargetGroup(&elbv2.DeleteTargetGroupInput{ TargetGroupArn: e.arn, }) if err != nil { return err } return nil } func (e *ELBv2TargetGroup) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range e.tags { properties.SetTag(tagValue.Key, tagValue.Value) } return properties } func (e *ELBv2TargetGroup) String() string { return *e.name } aws-nuke-2.16.0/resources/emr-clusters.go000066400000000000000000000023531411137415400203240ustar00rootroot00000000000000package resources import ( "fmt" "strings" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/emr" ) type EMRCluster struct { svc *emr.EMR ID *string state *string } func init() { register("EMRCluster", ListEMRClusters) } func ListEMRClusters(sess *session.Session) ([]Resource, error) { svc := emr.New(sess) resources := []Resource{} params := &emr.ListClustersInput{} for { resp, err := svc.ListClusters(params) if err != nil { return nil, err } for _, cluster := range resp.Clusters { resources = append(resources, &EMRCluster{ svc: svc, ID: cluster.Id, state: cluster.Status.State, }) } if resp.Marker == nil { break } params.Marker = resp.Marker } return resources, nil } func (f *EMRCluster) Remove() error { //Call names are inconsistent in the SDK _, err := f.svc.TerminateJobFlows(&emr.TerminateJobFlowsInput{ JobFlowIds: []*string{f.ID}, }) // Force nil return due to async callbacks blocking if err == nil { return nil } return err } func (f *EMRCluster) String() string { return *f.ID } func (f *EMRCluster) Filter() error { if strings.Contains(*f.state, "TERMINATED") { return fmt.Errorf("already terminated") } return nil } aws-nuke-2.16.0/resources/emr-securityconfigurations.go000066400000000000000000000021541411137415400233010ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/emr" ) type EMRSecurityConfiguration struct { svc *emr.EMR name *string } func init() { register("EMRSecurityConfiguration", ListEMRSecurityConfiguration) } func ListEMRSecurityConfiguration(sess *session.Session) ([]Resource, error) { svc := emr.New(sess) resources := []Resource{} params := &emr.ListSecurityConfigurationsInput{} for { resp, err := svc.ListSecurityConfigurations(params) if err != nil { return nil, err } for _, securityConfiguration := range resp.SecurityConfigurations { resources = append(resources, &EMRSecurityConfiguration{ svc: svc, name: securityConfiguration.Name, }) } if resp.Marker == nil { break } params.Marker = resp.Marker } return resources, nil } func (f *EMRSecurityConfiguration) Remove() error { //Call names are inconsistent in the SDK _, err := f.svc.DeleteSecurityConfiguration(&emr.DeleteSecurityConfigurationInput{ Name: f.name, }) return err } func (f *EMRSecurityConfiguration) String() string { return *f.name } aws-nuke-2.16.0/resources/firehose-deliverystreams.go000066400000000000000000000025301411137415400227200ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/firehose" ) type FirehoseDeliveryStream struct { svc *firehose.Firehose deliveryStreamName *string } func init() { register("FirehoseDeliveryStream", ListFirehoseDeliveryStreams) } func ListFirehoseDeliveryStreams(sess *session.Session) ([]Resource, error) { svc := firehose.New(sess) resources := []Resource{} var lastDeliveryStreamName *string params := &firehose.ListDeliveryStreamsInput{ Limit: aws.Int64(25), } for { output, err := svc.ListDeliveryStreams(params) if err != nil { return nil, err } for _, deliveryStreamName := range output.DeliveryStreamNames { resources = append(resources, &FirehoseDeliveryStream{ svc: svc, deliveryStreamName: deliveryStreamName, }) lastDeliveryStreamName = deliveryStreamName } if *output.HasMoreDeliveryStreams == false { break } params.ExclusiveStartDeliveryStreamName = lastDeliveryStreamName } return resources, nil } func (f *FirehoseDeliveryStream) Remove() error { _, err := f.svc.DeleteDeliveryStream(&firehose.DeleteDeliveryStreamInput{ DeliveryStreamName: f.deliveryStreamName, }) return err } func (f *FirehoseDeliveryStream) String() string { return *f.deliveryStreamName } aws-nuke-2.16.0/resources/fms_notification_channels.go000066400000000000000000000023271411137415400231060ustar00rootroot00000000000000package 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/fms" "github.com/rebuy-de/aws-nuke/pkg/types" ) type FMSNotificationChannel struct { svc *fms.FMS } func init() { register("FMSNotificationChannel", ListFMSNotificationChannel) } func ListFMSNotificationChannel(sess *session.Session) ([]Resource, error) { svc := fms.New(sess) resources := []Resource{} if _, err := svc.GetNotificationChannel(&fms.GetNotificationChannelInput{}); err != nil { if aerr, ok := err.(awserr.Error); ok { if aerr.Code() != fms.ErrCodeResourceNotFoundException { return nil, err } } else { return nil, err } } else { resources = append(resources, &FMSNotificationChannel{ svc: svc, }) } return resources, nil } func (f *FMSNotificationChannel) Remove() error { _, err := f.svc.DeleteNotificationChannel(&fms.DeleteNotificationChannelInput{}) return err } func (f *FMSNotificationChannel) String() string { return "fms-notification-channel" } func (f *FMSNotificationChannel) Properties() types.Properties { properties := types.NewProperties() properties.Set("NotificationChannelEnabled", "true") return properties } aws-nuke-2.16.0/resources/fms_policies.go000066400000000000000000000024421411137415400203520ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/fms" "github.com/rebuy-de/aws-nuke/pkg/types" ) type FMSPolicy struct { svc *fms.FMS policy *fms.PolicySummary } func init() { register("FMSPolicy", ListFMSPolicies) } func ListFMSPolicies(sess *session.Session) ([]Resource, error) { svc := fms.New(sess) resources := []Resource{} params := &fms.ListPoliciesInput{ MaxResults: aws.Int64(50), } for { resp, err := svc.ListPolicies(params) if err != nil { return nil, err } for _, policy := range resp.PolicyList { resources = append(resources, &FMSPolicy{ svc: svc, policy: policy, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *FMSPolicy) Remove() error { _, err := f.svc.DeletePolicy(&fms.DeletePolicyInput{ PolicyId: f.policy.PolicyId, DeleteAllPolicyResources: aws.Bool(false), }) return err } func (f *FMSPolicy) String() string { return *f.policy.PolicyId } func (f *FMSPolicy) Properties() types.Properties { properties := types.NewProperties() properties.Set("PolicyID", f.policy.PolicyId) properties.Set("PolicyName", f.policy.PolicyName) return properties } aws-nuke-2.16.0/resources/fsx-backups.go000066400000000000000000000024011411137415400201170ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/fsx" "github.com/rebuy-de/aws-nuke/pkg/types" ) type FSxBackup struct { svc *fsx.FSx backup *fsx.Backup } func init() { register("FSxBackup", ListFSxBackups) } func ListFSxBackups(sess *session.Session) ([]Resource, error) { svc := fsx.New(sess) resources := []Resource{} params := &fsx.DescribeBackupsInput{ MaxResults: aws.Int64(100), } for { resp, err := svc.DescribeBackups(params) if err != nil { return nil, err } for _, backup := range resp.Backups { resources = append(resources, &FSxBackup{ svc: svc, backup: backup, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *FSxBackup) Remove() error { _, err := f.svc.DeleteBackup(&fsx.DeleteBackupInput{ BackupId: f.backup.BackupId, }) return err } func (f *FSxBackup) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range f.backup.Tags { properties.SetTag(tagValue.Key, tagValue.Value) } properties.Set("Type", f.backup.Type) return properties } func (f *FSxBackup) String() string { return *f.backup.BackupId } aws-nuke-2.16.0/resources/fsx-filesystems.go000066400000000000000000000025671411137415400210530ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/fsx" "github.com/rebuy-de/aws-nuke/pkg/types" ) type FSxFileSystem struct { svc *fsx.FSx filesystem *fsx.FileSystem } func init() { register("FSxFileSystem", ListFSxFileSystems) } func ListFSxFileSystems(sess *session.Session) ([]Resource, error) { svc := fsx.New(sess) resources := []Resource{} params := &fsx.DescribeFileSystemsInput{ MaxResults: aws.Int64(100), } for { resp, err := svc.DescribeFileSystems(params) if err != nil { return nil, err } for _, filesystem := range resp.FileSystems { resources = append(resources, &FSxFileSystem{ svc: svc, filesystem: filesystem, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *FSxFileSystem) Remove() error { _, err := f.svc.DeleteFileSystem(&fsx.DeleteFileSystemInput{ FileSystemId: f.filesystem.FileSystemId, }) return err } func (f *FSxFileSystem) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range f.filesystem.Tags { properties.SetTag(tagValue.Key, tagValue.Value) } properties.Set("Type", f.filesystem.FileSystemType) return properties } func (f *FSxFileSystem) String() string { return *f.filesystem.FileSystemId } aws-nuke-2.16.0/resources/ga-accelerators.go000066400000000000000000000027461411137415400207410ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/globalaccelerator" "github.com/rebuy-de/aws-nuke/pkg/types" ) // GlobalAccelerator model type GlobalAccelerator struct { svc *globalaccelerator.GlobalAccelerator ARN *string } func init() { register("GlobalAccelerator", ListGlobalAccelerators) } // ListGlobalAccelerators enumerates all available accelerators func ListGlobalAccelerators(sess *session.Session) ([]Resource, error) { svc := globalaccelerator.New(sess) resources := []Resource{} params := &globalaccelerator.ListAcceleratorsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListAccelerators(params) if err != nil { return nil, err } for _, accelerator := range output.Accelerators { resources = append(resources, &GlobalAccelerator{ svc: svc, ARN: accelerator.AcceleratorArn, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } // Remove resource func (ga *GlobalAccelerator) Remove() error { _, err := ga.svc.DeleteAccelerator(&globalaccelerator.DeleteAcceleratorInput{ AcceleratorArn: ga.ARN, }) return err } // Properties definition func (ga *GlobalAccelerator) Properties() types.Properties { properties := types.NewProperties() properties.Set("ARN", ga.ARN) return properties } // String representation func (ga *GlobalAccelerator) String() string { return *ga.ARN } aws-nuke-2.16.0/resources/ga-endpoints.go000066400000000000000000000055431411137415400202730ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/globalaccelerator" "github.com/rebuy-de/aws-nuke/pkg/types" ) // GlobalAcceleratorEndpointGroup model type GlobalAcceleratorEndpointGroup struct { svc *globalaccelerator.GlobalAccelerator ARN *string } func init() { register("GlobalAcceleratorEndpointGroup", ListGlobalAcceleratorEndpointGroups) } // ListGlobalAcceleratorEndpointGroups enumerates all available accelerators func ListGlobalAcceleratorEndpointGroups(sess *session.Session) ([]Resource, error) { svc := globalaccelerator.New(sess) acceleratorARNs := []*string{} listenerARNs := []*string{} resources := []Resource{} // get all accelerator arns acceleratorParams := &globalaccelerator.ListAcceleratorsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListAccelerators(acceleratorParams) if err != nil { return nil, err } for _, accelerator := range output.Accelerators { acceleratorARNs = append(acceleratorARNs, accelerator.AcceleratorArn) } if output.NextToken == nil { break } acceleratorParams.NextToken = output.NextToken } // get all listerners arns of all accelerators for _, acceleratorARN := range acceleratorARNs { listenerParams := &globalaccelerator.ListListenersInput{ MaxResults: aws.Int64(100), AcceleratorArn: acceleratorARN, } for { output, err := svc.ListListeners(listenerParams) if err != nil { return nil, err } for _, listener := range output.Listeners { listenerARNs = append(listenerARNs, listener.ListenerArn) } if output.NextToken == nil { break } listenerParams.NextToken = output.NextToken } } // get all endpoints based on all listeners based on all accelerator for _, listenerArn := range listenerARNs { params := &globalaccelerator.ListEndpointGroupsInput{ MaxResults: aws.Int64(100), ListenerArn: listenerArn, } for { output, err := svc.ListEndpointGroups(params) if err != nil { return nil, err } for _, endpointGroup := range output.EndpointGroups { resources = append(resources, &GlobalAcceleratorEndpointGroup{ svc: svc, ARN: endpointGroup.EndpointGroupArn, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } } return resources, nil } // Remove resource func (gaeg *GlobalAcceleratorEndpointGroup) Remove() error { _, err := gaeg.svc.DeleteEndpointGroup(&globalaccelerator.DeleteEndpointGroupInput{ EndpointGroupArn: gaeg.ARN, }) return err } // Properties definition func (gaeg *GlobalAcceleratorEndpointGroup) Properties() types.Properties { properties := types.NewProperties() properties.Set("ARN", gaeg.ARN) return properties } // String representation func (gaeg *GlobalAcceleratorEndpointGroup) String() string { return *gaeg.ARN } aws-nuke-2.16.0/resources/ga-listeners.go000066400000000000000000000042601411137415400202730ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/globalaccelerator" "github.com/rebuy-de/aws-nuke/pkg/types" ) // GlobalAcceleratorListener model type GlobalAcceleratorListener struct { svc *globalaccelerator.GlobalAccelerator ARN *string } func init() { register("GlobalAcceleratorListener", ListGlobalAcceleratorListeners) } // ListGlobalAcceleratorListeners enumerates all available listeners of all available accelerators func ListGlobalAcceleratorListeners(sess *session.Session) ([]Resource, error) { svc := globalaccelerator.New(sess) acceleratorARNs := []*string{} resources := []Resource{} // get all accelerator arns acceleratorParams := &globalaccelerator.ListAcceleratorsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListAccelerators(acceleratorParams) if err != nil { return nil, err } for _, accelerator := range output.Accelerators { acceleratorARNs = append(acceleratorARNs, accelerator.AcceleratorArn) } if output.NextToken == nil { break } acceleratorParams.NextToken = output.NextToken } // get all listerners for _, acceleratorARN := range acceleratorARNs { params := &globalaccelerator.ListListenersInput{ MaxResults: aws.Int64(100), AcceleratorArn: acceleratorARN, } for { output, err := svc.ListListeners(params) if err != nil { return nil, err } for _, listener := range output.Listeners { resources = append(resources, &GlobalAcceleratorListener{ svc: svc, ARN: listener.ListenerArn, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } } return resources, nil } // Remove resource func (gal *GlobalAcceleratorListener) Remove() error { _, err := gal.svc.DeleteListener(&globalaccelerator.DeleteListenerInput{ ListenerArn: gal.ARN, }) return err } // Properties definition func (gal *GlobalAcceleratorListener) Properties() types.Properties { properties := types.NewProperties() properties.Set("ARN", gal.ARN) return properties } // String representation func (gal *GlobalAcceleratorListener) String() string { return *gal.ARN } aws-nuke-2.16.0/resources/glue-classifiers.go000066400000000000000000000026201411137415400211350ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/glue" ) type GlueClassifier struct { svc *glue.Glue name *string } func init() { register("GlueClassifier", ListGlueClassifiers) } func ListGlueClassifiers(sess *session.Session) ([]Resource, error) { svc := glue.New(sess) resources := []Resource{} params := &glue.GetClassifiersInput{ MaxResults: aws.Int64(100), } for { output, err := svc.GetClassifiers(params) if err != nil { return nil, err } for _, classifier := range output.Classifiers { switch { case classifier.GrokClassifier != nil: resources = append(resources, &GlueClassifier{ svc: svc, name: classifier.GrokClassifier.Name, }) case classifier.JsonClassifier != nil: resources = append(resources, &GlueClassifier{ svc: svc, name: classifier.JsonClassifier.Name, }) case classifier.XMLClassifier != nil: resources = append(resources, &GlueClassifier{ svc: svc, name: classifier.XMLClassifier.Name, }) } } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *GlueClassifier) Remove() error { _, err := f.svc.DeleteClassifier(&glue.DeleteClassifierInput{ Name: f.name, }) return err } func (f *GlueClassifier) String() string { return *f.name } aws-nuke-2.16.0/resources/glue-connections.go000066400000000000000000000021201411137415400211430ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/glue" ) type GlueConnection struct { svc *glue.Glue connectionName *string } func init() { register("GlueConnection", ListGlueConnections) } func ListGlueConnections(sess *session.Session) ([]Resource, error) { svc := glue.New(sess) resources := []Resource{} params := &glue.GetConnectionsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.GetConnections(params) if err != nil { return nil, err } for _, connection := range output.ConnectionList { resources = append(resources, &GlueConnection{ svc: svc, connectionName: connection.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *GlueConnection) Remove() error { _, err := f.svc.DeleteConnection(&glue.DeleteConnectionInput{ ConnectionName: f.connectionName, }) return err } func (f *GlueConnection) String() string { return *f.connectionName } aws-nuke-2.16.0/resources/glue-crawlers.go000066400000000000000000000017351411137415400204560ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/glue" ) type GlueCrawler struct { svc *glue.Glue name *string } func init() { register("GlueCrawler", ListGlueCrawlers) } func ListGlueCrawlers(sess *session.Session) ([]Resource, error) { svc := glue.New(sess) resources := []Resource{} params := &glue.GetCrawlersInput{ MaxResults: aws.Int64(100), } for { output, err := svc.GetCrawlers(params) if err != nil { return nil, err } for _, crawler := range output.Crawlers { resources = append(resources, &GlueCrawler{ svc: svc, name: crawler.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *GlueCrawler) Remove() error { _, err := f.svc.DeleteCrawler(&glue.DeleteCrawlerInput{ Name: f.name, }) return err } func (f *GlueCrawler) String() string { return *f.name } aws-nuke-2.16.0/resources/glue-databases.go000066400000000000000000000017561411137415400205660ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/glue" ) type GlueDatabase struct { svc *glue.Glue name *string } func init() { register("GlueDatabase", ListGlueDatabases) } func ListGlueDatabases(sess *session.Session) ([]Resource, error) { svc := glue.New(sess) resources := []Resource{} params := &glue.GetDatabasesInput{ MaxResults: aws.Int64(100), } for { output, err := svc.GetDatabases(params) if err != nil { return nil, err } for _, database := range output.DatabaseList { resources = append(resources, &GlueDatabase{ svc: svc, name: database.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *GlueDatabase) Remove() error { _, err := f.svc.DeleteDatabase(&glue.DeleteDatabaseInput{ Name: f.name, }) return err } func (f *GlueDatabase) String() string { return *f.name } aws-nuke-2.16.0/resources/glue-devendpoints.go000066400000000000000000000022521411137415400213310ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/glue" ) type GlueDevEndpoint struct { svc *glue.Glue endpointName *string } func init() { register("GlueDevEndpoint", ListGlueDevEndpoints) } func ListGlueDevEndpoints(sess *session.Session) ([]Resource, error) { svc := glue.New(sess) resources := []Resource{} params := &glue.GetDevEndpointsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.GetDevEndpoints(params) if err != nil { return nil, err } for _, devEndpoint := range output.DevEndpoints { resources = append(resources, &GlueDevEndpoint{ svc: svc, endpointName: devEndpoint.EndpointName, }) } // This one API can and does return an empty string if output.NextToken == nil || len(*output.NextToken) == 0 { break } params.NextToken = output.NextToken } return resources, nil } func (f *GlueDevEndpoint) Remove() error { _, err := f.svc.DeleteDevEndpoint(&glue.DeleteDevEndpointInput{ EndpointName: f.endpointName, }) return err } func (f *GlueDevEndpoint) String() string { return *f.endpointName } aws-nuke-2.16.0/resources/glue-jobs.go000066400000000000000000000016721411137415400175710ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/glue" ) type GlueJob struct { svc *glue.Glue jobName *string } func init() { register("GlueJob", ListGlueJobs) } func ListGlueJobs(sess *session.Session) ([]Resource, error) { svc := glue.New(sess) resources := []Resource{} params := &glue.GetJobsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.GetJobs(params) if err != nil { return nil, err } for _, job := range output.Jobs { resources = append(resources, &GlueJob{ svc: svc, jobName: job.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *GlueJob) Remove() error { _, err := f.svc.DeleteJob(&glue.DeleteJobInput{ JobName: f.jobName, }) return err } func (f *GlueJob) String() string { return *f.jobName } aws-nuke-2.16.0/resources/glue-triggers.go000066400000000000000000000017351411137415400204620ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/glue" ) type GlueTrigger struct { svc *glue.Glue name *string } func init() { register("GlueTrigger", ListGlueTriggers) } func ListGlueTriggers(sess *session.Session) ([]Resource, error) { svc := glue.New(sess) resources := []Resource{} params := &glue.GetTriggersInput{ MaxResults: aws.Int64(100), } for { output, err := svc.GetTriggers(params) if err != nil { return nil, err } for _, trigger := range output.Triggers { resources = append(resources, &GlueTrigger{ svc: svc, name: trigger.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *GlueTrigger) Remove() error { _, err := f.svc.DeleteTrigger(&glue.DeleteTriggerInput{ Name: f.name, }) return err } func (f *GlueTrigger) String() string { return *f.name } aws-nuke-2.16.0/resources/guardduty.go000066400000000000000000000023031411137415400177020ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/guardduty" "github.com/rebuy-de/aws-nuke/pkg/types" ) type GuardDutyDetector struct { svc *guardduty.GuardDuty id *string } func init() { register("GuardDutyDetector", ListGuardDutyDetectors) } func ListGuardDutyDetectors(sess *session.Session) ([]Resource, error) { svc := guardduty.New(sess) detectors := make([]Resource, 0) params := &guardduty.ListDetectorsInput{} err := svc.ListDetectorsPages(params, func(page *guardduty.ListDetectorsOutput, lastPage bool) bool { for _, out := range page.DetectorIds { detectors = append(detectors, &GuardDutyDetector{ svc: svc, id: out, }) } return true }) if err != nil { return nil, err } return detectors, nil } func (detector *GuardDutyDetector) Remove() error { _, err := detector.svc.DeleteDetector(&guardduty.DeleteDetectorInput{ DetectorId: detector.id, }) return err } func (detector *GuardDutyDetector) Properties() types.Properties { properties := types.NewProperties() properties.Set("DetectorID", detector.id) return properties } func (detector *GuardDutyDetector) String() string { return *detector.id } aws-nuke-2.16.0/resources/iam-group-policies.go000066400000000000000000000022611411137415400214020ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" ) type IAMGroupPolicy struct { svc *iam.IAM policyName string groupName string } func init() { register("IAMGroupPolicy", ListIAMGroupPolicies) } func ListIAMGroupPolicies(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) resp, err := svc.ListGroups(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, group := range resp.Groups { resp, err := svc.ListGroupPolicies( &iam.ListGroupPoliciesInput{ GroupName: group.GroupName, }) if err != nil { return nil, err } for _, pol := range resp.PolicyNames { resources = append(resources, &IAMGroupPolicy{ svc: svc, policyName: *pol, groupName: *group.GroupName, }) } } return resources, nil } func (e *IAMGroupPolicy) Remove() error { _, err := e.svc.DeleteGroupPolicy( &iam.DeleteGroupPolicyInput{ PolicyName: &e.policyName, GroupName: &e.groupName, }) if err != nil { return err } return nil } func (e *IAMGroupPolicy) String() string { return fmt.Sprintf("%s -> %s", e.groupName, e.policyName) } aws-nuke-2.16.0/resources/iam-group-policy-attachments.go000066400000000000000000000030611411137415400234020ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" "github.com/rebuy-de/aws-nuke/pkg/types" ) type IAMGroupPolicyAttachment struct { svc *iam.IAM policyArn string policyName string roleName string } func init() { register("IAMGroupPolicyAttachment", ListIAMGroupPolicyAttachments) } func ListIAMGroupPolicyAttachments(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) resp, err := svc.ListGroups(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, role := range resp.Groups { resp, err := svc.ListAttachedGroupPolicies( &iam.ListAttachedGroupPoliciesInput{ GroupName: role.GroupName, }) if err != nil { return nil, err } for _, pol := range resp.AttachedPolicies { resources = append(resources, &IAMGroupPolicyAttachment{ svc: svc, policyArn: *pol.PolicyArn, policyName: *pol.PolicyName, roleName: *role.GroupName, }) } } return resources, nil } func (e *IAMGroupPolicyAttachment) Remove() error { _, err := e.svc.DetachGroupPolicy( &iam.DetachGroupPolicyInput{ PolicyArn: &e.policyArn, GroupName: &e.roleName, }) if err != nil { return err } return nil } func (e *IAMGroupPolicyAttachment) Properties() types.Properties { return types.NewProperties(). Set("RoleName", e.roleName). Set("PolicyName", e.policyName). Set("PolicyArn", e.policyArn) } func (e *IAMGroupPolicyAttachment) String() string { return fmt.Sprintf("%s -> %s", e.roleName, e.policyName) } aws-nuke-2.16.0/resources/iam-groups.go000066400000000000000000000014201411137415400177540ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" ) type IAMGroup struct { svc *iam.IAM name string } func init() { register("IAMGroup", ListIAMGroups) } func ListIAMGroups(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) resp, err := svc.ListGroups(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.Groups { resources = append(resources, &IAMGroup{ svc: svc, name: *out.GroupName, }) } return resources, nil } func (e *IAMGroup) Remove() error { _, err := e.svc.DeleteGroup(&iam.DeleteGroupInput{ GroupName: &e.name, }) if err != nil { return err } return nil } func (e *IAMGroup) String() string { return e.name } aws-nuke-2.16.0/resources/iam-instance-profile-roles.go000066400000000000000000000024141411137415400230250ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" ) type IAMInstanceProfileRole struct { svc *iam.IAM role string profile string } func init() { register("IAMInstanceProfileRole", ListIAMInstanceProfileRoles) } func ListIAMInstanceProfileRoles(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) params := &iam.ListInstanceProfilesInput{} resources := make([]Resource, 0) for { resp, err := svc.ListInstanceProfiles(params) if err != nil { return nil, err } for _, out := range resp.InstanceProfiles { for _, role := range out.Roles { resources = append(resources, &IAMInstanceProfileRole{ svc: svc, profile: *out.InstanceProfileName, role: *role.RoleName, }) } } if *resp.IsTruncated == false { break } params.Marker = resp.Marker } return resources, nil } func (e *IAMInstanceProfileRole) Remove() error { _, err := e.svc.RemoveRoleFromInstanceProfile( &iam.RemoveRoleFromInstanceProfileInput{ InstanceProfileName: &e.profile, RoleName: &e.role, }) if err != nil { return err } return nil } func (e *IAMInstanceProfileRole) String() string { return fmt.Sprintf("%s -> %s", e.profile, e.role) } aws-nuke-2.16.0/resources/iam-instance-profiles.go000066400000000000000000000020441411137415400220650ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" ) type IAMInstanceProfile struct { svc *iam.IAM name string } func init() { register("IAMInstanceProfile", ListIAMInstanceProfiles) } func ListIAMInstanceProfiles(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) params := &iam.ListInstanceProfilesInput{} resources := make([]Resource, 0) for { resp, err := svc.ListInstanceProfiles(params) if err != nil { return nil, err } for _, out := range resp.InstanceProfiles { resources = append(resources, &IAMInstanceProfile{ svc: svc, name: *out.InstanceProfileName, }) } if *resp.IsTruncated == false { break } params.Marker = resp.Marker } return resources, nil } func (e *IAMInstanceProfile) Remove() error { _, err := e.svc.DeleteInstanceProfile(&iam.DeleteInstanceProfileInput{ InstanceProfileName: &e.name, }) if err != nil { return err } return nil } func (e *IAMInstanceProfile) String() string { return e.name } aws-nuke-2.16.0/resources/iam-list-user-group-attachments.go000066400000000000000000000023341411137415400240340ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" ) type IAMUserGroupAttachment struct { svc *iam.IAM groupName string userName string } func init() { register("IAMUserGroupAttachment", ListIAMUserGroupAttachments) } func ListIAMUserGroupAttachments(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) resp, err := svc.ListUsers(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, role := range resp.Users { resp, err := svc.ListGroupsForUser( &iam.ListGroupsForUserInput{ UserName: role.UserName, }) if err != nil { return nil, err } for _, grp := range resp.Groups { resources = append(resources, &IAMUserGroupAttachment{ svc: svc, groupName: *grp.GroupName, userName: *role.UserName, }) } } return resources, nil } func (e *IAMUserGroupAttachment) Remove() error { _, err := e.svc.RemoveUserFromGroup( &iam.RemoveUserFromGroupInput{ GroupName: &e.groupName, UserName: &e.userName, }) if err != nil { return err } return nil } func (e *IAMUserGroupAttachment) String() string { return fmt.Sprintf("%s -> %s", e.userName, e.groupName) } aws-nuke-2.16.0/resources/iam-login-profiles.go000066400000000000000000000030271411137415400213730ustar00rootroot00000000000000package 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/rebuy-de/aws-nuke/pkg/types" "github.com/sirupsen/logrus" ) type IAMLoginProfile struct { svc *iam.IAM name string } func init() { register("IAMLoginProfile", ListIAMLoginProfiles) } func ListIAMLoginProfiles(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) resp, err := svc.ListUsers(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.Users { lpresp, err := svc.GetLoginProfile(&iam.GetLoginProfileInput{UserName: out.UserName}) if err != nil { if aerr, ok := err.(awserr.Error); ok { switch aerr.Code() { case iam.ErrCodeNoSuchEntityException: // The user does not have a login profile and we do not // need to print an error for that. continue } } logrus.Errorf("failed to list login profile for user %s: %v", *out.UserName, err) continue } if lpresp.LoginProfile != nil { resources = append(resources, &IAMLoginProfile{ svc: svc, name: *out.UserName, }) } } return resources, nil } func (e *IAMLoginProfile) Remove() error { _, err := e.svc.DeleteLoginProfile(&iam.DeleteLoginProfileInput{UserName: &e.name}) if err != nil { return err } return nil } func (e *IAMLoginProfile) Properties() types.Properties { return types.NewProperties(). Set("UserName", e.name) } func (e *IAMLoginProfile) String() string { return e.name } aws-nuke-2.16.0/resources/iam-open-id-connect-provider.go000066400000000000000000000017711411137415400232600ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" ) type IAMOpenIDConnectProvider struct { svc *iam.IAM arn string } func init() { register("IAMOpenIDConnectProvider", ListIAMOpenIDConnectProvider) } func ListIAMOpenIDConnectProvider(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) params := &iam.ListOpenIDConnectProvidersInput{} resources := make([]Resource, 0) resp, err := svc.ListOpenIDConnectProviders(params) if err != nil { return nil, err } for _, out := range resp.OpenIDConnectProviderList { resources = append(resources, &IAMOpenIDConnectProvider{ svc: svc, arn: *out.Arn, }) } return resources, nil } func (e *IAMOpenIDConnectProvider) Remove() error { _, err := e.svc.DeleteOpenIDConnectProvider(&iam.DeleteOpenIDConnectProviderInput{ OpenIDConnectProviderArn: &e.arn, }) if err != nil { return err } return nil } func (e *IAMOpenIDConnectProvider) String() string { return e.arn } aws-nuke-2.16.0/resources/iam-policies.go000066400000000000000000000046471411137415400202620ustar00rootroot00000000000000package resources import ( "github.com/sirupsen/logrus" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" "github.com/rebuy-de/aws-nuke/pkg/types" ) type IAMPolicy struct { svc *iam.IAM name string policyId string arn string path string tags []*iam.Tag } func init() { register("IAMPolicy", ListIAMPolicies) } func GetIAMPolicy(svc *iam.IAM, policyArn *string) (*iam.Policy, error) { params := &iam.GetPolicyInput{ PolicyArn: policyArn, } resp, err := svc.GetPolicy(params) return resp.Policy, err } func ListIAMPolicies(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) params := &iam.ListPoliciesInput{ Scope: aws.String("Local"), } policies := make([]*iam.Policy, 0) err := svc.ListPoliciesPages(params, func(page *iam.ListPoliciesOutput, lastPage bool) bool { for _, listedPolicy := range page.Policies { policy, err := GetIAMPolicy(svc, listedPolicy.Arn) if err != nil { logrus.Errorf("Failed to get listed policy %s: %v", *listedPolicy.PolicyName, err) break } policies = append(policies, policy) } return true }) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range policies { resources = append(resources, &IAMPolicy{ svc: svc, name: *out.PolicyName, path: *out.Path, arn: *out.Arn, policyId: *out.PolicyId, tags: out.Tags, }) } return resources, nil } func (e *IAMPolicy) Remove() error { resp, err := e.svc.ListPolicyVersions(&iam.ListPolicyVersionsInput{ PolicyArn: &e.arn, }) if err != nil { return err } for _, version := range resp.Versions { if !*version.IsDefaultVersion { _, err = e.svc.DeletePolicyVersion(&iam.DeletePolicyVersionInput{ PolicyArn: &e.arn, VersionId: version.VersionId, }) if err != nil { return err } } } _, err = e.svc.DeletePolicy(&iam.DeletePolicyInput{ PolicyArn: &e.arn, }) if err != nil { return err } return nil } func (policy *IAMPolicy) Properties() types.Properties { properties := types.NewProperties() properties.Set("Name", policy.name) properties.Set("ARN", policy.arn) properties.Set("Path", policy.path) properties.Set("PolicyID", policy.policyId) for _, tag := range policy.tags { properties.SetTag(tag.Key, tag.Value) } return properties } func (e *IAMPolicy) String() string { return e.arn } aws-nuke-2.16.0/resources/iam-role-policy-attachments.go000066400000000000000000000050201411137415400232040ustar00rootroot00000000000000package resources import ( "fmt" "strings" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" "github.com/rebuy-de/aws-nuke/pkg/types" "github.com/sirupsen/logrus" ) type IAMRolePolicyAttachment struct { svc *iam.IAM policyArn string policyName string roleName string roleTags []*iam.Tag } func init() { register("IAMRolePolicyAttachment", ListIAMRolePolicyAttachments) } func ListIAMRolePolicyAttachments(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) roleParams := &iam.ListRolesInput{} resources := make([]Resource, 0) for { roleResp, err := svc.ListRoles(roleParams) if err != nil { return nil, err } for _, listedRole := range roleResp.Roles { role, err := GetIAMRole(svc, listedRole.RoleName) if err != nil { logrus.Errorf("Failed to get listed role %s: %v", *listedRole.RoleName, err) continue } polParams := &iam.ListAttachedRolePoliciesInput{ RoleName: role.RoleName, } for { polResp, err := svc.ListAttachedRolePolicies(polParams) if err != nil { logrus.Errorf("failed to list attached policies for role %s: %v", *role.RoleName, err) break } for _, pol := range polResp.AttachedPolicies { resources = append(resources, &IAMRolePolicyAttachment{ svc: svc, policyArn: *pol.PolicyArn, policyName: *pol.PolicyName, roleName: *role.RoleName, roleTags: role.Tags, }) } if *polResp.IsTruncated == false { break } polParams.Marker = polResp.Marker } } if *roleResp.IsTruncated == false { break } roleParams.Marker = roleResp.Marker } return resources, nil } func (e *IAMRolePolicyAttachment) Filter() error { if strings.HasPrefix(e.policyArn, "arn:aws:iam::aws:policy/aws-service-role/") { return fmt.Errorf("cannot detach from service roles") } return nil } func (e *IAMRolePolicyAttachment) Remove() error { _, err := e.svc.DetachRolePolicy( &iam.DetachRolePolicyInput{ PolicyArn: &e.policyArn, RoleName: &e.roleName, }) if err != nil { return err } return nil } func (e *IAMRolePolicyAttachment) Properties() types.Properties { properties := types.NewProperties(). Set("RoleName", e.roleName). Set("PolicyName", e.policyName). Set("PolicyArn", e.policyArn) for _, tag := range e.roleTags { properties.SetTagWithPrefix("role", tag.Key, tag.Value) } return properties } func (e *IAMRolePolicyAttachment) String() string { return fmt.Sprintf("%s -> %s", e.roleName, e.policyName) } aws-nuke-2.16.0/resources/iam-role-policy.go000066400000000000000000000047321411137415400207040ustar00rootroot00000000000000package resources import ( "fmt" "github.com/sirupsen/logrus" "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" "github.com/rebuy-de/aws-nuke/pkg/types" ) type IAMRolePolicy struct { svc *iam.IAM role iam.Role policyName string } func init() { register("IAMRolePolicy", ListIAMRolePolicies) } func ListIAMRolePolicies(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) roleParams := &iam.ListRolesInput{} resources := make([]Resource, 0) for { roles, err := svc.ListRoles(roleParams) if err != nil { return nil, err } for _, listedRole := range roles.Roles { role, err := GetIAMRole(svc, listedRole.RoleName) if err != nil { logrus.Errorf("Failed to get listed role %s: %v", *listedRole.RoleName, err) continue } polParams := &iam.ListRolePoliciesInput{ RoleName: role.RoleName, } for { policies, err := svc.ListRolePolicies(polParams) if err != nil { logrus. WithError(err). WithField("roleName", *role.RoleName). Error("Failed to list policies") break } for _, policyName := range policies.PolicyNames { resources = append(resources, &IAMRolePolicy{ svc: svc, role: *role, policyName: *policyName, }) } if *policies.IsTruncated == false { break } polParams.Marker = policies.Marker } } if *roles.IsTruncated == false { break } roleParams.Marker = roles.Marker } return resources, nil } func (e *IAMRolePolicy) Filter() error { if strings.HasPrefix(aws.StringValue(e.role.Path), "/aws-service-role/") { return fmt.Errorf("cannot alter service roles") } return nil } func (e *IAMRolePolicy) Remove() error { _, err := e.svc.DeleteRolePolicy( &iam.DeleteRolePolicyInput{ RoleName: e.role.RoleName, PolicyName: &e.policyName, }) if err != nil { return err } return nil } func (e *IAMRolePolicy) Properties() types.Properties { properties := types.NewProperties() properties.Set("PolicyName", e.policyName) properties.Set("role:RoleName", e.role.RoleName) properties.Set("role:RoleID", e.role.RoleId) properties.Set("role:Path", e.role.Path) for _, tagValue := range e.role.Tags { properties.SetTagWithPrefix("role", tagValue.Key, tagValue.Value) } return properties } func (e *IAMRolePolicy) String() string { return fmt.Sprintf("%s -> %s", aws.StringValue(e.role.RoleName), e.policyName) } aws-nuke-2.16.0/resources/iam-roles.go000066400000000000000000000035271411137415400175730ustar00rootroot00000000000000package resources import ( "fmt" "strings" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" "github.com/rebuy-de/aws-nuke/pkg/types" "github.com/sirupsen/logrus" ) type IAMRole struct { svc *iam.IAM role *iam.Role name string path string } func init() { register("IAMRole", ListIAMRoles) } func GetIAMRole(svc *iam.IAM, roleName *string) (*iam.Role, error) { params := &iam.GetRoleInput{ RoleName: roleName, } resp, err := svc.GetRole(params) return resp.Role, err } func ListIAMRoles(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) params := &iam.ListRolesInput{} resources := make([]Resource, 0) for { resp, err := svc.ListRoles(params) if err != nil { return nil, err } for _, out := range resp.Roles { role, err := GetIAMRole(svc, out.RoleName) if err != nil { logrus. WithError(err). WithField("roleName", *out.RoleName). Error("Failed to get listed role") continue } resources = append(resources, &IAMRole{ svc: svc, role: role, name: *role.RoleName, path: *role.Path, }) } if *resp.IsTruncated == false { break } params.Marker = resp.Marker } return resources, nil } func (e *IAMRole) Filter() error { if strings.HasPrefix(e.path, "/aws-service-role/") { return fmt.Errorf("cannot delete service roles") } return nil } func (e *IAMRole) Remove() error { _, err := e.svc.DeleteRole(&iam.DeleteRoleInput{ RoleName: &e.name, }) if err != nil { return err } return nil } func (role *IAMRole) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range role.role.Tags { properties.SetTag(tagValue.Key, tagValue.Value) } properties. Set("Name", role.name). Set("Path", role.path) return properties } func (e *IAMRole) String() string { return e.name } aws-nuke-2.16.0/resources/iam-saml-provider.go000066400000000000000000000016041411137415400212250ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" ) type IAMSAMLProvider struct { svc *iam.IAM arn string } func init() { register("IAMSAMLProvider", ListIAMSAMLProvider) } func ListIAMSAMLProvider(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) params := &iam.ListSAMLProvidersInput{} resources := make([]Resource, 0) resp, err := svc.ListSAMLProviders(params) if err != nil { return nil, err } for _, out := range resp.SAMLProviderList { resources = append(resources, &IAMSAMLProvider{ svc: svc, arn: *out.Arn, }) } return resources, nil } func (e *IAMSAMLProvider) Remove() error { _, err := e.svc.DeleteSAMLProvider(&iam.DeleteSAMLProviderInput{ SAMLProviderArn: &e.arn, }) if err != nil { return err } return nil } func (e *IAMSAMLProvider) String() string { return e.arn } aws-nuke-2.16.0/resources/iam-server-certificate.go000066400000000000000000000016711411137415400222330ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" ) type IAMServerCertificate struct { svc *iam.IAM name string } func init() { register("IAMServerCertificate", ListIAMServerCertificates) } func ListIAMServerCertificates(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) resp, err := svc.ListServerCertificates(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, meta := range resp.ServerCertificateMetadataList { resources = append(resources, &IAMServerCertificate{ svc: svc, name: *meta.ServerCertificateName, }) } return resources, nil } func (e *IAMServerCertificate) Remove() error { _, err := e.svc.DeleteServerCertificate(&iam.DeleteServerCertificateInput{ ServerCertificateName: &e.name, }) if err != nil { return err } return nil } func (e *IAMServerCertificate) String() string { return e.name } aws-nuke-2.16.0/resources/iam-service-specific-credentials.go000066400000000000000000000036631411137415400241660ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" "github.com/rebuy-de/aws-nuke/pkg/types" "github.com/sirupsen/logrus" ) type IAMServiceSpecificCredential struct { svc *iam.IAM name string serviceName string id string userName string } func init() { register("IAMServiceSpecificCredential", ListServiceSpecificCredentials) } func ListServiceSpecificCredentials(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) users, usersErr := ListIAMUsers(sess) if usersErr != nil { return nil, usersErr } resources := make([]Resource, 0) for _, userResource := range users { user, ok := userResource.(*IAMUser) if !ok { logrus.Errorf("Unable to cast IAMUser.") continue } params := &iam.ListServiceSpecificCredentialsInput{ UserName: &user.name, } serviceCredentials, err := svc.ListServiceSpecificCredentials(params) if err != nil { return nil, err } for _, credential := range serviceCredentials.ServiceSpecificCredentials { resources = append(resources, &IAMServiceSpecificCredential{ svc: svc, name: *credential.ServiceUserName, serviceName: *credential.ServiceName, id: *credential.ServiceSpecificCredentialId, userName: user.name, }) } } return resources, nil } func (e *IAMServiceSpecificCredential) Remove() error { params := &iam.DeleteServiceSpecificCredentialInput{ ServiceSpecificCredentialId: &e.id, UserName: &e.userName, } _, err := e.svc.DeleteServiceSpecificCredential(params) if err != nil { return err } return nil } func (e *IAMServiceSpecificCredential) Properties() types.Properties { properties := types.NewProperties() properties.Set("ServiceName", e.serviceName) properties.Set("ID", e.id) return properties } func (e *IAMServiceSpecificCredential) String() string { return e.userName + " -> " + e.name } aws-nuke-2.16.0/resources/iam-user-access-keys.go000066400000000000000000000027041411137415400216310ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" "github.com/rebuy-de/aws-nuke/pkg/types" ) type IAMUserAccessKey struct { svc *iam.IAM accessKeyId string userName string status string } func init() { register("IAMUserAccessKey", ListIAMUserAccessKeys) } func ListIAMUserAccessKeys(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) resp, err := svc.ListUsers(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, role := range resp.Users { resp, err := svc.ListAccessKeys( &iam.ListAccessKeysInput{ UserName: role.UserName, }) if err != nil { return nil, err } for _, meta := range resp.AccessKeyMetadata { resources = append(resources, &IAMUserAccessKey{ svc: svc, accessKeyId: *meta.AccessKeyId, userName: *meta.UserName, status: *meta.Status, }) } } return resources, nil } func (e *IAMUserAccessKey) Remove() error { _, err := e.svc.DeleteAccessKey( &iam.DeleteAccessKeyInput{ AccessKeyId: &e.accessKeyId, UserName: &e.userName, }) if err != nil { return err } return nil } func (e *IAMUserAccessKey) Properties() types.Properties { return types.NewProperties(). Set("UserName", e.userName). Set("AccessKeyID", e.accessKeyId) } func (e *IAMUserAccessKey) String() string { return fmt.Sprintf("%s -> %s", e.userName, e.accessKeyId) } aws-nuke-2.16.0/resources/iam-user-policy-attachments.go000066400000000000000000000030401411137415400232210ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" "github.com/rebuy-de/aws-nuke/pkg/types" ) type IAMUserPolicyAttachment struct { svc *iam.IAM policyArn string policyName string userName string } func init() { register("IAMUserPolicyAttachment", ListIAMUserPolicyAttachments) } func ListIAMUserPolicyAttachments(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) resp, err := svc.ListUsers(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, role := range resp.Users { resp, err := svc.ListAttachedUserPolicies( &iam.ListAttachedUserPoliciesInput{ UserName: role.UserName, }) if err != nil { return nil, err } for _, pol := range resp.AttachedPolicies { resources = append(resources, &IAMUserPolicyAttachment{ svc: svc, policyArn: *pol.PolicyArn, policyName: *pol.PolicyName, userName: *role.UserName, }) } } return resources, nil } func (e *IAMUserPolicyAttachment) Remove() error { _, err := e.svc.DetachUserPolicy( &iam.DetachUserPolicyInput{ PolicyArn: &e.policyArn, UserName: &e.userName, }) if err != nil { return err } return nil } func (e *IAMUserPolicyAttachment) Properties() types.Properties { return types.NewProperties(). Set("PolicyArn", e.policyArn). Set("PolicyName", e.policyName). Set("UserName", e.userName) } func (e *IAMUserPolicyAttachment) String() string { return fmt.Sprintf("%s -> %s", e.userName, e.policyName) } aws-nuke-2.16.0/resources/iam-user-policy.go000066400000000000000000000022561411137415400207200ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" ) type IAMUserPolicy struct { svc *iam.IAM userName string policyName string } func init() { register("IAMUserPolicy", ListIAMUserPolicies) } func ListIAMUserPolicies(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) users, err := svc.ListUsers(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, user := range users.Users { policies, err := svc.ListUserPolicies(&iam.ListUserPoliciesInput{ UserName: user.UserName, }) if err != nil { return nil, err } for _, policyName := range policies.PolicyNames { resources = append(resources, &IAMUserPolicy{ svc: svc, policyName: *policyName, userName: *user.UserName, }) } } return resources, nil } func (e *IAMUserPolicy) Remove() error { _, err := e.svc.DeleteUserPolicy( &iam.DeleteUserPolicyInput{ UserName: &e.userName, PolicyName: &e.policyName, }) if err != nil { return err } return nil } func (e *IAMUserPolicy) String() string { return fmt.Sprintf("%s -> %s", e.userName, e.policyName) } aws-nuke-2.16.0/resources/iam-user-ssh-keys.go000066400000000000000000000025371411137415400211710ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" "github.com/rebuy-de/aws-nuke/pkg/types" ) type UserSSHKey struct { svc *iam.IAM userName string sshKeyID string } func init() { register("IAMUserSSHPublicKey", ListIAMUserSSHPublicKeys) } func ListIAMUserSSHPublicKeys(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) usersOutput, err := svc.ListUsers(nil) if err != nil { return nil, err } var resources []Resource for _, user := range usersOutput.Users { listOutput, err := svc.ListSSHPublicKeys(&iam.ListSSHPublicKeysInput{ UserName: user.UserName, }) if err != nil { return nil, err } for _, publicKey := range listOutput.SSHPublicKeys { resources = append(resources, &UserSSHKey{ svc: svc, userName: *user.UserName, sshKeyID: *publicKey.SSHPublicKeyId, }) } } return resources, nil } func (u *UserSSHKey) Properties() types.Properties { return types.NewProperties(). Set("UserName", u.userName). Set("SSHKeyID", u.sshKeyID) } func (u *UserSSHKey) String() string { return fmt.Sprintf("%s -> %s", u.userName, u.sshKeyID) } func (u *UserSSHKey) Remove() error { _, err := u.svc.DeleteSSHPublicKey(&iam.DeleteSSHPublicKeyInput{ UserName: &u.userName, SSHPublicKeyId: &u.sshKeyID, }) return err } aws-nuke-2.16.0/resources/iam-users.go000066400000000000000000000014031411137415400175770ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" ) type IAMUser struct { svc *iam.IAM name string } func init() { register("IAMUser", ListIAMUsers) } func ListIAMUsers(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) resp, err := svc.ListUsers(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.Users { resources = append(resources, &IAMUser{ svc: svc, name: *out.UserName, }) } return resources, nil } func (e *IAMUser) Remove() error { _, err := e.svc.DeleteUser(&iam.DeleteUserInput{ UserName: &e.name, }) if err != nil { return err } return nil } func (e *IAMUser) String() string { return e.name } aws-nuke-2.16.0/resources/iam-virtual-mfa-devices.go000066400000000000000000000025761411137415400223210ustar00rootroot00000000000000package resources import ( "fmt" "strings" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iam" ) type IAMVirtualMFADevice struct { svc *iam.IAM user *iam.User serialNumber string } func init() { register("IAMVirtualMFADevice", ListIAMVirtualMFADevices) } func ListIAMVirtualMFADevices(sess *session.Session) ([]Resource, error) { svc := iam.New(sess) resp, err := svc.ListVirtualMFADevices(&iam.ListVirtualMFADevicesInput{}) if err != nil { return nil, err } resources := make([]Resource, 0) for _, out := range resp.VirtualMFADevices { resources = append(resources, &IAMVirtualMFADevice{ svc: svc, user: out.User, serialNumber: *out.SerialNumber, }) } return resources, nil } func (v *IAMVirtualMFADevice) Filter() error { if strings.HasSuffix(v.serialNumber, "/root-account-mfa-device") { return fmt.Errorf("Cannot delete root MFA device") } return nil } func (v *IAMVirtualMFADevice) Remove() error { if v.user != nil { _, err := v.svc.DeactivateMFADevice(&iam.DeactivateMFADeviceInput{ UserName: v.user.UserName, SerialNumber: &v.serialNumber, }) if err != nil { return err } } _, err := v.svc.DeleteVirtualMFADevice(&iam.DeleteVirtualMFADeviceInput{ SerialNumber: &v.serialNumber, }) return err } func (v *IAMVirtualMFADevice) String() string { return v.serialNumber } aws-nuke-2.16.0/resources/imagebuilder-components.go000066400000000000000000000040061411137415400225100ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/imagebuilder" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ImageBuilderComponent struct { svc *imagebuilder.Imagebuilder arn string } func init() { register("ImageBuilderComponent", ListImageBuilderComponents) } func ListImageBuilderComponents(sess *session.Session) ([]Resource, error) { svc := imagebuilder.New(sess) params := &imagebuilder.ListComponentsInput{} resources := make([]Resource, 0) for { resp, err := svc.ListComponents(params) if err != nil { return nil, err } for _, out := range resp.ComponentVersionList { resources, err = ListImageBuilderComponentVersions(svc, out.Arn, resources) if err != nil { return nil, err } } if resp.NextToken == nil { break } params = &imagebuilder.ListComponentsInput{ NextToken: resp.NextToken, } } return resources, nil } func ListImageBuilderComponentVersions(svc *imagebuilder.Imagebuilder, componentVersionArn *string, resources []Resource) ([]Resource, error) { params := &imagebuilder.ListComponentBuildVersionsInput{ ComponentVersionArn: componentVersionArn, } for { resp, err := svc.ListComponentBuildVersions(params) if err != nil { return nil, err } for _, out := range resp.ComponentSummaryList { resources = append(resources, &ImageBuilderComponent{ svc: svc, arn: *out.Arn, }) } if resp.NextToken == nil { break } params = &imagebuilder.ListComponentBuildVersionsInput{ ComponentVersionArn: componentVersionArn, NextToken: resp.NextToken, } } return resources, nil } func (e *ImageBuilderComponent) Remove() error { _, err := e.svc.DeleteComponent(&imagebuilder.DeleteComponentInput{ ComponentBuildVersionArn: &e.arn, }) return err } func (e *ImageBuilderComponent) Properties() types.Properties { properties := types.NewProperties() properties.Set("arn", e.arn) return properties } func (e *ImageBuilderComponent) String() string { return e.arn } aws-nuke-2.16.0/resources/imagebuilder-distribution-configurations.go000066400000000000000000000027741411137415400261040ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/imagebuilder" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ImageBuilderDistributionConfiguration struct { svc *imagebuilder.Imagebuilder arn string } func init() { register("ImageBuilderDistributionConfiguration", ListImageBuilderDistributionConfigurations) } func ListImageBuilderDistributionConfigurations(sess *session.Session) ([]Resource, error) { svc := imagebuilder.New(sess) params := &imagebuilder.ListDistributionConfigurationsInput{} resources := make([]Resource, 0) for { resp, err := svc.ListDistributionConfigurations(params) if err != nil { return nil, err } for _, out := range resp.DistributionConfigurationSummaryList { resources = append(resources, &ImageBuilderDistributionConfiguration{ svc: svc, arn: *out.Arn, }) } if resp.NextToken == nil { break } params = &imagebuilder.ListDistributionConfigurationsInput{ NextToken: resp.NextToken, } } return resources, nil } func (e *ImageBuilderDistributionConfiguration) Remove() error { _, err := e.svc.DeleteDistributionConfiguration(&imagebuilder.DeleteDistributionConfigurationInput{ DistributionConfigurationArn: &e.arn, }) return err } func (e *ImageBuilderDistributionConfiguration) Properties() types.Properties { properties := types.NewProperties() properties.Set("arn", e.arn) return properties } func (e *ImageBuilderDistributionConfiguration) String() string { return e.arn } aws-nuke-2.16.0/resources/imagebuilder-images.go000066400000000000000000000036041411137415400215730ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/imagebuilder" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ImageBuilderImage struct { svc *imagebuilder.Imagebuilder arn string } func init() { register("ImageBuilderImage", ListImageBuilderImages) } func ListImageBuilderImages(sess *session.Session) ([]Resource, error) { svc := imagebuilder.New(sess) params := &imagebuilder.ListImagesInput{} resources := make([]Resource, 0) for { resp, err := svc.ListImages(params) if err != nil { return nil, err } for _, out := range resp.ImageVersionList { resources, err = ImageBuildVersions(svc, out.Arn, resources) if err != nil { return nil, err } } if resp.NextToken == nil { break } params = &imagebuilder.ListImagesInput{ NextToken: resp.NextToken, } } return resources, nil } func ImageBuildVersions(svc *imagebuilder.Imagebuilder, imageVersionArn *string, resources []Resource) ([]Resource, error) { params := &imagebuilder.ListImageBuildVersionsInput{ ImageVersionArn: imageVersionArn, } for { resp, err := svc.ListImageBuildVersions(params) if err != nil { return nil, err } for _, out := range resp.ImageSummaryList { resources = append(resources, &ImageBuilderImage{ svc: svc, arn: *out.Arn, }) } if resp.NextToken == nil { break } params = &imagebuilder.ListImageBuildVersionsInput{ ImageVersionArn: imageVersionArn, NextToken: resp.NextToken, } } return resources, nil } func (e *ImageBuilderImage) Remove() error { _, err := e.svc.DeleteImage(&imagebuilder.DeleteImageInput{ ImageBuildVersionArn: &e.arn, }) return err } func (e *ImageBuilderImage) Properties() types.Properties { properties := types.NewProperties() properties.Set("arn", e.arn) return properties } func (e *ImageBuilderImage) String() string { return e.arn } aws-nuke-2.16.0/resources/imagebuilder-infrastructure-configurations.go000066400000000000000000000030321411137415400264310ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/imagebuilder" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ImageBuilderInfrastructureConfiguration struct { svc *imagebuilder.Imagebuilder arn string } func init() { register("ImageBuilderInfrastructureConfiguration", ListImageBuilderInfrastructureConfigurations) } func ListImageBuilderInfrastructureConfigurations(sess *session.Session) ([]Resource, error) { svc := imagebuilder.New(sess) params := &imagebuilder.ListInfrastructureConfigurationsInput{} resources := make([]Resource, 0) for { resp, err := svc.ListInfrastructureConfigurations(params) if err != nil { return nil, err } for _, out := range resp.InfrastructureConfigurationSummaryList { resources = append(resources, &ImageBuilderInfrastructureConfiguration{ svc: svc, arn: *out.Arn, }) } if resp.NextToken == nil { break } params = &imagebuilder.ListInfrastructureConfigurationsInput{ NextToken: resp.NextToken, } } return resources, nil } func (e *ImageBuilderInfrastructureConfiguration) Remove() error { _, err := e.svc.DeleteInfrastructureConfiguration(&imagebuilder.DeleteInfrastructureConfigurationInput{ InfrastructureConfigurationArn: &e.arn, }) return err } func (e *ImageBuilderInfrastructureConfiguration) Properties() types.Properties { properties := types.NewProperties() properties.Set("arn", e.arn) return properties } func (e *ImageBuilderInfrastructureConfiguration) String() string { return e.arn } aws-nuke-2.16.0/resources/imagebuilder-pipelines.go000066400000000000000000000024311411137415400223130ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/imagebuilder" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ImageBuilderPipeline struct { svc *imagebuilder.Imagebuilder arn string } func init() { register("ImageBuilderPipeline", ListImageBuilderPipelines) } func ListImageBuilderPipelines(sess *session.Session) ([]Resource, error) { svc := imagebuilder.New(sess) params := &imagebuilder.ListImagePipelinesInput{} resources := make([]Resource, 0) for { resp, err := svc.ListImagePipelines(params) if err != nil { return nil, err } for _, out := range resp.ImagePipelineList { resources = append(resources, &ImageBuilderPipeline{ svc: svc, arn: *out.Arn, }) } if resp.NextToken == nil { break } params = &imagebuilder.ListImagePipelinesInput{ NextToken: resp.NextToken, } } return resources, nil } func (e *ImageBuilderPipeline) Remove() error { _, err := e.svc.DeleteImagePipeline(&imagebuilder.DeleteImagePipelineInput{ ImagePipelineArn: &e.arn, }) return err } func (e *ImageBuilderPipeline) Properties() types.Properties { properties := types.NewProperties() properties.Set("arn", e.arn) return properties } func (e *ImageBuilderPipeline) String() string { return e.arn } aws-nuke-2.16.0/resources/imagebuilder-recipes.go000066400000000000000000000024021411137415400217530ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/imagebuilder" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ImageBuilderRecipe struct { svc *imagebuilder.Imagebuilder arn string } func init() { register("ImageBuilderRecipe", ListImageBuilderRecipes) } func ListImageBuilderRecipes(sess *session.Session) ([]Resource, error) { svc := imagebuilder.New(sess) params := &imagebuilder.ListImageRecipesInput{} resources := make([]Resource, 0) for { resp, err := svc.ListImageRecipes(params) if err != nil { return nil, err } for _, out := range resp.ImageRecipeSummaryList { resources = append(resources, &ImageBuilderRecipe{ svc: svc, arn: *out.Arn, }) } if resp.NextToken == nil { break } params = &imagebuilder.ListImageRecipesInput{ NextToken: resp.NextToken, } } return resources, nil } func (e *ImageBuilderRecipe) Remove() error { _, err := e.svc.DeleteImageRecipe(&imagebuilder.DeleteImageRecipeInput{ ImageRecipeArn: &e.arn, }) return err } func (e *ImageBuilderRecipe) Properties() types.Properties { properties := types.NewProperties() properties.Set("arn", e.arn) return properties } func (e *ImageBuilderRecipe) String() string { return e.arn } aws-nuke-2.16.0/resources/interface.go000066400000000000000000000022121411137415400176310ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/rebuy-de/aws-nuke/pkg/config" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ResourceListers map[string]ResourceLister type ResourceLister func(s *session.Session) ([]Resource, error) type Resource interface { Remove() error } type Filter interface { Resource Filter() error } type LegacyStringer interface { Resource String() string } type ResourcePropertyGetter interface { Resource Properties() types.Properties } type FeatureFlagGetter interface { Resource FeatureFlags(config.FeatureFlags) } var resourceListers = make(ResourceListers) func register(name string, lister ResourceLister) { _, exists := resourceListers[name] if exists { panic(fmt.Sprintf("a resource with the name %s already exists", name)) } resourceListers[name] = lister } func GetListers() ResourceListers { return resourceListers } func GetLister(name string) ResourceLister { return resourceListers[name] } func GetListerNames() []string { names := []string{} for resourceType, _ := range GetListers() { names = append(names, resourceType) } return names } aws-nuke-2.16.0/resources/iot-authorizers.go000066400000000000000000000015471411137415400210530ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iot" ) type IoTAuthorizer struct { svc *iot.IoT name *string } func init() { register("IoTAuthorizer", ListIoTAuthorizers) } func ListIoTAuthorizers(sess *session.Session) ([]Resource, error) { svc := iot.New(sess) resources := []Resource{} params := &iot.ListAuthorizersInput{} output, err := svc.ListAuthorizers(params) if err != nil { return nil, err } for _, authorizer := range output.Authorizers { resources = append(resources, &IoTAuthorizer{ svc: svc, name: authorizer.AuthorizerName, }) } return resources, nil } func (f *IoTAuthorizer) Remove() error { _, err := f.svc.DeleteAuthorizer(&iot.DeleteAuthorizerInput{ AuthorizerName: f.name, }) return err } func (f *IoTAuthorizer) String() string { return *f.name } aws-nuke-2.16.0/resources/iot-cacertificates.go000066400000000000000000000021131411137415400214330ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iot" ) type IoTCACertificate struct { svc *iot.IoT ID *string } func init() { register("IoTCACertificate", ListIoTCACertificates) } func ListIoTCACertificates(sess *session.Session) ([]Resource, error) { svc := iot.New(sess) resources := []Resource{} params := &iot.ListCACertificatesInput{} output, err := svc.ListCACertificates(params) if err != nil { return nil, err } for _, certificate := range output.Certificates { resources = append(resources, &IoTCACertificate{ svc: svc, ID: certificate.CertificateId, }) } return resources, nil } func (f *IoTCACertificate) Remove() error { _, err := f.svc.UpdateCACertificate(&iot.UpdateCACertificateInput{ CertificateId: f.ID, NewStatus: aws.String("INACTIVE"), }) if err != nil { return err } _, err = f.svc.DeleteCACertificate(&iot.DeleteCACertificateInput{ CertificateId: f.ID, }) return err } func (f *IoTCACertificate) String() string { return *f.ID } aws-nuke-2.16.0/resources/iot-certificates.go000066400000000000000000000020611411137415400211310ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iot" ) type IoTCertificate struct { svc *iot.IoT ID *string } func init() { register("IoTCertificate", ListIoTCertificates) } func ListIoTCertificates(sess *session.Session) ([]Resource, error) { svc := iot.New(sess) resources := []Resource{} params := &iot.ListCertificatesInput{} output, err := svc.ListCertificates(params) if err != nil { return nil, err } for _, certificate := range output.Certificates { resources = append(resources, &IoTCertificate{ svc: svc, ID: certificate.CertificateId, }) } return resources, nil } func (f *IoTCertificate) Remove() error { _, err := f.svc.UpdateCertificate(&iot.UpdateCertificateInput{ CertificateId: f.ID, NewStatus: aws.String("INACTIVE"), }) if err != nil { return err } _, err = f.svc.DeleteCertificate(&iot.DeleteCertificateInput{ CertificateId: f.ID, }) return err } func (f *IoTCertificate) String() string { return *f.ID } aws-nuke-2.16.0/resources/iot-jobs.go000066400000000000000000000017571411137415400174340ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iot" ) type IoTJob struct { svc *iot.IoT ID *string status *string } func init() { register("IoTJob", ListIoTJobs) } func ListIoTJobs(sess *session.Session) ([]Resource, error) { svc := iot.New(sess) resources := []Resource{} params := &iot.ListJobsInput{ MaxResults: aws.Int64(100), Status: aws.String("IN_PROGRESS"), } for { output, err := svc.ListJobs(params) if err != nil { return nil, err } for _, job := range output.Jobs { resources = append(resources, &IoTJob{ svc: svc, ID: job.JobId, status: job.Status, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *IoTJob) Remove() error { _, err := f.svc.CancelJob(&iot.CancelJobInput{ JobId: f.ID, }) return err } func (f *IoTJob) String() string { return *f.ID } aws-nuke-2.16.0/resources/iot-otaupdates.go000066400000000000000000000017621411137415400206440ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iot" ) type IoTOTAUpdate struct { svc *iot.IoT ID *string } func init() { register("IoTOTAUpdate", ListIoTOTAUpdates) } func ListIoTOTAUpdates(sess *session.Session) ([]Resource, error) { svc := iot.New(sess) resources := []Resource{} params := &iot.ListOTAUpdatesInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListOTAUpdates(params) if err != nil { return nil, err } for _, otaUpdate := range output.OtaUpdates { resources = append(resources, &IoTOTAUpdate{ svc: svc, ID: otaUpdate.OtaUpdateId, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *IoTOTAUpdate) Remove() error { _, err := f.svc.DeleteOTAUpdate(&iot.DeleteOTAUpdateInput{ OtaUpdateId: f.ID, }) return err } func (f *IoTOTAUpdate) String() string { return *f.ID } aws-nuke-2.16.0/resources/iot-policies.go000066400000000000000000000050401411137415400202730ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iot" ) type IoTPolicy struct { svc *iot.IoT name *string targets []*string deprecatedVersions []*string } func init() { register("IoTPolicy", ListIoTPolicies) } func listIoTPolicyTargets(f *IoTPolicy) (*IoTPolicy, error) { targets := []*string{} params := &iot.ListTargetsForPolicyInput{ PolicyName: f.name, PageSize: aws.Int64(25), } for { output, err := f.svc.ListTargetsForPolicy(params) if err != nil { return nil, err } targets = append(targets, output.Targets...) if output.NextMarker == nil { break } params.Marker = output.NextMarker } f.targets = targets return f, nil } func listIoTPolicyDeprecatedVersions(f *IoTPolicy) (*IoTPolicy, error) { deprecatedVersions := []*string{} params := &iot.ListPolicyVersionsInput{ PolicyName: f.name, } output, err := f.svc.ListPolicyVersions(params) if err != nil { return nil, err } for _, policyVersion := range output.PolicyVersions { if *policyVersion.IsDefaultVersion != true { deprecatedVersions = append(deprecatedVersions, policyVersion.VersionId) } } f.deprecatedVersions = deprecatedVersions return f, nil } func ListIoTPolicies(sess *session.Session) ([]Resource, error) { svc := iot.New(sess) resources := []Resource{} params := &iot.ListPoliciesInput{ PageSize: aws.Int64(25), } for { output, err := svc.ListPolicies(params) if err != nil { return nil, err } for _, policy := range output.Policies { p := &IoTPolicy{ svc: svc, name: policy.PolicyName, } p, err = listIoTPolicyTargets(p) if err != nil { return nil, err } p, err = listIoTPolicyDeprecatedVersions(p) if err != nil { return nil, err } resources = append(resources, p) } if output.NextMarker == nil { break } params.Marker = output.NextMarker } return resources, nil } func (f *IoTPolicy) Remove() error { // detach attached targets first for _, target := range f.targets { f.svc.DetachPolicy(&iot.DetachPolicyInput{ PolicyName: f.name, Target: target, }) } // delete deprecated versions for _, version := range f.deprecatedVersions { f.svc.DeletePolicyVersion(&iot.DeletePolicyVersionInput{ PolicyName: f.name, PolicyVersionId: version, }) } _, err := f.svc.DeletePolicy(&iot.DeletePolicyInput{ PolicyName: f.name, }) return err } func (f *IoTPolicy) String() string { return *f.name } aws-nuke-2.16.0/resources/iot-rolealiases.go000066400000000000000000000020131411137415400207640ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iot" ) type IoTRoleAlias struct { svc *iot.IoT roleAlias *string } func init() { register("IoTRoleAlias", ListIoTRoleAliases) } func ListIoTRoleAliases(sess *session.Session) ([]Resource, error) { svc := iot.New(sess) resources := []Resource{} params := &iot.ListRoleAliasesInput{ PageSize: aws.Int64(25), } for { output, err := svc.ListRoleAliases(params) if err != nil { return nil, err } for _, roleAlias := range output.RoleAliases { resources = append(resources, &IoTRoleAlias{ svc: svc, roleAlias: roleAlias, }) } if output.NextMarker == nil { break } params.Marker = output.NextMarker } return resources, nil } func (f *IoTRoleAlias) Remove() error { _, err := f.svc.DeleteRoleAlias(&iot.DeleteRoleAliasInput{ RoleAlias: f.roleAlias, }) return err } func (f *IoTRoleAlias) String() string { return *f.roleAlias } aws-nuke-2.16.0/resources/iot-streams.go000066400000000000000000000017021411137415400201430ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iot" ) type IoTStream struct { svc *iot.IoT ID *string } func init() { register("IoTStream", ListIoTStreams) } func ListIoTStreams(sess *session.Session) ([]Resource, error) { svc := iot.New(sess) resources := []Resource{} params := &iot.ListStreamsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListStreams(params) if err != nil { return nil, err } for _, stream := range output.Streams { resources = append(resources, &IoTStream{ svc: svc, ID: stream.StreamId, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *IoTStream) Remove() error { _, err := f.svc.DeleteStream(&iot.DeleteStreamInput{ StreamId: f.ID, }) return err } func (f *IoTStream) String() string { return *f.ID } aws-nuke-2.16.0/resources/iot-thinggroups.go000066400000000000000000000026021411137415400210360ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iot" ) type IoTThingGroup struct { svc *iot.IoT name *string version *int64 } func init() { register("IoTThingGroup", ListIoTThingGroups) } func ListIoTThingGroups(sess *session.Session) ([]Resource, error) { svc := iot.New(sess) resources := []Resource{} thingGroups := []*iot.GroupNameAndArn{} params := &iot.ListThingGroupsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListThingGroups(params) if err != nil { return nil, err } for _, thingGroup := range output.ThingGroups { thingGroups = append(thingGroups, thingGroup) } if output.NextToken == nil { break } params.NextToken = output.NextToken } for _, thingGroup := range thingGroups { output, err := svc.DescribeThingGroup(&iot.DescribeThingGroupInput{ ThingGroupName: thingGroup.GroupName, }) if err != nil { return nil, err } resources = append(resources, &IoTThingGroup{ svc: svc, name: thingGroup.GroupName, version: output.Version, }) } return resources, nil } func (f *IoTThingGroup) Remove() error { _, err := f.svc.DeleteThingGroup(&iot.DeleteThingGroupInput{ ThingGroupName: f.name, ExpectedVersion: f.version, }) return err } func (f *IoTThingGroup) String() string { return *f.name } aws-nuke-2.16.0/resources/iot-things.go000066400000000000000000000031771411137415400177710ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iot" ) type IoTThing struct { svc *iot.IoT name *string version *int64 principals []*string } func init() { register("IoTThing", ListIoTThings) } func listIoTThingPrincipals(f *IoTThing) (*IoTThing, error) { params := &iot.ListThingPrincipalsInput{ ThingName: f.name, } output, err := f.svc.ListThingPrincipals(params) if err != nil { return nil, err } f.principals = output.Principals return f, nil } func ListIoTThings(sess *session.Session) ([]Resource, error) { svc := iot.New(sess) resources := []Resource{} params := &iot.ListThingsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListThings(params) if err != nil { return nil, err } // gather dependent principals for _, thing := range output.Things { t, err := listIoTThingPrincipals(&IoTThing{ svc: svc, name: thing.ThingName, version: thing.Version, }) if err != nil { return nil, err } resources = append(resources, t) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *IoTThing) Remove() error { // detach attached principals first for _, principal := range f.principals { f.svc.DetachThingPrincipal(&iot.DetachThingPrincipalInput{ Principal: principal, ThingName: f.name, }) } _, err := f.svc.DeleteThing(&iot.DeleteThingInput{ ThingName: f.name, ExpectedVersion: f.version, }) return err } func (f *IoTThing) String() string { return *f.name } aws-nuke-2.16.0/resources/iot-thingtypes.go000066400000000000000000000017761411137415400206760ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iot" ) type IoTThingType struct { svc *iot.IoT name *string } func init() { register("IoTThingType", ListIoTThingTypes) } func ListIoTThingTypes(sess *session.Session) ([]Resource, error) { svc := iot.New(sess) resources := []Resource{} params := &iot.ListThingTypesInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListThingTypes(params) if err != nil { return nil, err } for _, thingType := range output.ThingTypes { resources = append(resources, &IoTThingType{ svc: svc, name: thingType.ThingTypeName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *IoTThingType) Remove() error { _, err := f.svc.DeleteThingType(&iot.DeleteThingTypeInput{ ThingTypeName: f.name, }) return err } func (f *IoTThingType) String() string { return *f.name } aws-nuke-2.16.0/resources/iot-thingtypestates.go000066400000000000000000000033061411137415400217260ustar00rootroot00000000000000package resources import ( "fmt" "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iot" ) type IoTThingTypeState struct { svc *iot.IoT name *string deprecated *bool deprecatedEpoch *time.Time } func init() { register("IoTThingTypeState", ListIoTThingTypeStates) } func ListIoTThingTypeStates(sess *session.Session) ([]Resource, error) { svc := iot.New(sess) resources := []Resource{} params := &iot.ListThingTypesInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListThingTypes(params) if err != nil { return nil, err } for _, thingType := range output.ThingTypes { resources = append(resources, &IoTThingTypeState{ svc: svc, name: thingType.ThingTypeName, deprecated: thingType.ThingTypeMetadata.Deprecated, deprecatedEpoch: thingType.ThingTypeMetadata.DeprecationDate, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *IoTThingTypeState) Remove() error { _, err := f.svc.DeprecateThingType(&iot.DeprecateThingTypeInput{ ThingTypeName: f.name, }) return err } func (f *IoTThingTypeState) String() string { return *f.name } func (f *IoTThingTypeState) Filter() error { //Ensure we don't inspect time unless its already deprecated if *f.deprecated == true { currentTime := time.Now() timeDiff := currentTime.Sub(*f.deprecatedEpoch) // Must wait for 300 seconds before deleting a ThingType after deprecation // Padding 5 seconds to ensure we are beyond any skew if timeDiff < 305 { return fmt.Errorf("already deprecated") } } return nil } aws-nuke-2.16.0/resources/iot-topicrules.go000066400000000000000000000017451411137415400206650ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/iot" ) type IoTTopicRule struct { svc *iot.IoT name *string } func init() { register("IoTTopicRule", ListIoTTopicRules) } func ListIoTTopicRules(sess *session.Session) ([]Resource, error) { svc := iot.New(sess) resources := []Resource{} params := &iot.ListTopicRulesInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListTopicRules(params) if err != nil { return nil, err } for _, rule := range output.Rules { resources = append(resources, &IoTTopicRule{ svc: svc, name: rule.RuleName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *IoTTopicRule) Remove() error { _, err := f.svc.DeleteTopicRule(&iot.DeleteTopicRuleInput{ RuleName: f.name, }) return err } func (f *IoTTopicRule) String() string { return *f.name } aws-nuke-2.16.0/resources/kinesis-streams.go000066400000000000000000000021621411137415400210160ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/kinesis" ) type KinesisStream struct { svc *kinesis.Kinesis streamName *string } func init() { register("KinesisStream", ListKinesisStreams) } func ListKinesisStreams(sess *session.Session) ([]Resource, error) { svc := kinesis.New(sess) resources := []Resource{} var lastStreamName *string params := &kinesis.ListStreamsInput{ Limit: aws.Int64(25), } for { output, err := svc.ListStreams(params) if err != nil { return nil, err } for _, streamName := range output.StreamNames { resources = append(resources, &KinesisStream{ svc: svc, streamName: streamName, }) lastStreamName = streamName } if *output.HasMoreStreams == false { break } params.ExclusiveStartStreamName = lastStreamName } return resources, nil } func (f *KinesisStream) Remove() error { _, err := f.svc.DeleteStream(&kinesis.DeleteStreamInput{ StreamName: f.streamName, }) return err } func (f *KinesisStream) String() string { return *f.streamName } aws-nuke-2.16.0/resources/kinesisanalytics-streams.go000066400000000000000000000032361411137415400227310ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/kinesisanalytics" ) type KinesisAnalyticsApplication struct { svc *kinesisanalytics.KinesisAnalytics applicationName *string } func init() { register("KinesisAnalyticsApplication", ListKinesisAnalyticsApplications) } func ListKinesisAnalyticsApplications(sess *session.Session) ([]Resource, error) { svc := kinesisanalytics.New(sess) resources := []Resource{} var lastApplicationName *string params := &kinesisanalytics.ListApplicationsInput{ Limit: aws.Int64(25), } for { output, err := svc.ListApplications(params) if err != nil { return nil, err } for _, applicationSummary := range output.ApplicationSummaries { resources = append(resources, &KinesisAnalyticsApplication{ svc: svc, applicationName: applicationSummary.ApplicationName, }) lastApplicationName = applicationSummary.ApplicationName } if *output.HasMoreApplications == false { break } params.ExclusiveStartApplicationName = lastApplicationName } return resources, nil } func (f *KinesisAnalyticsApplication) Remove() error { output, err := f.svc.DescribeApplication(&kinesisanalytics.DescribeApplicationInput{ ApplicationName: f.applicationName, }) if err != nil { return err } createTimestamp := output.ApplicationDetail.CreateTimestamp _, err = f.svc.DeleteApplication(&kinesisanalytics.DeleteApplicationInput{ ApplicationName: f.applicationName, CreateTimestamp: createTimestamp, }) return err } func (f *KinesisAnalyticsApplication) String() string { return *f.applicationName } aws-nuke-2.16.0/resources/kinesisvideo-streams.go000066400000000000000000000021671411137415400220520ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/kinesisvideo" ) type KinesisVideoProject struct { svc *kinesisvideo.KinesisVideo streamARN *string } func init() { register("KinesisVideoProject", ListKinesisVideoProjects) } func ListKinesisVideoProjects(sess *session.Session) ([]Resource, error) { svc := kinesisvideo.New(sess) resources := []Resource{} params := &kinesisvideo.ListStreamsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListStreams(params) if err != nil { return nil, err } for _, streamInfo := range output.StreamInfoList { resources = append(resources, &KinesisVideoProject{ svc: svc, streamARN: streamInfo.StreamARN, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *KinesisVideoProject) Remove() error { _, err := f.svc.DeleteStream(&kinesisvideo.DeleteStreamInput{ StreamARN: f.streamARN, }) return err } func (f *KinesisVideoProject) String() string { return *f.streamARN } aws-nuke-2.16.0/resources/kms-aliases.go000066400000000000000000000021301411137415400201010ustar00rootroot00000000000000package resources import ( "fmt" "strings" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/kms" "github.com/rebuy-de/aws-nuke/pkg/types" ) type KMSAlias struct { svc *kms.KMS name string } func init() { register("KMSAlias", ListKMSAliases) } func ListKMSAliases(sess *session.Session) ([]Resource, error) { svc := kms.New(sess) resp, err := svc.ListAliases(nil) if err != nil { return nil, err } resources := make([]Resource, 0) for _, alias := range resp.Aliases { resources = append(resources, &KMSAlias{ svc: svc, name: *alias.AliasName, }) } return resources, nil } func (e *KMSAlias) Filter() error { if strings.HasPrefix(e.name, "alias/aws/") { return fmt.Errorf("cannot delete AWS alias") } return nil } func (e *KMSAlias) Remove() error { _, err := e.svc.DeleteAlias(&kms.DeleteAliasInput{ AliasName: &e.name, }) return err } func (e *KMSAlias) String() string { return e.name } func (e *KMSAlias) Properties() types.Properties { properties := types.NewProperties() properties. Set("Name", e.name) return properties } aws-nuke-2.16.0/resources/kms-keys.go000066400000000000000000000042371411137415400174450ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/kms" "github.com/rebuy-de/aws-nuke/pkg/types" ) type KMSKey struct { svc *kms.KMS id string state string manager *string tags []*kms.Tag } func init() { register("KMSKey", ListKMSKeys) } func ListKMSKeys(sess *session.Session) ([]Resource, error) { svc := kms.New(sess) resources := make([]Resource, 0) var innerErr error err := svc.ListKeysPages(nil, func(resp *kms.ListKeysOutput, lastPage bool) bool { for _, key := range resp.Keys { resp, err := svc.DescribeKey(&kms.DescribeKeyInput{ KeyId: key.KeyId, }) if err != nil { innerErr = err return false } if *resp.KeyMetadata.KeyManager == kms.KeyManagerTypeAws { continue } if *resp.KeyMetadata.KeyState == kms.KeyStatePendingDeletion { continue } kmsKey := &KMSKey{ svc: svc, id: *resp.KeyMetadata.KeyId, state: *resp.KeyMetadata.KeyState, manager: resp.KeyMetadata.KeyManager, } tags, err := svc.ListResourceTags(&kms.ListResourceTagsInput{ KeyId: key.KeyId, }) if err != nil { innerErr = err return false } kmsKey.tags = tags.Tags resources = append(resources, kmsKey) } if lastPage { return false } return true }) if err != nil { return nil, err } if innerErr != nil { return nil, err } return resources, nil } func (e *KMSKey) Filter() error { if e.state == "PendingDeletion" { return fmt.Errorf("is already in PendingDeletion state") } if e.manager != nil && *e.manager == kms.KeyManagerTypeAws { return fmt.Errorf("cannot delete AWS managed key") } return nil } func (e *KMSKey) Remove() error { _, err := e.svc.ScheduleKeyDeletion(&kms.ScheduleKeyDeletionInput{ KeyId: &e.id, PendingWindowInDays: aws.Int64(7), }) return err } func (e *KMSKey) String() string { return e.id } func (i *KMSKey) Properties() types.Properties { properties := types.NewProperties() properties. Set("ID", i.id) for _, tag := range i.tags { properties.SetTag(tag.TagKey, tag.TagValue) } return properties } aws-nuke-2.16.0/resources/lambda-event-source-mapping.go000066400000000000000000000026021411137415400231620ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/lambda" "github.com/rebuy-de/aws-nuke/pkg/types" ) type LambdaEventSourceMapping struct { svc *lambda.Lambda mapping *lambda.EventSourceMappingConfiguration } func init() { register("LambdaEventSourceMapping", ListLambdaEventSourceMapping) } func ListLambdaEventSourceMapping(sess *session.Session) ([]Resource, error) { svc := lambda.New(sess) resources := []Resource{} params := &lambda.ListEventSourceMappingsInput{} for { resp, err := svc.ListEventSourceMappings(params) if err != nil { return nil, err } for _, mapping := range resp.EventSourceMappings { resources = append(resources, &LambdaEventSourceMapping{ svc: svc, mapping: mapping, }) } if resp.NextMarker == nil { break } params.Marker = resp.NextMarker } return resources, nil } func (m *LambdaEventSourceMapping) Remove() error { _, err := m.svc.DeleteEventSourceMapping(&lambda.DeleteEventSourceMappingInput{ UUID: m.mapping.UUID, }) return err } func (m *LambdaEventSourceMapping) Properties() types.Properties { properties := types.NewProperties() properties.Set("UUID", m.mapping.UUID) properties.Set("EventSourceArn", m.mapping.EventSourceArn) properties.Set("FunctionArn", m.mapping.FunctionArn) properties.Set("State", m.mapping.State) return properties } aws-nuke-2.16.0/resources/lambda-functions.go000066400000000000000000000030721411137415400211240ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/lambda" "github.com/rebuy-de/aws-nuke/pkg/types" ) type LambdaFunction struct { svc *lambda.Lambda functionName *string tags map[string]*string } func init() { register("LambdaFunction", ListLambdaFunctions) } func ListLambdaFunctions(sess *session.Session) ([]Resource, error) { svc := lambda.New(sess) functions := make([]*lambda.FunctionConfiguration, 0) params := &lambda.ListFunctionsInput{} err := svc.ListFunctionsPages(params, func(page *lambda.ListFunctionsOutput, lastPage bool) bool { for _, out := range page.Functions { functions = append(functions, out) } return true }) if err != nil { return nil, err } resources := make([]Resource, 0) for _, function := range functions { tags, err := svc.ListTags(&lambda.ListTagsInput{ Resource: function.FunctionArn, }) if err != nil { continue } resources = append(resources, &LambdaFunction{ svc: svc, functionName: function.FunctionName, tags: tags.Tags, }) } return resources, nil } func (f *LambdaFunction) Properties() types.Properties { properties := types.NewProperties() properties.Set("Name", f.functionName) for key, val := range f.tags { properties.SetTag(&key, val) } return properties } func (f *LambdaFunction) Remove() error { _, err := f.svc.DeleteFunction(&lambda.DeleteFunctionInput{ FunctionName: f.functionName, }) return err } func (f *LambdaFunction) String() string { return *f.functionName } aws-nuke-2.16.0/resources/lambda-layers.go000066400000000000000000000032441411137415400204140ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/lambda" "github.com/rebuy-de/aws-nuke/pkg/types" ) type lambdaLayer struct { svc *lambda.Lambda layerName *string version int64 } func init() { register("LambdaLayer", ListLambdaLayers) } func ListLambdaLayers(sess *session.Session) ([]Resource, error) { svc := lambda.New(sess) layers := make([]*lambda.LayersListItem, 0) params := &lambda.ListLayersInput{} err := svc.ListLayersPages(params, func(page *lambda.ListLayersOutput, lastPage bool) bool { for _, out := range page.Layers { layers = append(layers, out) } return true }) if err != nil { return nil, err } resources := make([]Resource, 0) for _, layer := range layers { versionsParams := &lambda.ListLayerVersionsInput{ LayerName: layer.LayerName, } err := svc.ListLayerVersionsPages(versionsParams, func(page *lambda.ListLayerVersionsOutput, lastPage bool) bool { for _, out := range page.LayerVersions { resources = append(resources, &lambdaLayer{ svc: svc, layerName: layer.LayerName, version: *out.Version, }) } return true }) if err != nil { return nil, err } } return resources, nil } func (l *lambdaLayer) Remove() error { _, err := l.svc.DeleteLayerVersion(&lambda.DeleteLayerVersionInput{ LayerName: l.layerName, VersionNumber: &l.version, }) return err } func (l *lambdaLayer) Properties() types.Properties { properties := types.NewProperties() properties.Set("Name", l.layerName) properties.Set("Version", l.version) return properties } func (l *lambdaLayer) String() string { return *l.layerName } aws-nuke-2.16.0/resources/lex-bot.go000066400000000000000000000024241411137415400172500ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/lexmodelbuildingservice" "github.com/rebuy-de/aws-nuke/pkg/types" ) type LexBot struct { svc *lexmodelbuildingservice.LexModelBuildingService name *string status *string } func init() { register("LexBot", ListLexBots) } func ListLexBots(sess *session.Session) ([]Resource, error) { svc := lexmodelbuildingservice.New(sess) resources := []Resource{} params := &lexmodelbuildingservice.GetBotsInput{ MaxResults: aws.Int64(10), } for { output, err := svc.GetBots(params) if err != nil { return nil, err } for _, bot := range output.Bots { resources = append(resources, &LexBot{ svc: svc, name: bot.Name, status: bot.Status, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *LexBot) Remove() error { _, err := f.svc.DeleteBot(&lexmodelbuildingservice.DeleteBotInput{ Name: f.name, }) return err } func (f *LexBot) String() string { return *f.name } func (f *LexBot) Properties() types.Properties { properties := types.NewProperties() properties. Set("Name", f.name). Set("Status", f.status) return properties } aws-nuke-2.16.0/resources/lex-intent.go000066400000000000000000000023601411137415400177640ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/lexmodelbuildingservice" "github.com/rebuy-de/aws-nuke/pkg/types" ) type LexIntent struct { svc *lexmodelbuildingservice.LexModelBuildingService name *string } func init() { register("LexIntent", ListLexIntents) } func ListLexIntents(sess *session.Session) ([]Resource, error) { svc := lexmodelbuildingservice.New(sess) resources := []Resource{} params := &lexmodelbuildingservice.GetIntentsInput{ MaxResults: aws.Int64(20), } for { output, err := svc.GetIntents(params) if err != nil { return nil, err } for _, bot := range output.Intents { resources = append(resources, &LexIntent{ svc: svc, name: bot.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *LexIntent) Remove() error { _, err := f.svc.DeleteIntent(&lexmodelbuildingservice.DeleteIntentInput{ Name: f.name, }) return err } func (f *LexIntent) String() string { return *f.name } func (f *LexIntent) Properties() types.Properties { properties := types.NewProperties() properties. Set("Name", f.name) return properties } aws-nuke-2.16.0/resources/lex-slot-types.go000066400000000000000000000024121411137415400206040ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/lexmodelbuildingservice" "github.com/rebuy-de/aws-nuke/pkg/types" ) type LexSlotType struct { svc *lexmodelbuildingservice.LexModelBuildingService name *string } func init() { register("LexSlotType", ListLexSlotTypes) } func ListLexSlotTypes(sess *session.Session) ([]Resource, error) { svc := lexmodelbuildingservice.New(sess) resources := []Resource{} params := &lexmodelbuildingservice.GetSlotTypesInput{ MaxResults: aws.Int64(20), } for { output, err := svc.GetSlotTypes(params) if err != nil { return nil, err } for _, bot := range output.SlotTypes { resources = append(resources, &LexSlotType{ svc: svc, name: bot.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *LexSlotType) Remove() error { _, err := f.svc.DeleteSlotType(&lexmodelbuildingservice.DeleteSlotTypeInput{ Name: f.name, }) return err } func (f *LexSlotType) String() string { return *f.name } func (f *LexSlotType) Properties() types.Properties { properties := types.NewProperties() properties. Set("Name", f.name) return properties } aws-nuke-2.16.0/resources/lightsail-disks.go000066400000000000000000000017271411137415400207760ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/lightsail" ) type LightsailDisk struct { svc *lightsail.Lightsail diskName *string } func init() { register("LightsailDisk", ListLightsailDisks) } func ListLightsailDisks(sess *session.Session) ([]Resource, error) { svc := lightsail.New(sess) resources := []Resource{} params := &lightsail.GetDisksInput{} for { output, err := svc.GetDisks(params) if err != nil { return nil, err } for _, disk := range output.Disks { resources = append(resources, &LightsailDisk{ svc: svc, diskName: disk.Name, }) } if output.NextPageToken == nil { break } params.PageToken = output.NextPageToken } return resources, nil } func (f *LightsailDisk) Remove() error { _, err := f.svc.DeleteDisk(&lightsail.DeleteDiskInput{ DiskName: f.diskName, }) return err } func (f *LightsailDisk) String() string { return *f.diskName } aws-nuke-2.16.0/resources/lightsail-domains.go000066400000000000000000000023111411137415400213010ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/lightsail" ) type LightsailDomain struct { svc *lightsail.Lightsail domainName *string } func init() { register("LightsailDomain", ListLightsailDomains) } func ListLightsailDomains(sess *session.Session) ([]Resource, error) { svc := lightsail.New(sess) resources := []Resource{} if sess.Config.Region == nil || *sess.Config.Region != endpoints.UsEast1RegionID { // LightsailDomain only supports us-east-1 return resources, nil } params := &lightsail.GetDomainsInput{} for { output, err := svc.GetDomains(params) if err != nil { return nil, err } for _, domain := range output.Domains { resources = append(resources, &LightsailDomain{ svc: svc, domainName: domain.Name, }) } if output.NextPageToken == nil { break } params.PageToken = output.NextPageToken } return resources, nil } func (f *LightsailDomain) Remove() error { _, err := f.svc.DeleteDomain(&lightsail.DeleteDomainInput{ DomainName: f.domainName, }) return err } func (f *LightsailDomain) String() string { return *f.domainName } aws-nuke-2.16.0/resources/lightsail-instances.go000066400000000000000000000032261411137415400216440ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/lightsail" "github.com/rebuy-de/aws-nuke/pkg/config" "github.com/rebuy-de/aws-nuke/pkg/types" ) type LightsailInstance struct { svc *lightsail.Lightsail instanceName *string tags []*lightsail.Tag featureFlags config.FeatureFlags } func init() { register("LightsailInstance", ListLightsailInstances) } func ListLightsailInstances(sess *session.Session) ([]Resource, error) { svc := lightsail.New(sess) resources := []Resource{} params := &lightsail.GetInstancesInput{} for { output, err := svc.GetInstances(params) if err != nil { return nil, err } for _, instance := range output.Instances { resources = append(resources, &LightsailInstance{ svc: svc, instanceName: instance.Name, tags: instance.Tags, }) } if output.NextPageToken == nil { break } params.PageToken = output.NextPageToken } return resources, nil } func (f *LightsailInstance) FeatureFlags(ff config.FeatureFlags) { f.featureFlags = ff } func (f *LightsailInstance) Remove() error { _, err := f.svc.DeleteInstance(&lightsail.DeleteInstanceInput{ InstanceName: f.instanceName, ForceDeleteAddOns: aws.Bool(f.featureFlags.ForceDeleteLightsailAddOns), }) return err } func (f *LightsailInstance) Properties() types.Properties { properties := types.NewProperties() for _, tag := range f.tags { properties.SetTag(tag.Key, tag.Value) } properties.Set("Name", f.instanceName) return properties } func (f *LightsailInstance) String() string { return *f.instanceName } aws-nuke-2.16.0/resources/lightsail-keypairs.go000066400000000000000000000020261411137415400215010ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/lightsail" ) type LightsailKeyPair struct { svc *lightsail.Lightsail keyPairName *string } func init() { register("LightsailKeyPair", ListLightsailKeyPairs) } func ListLightsailKeyPairs(sess *session.Session) ([]Resource, error) { svc := lightsail.New(sess) resources := []Resource{} params := &lightsail.GetKeyPairsInput{} for { output, err := svc.GetKeyPairs(params) if err != nil { return nil, err } for _, keyPair := range output.KeyPairs { resources = append(resources, &LightsailKeyPair{ svc: svc, keyPairName: keyPair.Name, }) } if output.NextPageToken == nil { break } params.PageToken = output.NextPageToken } return resources, nil } func (f *LightsailKeyPair) Remove() error { _, err := f.svc.DeleteKeyPair(&lightsail.DeleteKeyPairInput{ KeyPairName: f.keyPairName, }) return err } func (f *LightsailKeyPair) String() string { return *f.keyPairName } aws-nuke-2.16.0/resources/lightsail-loadbalancers.go000066400000000000000000000021771411137415400224530ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/lightsail" ) type LightsailLoadBalancer struct { svc *lightsail.Lightsail loadBalancerName *string } func init() { register("LightsailLoadBalancer", ListLightsailLoadBalancers) } func ListLightsailLoadBalancers(sess *session.Session) ([]Resource, error) { svc := lightsail.New(sess) resources := []Resource{} params := &lightsail.GetLoadBalancersInput{} for { output, err := svc.GetLoadBalancers(params) if err != nil { return nil, err } for _, loadbalancer := range output.LoadBalancers { resources = append(resources, &LightsailLoadBalancer{ svc: svc, loadBalancerName: loadbalancer.Name, }) } if output.NextPageToken == nil { break } params.PageToken = output.NextPageToken } return resources, nil } func (f *LightsailLoadBalancer) Remove() error { _, err := f.svc.DeleteLoadBalancer(&lightsail.DeleteLoadBalancerInput{ LoadBalancerName: f.loadBalancerName, }) return err } func (f *LightsailLoadBalancer) String() string { return *f.loadBalancerName } aws-nuke-2.16.0/resources/lightsail-staticips.go000066400000000000000000000020551411137415400216570ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/lightsail" ) type LightsailStaticIP struct { svc *lightsail.Lightsail staticIPName *string } func init() { register("LightsailStaticIP", ListLightsailStaticIPs) } func ListLightsailStaticIPs(sess *session.Session) ([]Resource, error) { svc := lightsail.New(sess) resources := []Resource{} params := &lightsail.GetStaticIpsInput{} for { output, err := svc.GetStaticIps(params) if err != nil { return nil, err } for _, staticIP := range output.StaticIps { resources = append(resources, &LightsailStaticIP{ svc: svc, staticIPName: staticIP.Name, }) } if output.NextPageToken == nil { break } params.PageToken = output.NextPageToken } return resources, nil } func (f *LightsailStaticIP) Remove() error { _, err := f.svc.ReleaseStaticIp(&lightsail.ReleaseStaticIpInput{ StaticIpName: f.staticIPName, }) return err } func (f *LightsailStaticIP) String() string { return *f.staticIPName } aws-nuke-2.16.0/resources/machinelearning-batchpredictions.go000066400000000000000000000023371411137415400243500ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/machinelearning" ) type MachineLearningBranchPrediction struct { svc *machinelearning.MachineLearning ID *string } func init() { register("MachineLearningBranchPrediction", ListMachineLearningBranchPredictions) } func ListMachineLearningBranchPredictions(sess *session.Session) ([]Resource, error) { svc := machinelearning.New(sess) resources := []Resource{} params := &machinelearning.DescribeBatchPredictionsInput{ Limit: aws.Int64(100), } for { output, err := svc.DescribeBatchPredictions(params) if err != nil { return nil, err } for _, result := range output.Results { resources = append(resources, &MachineLearningBranchPrediction{ svc: svc, ID: result.BatchPredictionId, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *MachineLearningBranchPrediction) Remove() error { _, err := f.svc.DeleteBatchPrediction(&machinelearning.DeleteBatchPredictionInput{ BatchPredictionId: f.ID, }) return err } func (f *MachineLearningBranchPrediction) String() string { return *f.ID } aws-nuke-2.16.0/resources/machinelearning-datasources.go000066400000000000000000000022271411137415400233360ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/machinelearning" ) type MachineLearningDataSource struct { svc *machinelearning.MachineLearning ID *string } func init() { register("MachineLearningDataSource", ListMachineLearningDataSources) } func ListMachineLearningDataSources(sess *session.Session) ([]Resource, error) { svc := machinelearning.New(sess) resources := []Resource{} params := &machinelearning.DescribeDataSourcesInput{ Limit: aws.Int64(100), } for { output, err := svc.DescribeDataSources(params) if err != nil { return nil, err } for _, result := range output.Results { resources = append(resources, &MachineLearningDataSource{ svc: svc, ID: result.DataSourceId, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *MachineLearningDataSource) Remove() error { _, err := f.svc.DeleteDataSource(&machinelearning.DeleteDataSourceInput{ DataSourceId: f.ID, }) return err } func (f *MachineLearningDataSource) String() string { return *f.ID } aws-nuke-2.16.0/resources/machinelearning-evaluations.go000066400000000000000000000022271411137415400233530ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/machinelearning" ) type MachineLearningEvaluation struct { svc *machinelearning.MachineLearning ID *string } func init() { register("MachineLearningEvaluation", ListMachineLearningEvaluations) } func ListMachineLearningEvaluations(sess *session.Session) ([]Resource, error) { svc := machinelearning.New(sess) resources := []Resource{} params := &machinelearning.DescribeEvaluationsInput{ Limit: aws.Int64(100), } for { output, err := svc.DescribeEvaluations(params) if err != nil { return nil, err } for _, result := range output.Results { resources = append(resources, &MachineLearningEvaluation{ svc: svc, ID: result.EvaluationId, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *MachineLearningEvaluation) Remove() error { _, err := f.svc.DeleteEvaluation(&machinelearning.DeleteEvaluationInput{ EvaluationId: f.ID, }) return err } func (f *MachineLearningEvaluation) String() string { return *f.ID } aws-nuke-2.16.0/resources/machinelearning-mlmodels.go000066400000000000000000000021601411137415400226310ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/machinelearning" ) type MachineLearningMLModel struct { svc *machinelearning.MachineLearning ID *string } func init() { register("MachineLearningMLModel", ListMachineLearningMLModels) } func ListMachineLearningMLModels(sess *session.Session) ([]Resource, error) { svc := machinelearning.New(sess) resources := []Resource{} params := &machinelearning.DescribeMLModelsInput{ Limit: aws.Int64(100), } for { output, err := svc.DescribeMLModels(params) if err != nil { return nil, err } for _, result := range output.Results { resources = append(resources, &MachineLearningMLModel{ svc: svc, ID: result.MLModelId, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *MachineLearningMLModel) Remove() error { _, err := f.svc.DeleteMLModel(&machinelearning.DeleteMLModelInput{ MLModelId: f.ID, }) return err } func (f *MachineLearningMLModel) String() string { return *f.ID } aws-nuke-2.16.0/resources/mediaconvert-jobtemplates.go000066400000000000000000000026621411137415400230510ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/mediaconvert" ) type MediaConvertJobTemplate struct { svc *mediaconvert.MediaConvert name *string } func init() { register("MediaConvertJobTemplate", ListMediaConvertJobTemplates) } func ListMediaConvertJobTemplates(sess *session.Session) ([]Resource, error) { svc := mediaconvert.New(sess) resources := []Resource{} var mediaEndpoint *string output, err := svc.DescribeEndpoints(&mediaconvert.DescribeEndpointsInput{}) if err != nil { return nil, err } for _, mediaconvert := range output.Endpoints { mediaEndpoint = mediaconvert.Url } // Update svc to use custom media endpoint svc.Endpoint = *mediaEndpoint params := &mediaconvert.ListJobTemplatesInput{ MaxResults: aws.Int64(20), } for { output, err := svc.ListJobTemplates(params) if err != nil { return nil, err } for _, jobTemplate := range output.JobTemplates { resources = append(resources, &MediaConvertJobTemplate{ svc: svc, name: jobTemplate.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *MediaConvertJobTemplate) Remove() error { _, err := f.svc.DeleteJobTemplate(&mediaconvert.DeleteJobTemplateInput{ Name: f.name, }) return err } func (f *MediaConvertJobTemplate) String() string { return *f.name } aws-nuke-2.16.0/resources/mediaconvert-presets.go000066400000000000000000000025541411137415400220450ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/mediaconvert" ) type MediaConvertPreset struct { svc *mediaconvert.MediaConvert name *string } func init() { register("MediaConvertPreset", ListMediaConvertPresets) } func ListMediaConvertPresets(sess *session.Session) ([]Resource, error) { svc := mediaconvert.New(sess) resources := []Resource{} var mediaEndpoint *string output, err := svc.DescribeEndpoints(&mediaconvert.DescribeEndpointsInput{}) if err != nil { return nil, err } for _, mediaconvert := range output.Endpoints { mediaEndpoint = mediaconvert.Url } // Update svc to use custom media endpoint svc.Endpoint = *mediaEndpoint params := &mediaconvert.ListPresetsInput{ MaxResults: aws.Int64(20), } for { output, err := svc.ListPresets(params) if err != nil { return nil, err } for _, preset := range output.Presets { resources = append(resources, &MediaConvertPreset{ svc: svc, name: preset.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *MediaConvertPreset) Remove() error { _, err := f.svc.DeletePreset(&mediaconvert.DeletePresetInput{ Name: f.name, }) return err } func (f *MediaConvertPreset) String() string { return *f.name } aws-nuke-2.16.0/resources/mediaconvert-queues.go000066400000000000000000000030161411137415400216610ustar00rootroot00000000000000package resources import ( "fmt" "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/mediaconvert" ) type MediaConvertQueue struct { svc *mediaconvert.MediaConvert name *string } func init() { register("MediaConvertQueue", ListMediaConvertQueues) } func ListMediaConvertQueues(sess *session.Session) ([]Resource, error) { svc := mediaconvert.New(sess) resources := []Resource{} var mediaEndpoint *string output, err := svc.DescribeEndpoints(&mediaconvert.DescribeEndpointsInput{}) if err != nil { return nil, err } for _, mediaconvert := range output.Endpoints { mediaEndpoint = mediaconvert.Url } // Update svc to use custom media endpoint svc.Endpoint = *mediaEndpoint params := &mediaconvert.ListQueuesInput{ MaxResults: aws.Int64(20), } for { output, err := svc.ListQueues(params) if err != nil { return nil, err } for _, queue := range output.Queues { resources = append(resources, &MediaConvertQueue{ svc: svc, name: queue.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *MediaConvertQueue) Remove() error { _, err := f.svc.DeleteQueue(&mediaconvert.DeleteQueueInput{ Name: f.name, }) return err } func (f *MediaConvertQueue) String() string { return *f.name } func (f *MediaConvertQueue) Filter() error { if strings.Contains(*f.name, "Default") { return fmt.Errorf("cannot delete default queue") } return nil } aws-nuke-2.16.0/resources/medialive-channels.go000066400000000000000000000020321411137415400214210ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/medialive" ) type MediaLiveChannel struct { svc *medialive.MediaLive ID *string } func init() { register("MediaLiveChannel", ListMediaLiveChannels) } func ListMediaLiveChannels(sess *session.Session) ([]Resource, error) { svc := medialive.New(sess) resources := []Resource{} params := &medialive.ListChannelsInput{ MaxResults: aws.Int64(20), } for { output, err := svc.ListChannels(params) if err != nil { return nil, err } for _, channel := range output.Channels { resources = append(resources, &MediaLiveChannel{ svc: svc, ID: channel.Id, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *MediaLiveChannel) Remove() error { _, err := f.svc.DeleteChannel(&medialive.DeleteChannelInput{ ChannelId: f.ID, }) return err } func (f *MediaLiveChannel) String() string { return *f.ID } aws-nuke-2.16.0/resources/medialive-inputs.go000066400000000000000000000017741411137415400211640ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/medialive" ) type MediaLiveInput struct { svc *medialive.MediaLive ID *string } func init() { register("MediaLiveInput", ListMediaLiveInputs) } func ListMediaLiveInputs(sess *session.Session) ([]Resource, error) { svc := medialive.New(sess) resources := []Resource{} params := &medialive.ListInputsInput{ MaxResults: aws.Int64(20), } for { output, err := svc.ListInputs(params) if err != nil { return nil, err } for _, input := range output.Inputs { resources = append(resources, &MediaLiveInput{ svc: svc, ID: input.Id, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *MediaLiveInput) Remove() error { _, err := f.svc.DeleteInput(&medialive.DeleteInputInput{ InputId: f.ID, }) return err } func (f *MediaLiveInput) String() string { return *f.ID } aws-nuke-2.16.0/resources/medialive-inputsecuritygroups.go000066400000000000000000000022771411137415400240300ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/medialive" ) type MediaLiveInputSecurityGroup struct { svc *medialive.MediaLive ID *string } func init() { register("MediaLiveInputSecurityGroup", ListMediaLiveInputSecurityGroups) } func ListMediaLiveInputSecurityGroups(sess *session.Session) ([]Resource, error) { svc := medialive.New(sess) resources := []Resource{} params := &medialive.ListInputSecurityGroupsInput{ MaxResults: aws.Int64(20), } for { output, err := svc.ListInputSecurityGroups(params) if err != nil { return nil, err } for _, inputSecurityGroup := range output.InputSecurityGroups { resources = append(resources, &MediaLiveInputSecurityGroup{ svc: svc, ID: inputSecurityGroup.Id, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *MediaLiveInputSecurityGroup) Remove() error { _, err := f.svc.DeleteInputSecurityGroup(&medialive.DeleteInputSecurityGroupInput{ InputSecurityGroupId: f.ID, }) return err } func (f *MediaLiveInputSecurityGroup) String() string { return *f.ID } aws-nuke-2.16.0/resources/mediapackage-channels.go000066400000000000000000000020721411137415400220610ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/mediapackage" ) type MediaPackageChannel struct { svc *mediapackage.MediaPackage ID *string } func init() { register("MediaPackageChannel", ListMediaPackageChannels) } func ListMediaPackageChannels(sess *session.Session) ([]Resource, error) { svc := mediapackage.New(sess) resources := []Resource{} params := &mediapackage.ListChannelsInput{ MaxResults: aws.Int64(50), } for { output, err := svc.ListChannels(params) if err != nil { return nil, err } for _, channel := range output.Channels { resources = append(resources, &MediaPackageChannel{ svc: svc, ID: channel.Id, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *MediaPackageChannel) Remove() error { _, err := f.svc.DeleteChannel(&mediapackage.DeleteChannelInput{ Id: f.ID, }) return err } func (f *MediaPackageChannel) String() string { return *f.ID } aws-nuke-2.16.0/resources/mediapackage-originendpoints.go000066400000000000000000000022341411137415400235010ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/mediapackage" ) type MediaPackageOriginEndpoint struct { svc *mediapackage.MediaPackage ID *string } func init() { register("MediaPackageOriginEndpoint", ListMediaPackageOriginEndpoints) } func ListMediaPackageOriginEndpoints(sess *session.Session) ([]Resource, error) { svc := mediapackage.New(sess) resources := []Resource{} params := &mediapackage.ListOriginEndpointsInput{ MaxResults: aws.Int64(50), } for { output, err := svc.ListOriginEndpoints(params) if err != nil { return nil, err } for _, originEndpoint := range output.OriginEndpoints { resources = append(resources, &MediaPackageOriginEndpoint{ svc: svc, ID: originEndpoint.Id, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *MediaPackageOriginEndpoint) Remove() error { _, err := f.svc.DeleteOriginEndpoint(&mediapackage.DeleteOriginEndpointInput{ Id: f.ID, }) return err } func (f *MediaPackageOriginEndpoint) String() string { return *f.ID } aws-nuke-2.16.0/resources/mediastore-containers.go000066400000000000000000000021221411137415400221700ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/mediastore" ) type MediaStoreContainer struct { svc *mediastore.MediaStore name *string } func init() { register("MediaStoreContainer", ListMediaStoreContainers) } func ListMediaStoreContainers(sess *session.Session) ([]Resource, error) { svc := mediastore.New(sess) resources := []Resource{} params := &mediastore.ListContainersInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListContainers(params) if err != nil { return nil, err } for _, container := range output.Containers { resources = append(resources, &MediaStoreContainer{ svc: svc, name: container.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *MediaStoreContainer) Remove() error { _, err := f.svc.DeleteContainer(&mediastore.DeleteContainerInput{ ContainerName: f.name, }) return err } func (f *MediaStoreContainer) String() string { return *f.name } aws-nuke-2.16.0/resources/mediastoredata-items.go000066400000000000000000000034421411137415400220040ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/mediastore" "github.com/aws/aws-sdk-go/service/mediastoredata" ) type MediaStoreDataItems struct { svc *mediastoredata.MediaStoreData path *string } func init() { register("MediaStoreDataItems", ListMediaStoreDataItems) } func ListMediaStoreDataItems(sess *session.Session) ([]Resource, error) { containerSvc := mediastore.New(sess) svc := mediastoredata.New(sess) svc.ClientInfo.SigningName = "mediastore" resources := []Resource{} containers := []*mediastore.Container{} //List all containers containerParams := &mediastore.ListContainersInput{ MaxResults: aws.Int64(100), } for { output, err := containerSvc.ListContainers(containerParams) if err != nil { return nil, err } for _, container := range output.Containers { containers = append(containers, container) } if output.NextToken == nil { break } containerParams.NextToken = output.NextToken } // List all Items per Container params := &mediastoredata.ListItemsInput{ MaxResults: aws.Int64(100), } for _, container := range containers { if container.Endpoint == nil { continue } svc.Endpoint = *container.Endpoint output, err := svc.ListItems(params) if err != nil { return nil, err } for _, item := range output.Items { resources = append(resources, &MediaStoreDataItems{ svc: svc, path: item.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *MediaStoreDataItems) Remove() error { _, err := f.svc.DeleteObject(&mediastoredata.DeleteObjectInput{ Path: f.path, }) return err } func (f *MediaStoreDataItems) String() string { return *f.path } aws-nuke-2.16.0/resources/mediatailor-configurations.go000066400000000000000000000022111411137415400232120ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/mediatailor" ) type MediaTailorConfiguration struct { svc *mediatailor.MediaTailor name *string } func init() { register("MediaTailorConfiguration", ListMediaTailorConfigurations) } func ListMediaTailorConfigurations(sess *session.Session) ([]Resource, error) { svc := mediatailor.New(sess) resources := []Resource{} params := &mediatailor.ListPlaybackConfigurationsInput{ MaxResults: aws.Int64(100), } for { resp, err := svc.ListPlaybackConfigurations(params) if err != nil { return nil, err } for _, item := range resp.Items { resources = append(resources, &MediaTailorConfiguration{ svc: svc, name: item.Name, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *MediaTailorConfiguration) Remove() error { _, err := f.svc.DeletePlaybackConfiguration(&mediatailor.DeletePlaybackConfigurationInput{ Name: f.name, }) return err } func (f *MediaTailorConfiguration) String() string { return *f.name } aws-nuke-2.16.0/resources/mobile-projects.go000066400000000000000000000021251411137415400207720ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/mobile" ) type MobileProject struct { svc *mobile.Mobile projectID *string } func init() { register("MobileProject", ListMobileProjects) } func ListMobileProjects(sess *session.Session) ([]Resource, error) { svc := mobile.New(sess) svc.ClientInfo.SigningName = "AWSMobileHubService" resources := []Resource{} params := &mobile.ListProjectsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListProjects(params) if err != nil { return nil, err } for _, project := range output.Projects { resources = append(resources, &MobileProject{ svc: svc, projectID: project.ProjectId, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *MobileProject) Remove() error { _, err := f.svc.DeleteProject(&mobile.DeleteProjectInput{ ProjectId: f.projectID, }) return err } func (f *MobileProject) String() string { return *f.projectID } aws-nuke-2.16.0/resources/mq-broker.go000066400000000000000000000017251411137415400176000ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/mq" ) type MQBroker struct { svc *mq.MQ brokerID *string } func init() { register("MQBroker", ListMQBrokers) } func ListMQBrokers(sess *session.Session) ([]Resource, error) { svc := mq.New(sess) resources := []Resource{} params := &mq.ListBrokersInput{ MaxResults: aws.Int64(100), } for { resp, err := svc.ListBrokers(params) if err != nil { return nil, err } for _, broker := range resp.BrokerSummaries { resources = append(resources, &MQBroker{ svc: svc, brokerID: broker.BrokerId, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *MQBroker) Remove() error { _, err := f.svc.DeleteBroker(&mq.DeleteBrokerInput{ BrokerId: f.brokerID, }) return err } func (f *MQBroker) String() string { return *f.brokerID } aws-nuke-2.16.0/resources/msk-cluster.go000066400000000000000000000021741411137415400201510ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/kafka" "github.com/rebuy-de/aws-nuke/pkg/types" ) type MSKCluster struct { svc *kafka.Kafka arn string name string } func init() { register("MSKCluster", ListMSKCluster) } func ListMSKCluster(sess *session.Session) ([]Resource, error) { svc := kafka.New(sess) params := &kafka.ListClustersInput{} resp, err := svc.ListClusters(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, cluster := range resp.ClusterInfoList { resources = append(resources, &MSKCluster{ svc: svc, arn: *cluster.ClusterArn, name: *cluster.ClusterName, }) } return resources, nil } func (m *MSKCluster) Remove() error { params := &kafka.DeleteClusterInput{ ClusterArn: &m.arn, } _, err := m.svc.DeleteCluster(params) if err != nil { return err } return nil } func (m *MSKCluster) String() string { return m.arn } func (m *MSKCluster) Properties() types.Properties { properties := types.NewProperties() properties.Set("ARN", m.arn) properties.Set("Name", m.name) return properties } aws-nuke-2.16.0/resources/msk-configuration.go000066400000000000000000000023031411137415400213310ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/kafka" "github.com/rebuy-de/aws-nuke/pkg/types" ) type MSKConfiguration struct { svc *kafka.Kafka arn string name string } func init() { register("MSKConfiguration", ListMSKConfigurations) } func ListMSKConfigurations(sess *session.Session) ([]Resource, error) { svc := kafka.New(sess) params := &kafka.ListConfigurationsInput{} resp, err := svc.ListConfigurations(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, configuration := range resp.Configurations { resources = append(resources, &MSKConfiguration{ svc: svc, arn: *configuration.Arn, name: *configuration.Name, }) } return resources, nil } func (m *MSKConfiguration) Remove() error { params := &kafka.DeleteConfigurationInput{ Arn: &m.arn, } _, err := m.svc.DeleteConfiguration(params) if err != nil { return err } return nil } func (m *MSKConfiguration) String() string { return m.arn } func (m *MSKConfiguration) Properties() types.Properties { properties := types.NewProperties() properties.Set("ARN", m.arn) properties.Set("Name", m.name) return properties } aws-nuke-2.16.0/resources/neptune-clusters.go000066400000000000000000000021201411137415400212070ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/neptune" ) type NeptuneCluster struct { svc *neptune.Neptune ID *string } func init() { register("NeptuneCluster", ListNeptuneClusters) } func ListNeptuneClusters(sess *session.Session) ([]Resource, error) { svc := neptune.New(sess) resources := []Resource{} params := &neptune.DescribeDBClustersInput{ MaxRecords: aws.Int64(100), } for { output, err := svc.DescribeDBClusters(params) if err != nil { return nil, err } for _, dbCluster := range output.DBClusters { resources = append(resources, &NeptuneCluster{ svc: svc, ID: dbCluster.DBClusterIdentifier, }) } if output.Marker == nil { break } params.Marker = output.Marker } return resources, nil } func (f *NeptuneCluster) Remove() error { _, err := f.svc.DeleteDBCluster(&neptune.DeleteDBClusterInput{ DBClusterIdentifier: f.ID, SkipFinalSnapshot: aws.Bool(true), }) return err } func (f *NeptuneCluster) String() string { return *f.ID } aws-nuke-2.16.0/resources/neptune-instances.go000066400000000000000000000021411411137415400213350ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/neptune" ) type NeptuneInstance struct { svc *neptune.Neptune ID *string } func init() { register("NeptuneInstance", ListNeptuneInstances) } func ListNeptuneInstances(sess *session.Session) ([]Resource, error) { svc := neptune.New(sess) resources := []Resource{} params := &neptune.DescribeDBInstancesInput{ MaxRecords: aws.Int64(100), } for { output, err := svc.DescribeDBInstances(params) if err != nil { return nil, err } for _, dbInstance := range output.DBInstances { resources = append(resources, &NeptuneInstance{ svc: svc, ID: dbInstance.DBInstanceIdentifier, }) } if output.Marker == nil { break } params.Marker = output.Marker } return resources, nil } func (f *NeptuneInstance) Remove() error { _, err := f.svc.DeleteDBInstance(&neptune.DeleteDBInstanceInput{ DBInstanceIdentifier: f.ID, SkipFinalSnapshot: aws.Bool(true), }) return err } func (f *NeptuneInstance) String() string { return *f.ID } aws-nuke-2.16.0/resources/neptune-snapshots.go000066400000000000000000000021701411137415400213720ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/neptune" ) type NetpuneSnapshot struct { svc *neptune.Neptune ID *string } func init() { register("NetpuneSnapshot", ListNetpuneSnapshots) } func ListNetpuneSnapshots(sess *session.Session) ([]Resource, error) { svc := neptune.New(sess) resources := []Resource{} params := &neptune.DescribeDBClusterSnapshotsInput{ MaxRecords: aws.Int64(100), } for { output, err := svc.DescribeDBClusterSnapshots(params) if err != nil { return nil, err } for _, dbClusterSnapshot := range output.DBClusterSnapshots { resources = append(resources, &NetpuneSnapshot{ svc: svc, ID: dbClusterSnapshot.DBClusterSnapshotIdentifier, }) } if output.Marker == nil { break } params.Marker = output.Marker } return resources, nil } func (f *NetpuneSnapshot) Remove() error { _, err := f.svc.DeleteDBClusterSnapshot(&neptune.DeleteDBClusterSnapshotInput{ DBClusterSnapshotIdentifier: f.ID, }) return err } func (f *NetpuneSnapshot) String() string { return *f.ID } aws-nuke-2.16.0/resources/opsworks-apps.go000066400000000000000000000020311411137415400205200ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/opsworks" ) type OpsWorksApp struct { svc *opsworks.OpsWorks ID *string } func init() { register("OpsWorksApp", ListOpsWorksApps) } func ListOpsWorksApps(sess *session.Session) ([]Resource, error) { svc := opsworks.New(sess) resources := []Resource{} stackParams := &opsworks.DescribeStacksInput{} resp, err := svc.DescribeStacks(stackParams) if err != nil { return nil, err } appsParams := &opsworks.DescribeAppsInput{} for _, stack := range resp.Stacks { appsParams.StackId = stack.StackId output, err := svc.DescribeApps(appsParams) if err != nil { return nil, err } for _, app := range output.Apps { resources = append(resources, &OpsWorksApp{ svc: svc, ID: app.AppId, }) } } return resources, nil } func (f *OpsWorksApp) Remove() error { _, err := f.svc.DeleteApp(&opsworks.DeleteAppInput{ AppId: f.ID, }) return err } func (f *OpsWorksApp) String() string { return *f.ID } aws-nuke-2.16.0/resources/opsworks-instances.go000066400000000000000000000021641411137415400215530ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/opsworks" ) type OpsWorksInstance struct { svc *opsworks.OpsWorks ID *string } func init() { register("OpsWorksInstance", ListOpsWorksInstances) } func ListOpsWorksInstances(sess *session.Session) ([]Resource, error) { svc := opsworks.New(sess) resources := []Resource{} stackParams := &opsworks.DescribeStacksInput{} resp, err := svc.DescribeStacks(stackParams) if err != nil { return nil, err } instanceParams := &opsworks.DescribeInstancesInput{} for _, stack := range resp.Stacks { instanceParams.StackId = stack.StackId output, err := svc.DescribeInstances(instanceParams) if err != nil { return nil, err } for _, instance := range output.Instances { resources = append(resources, &OpsWorksInstance{ svc: svc, ID: instance.InstanceId, }) } } return resources, nil } func (f *OpsWorksInstance) Remove() error { _, err := f.svc.DeleteInstance(&opsworks.DeleteInstanceInput{ InstanceId: f.ID, }) return err } func (f *OpsWorksInstance) String() string { return *f.ID } aws-nuke-2.16.0/resources/opsworks-layers.go000066400000000000000000000020741411137415400210630ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/opsworks" ) type OpsWorksLayer struct { svc *opsworks.OpsWorks ID *string } func init() { register("OpsWorksLayer", ListOpsWorksLayers) } func ListOpsWorksLayers(sess *session.Session) ([]Resource, error) { svc := opsworks.New(sess) resources := []Resource{} stackParams := &opsworks.DescribeStacksInput{} resp, err := svc.DescribeStacks(stackParams) if err != nil { return nil, err } layerParams := &opsworks.DescribeLayersInput{} for _, stack := range resp.Stacks { layerParams.StackId = stack.StackId output, err := svc.DescribeLayers(layerParams) if err != nil { return nil, err } for _, layer := range output.Layers { resources = append(resources, &OpsWorksLayer{ svc: svc, ID: layer.LayerId, }) } } return resources, nil } func (f *OpsWorksLayer) Remove() error { _, err := f.svc.DeleteLayer(&opsworks.DeleteLayerInput{ LayerId: f.ID, }) return err } func (f *OpsWorksLayer) String() string { return *f.ID } aws-nuke-2.16.0/resources/opsworks-userprofiles.go000066400000000000000000000024771411137415400223150ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/opsworks" "github.com/aws/aws-sdk-go/service/sts" ) type OpsWorksUserProfile struct { svc *opsworks.OpsWorks ARN *string callingArn *string } func init() { register("OpsWorksUserProfile", ListOpsWorksUserProfiles) } func ListOpsWorksUserProfiles(sess *session.Session) ([]Resource, error) { svc := opsworks.New(sess) resources := []Resource{} identityOutput, err := sts.New(sess).GetCallerIdentity(nil) if err != nil { return nil, err } params := &opsworks.DescribeUserProfilesInput{} output, err := svc.DescribeUserProfiles(params) if err != nil { return nil, err } for _, userProfile := range output.UserProfiles { resources = append(resources, &OpsWorksUserProfile{ svc: svc, callingArn: identityOutput.Arn, ARN: userProfile.IamUserArn, }) } return resources, nil } func (f *OpsWorksUserProfile) Filter() error { if *f.callingArn == *f.ARN { return fmt.Errorf("Cannot delete OpsWorksUserProfile of calling User") } return nil } func (f *OpsWorksUserProfile) Remove() error { _, err := f.svc.DeleteUserProfile(&opsworks.DeleteUserProfileInput{ IamUserArn: f.ARN, }) return err } func (f *OpsWorksUserProfile) String() string { return *f.ARN } aws-nuke-2.16.0/resources/opsworkscm-backups.go000066400000000000000000000015761411137415400215420ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/opsworkscm" ) type OpsWorksCMBackup struct { svc *opsworkscm.OpsWorksCM ID *string } func init() { register("OpsWorksCMBackup", ListOpsWorksCMBackups) } func ListOpsWorksCMBackups(sess *session.Session) ([]Resource, error) { svc := opsworkscm.New(sess) resources := []Resource{} params := &opsworkscm.DescribeBackupsInput{} output, err := svc.DescribeBackups(params) if err != nil { return nil, err } for _, backup := range output.Backups { resources = append(resources, &OpsWorksCMBackup{ svc: svc, ID: backup.BackupId, }) } return resources, nil } func (f *OpsWorksCMBackup) Remove() error { _, err := f.svc.DeleteBackup(&opsworkscm.DeleteBackupInput{ BackupId: f.ID, }) return err } func (f *OpsWorksCMBackup) String() string { return *f.ID } aws-nuke-2.16.0/resources/opsworkscm-servers.go000066400000000000000000000016361411137415400216000ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/opsworkscm" ) type OpsWorksCMServer struct { svc *opsworkscm.OpsWorksCM name *string status *string } func init() { register("OpsWorksCMServer", ListOpsWorksCMServers) } func ListOpsWorksCMServers(sess *session.Session) ([]Resource, error) { svc := opsworkscm.New(sess) resources := []Resource{} params := &opsworkscm.DescribeServersInput{} output, err := svc.DescribeServers(params) if err != nil { return nil, err } for _, server := range output.Servers { resources = append(resources, &OpsWorksCMServer{ svc: svc, name: server.ServerName, }) } return resources, nil } func (f *OpsWorksCMServer) Remove() error { _, err := f.svc.DeleteServer(&opsworkscm.DeleteServerInput{ ServerName: f.name, }) return err } func (f *OpsWorksCMServer) String() string { return *f.name } aws-nuke-2.16.0/resources/opsworkscm-serverstates.go000066400000000000000000000020521411137415400226320ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/opsworkscm" ) type OpsWorksCMServerState struct { svc *opsworkscm.OpsWorksCM name *string status *string } func init() { register("OpsWorksCMServerState", ListOpsWorksCMServerStates) } func ListOpsWorksCMServerStates(sess *session.Session) ([]Resource, error) { svc := opsworkscm.New(sess) resources := []Resource{} params := &opsworkscm.DescribeServersInput{} output, err := svc.DescribeServers(params) if err != nil { return nil, err } for _, server := range output.Servers { resources = append(resources, &OpsWorksCMServerState{ svc: svc, name: server.ServerName, status: server.Status, }) } return resources, nil } func (f *OpsWorksCMServerState) Remove() error { return nil } func (f *OpsWorksCMServerState) String() string { return *f.name } func (f *OpsWorksCMServerState) Filter() error { if *f.status == "CREATING" { return nil } else { return fmt.Errorf("available for transition") } } aws-nuke-2.16.0/resources/prometheusservice-workspace.go000066400000000000000000000027241411137415400234510ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/prometheusservice" "github.com/rebuy-de/aws-nuke/pkg/types" ) type AMPWorkspace struct { svc *prometheusservice.PrometheusService workspaceAlias *string workspaceARN *string workspaceId *string } func init() { register("AMPWorkspace", ListAMPWorkspaces) } func ListAMPWorkspaces(sess *session.Session) ([]Resource, error) { svc := prometheusservice.New(sess) resources := []Resource{} var ampWorkspaces []*prometheusservice.WorkspaceSummary err := svc.ListWorkspacesPages( &prometheusservice.ListWorkspacesInput{}, func(page *prometheusservice.ListWorkspacesOutput, lastPage bool) bool { ampWorkspaces = append(ampWorkspaces, page.Workspaces...) return true }, ) if err != nil { return nil, err } for _, ws := range ampWorkspaces { resources = append(resources, &Workspace{ svc: svc, workspaceAlias: ws.Alias, workspaceARN: ws.Arn, workspaceId: ws.WorkspaceId, }) } return resources, nil } func (f *AMPWorkspace) Remove() error { _, err := f.svc.DeleteWorkspace(&prometheusservice.DeleteWorkspaceInput{ WorkspaceId: f.workspaceId, }) return err } func (f *AMPWorkspace) Properties() types.Properties { properties := types.NewProperties() properties. Set("WorkspaceAlias", f.workspaceAlias). Set("WorkspaceARN", f.workspaceARN). Set("WorkspaceId", f.workspaceId) return properties } aws-nuke-2.16.0/resources/rds-clusters.go000066400000000000000000000037721411137415400203370ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/rds" "github.com/rebuy-de/aws-nuke/pkg/types" ) type RDSDBCluster struct { svc *rds.RDS id string deletionProtection bool tags []*rds.Tag } func init() { register("RDSDBCluster", ListRDSClusters) } func ListRDSClusters(sess *session.Session) ([]Resource, error) { svc := rds.New(sess) params := &rds.DescribeDBClustersInput{} resp, err := svc.DescribeDBClusters(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, instance := range resp.DBClusters { tags, err := svc.ListTagsForResource(&rds.ListTagsForResourceInput{ ResourceName: instance.DBClusterArn, }) if err != nil { continue } resources = append(resources, &RDSDBCluster{ svc: svc, id: *instance.DBClusterIdentifier, deletionProtection: *instance.DeletionProtection, tags: tags.TagList, }) } return resources, nil } func (i *RDSDBCluster) Remove() error { if (i.deletionProtection) { modifyParams := &rds.ModifyDBClusterInput{ DBClusterIdentifier: &i.id, DeletionProtection: aws.Bool(false), } _, err := i.svc.ModifyDBCluster(modifyParams) if err != nil { return err } } params := &rds.DeleteDBClusterInput{ DBClusterIdentifier: &i.id, SkipFinalSnapshot: aws.Bool(true), } _, err := i.svc.DeleteDBCluster(params) if err != nil { return err } return nil } func (i *RDSDBCluster) String() string { return i.id } func (i *RDSDBCluster) Properties() types.Properties { properties := types.NewProperties() properties.Set("Identifier", i.id) properties.Set("Deletion Protection", i.deletionProtection) for _, tag := range i.tags { properties.SetTag(tag.Key, tag.Value) } return properties } aws-nuke-2.16.0/resources/rds-dbclusterparametergroups.go000066400000000000000000000036221411137415400236150ustar00rootroot00000000000000package resources import ( "fmt" "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/rds" "github.com/rebuy-de/aws-nuke/pkg/types" ) type RDSDBClusterParameterGroup struct { svc *rds.RDS name *string tags []*rds.Tag } func init() { register("RDSDBClusterParameterGroup", ListRDSClusterParameterGroups) } func ListRDSClusterParameterGroups(sess *session.Session) ([]Resource, error) { svc := rds.New(sess) params := &rds.DescribeDBClusterParameterGroupsInput{MaxRecords: aws.Int64(100)} resp, err := svc.DescribeDBClusterParameterGroups(params) if err != nil { return nil, err } var resources []Resource for _, parametergroup := range resp.DBClusterParameterGroups { tags, err := svc.ListTagsForResource(&rds.ListTagsForResourceInput{ ResourceName: parametergroup.DBClusterParameterGroupArn, }) if err != nil { continue } resources = append(resources, &RDSDBClusterParameterGroup{ svc: svc, name: parametergroup.DBClusterParameterGroupName, tags: tags.TagList, }) } return resources, nil } func (i *RDSDBClusterParameterGroup) Filter() error { if strings.HasPrefix(*i.name, "default.") { return fmt.Errorf("Cannot delete default parameter group") } return nil } func (i *RDSDBClusterParameterGroup) Remove() error { params := &rds.DeleteDBClusterParameterGroupInput{ DBClusterParameterGroupName: i.name, } _, err := i.svc.DeleteDBClusterParameterGroup(params) if err != nil { return err } return nil } func (i *RDSDBClusterParameterGroup) String() string { return *i.name } func (i *RDSDBClusterParameterGroup) Properties() types.Properties { properties := types.NewProperties() properties.Set("Name", i.name) for _, tag := range i.tags { properties.SetTag(tag.Key, tag.Value) } return properties } aws-nuke-2.16.0/resources/rds-dbparametergroups.go000066400000000000000000000033071411137415400222130ustar00rootroot00000000000000package resources import ( "fmt" "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/rds" "github.com/rebuy-de/aws-nuke/pkg/types" ) type RDSDBParameterGroup struct { svc *rds.RDS name *string tags []*rds.Tag } func init() { register("RDSDBParameterGroup", ListRDSParameterGroups) } func ListRDSParameterGroups(sess *session.Session) ([]Resource, error) { svc := rds.New(sess) params := &rds.DescribeDBParameterGroupsInput{MaxRecords: aws.Int64(100)} resp, err := svc.DescribeDBParameterGroups(params) if err != nil { return nil, err } var resources []Resource for _, parametergroup := range resp.DBParameterGroups { tags, err := svc.ListTagsForResource(&rds.ListTagsForResourceInput{ ResourceName: parametergroup.DBParameterGroupArn, }) if err != nil { continue } resources = append(resources, &RDSDBParameterGroup{ svc: svc, name: parametergroup.DBParameterGroupName, tags: tags.TagList, }) } return resources, nil } func (i *RDSDBParameterGroup) Filter() error { if strings.HasPrefix(*i.name, "default.") { return fmt.Errorf("Cannot delete default parameter group") } return nil } func (i *RDSDBParameterGroup) Remove() error { params := &rds.DeleteDBParameterGroupInput{ DBParameterGroupName: i.name, } _, err := i.svc.DeleteDBParameterGroup(params) if err != nil { return err } return nil } func (i *RDSDBParameterGroup) String() string { return *i.name } func (i *RDSDBParameterGroup) Properties() types.Properties { properties := types.NewProperties() properties.Set("Name", i.name) for _, tag := range i.tags { properties.SetTag(tag.Key, tag.Value) } return properties } aws-nuke-2.16.0/resources/rds-event-subscriptions.go000066400000000000000000000032101411137415400225040ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/rds" "github.com/rebuy-de/aws-nuke/pkg/types" ) type RDSEventSubscription struct { svc *rds.RDS id *string enabled *bool tags []*rds.Tag } func init() { register("RDSEventSubscription", ListRDSEventSubscriptions) } func ListRDSEventSubscriptions(sess *session.Session) ([]Resource, error) { svc := rds.New(sess) params := &rds.DescribeEventSubscriptionsInput{ MaxRecords: aws.Int64(100), } resp, err := svc.DescribeEventSubscriptions(params) if err != nil { return nil, err } var resources []Resource for _, eventSubscription := range resp.EventSubscriptionsList { tags, err := svc.ListTagsForResource(&rds.ListTagsForResourceInput{ ResourceName: eventSubscription.EventSubscriptionArn, }) if err != nil { continue } resources = append(resources, &RDSEventSubscription{ svc: svc, id: eventSubscription.CustSubscriptionId, enabled: eventSubscription.Enabled, tags: tags.TagList, }) } return resources, nil } func (i *RDSEventSubscription) Remove() error { params := &rds.DeleteEventSubscriptionInput{ SubscriptionName: i.id, } _, err := i.svc.DeleteEventSubscription(params) if err != nil { return err } return nil } func (i *RDSEventSubscription) String() string { return *i.id } func (i *RDSEventSubscription) Properties() types.Properties { properties := types.NewProperties() properties. Set("ID", i.id). Set("Enabled", i.enabled) for _, tag := range i.tags { properties.SetTag(tag.Key, tag.Value) } return properties } aws-nuke-2.16.0/resources/rds-instances.go000066400000000000000000000046651411137415400204640ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/rds" "github.com/rebuy-de/aws-nuke/pkg/config" "github.com/rebuy-de/aws-nuke/pkg/types" ) type RDSInstance struct { svc *rds.RDS instance *rds.DBInstance tags []*rds.Tag featureFlags config.FeatureFlags } func init() { register("RDSInstance", ListRDSInstances) } func ListRDSInstances(sess *session.Session) ([]Resource, error) { svc := rds.New(sess) params := &rds.DescribeDBInstancesInput{} resp, err := svc.DescribeDBInstances(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, instance := range resp.DBInstances { tags, err := svc.ListTagsForResource(&rds.ListTagsForResourceInput{ ResourceName: instance.DBInstanceArn, }) if err != nil { continue } resources = append(resources, &RDSInstance{ svc: svc, instance: instance, tags: tags.TagList, }) } return resources, nil } func (i *RDSInstance) FeatureFlags(ff config.FeatureFlags) { i.featureFlags = ff } func (i *RDSInstance) Remove() error { if aws.BoolValue(i.instance.DeletionProtection) && i.featureFlags.DisableDeletionProtection.RDSInstance { modifyParams := &rds.ModifyDBInstanceInput{ DBInstanceIdentifier: i.instance.DBInstanceIdentifier, DeletionProtection: aws.Bool(false), } _, err := i.svc.ModifyDBInstance(modifyParams) if err != nil { return err } } params := &rds.DeleteDBInstanceInput{ DBInstanceIdentifier: i.instance.DBInstanceIdentifier, SkipFinalSnapshot: aws.Bool(true), } _, err := i.svc.DeleteDBInstance(params) if err != nil { return err } return nil } func (i *RDSInstance) Properties() types.Properties { properties := types.NewProperties() properties.Set("Identifier", i.instance.DBInstanceIdentifier) properties.Set("DeletionProtection", i.instance.DeletionProtection) properties.Set("AvailabilityZone", i.instance.AvailabilityZone) properties.Set("InstanceClass", i.instance.DBInstanceClass) properties.Set("Engine", i.instance.Engine) properties.Set("EngineVersion", i.instance.EngineVersion) properties.Set("MultiAZ", i.instance.MultiAZ) properties.Set("PubliclyAccessible", i.instance.PubliclyAccessible) for _, tag := range i.tags { properties.SetTag(tag.Key, tag.Value) } return properties } func (i *RDSInstance) String() string { return aws.StringValue(i.instance.DBInstanceIdentifier) } aws-nuke-2.16.0/resources/rds-optiongroups.go000066400000000000000000000031561411137415400212370ustar00rootroot00000000000000package resources import ( "fmt" "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/rds" "github.com/rebuy-de/aws-nuke/pkg/types" ) type RDSOptionGroup struct { svc *rds.RDS name *string tags []*rds.Tag } func init() { register("RDSOptionGroup", ListRDSOptionGroups) } func ListRDSOptionGroups(sess *session.Session) ([]Resource, error) { svc := rds.New(sess) params := &rds.DescribeOptionGroupsInput{MaxRecords: aws.Int64(100)} resp, err := svc.DescribeOptionGroups(params) if err != nil { return nil, err } var resources []Resource for _, optionGroup := range resp.OptionGroupsList { tags, err := svc.ListTagsForResource(&rds.ListTagsForResourceInput{ ResourceName: optionGroup.OptionGroupArn, }) if err != nil { continue } resources = append(resources, &RDSOptionGroup{ svc: svc, name: optionGroup.OptionGroupName, tags: tags.TagList, }) } return resources, nil } func (i *RDSOptionGroup) Filter() error { if strings.HasPrefix(*i.name, "default:") { return fmt.Errorf("cannot delete default Option group") } return nil } func (i *RDSOptionGroup) Remove() error { params := &rds.DeleteOptionGroupInput{ OptionGroupName: i.name, } _, err := i.svc.DeleteOptionGroup(params) if err != nil { return err } return nil } func (i *RDSOptionGroup) String() string { return *i.name } func (i *RDSOptionGroup) Properties() types.Properties { properties := types.NewProperties() properties.Set("Name", i.name) for _, tag := range i.tags { properties.SetTag(tag.Key, tag.Value) } return properties } aws-nuke-2.16.0/resources/rds-proxies.go000066400000000000000000000024541411137415400201600ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/rds" "github.com/rebuy-de/aws-nuke/pkg/types" ) type RDSProxy struct { svc *rds.RDS id string tags []*rds.Tag } func init() { register("RDSProxy", ListRDSProxies) } func ListRDSProxies(sess *session.Session) ([]Resource, error) { svc := rds.New(sess) params := &rds.DescribeDBProxiesInput{} resp, err := svc.DescribeDBProxies(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, instance := range resp.DBProxies { tags, err := svc.ListTagsForResource(&rds.ListTagsForResourceInput{ ResourceName: instance.DBProxyArn, }) if err != nil { continue } resources = append(resources, &RDSProxy{ svc: svc, id: *instance.DBProxyName, tags: tags.TagList, }) } return resources, nil } func (i *RDSProxy) Remove() error { params := &rds.DeleteDBProxyInput{ DBProxyName: &i.id, } _, err := i.svc.DeleteDBProxy(params) if err != nil { return err } return nil } func (i *RDSProxy) String() string { return i.id } func (i *RDSProxy) Properties() types.Properties { properties := types.NewProperties() properties.Set("ProxyName", i.id) for _, tag := range i.tags { properties.SetTag(tag.Key, tag.Value) } return properties } aws-nuke-2.16.0/resources/rds-snapshots.go000066400000000000000000000040141411137415400205030ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/rds" "github.com/rebuy-de/aws-nuke/pkg/types" ) type RDSSnapshot struct { svc *rds.RDS snapshot *rds.DBSnapshot tags []*rds.Tag } func init() { register("RDSSnapshot", ListRDSSnapshots) } func ListRDSSnapshots(sess *session.Session) ([]Resource, error) { svc := rds.New(sess) params := &rds.DescribeDBSnapshotsInput{MaxRecords: aws.Int64(100)} resp, err := svc.DescribeDBSnapshots(params) if err != nil { return nil, err } var resources []Resource for _, snapshot := range resp.DBSnapshots { tags, err := svc.ListTagsForResource(&rds.ListTagsForResourceInput{ ResourceName: snapshot.DBSnapshotArn, }) if err != nil { return nil, err } resources = append(resources, &RDSSnapshot{ svc: svc, snapshot: snapshot, tags: tags.TagList, }) } return resources, nil } func (i *RDSSnapshot) Filter() error { if *i.snapshot.SnapshotType == "automated" { return fmt.Errorf("cannot delete automated snapshots") } return nil } func (i *RDSSnapshot) Remove() error { if i.snapshot.DBSnapshotIdentifier == nil { // Sanity check to make sure the delete request does not skip the // identifier. return nil } params := &rds.DeleteDBSnapshotInput{ DBSnapshotIdentifier: i.snapshot.DBSnapshotIdentifier, } _, err := i.svc.DeleteDBSnapshot(params) if err != nil { return err } return nil } func (i *RDSSnapshot) String() string { return *i.snapshot.DBSnapshotIdentifier } func (i *RDSSnapshot) Properties() types.Properties { properties := types.NewProperties() properties.Set("ARN", i.snapshot.DBSnapshotArn) properties.Set("Identifier", i.snapshot.DBSnapshotIdentifier) properties.Set("SnapshotType", i.snapshot.SnapshotType) properties.Set("Status", i.snapshot.Status) properties.Set("AvailabilityZone", i.snapshot.AvailabilityZone) for _, tag := range i.tags { properties.SetTag(tag.Key, tag.Value) } return properties } aws-nuke-2.16.0/resources/rds-subnets.go000066400000000000000000000031251411137415400201460ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/rds" "github.com/rebuy-de/aws-nuke/pkg/types" ) type RDSDBSubnetGroup struct { svc *rds.RDS name *string tags []*rds.Tag } func init() { register("RDSDBSubnetGroup", ListRDSSubnetGroups) } func ListRDSSubnetGroups(sess *session.Session) ([]Resource, error) { svc := rds.New(sess) params := &rds.DescribeDBSubnetGroupsInput{MaxRecords: aws.Int64(100)} resp, err := svc.DescribeDBSubnetGroups(params) if err != nil { return nil, err } var resources []Resource for _, subnetGroup := range resp.DBSubnetGroups { tags, err := svc.ListTagsForResource(&rds.ListTagsForResourceInput{ ResourceName: subnetGroup.DBSubnetGroupArn, }) if err != nil { continue } resources = append(resources, &RDSDBSubnetGroup{ svc: svc, name: subnetGroup.DBSubnetGroupName, tags: tags.TagList, }) } return resources, nil } func (i *RDSDBSubnetGroup) Remove() error { params := &rds.DeleteDBSubnetGroupInput{ DBSubnetGroupName: i.name, } _, err := i.svc.DeleteDBSubnetGroup(params) if err != nil { return err } return nil } func (i *RDSDBSubnetGroup) String() string { return *i.name } func (i *RDSDBSubnetGroup) Properties() types.Properties { properties := types.NewProperties() properties.Set("Name", i.name) for _, tag := range i.tags { properties.SetTag(tag.Key, tag.Value) } return properties } aws-nuke-2.16.0/resources/redshift-clusters.go000066400000000000000000000022551411137415400213520ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/redshift" ) type RedshiftCluster struct { svc *redshift.Redshift clusterIdentifier *string } func init() { register("RedshiftCluster", ListRedshiftClusters) } func ListRedshiftClusters(sess *session.Session) ([]Resource, error) { svc := redshift.New(sess) resources := []Resource{} params := &redshift.DescribeClustersInput{ MaxRecords: aws.Int64(100), } for { output, err := svc.DescribeClusters(params) if err != nil { return nil, err } for _, cluster := range output.Clusters { resources = append(resources, &RedshiftCluster{ svc: svc, clusterIdentifier: cluster.ClusterIdentifier, }) } if output.Marker == nil { break } params.Marker = output.Marker } return resources, nil } func (f *RedshiftCluster) Remove() error { _, err := f.svc.DeleteCluster(&redshift.DeleteClusterInput{ ClusterIdentifier: f.clusterIdentifier, SkipFinalClusterSnapshot: aws.Bool(true), }) return err } func (f *RedshiftCluster) String() string { return *f.clusterIdentifier } aws-nuke-2.16.0/resources/redshift-parametergroups.go000066400000000000000000000025451411137415400227300ustar00rootroot00000000000000package resources import ( "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/redshift" ) type RedshiftParameterGroup struct { svc *redshift.Redshift parameterGroupName *string } func init() { register("RedshiftParameterGroup", ListRedshiftParameterGroup) } func ListRedshiftParameterGroup(sess *session.Session) ([]Resource, error) { svc := redshift.New(sess) resources := []Resource{} params := &redshift.DescribeClusterParameterGroupsInput{ MaxRecords: aws.Int64(100), } for { output, err := svc.DescribeClusterParameterGroups(params) if err != nil { return nil, err } for _, parameterGroup := range output.ParameterGroups { if !strings.Contains(*parameterGroup.ParameterGroupName, "default.redshift") { resources = append(resources, &RedshiftParameterGroup{ svc: svc, parameterGroupName: parameterGroup.ParameterGroupName, }) } } if output.Marker == nil { break } params.Marker = output.Marker } return resources, nil } func (f *RedshiftParameterGroup) Remove() error { _, err := f.svc.DeleteClusterParameterGroup(&redshift.DeleteClusterParameterGroupInput{ ParameterGroupName: f.parameterGroupName, }) return err } func (f *RedshiftParameterGroup) String() string { return *f.parameterGroupName } aws-nuke-2.16.0/resources/redshift-snapshots.go000066400000000000000000000022541411137415400215270ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/redshift" ) type RedshiftSnapshot struct { svc *redshift.Redshift snapshotIdentifier *string } func init() { register("RedshiftSnapshot", ListRedshiftSnapshots) } func ListRedshiftSnapshots(sess *session.Session) ([]Resource, error) { svc := redshift.New(sess) resources := []Resource{} params := &redshift.DescribeClusterSnapshotsInput{ MaxRecords: aws.Int64(100), } for { output, err := svc.DescribeClusterSnapshots(params) if err != nil { return nil, err } for _, snapshot := range output.Snapshots { resources = append(resources, &RedshiftSnapshot{ svc: svc, snapshotIdentifier: snapshot.SnapshotIdentifier, }) } if output.Marker == nil { break } params.Marker = output.Marker } return resources, nil } func (f *RedshiftSnapshot) Remove() error { _, err := f.svc.DeleteClusterSnapshot(&redshift.DeleteClusterSnapshotInput{ SnapshotIdentifier: f.snapshotIdentifier, }) return err } func (f *RedshiftSnapshot) String() string { return *f.snapshotIdentifier } aws-nuke-2.16.0/resources/redshift-subnetgroups.go000066400000000000000000000023521411137415400222440ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/redshift" ) type RedshiftSubnetGroup struct { svc *redshift.Redshift clusterSubnetGroupName *string } func init() { register("RedshiftSubnetGroup", ListRedshiftSubnetGroups) } func ListRedshiftSubnetGroups(sess *session.Session) ([]Resource, error) { svc := redshift.New(sess) resources := []Resource{} params := &redshift.DescribeClusterSubnetGroupsInput{ MaxRecords: aws.Int64(100), } for { output, err := svc.DescribeClusterSubnetGroups(params) if err != nil { return nil, err } for _, subnetGroup := range output.ClusterSubnetGroups { resources = append(resources, &RedshiftSubnetGroup{ svc: svc, clusterSubnetGroupName: subnetGroup.ClusterSubnetGroupName, }) } if output.Marker == nil { break } params.Marker = output.Marker } return resources, nil } func (f *RedshiftSubnetGroup) Remove() error { _, err := f.svc.DeleteClusterSubnetGroup(&redshift.DeleteClusterSubnetGroupInput{ ClusterSubnetGroupName: f.clusterSubnetGroupName, }) return err } func (f *RedshiftSubnetGroup) String() string { return *f.clusterSubnetGroupName } aws-nuke-2.16.0/resources/rekognition-collection.go000066400000000000000000000021411411137415400223530ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/rekognition" ) type RekognitionCollection struct { svc *rekognition.Rekognition id *string } func init() { register("RekognitionCollection", ListRekognitionCollections) } func ListRekognitionCollections(sess *session.Session) ([]Resource, error) { svc := rekognition.New(sess) resources := []Resource{} params := &rekognition.ListCollectionsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListCollections(params) if err != nil { return nil, err } for _, collection := range output.CollectionIds { resources = append(resources, &RekognitionCollection{ svc: svc, id: collection, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *RekognitionCollection) Remove() error { _, err := f.svc.DeleteCollection(&rekognition.DeleteCollectionInput{ CollectionId: f.id, }) return err } func (f *RekognitionCollection) String() string { return *f.id } aws-nuke-2.16.0/resources/resourcegroups-groups.go000066400000000000000000000021401411137415400222750ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/resourcegroups" ) type ResourceGroupGroup struct { svc *resourcegroups.ResourceGroups groupName *string } func init() { register("ResourceGroupGroup", ListResourceGroupGroups) } func ListResourceGroupGroups(sess *session.Session) ([]Resource, error) { svc := resourcegroups.New(sess) resources := []Resource{} params := &resourcegroups.ListGroupsInput{ MaxResults: aws.Int64(50), } for { output, err := svc.ListGroups(params) if err != nil { return nil, err } for _, group := range output.Groups { resources = append(resources, &ResourceGroupGroup{ svc: svc, groupName: group.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *ResourceGroupGroup) Remove() error { _, err := f.svc.DeleteGroup(&resourcegroups.DeleteGroupInput{ GroupName: f.groupName, }) return err } func (f *ResourceGroupGroup) String() string { return *f.groupName } aws-nuke-2.16.0/resources/robomaker-deployment-jobs.go000066400000000000000000000026761411137415400230010ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/robomaker" ) type RoboMakerDeploymentJob struct { svc *robomaker.RoboMaker name *string arn *string } func init() { register("RoboMakerDeploymentJob", ListRoboMakerDeploymentJobs) } func deploymentJobNeedsToBeCanceled(job *robomaker.DeploymentJob) bool { for _, n := range []string{"Completed", "Failed", "RunningFailed", "Terminating", "Terminated", "Canceled"} { if job.Status != nil && *job.Status == n { return false } } return true } func ListRoboMakerDeploymentJobs(sess *session.Session) ([]Resource, error) { svc := robomaker.New(sess) resources := []Resource{} params := &robomaker.ListDeploymentJobsInput{ MaxResults: aws.Int64(30), } for { resp, err := svc.ListDeploymentJobs(params) if err != nil { return nil, err } for _, deploymentJob := range resp.DeploymentJobs { if deploymentJobNeedsToBeCanceled(deploymentJob) { resources = append(resources, &RoboMakerDeploymentJob{ svc: svc, arn: deploymentJob.Arn, }) } } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *RoboMakerDeploymentJob) Remove() error { _, err := f.svc.CancelDeploymentJob(&robomaker.CancelDeploymentJobInput{ Job: f.arn, }) return err } func (f *RoboMakerDeploymentJob) String() string { return *f.arn } aws-nuke-2.16.0/resources/robomaker-fleets.go000066400000000000000000000020441411137415400211350ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/robomaker" ) type RoboMakerFleet struct { svc *robomaker.RoboMaker name *string arn *string } func init() { register("RoboMakerFleet", ListRoboMakerFleets) } func ListRoboMakerFleets(sess *session.Session) ([]Resource, error) { svc := robomaker.New(sess) resources := []Resource{} params := &robomaker.ListFleetsInput{ MaxResults: aws.Int64(30), } for { resp, err := svc.ListFleets(params) if err != nil { return nil, err } for _, fleet := range resp.FleetDetails { resources = append(resources, &RoboMakerFleet{ svc: svc, name: fleet.Name, arn: fleet.Arn, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *RoboMakerFleet) Remove() error { _, err := f.svc.DeleteFleet(&robomaker.DeleteFleetInput{ Fleet: f.arn, }) return err } func (f *RoboMakerFleet) String() string { return *f.name } aws-nuke-2.16.0/resources/robomaker-robot-applications.go000066400000000000000000000026161411137415400234710ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/robomaker" ) type RoboMakerRobotApplication struct { svc *robomaker.RoboMaker name *string arn *string version *string } func init() { register("RoboMakerRobotApplication", ListRoboMakerRobotApplications) } func ListRoboMakerRobotApplications(sess *session.Session) ([]Resource, error) { svc := robomaker.New(sess) resources := []Resource{} params := &robomaker.ListRobotApplicationsInput{ MaxResults: aws.Int64(30), } for { resp, err := svc.ListRobotApplications(params) if err != nil { return nil, err } for _, robotApplication := range resp.RobotApplicationSummaries { resources = append(resources, &RoboMakerRobotApplication{ svc: svc, name: robotApplication.Name, arn: robotApplication.Arn, version: robotApplication.Version, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *RoboMakerRobotApplication) Remove() error { request := robomaker.DeleteRobotApplicationInput{ Application: f.arn, } if f.version != nil && *f.version != "$LATEST" { request.ApplicationVersion = f.version } _, err := f.svc.DeleteRobotApplication(&request) return err } func (f *RoboMakerRobotApplication) String() string { return *f.name } aws-nuke-2.16.0/resources/robomaker-robots.go000066400000000000000000000020361411137415400211640ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/robomaker" ) type RoboMakerRobot struct { svc *robomaker.RoboMaker name *string arn *string } func init() { register("RoboMakerRobot", ListRoboMakerRobots) } func ListRoboMakerRobots(sess *session.Session) ([]Resource, error) { svc := robomaker.New(sess) resources := []Resource{} params := &robomaker.ListRobotsInput{ MaxResults: aws.Int64(30), } for { resp, err := svc.ListRobots(params) if err != nil { return nil, err } for _, robot := range resp.Robots { resources = append(resources, &RoboMakerRobot{ svc: svc, name: robot.Name, arn: robot.Arn, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *RoboMakerRobot) Remove() error { _, err := f.svc.DeleteRobot(&robomaker.DeleteRobotInput{ Robot: f.arn, }) return err } func (f *RoboMakerRobot) String() string { return *f.name } aws-nuke-2.16.0/resources/robomaker-simulation-applications.go000066400000000000000000000027611411137415400245310ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/robomaker" ) type RoboMakerSimulationApplication struct { svc *robomaker.RoboMaker name *string arn *string version *string } func init() { register("RoboMakerSimulationApplication", ListRoboMakerSimulationApplications) } func ListRoboMakerSimulationApplications(sess *session.Session) ([]Resource, error) { svc := robomaker.New(sess) resources := []Resource{} params := &robomaker.ListSimulationApplicationsInput{ MaxResults: aws.Int64(30), } for { resp, err := svc.ListSimulationApplications(params) if err != nil { return nil, err } for _, robotSimulationApplication := range resp.SimulationApplicationSummaries { resources = append(resources, &RoboMakerSimulationApplication{ svc: svc, name: robotSimulationApplication.Name, arn: robotSimulationApplication.Arn, version: robotSimulationApplication.Version, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *RoboMakerSimulationApplication) Remove() error { request := robomaker.DeleteSimulationApplicationInput{ Application: f.arn, } if f.version != nil && *f.version != "$LATEST" { request.ApplicationVersion = f.version } _, err := f.svc.DeleteSimulationApplication(&request) return err } func (f *RoboMakerSimulationApplication) String() string { return *f.name } aws-nuke-2.16.0/resources/robomaker-simulation-jobs.go000066400000000000000000000027141411137415400227760ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/robomaker" ) type RoboMakerSimulationJob struct { svc *robomaker.RoboMaker name *string arn *string } func init() { register("RoboMakerSimulationJob", ListRoboMakerSimulationJobs) } func simulationJobNeedsToBeCanceled(job *robomaker.SimulationJobSummary) bool { for _, n := range []string{"Completed", "Failed", "RunningFailed", "Terminating", "Terminated", "Canceled"} { if job.Status != nil && *job.Status == n { return false } } return true } func ListRoboMakerSimulationJobs(sess *session.Session) ([]Resource, error) { svc := robomaker.New(sess) resources := []Resource{} params := &robomaker.ListSimulationJobsInput{ MaxResults: aws.Int64(30), } for { resp, err := svc.ListSimulationJobs(params) if err != nil { return nil, err } for _, simulationJob := range resp.SimulationJobSummaries { if simulationJobNeedsToBeCanceled(simulationJob) { resources = append(resources, &RoboMakerSimulationJob{ svc: svc, arn: simulationJob.Arn, }) } } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *RoboMakerSimulationJob) Remove() error { _, err := f.svc.CancelSimulationJob(&robomaker.CancelSimulationJobInput{ Job: f.arn, }) return err } func (f *RoboMakerSimulationJob) String() string { return *f.arn } aws-nuke-2.16.0/resources/route53-health-checks.go000066400000000000000000000024161411137415400217060ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/route53" "github.com/rebuy-de/aws-nuke/pkg/types" ) func init() { register("Route53HealthCheck", ListRoute53HealthChecks) } func ListRoute53HealthChecks(sess *session.Session) ([]Resource, error) { svc := route53.New(sess) params := &route53.ListHealthChecksInput{} resources := make([]Resource, 0) for { resp, err := svc.ListHealthChecks(params) if err != nil { return nil, err } for _, check := range resp.HealthChecks { resources = append(resources, &Route53HealthCheck{ svc: svc, id: check.Id, }) } if aws.BoolValue(resp.IsTruncated) == false { break } params.Marker = resp.NextMarker } return resources, nil } type Route53HealthCheck struct { svc *route53.Route53 id *string } func (hz *Route53HealthCheck) Remove() error { params := &route53.DeleteHealthCheckInput{ HealthCheckId: hz.id, } _, err := hz.svc.DeleteHealthCheck(params) if err != nil { return err } return nil } func (hz *Route53HealthCheck) Properties() types.Properties { return types.NewProperties(). Set("ID", hz.id) } func (hz *Route53HealthCheck) String() string { return fmt.Sprintf("%s", *hz.id) } aws-nuke-2.16.0/resources/route53-hosted-zones.go000066400000000000000000000030251411137415400216220ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/route53" "github.com/rebuy-de/aws-nuke/pkg/types" ) func init() { register("Route53HostedZone", ListRoute53HostedZones) } func ListRoute53HostedZones(sess *session.Session) ([]Resource, error) { svc := route53.New(sess) params := &route53.ListHostedZonesInput{} resp, err := svc.ListHostedZones(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, hz := range resp.HostedZones { tags, err := svc.ListTagsForResource(&route53.ListTagsForResourceInput{ ResourceId: hz.Id, ResourceType: aws.String("hostedzone"), }) if err != nil { return nil, err } resources = append(resources, &Route53HostedZone{ svc: svc, id: hz.Id, name: hz.Name, tags: tags.ResourceTagSet.Tags, }) } return resources, nil } type Route53HostedZone struct { svc *route53.Route53 id *string name *string tags []*route53.Tag } func (hz *Route53HostedZone) Remove() error { params := &route53.DeleteHostedZoneInput{ Id: hz.id, } _, err := hz.svc.DeleteHostedZone(params) if err != nil { return err } return nil } func (hz *Route53HostedZone) Properties() types.Properties { properties := types.NewProperties() for _, tag := range hz.tags { properties.SetTag(tag.Key, tag.Value) } properties.Set("Name", hz.name) return properties } func (hz *Route53HostedZone) String() string { return fmt.Sprintf("%s (%s)", *hz.id, *hz.name) } aws-nuke-2.16.0/resources/route53-resolver-endpoints.go000066400000000000000000000032441411137415400230450ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/route53resolver" "github.com/rebuy-de/aws-nuke/pkg/types" ) // Route53ResolverEndpoint is the resource type for nuking type Route53ResolverEndpoint struct { svc *route53resolver.Route53Resolver id *string name *string } func init() { register("Route53ResolverEndpoint", ListRoute53ResolverEndpoints) } // ListRoute53ResolverEndpoints produces the resources to be nuked func ListRoute53ResolverEndpoints(sess *session.Session) ([]Resource, error) { svc := route53resolver.New(sess) params := &route53resolver.ListResolverEndpointsInput{} var resources []Resource for { resp, err := svc.ListResolverEndpoints(params) if err != nil { return nil, err } for _, endpoint := range resp.ResolverEndpoints { resolverEndpoint := &Route53ResolverEndpoint{ svc: svc, id: endpoint.Id, name: endpoint.Name, } resources = append(resources, resolverEndpoint) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } // Remove implements Resource func (r *Route53ResolverEndpoint) Remove() error { _, err := r.svc.DeleteResolverEndpoint( &route53resolver.DeleteResolverEndpointInput{ ResolverEndpointId: r.id, }) if err != nil { return err } return nil } // Properties provides debugging output func (r *Route53ResolverEndpoint) Properties() types.Properties { return types.NewProperties(). Set("EndpointID", r.id). Set("Name", r.name) } // String implements Stringer func (r *Route53ResolverEndpoint) String() string { return fmt.Sprintf("%s (%s)", *r.id, *r.name) } aws-nuke-2.16.0/resources/route53-resolver-rules.go000066400000000000000000000060751411137415400222010ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/route53resolver" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ( // Route53ResolverRule is the resource type Route53ResolverRule struct { svc *route53resolver.Route53Resolver id *string name *string domainName *string vpcIds []*string } ) func init() { register("Route53ResolverRule", ListRoute53ResolverRules) } // ListRoute53ResolverRules produces the resources to be nuked. func ListRoute53ResolverRules(sess *session.Session) ([]Resource, error) { svc := route53resolver.New(sess) vpcAssociations, err := resolverRulesToVpcIDs(svc) if err != nil { return nil, err } var resources []Resource params := &route53resolver.ListResolverRulesInput{} for { resp, err := svc.ListResolverRules(params) if err != nil { return nil, err } for _, rule := range resp.ResolverRules { resources = append(resources, &Route53ResolverRule{ svc: svc, id: rule.Id, name: rule.Name, domainName: rule.DomainName, vpcIds: vpcAssociations[*rule.Id], }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } // Associate all the vpcIDs to their resolver rule ID to be disassociated before deleting the rule. func resolverRulesToVpcIDs(svc *route53resolver.Route53Resolver) (map[string][]*string, error) { vpcAssociations := map[string][]*string{} params := &route53resolver.ListResolverRuleAssociationsInput{} for { resp, err := svc.ListResolverRuleAssociations(params) if err != nil { return nil, err } for _, ruleAssociation := range resp.ResolverRuleAssociations { vpcID := ruleAssociation.VPCId if vpcID != nil { resolverRuleID := *ruleAssociation.ResolverRuleId if _, ok := vpcAssociations[resolverRuleID]; !ok { vpcAssociations[resolverRuleID] = []*string{vpcID} } else { vpcAssociations[resolverRuleID] = append(vpcAssociations[resolverRuleID], vpcID) } } } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return vpcAssociations, nil } // Filter removes resources automatically from being nuked func (r *Route53ResolverRule) Filter() error { if *r.domainName == "." { return fmt.Errorf(`Filtering DomainName "."`) } return nil } // Remove implements Resource func (r *Route53ResolverRule) Remove() error { for _, vpcID := range r.vpcIds { _, err := r.svc.DisassociateResolverRule(&route53resolver.DisassociateResolverRuleInput{ ResolverRuleId: r.id, VPCId: vpcID, }) if err != nil { return err } } _, err := r.svc.DeleteResolverRule(&route53resolver.DeleteResolverRuleInput{ ResolverRuleId: r.id, }) return err } // Properties provides debugging output func (r *Route53ResolverRule) Properties() types.Properties { return types.NewProperties(). Set("ID", r.id). Set("Name", r.name) } // String implements Stringer func (r *Route53ResolverRule) String() string { return fmt.Sprintf("%s (%s)", *r.id, *r.name) } aws-nuke-2.16.0/resources/route53-resource-records.go000066400000000000000000000051111411137415400224640ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/route53" "github.com/rebuy-de/aws-nuke/pkg/types" ) type Route53ResourceRecordSet struct { svc *route53.Route53 hostedZoneId *string hostedZoneName *string data *route53.ResourceRecordSet changeId *string } func init() { register("Route53ResourceRecordSet", ListRoute53ResourceRecordSets) } func ListRoute53ResourceRecordSets(sess *session.Session) ([]Resource, error) { svc := route53.New(sess) resources := make([]Resource, 0) sub, err := ListRoute53HostedZones(sess) if err != nil { return nil, err } for _, resource := range sub { zone := resource.(*Route53HostedZone) rrs, err := ListResourceRecordsForZone(svc, zone.id, zone.name) if err != nil { return nil, err } resources = append(resources, rrs...) } return resources, nil } func ListResourceRecordsForZone(svc *route53.Route53, zoneId *string, zoneName *string) ([]Resource, error) { params := &route53.ListResourceRecordSetsInput{ HostedZoneId: zoneId, } resources := make([]Resource, 0) for { resp, err := svc.ListResourceRecordSets(params) if err != nil { return nil, err } for _, rrs := range resp.ResourceRecordSets { resources = append(resources, &Route53ResourceRecordSet{ svc: svc, hostedZoneId: zoneId, hostedZoneName: zoneName, data: rrs, }) } // make sure to list all with more than 100 records if *resp.IsTruncated { params.StartRecordName = resp.NextRecordName continue } break } return resources, nil } func (r *Route53ResourceRecordSet) Filter() error { if *r.data.Type == "NS" && *r.hostedZoneName == *r.data.Name { return fmt.Errorf("cannot delete NS record") } if *r.data.Type == "SOA" { return fmt.Errorf("cannot delete SOA record") } return nil } func (r *Route53ResourceRecordSet) Remove() error { params := &route53.ChangeResourceRecordSetsInput{ HostedZoneId: r.hostedZoneId, ChangeBatch: &route53.ChangeBatch{ Changes: []*route53.Change{ &route53.Change{ Action: aws.String("DELETE"), ResourceRecordSet: r.data, }, }, }, } resp, err := r.svc.ChangeResourceRecordSets(params) if err != nil { return err } r.changeId = resp.ChangeInfo.Id return nil } func (r *Route53ResourceRecordSet) Properties() types.Properties { return types.NewProperties(). Set("Name", r.data.Name). Set("Type", r.data.Type) } func (r *Route53ResourceRecordSet) String() string { return *r.data.Name } aws-nuke-2.16.0/resources/route53-traffic-policies.go000066400000000000000000000052761411137415400224350ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/route53" "github.com/rebuy-de/aws-nuke/pkg/types" ) type Route53TrafficPolicy struct { svc *route53.Route53 id *string name *string version *int64 instances []*route53.TrafficPolicyInstance } func init() { register("Route53TrafficPolicy", ListRoute53TrafficPolicies) } func ListRoute53TrafficPolicies(sess *session.Session) ([]Resource, error) { svc := route53.New(sess) params := &route53.ListTrafficPoliciesInput{} resources := make([]Resource, 0) for { resp, err := svc.ListTrafficPolicies(params) if err != nil { return nil, err } for _, trafficPolicy := range resp.TrafficPolicySummaries { instances, err := instancesForPolicy(svc, trafficPolicy.Id, trafficPolicy.LatestVersion) if err != nil { return nil, fmt.Errorf("failed to get instance for policy %s %w", *trafficPolicy.Id, err) } resources = append(resources, &Route53TrafficPolicy{ svc: svc, id: trafficPolicy.Id, name: trafficPolicy.Name, version: trafficPolicy.LatestVersion, instances: instances, }) } if aws.BoolValue(resp.IsTruncated) == false { break } params.TrafficPolicyIdMarker = resp.TrafficPolicyIdMarker } return resources, nil } func instancesForPolicy(svc *route53.Route53, policyID *string, version *int64) ([]*route53.TrafficPolicyInstance, error) { var instances []*route53.TrafficPolicyInstance params := &route53.ListTrafficPolicyInstancesByPolicyInput{ TrafficPolicyId: policyID, TrafficPolicyVersion: version, } for { resp, err := svc.ListTrafficPolicyInstancesByPolicy(params) if err != nil { return nil, err } for _, instance := range resp.TrafficPolicyInstances { instances = append(instances, instance) } if aws.BoolValue(resp.IsTruncated) == false { break } params.TrafficPolicyInstanceTypeMarker = resp.TrafficPolicyInstanceTypeMarker params.TrafficPolicyInstanceNameMarker = resp.TrafficPolicyInstanceNameMarker } return instances, nil } func (tp *Route53TrafficPolicy) Remove() error { for _, instance := range tp.instances { _, err := tp.svc.DeleteTrafficPolicyInstance(&route53.DeleteTrafficPolicyInstanceInput{ Id: instance.Id, }) if err != nil { return fmt.Errorf("failed to delete instance %s %w", *instance.Id, err) } } params := &route53.DeleteTrafficPolicyInput{ Id: tp.id, Version: tp.version, } _, err := tp.svc.DeleteTrafficPolicy(params) return err } func (tp *Route53TrafficPolicy) Properties() types.Properties { return types.NewProperties(). Set("ID", *tp.id). Set("Name", *tp.name) } aws-nuke-2.16.0/resources/s3-buckets.go000066400000000000000000000114711411137415400176630ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" "github.com/aws/aws-sdk-go/service/s3/s3iface" "github.com/aws/aws-sdk-go/service/s3/s3manager" "github.com/rebuy-de/aws-nuke/pkg/types" ) func init() { register("S3Bucket", ListS3Buckets) } type S3Bucket struct { svc *s3.S3 name string tags []*s3.Tag } func ListS3Buckets(s *session.Session) ([]Resource, error) { svc := s3.New(s) buckets, err := DescribeS3Buckets(svc) if err != nil { return nil, err } resources := make([]Resource, 0) for _, name := range buckets { tags, err := svc.GetBucketTagging(&s3.GetBucketTaggingInput{ Bucket: aws.String(name), }) if err != nil { if aerr, ok := err.(awserr.Error); ok { if aerr.Code() == "NoSuchTagSet" { resources = append(resources, &S3Bucket{ svc: svc, name: name, tags: make([]*s3.Tag, 0), }) } } continue } resources = append(resources, &S3Bucket{ svc: svc, name: name, tags: tags.TagSet, }) } return resources, nil } func DescribeS3Buckets(svc *s3.S3) ([]string, error) { resp, err := svc.ListBuckets(nil) if err != nil { return nil, err } buckets := make([]string, 0) for _, out := range resp.Buckets { bucketLocationResponse, err := svc.GetBucketLocation(&s3.GetBucketLocationInput{Bucket: out.Name}) if err != nil { continue } location := UnPtrString(bucketLocationResponse.LocationConstraint, endpoints.UsEast1RegionID) region := UnPtrString(svc.Config.Region, endpoints.UsEast1RegionID) if location == region { buckets = append(buckets, *out.Name) } } return buckets, nil } func (e *S3Bucket) Remove() error { _, err := e.svc.DeleteBucketPolicy(&s3.DeleteBucketPolicyInput{ Bucket: &e.name, }) if err != nil { return err } _, err = e.svc.PutBucketLogging(&s3.PutBucketLoggingInput{ Bucket: &e.name, BucketLoggingStatus: &s3.BucketLoggingStatus{}, }) if err != nil { return err } err = e.RemoveAllVersions() if err != nil { return err } err = e.RemoveAllObjects() if err != nil { return err } _, err = e.svc.DeleteBucket(&s3.DeleteBucketInput{ Bucket: &e.name, }) return err } func (e *S3Bucket) RemoveAllVersions() error { params := &s3.ListObjectVersionsInput{ Bucket: &e.name, } iterator := newS3DeleteVersionListIterator(e.svc, params) return s3manager.NewBatchDeleteWithClient(e.svc).Delete(aws.BackgroundContext(), iterator) } func (e *S3Bucket) RemoveAllObjects() error { params := &s3.ListObjectsInput{ Bucket: &e.name, } iterator := s3manager.NewDeleteListIterator(e.svc, params) return s3manager.NewBatchDeleteWithClient(e.svc).Delete(aws.BackgroundContext(), iterator) } func (e *S3Bucket) Properties() types.Properties { properties := types.NewProperties() properties.Set("Name", e.name) for _, tag := range e.tags { properties.SetTag(tag.Key, tag.Value) } return properties } func (e *S3Bucket) String() string { return fmt.Sprintf("s3://%s", e.name) } type s3DeleteVersionListIterator struct { Bucket *string Paginator request.Pagination objects []*s3.ObjectVersion } func newS3DeleteVersionListIterator(svc s3iface.S3API, input *s3.ListObjectVersionsInput, opts ...func(*s3DeleteVersionListIterator)) s3manager.BatchDeleteIterator { iter := &s3DeleteVersionListIterator{ Bucket: input.Bucket, Paginator: request.Pagination{ NewRequest: func() (*request.Request, error) { var inCpy *s3.ListObjectVersionsInput if input != nil { tmp := *input inCpy = &tmp } req, _ := svc.ListObjectVersionsRequest(inCpy) return req, nil }, }, } for _, opt := range opts { opt(iter) } return iter } // Next will use the S3API client to iterate through a list of objects. func (iter *s3DeleteVersionListIterator) Next() bool { if len(iter.objects) > 0 { iter.objects = iter.objects[1:] } if len(iter.objects) == 0 && iter.Paginator.Next() { output := iter.Paginator.Page().(*s3.ListObjectVersionsOutput) iter.objects = output.Versions for _, entry := range output.DeleteMarkers { iter.objects = append(iter.objects, &s3.ObjectVersion{ Key: entry.Key, VersionId: entry.VersionId, }) } } return len(iter.objects) > 0 } // Err will return the last known error from Next. func (iter *s3DeleteVersionListIterator) Err() error { return iter.Paginator.Err() } // DeleteObject will return the current object to be deleted. func (iter *s3DeleteVersionListIterator) DeleteObject() s3manager.BatchDeleteObject { return s3manager.BatchDeleteObject{ Object: &s3.DeleteObjectInput{ Bucket: iter.Bucket, Key: iter.objects[0].Key, VersionId: iter.objects[0].VersionId, }, } } aws-nuke-2.16.0/resources/s3-multipart-uploads.go000066400000000000000000000032421411137415400217060ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" "github.com/rebuy-de/aws-nuke/pkg/types" ) type S3MultipartUpload struct { svc *s3.S3 bucket string key string uploadID string } func init() { register("S3MultipartUpload", ListS3MultipartUpload) } func ListS3MultipartUpload(sess *session.Session) ([]Resource, error) { svc := s3.New(sess) resources := make([]Resource, 0) buckets, err := DescribeS3Buckets(svc) if err != nil { return nil, err } for _, name := range buckets { params := &s3.ListMultipartUploadsInput{ Bucket: &name, } for { resp, err := svc.ListMultipartUploads(params) if err != nil { return nil, err } for _, upload := range resp.Uploads { if upload.Key == nil || upload.UploadId == nil { continue } resources = append(resources, &S3MultipartUpload{ svc: svc, bucket: name, key: *upload.Key, uploadID: *upload.UploadId, }) } if *resp.IsTruncated { params.KeyMarker = resp.NextKeyMarker continue } break } } return resources, nil } func (e *S3MultipartUpload) Remove() error { params := &s3.AbortMultipartUploadInput{ Bucket: &e.bucket, Key: &e.key, UploadId: &e.uploadID, } _, err := e.svc.AbortMultipartUpload(params) if err != nil { return err } return nil } func (e *S3MultipartUpload) Properties() types.Properties { return types.NewProperties(). Set("Bucket", e.bucket). Set("Key", e.key). Set("UploadID", e.uploadID) } func (e *S3MultipartUpload) String() string { return fmt.Sprintf("s3://%s/%s#%s", e.bucket, e.key, e.uploadID) } aws-nuke-2.16.0/resources/s3-objects.go000066400000000000000000000041461411137415400176550ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" "github.com/rebuy-de/aws-nuke/pkg/types" ) type S3Object struct { svc *s3.S3 bucket string key string versionID *string latest bool } func init() { register("S3Object", ListS3Objects) } func ListS3Objects(sess *session.Session) ([]Resource, error) { svc := s3.New(sess) resources := make([]Resource, 0) buckets, err := DescribeS3Buckets(svc) if err != nil { return nil, err } for _, name := range buckets { params := &s3.ListObjectVersionsInput{ Bucket: &name, } for { resp, err := svc.ListObjectVersions(params) if err != nil { return nil, err } for _, out := range resp.Versions { if out.Key == nil { continue } resources = append(resources, &S3Object{ svc: svc, bucket: name, key: *out.Key, versionID: out.VersionId, latest: UnPtrBool(out.IsLatest, false), }) } for _, out := range resp.DeleteMarkers { if out.Key == nil { continue } resources = append(resources, &S3Object{ svc: svc, bucket: name, key: *out.Key, versionID: out.VersionId, latest: UnPtrBool(out.IsLatest, false), }) } // make sure to list all with more than 1000 objects if *resp.IsTruncated { params.KeyMarker = resp.NextKeyMarker continue } break } } return resources, nil } func (e *S3Object) Remove() error { params := &s3.DeleteObjectInput{ Bucket: &e.bucket, Key: &e.key, VersionId: e.versionID, } _, err := e.svc.DeleteObject(params) if err != nil { return err } return nil } func (e *S3Object) Properties() types.Properties { return types.NewProperties(). Set("Bucket", e.bucket). Set("Key", e.key). Set("VersionID", e.versionID). Set("IsLatest", e.latest) } func (e *S3Object) String() string { if e.versionID != nil && *e.versionID != "null" && !e.latest { return fmt.Sprintf("s3://%s/%s#%s", e.bucket, e.key, *e.versionID) } return fmt.Sprintf("s3://%s/%s", e.bucket, e.key) } aws-nuke-2.16.0/resources/sagemaker-apps.go000066400000000000000000000034721411137415400206020ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sagemaker" "github.com/rebuy-de/aws-nuke/pkg/types" ) type SageMakerApp struct { svc *sagemaker.SageMaker domainID *string appName *string appType *string userProfileName *string status *string } func init() { register("SageMakerApp", ListSageMakerApps) } func ListSageMakerApps(sess *session.Session) ([]Resource, error) { svc := sagemaker.New(sess) resources := []Resource{} params := &sagemaker.ListAppsInput{ MaxResults: aws.Int64(30), } for { resp, err := svc.ListApps(params) if err != nil { return nil, err } for _, app := range resp.Apps { resources = append(resources, &SageMakerApp{ svc: svc, domainID: app.DomainId, appName: app.AppName, appType: app.AppType, userProfileName: app.UserProfileName, status: app.Status, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *SageMakerApp) Remove() error { _, err := f.svc.DeleteApp(&sagemaker.DeleteAppInput{ DomainId: f.domainID, AppName: f.appName, AppType: f.appType, UserProfileName: f.userProfileName, }) return err } func (f *SageMakerApp) String() string { return *f.appName } func (i *SageMakerApp) Properties() types.Properties { properties := types.NewProperties() properties. Set("DomainID", i.domainID). Set("AppName", i.appName). Set("AppType", i.appType). Set("UserProfileName", i.userProfileName) return properties } func (f *SageMakerApp) Filter() error { if *f.status == sagemaker.AppStatusDeleted { return fmt.Errorf("already deleted") } return nil } aws-nuke-2.16.0/resources/sagemaker-domain.go000066400000000000000000000025461411137415400211070ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sagemaker" "github.com/rebuy-de/aws-nuke/pkg/types" ) type SageMakerDomain struct { svc *sagemaker.SageMaker domainID *string } func init() { register("SageMakerDomain", ListSageMakerDomains) } func ListSageMakerDomains(sess *session.Session) ([]Resource, error) { svc := sagemaker.New(sess) resources := []Resource{} params := &sagemaker.ListDomainsInput{ MaxResults: aws.Int64(30), } for { resp, err := svc.ListDomains(params) if err != nil { return nil, err } for _, domain := range resp.Domains { resources = append(resources, &SageMakerDomain{ svc: svc, domainID: domain.DomainId, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *SageMakerDomain) Remove() error { _, err := f.svc.DeleteDomain(&sagemaker.DeleteDomainInput{ DomainId: f.domainID, RetentionPolicy: &sagemaker.RetentionPolicy{HomeEfsFileSystem: aws.String(sagemaker.RetentionTypeDelete)}, }) return err } func (f *SageMakerDomain) String() string { return *f.domainID } func (i *SageMakerDomain) Properties() types.Properties { properties := types.NewProperties() properties. Set("DomainID", i.domainID) return properties } aws-nuke-2.16.0/resources/sagemaker-endpointconfigs.go000066400000000000000000000023511411137415400230230ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sagemaker" ) type SageMakerEndpointConfig struct { svc *sagemaker.SageMaker endpointConfigName *string } func init() { register("SageMakerEndpointConfig", ListSageMakerEndpointConfigs) } func ListSageMakerEndpointConfigs(sess *session.Session) ([]Resource, error) { svc := sagemaker.New(sess) resources := []Resource{} params := &sagemaker.ListEndpointConfigsInput{ MaxResults: aws.Int64(30), } for { resp, err := svc.ListEndpointConfigs(params) if err != nil { return nil, err } for _, endpointConfig := range resp.EndpointConfigs { resources = append(resources, &SageMakerEndpointConfig{ svc: svc, endpointConfigName: endpointConfig.EndpointConfigName, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *SageMakerEndpointConfig) Remove() error { _, err := f.svc.DeleteEndpointConfig(&sagemaker.DeleteEndpointConfigInput{ EndpointConfigName: f.endpointConfigName, }) return err } func (f *SageMakerEndpointConfig) String() string { return *f.endpointConfigName } aws-nuke-2.16.0/resources/sagemaker-endpoints.go000066400000000000000000000021451411137415400216360ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sagemaker" ) type SageMakerEndpoint struct { svc *sagemaker.SageMaker endpointName *string } func init() { register("SageMakerEndpoint", ListSageMakerEndpoints) } func ListSageMakerEndpoints(sess *session.Session) ([]Resource, error) { svc := sagemaker.New(sess) resources := []Resource{} params := &sagemaker.ListEndpointsInput{ MaxResults: aws.Int64(30), } for { resp, err := svc.ListEndpoints(params) if err != nil { return nil, err } for _, endpoint := range resp.Endpoints { resources = append(resources, &SageMakerEndpoint{ svc: svc, endpointName: endpoint.EndpointName, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *SageMakerEndpoint) Remove() error { _, err := f.svc.DeleteEndpoint(&sagemaker.DeleteEndpointInput{ EndpointName: f.endpointName, }) return err } func (f *SageMakerEndpoint) String() string { return *f.endpointName } aws-nuke-2.16.0/resources/sagemaker-models.go000066400000000000000000000020431411137415400211130ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sagemaker" ) type SageMakerModel struct { svc *sagemaker.SageMaker modelName *string } func init() { register("SageMakerModel", ListSageMakerModels) } func ListSageMakerModels(sess *session.Session) ([]Resource, error) { svc := sagemaker.New(sess) resources := []Resource{} params := &sagemaker.ListModelsInput{ MaxResults: aws.Int64(30), } for { resp, err := svc.ListModels(params) if err != nil { return nil, err } for _, model := range resp.Models { resources = append(resources, &SageMakerModel{ svc: svc, modelName: model.ModelName, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *SageMakerModel) Remove() error { _, err := f.svc.DeleteModel(&sagemaker.DeleteModelInput{ ModelName: f.modelName, }) return err } func (f *SageMakerModel) String() string { return *f.modelName } aws-nuke-2.16.0/resources/sagemaker-notebookeinstancestates.go000066400000000000000000000031211411137415400245640ustar00rootroot00000000000000package resources import ( "fmt" "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sagemaker" ) type SageMakerNotebookInstanceState struct { svc *sagemaker.SageMaker notebookInstanceName *string instanceStatus *string } func init() { register("SageMakerNotebookInstanceState", ListSageMakerNotebookInstanceStates) } func ListSageMakerNotebookInstanceStates(sess *session.Session) ([]Resource, error) { svc := sagemaker.New(sess) resources := []Resource{} params := &sagemaker.ListNotebookInstancesInput{ MaxResults: aws.Int64(30), } for { resp, err := svc.ListNotebookInstances(params) if err != nil { return nil, err } for _, notebookInstance := range resp.NotebookInstances { resources = append(resources, &SageMakerNotebookInstanceState{ svc: svc, notebookInstanceName: notebookInstance.NotebookInstanceName, instanceStatus: notebookInstance.NotebookInstanceStatus, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *SageMakerNotebookInstanceState) Remove() error { _, err := f.svc.StopNotebookInstance(&sagemaker.StopNotebookInstanceInput{ NotebookInstanceName: f.notebookInstanceName, }) return err } func (f *SageMakerNotebookInstanceState) String() string { return *f.notebookInstanceName } func (f *SageMakerNotebookInstanceState) Filter() error { if strings.ToLower(*f.instanceStatus) == "stopped" { return fmt.Errorf("already stopped") } return nil } aws-nuke-2.16.0/resources/sagemaker-notebookinstancelifecycleconfigs.go000066400000000000000000000031401411137415400264250ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sagemaker" "github.com/rebuy-de/aws-nuke/pkg/types" ) type SageMakerNotebookInstanceLifecycleConfig struct { svc *sagemaker.SageMaker Name *string } func init() { register("SageMakerNotebookInstanceLifecycleConfig", ListSageMakerNotebookInstanceLifecycleConfigs) } func ListSageMakerNotebookInstanceLifecycleConfigs(sess *session.Session) ([]Resource, error) { svc := sagemaker.New(sess) resources := []Resource{} params := &sagemaker.ListNotebookInstanceLifecycleConfigsInput{ MaxResults: aws.Int64(30), } for { resp, err := svc.ListNotebookInstanceLifecycleConfigs(params) if err != nil { return nil, err } for _, lifecycleConfig := range resp.NotebookInstanceLifecycleConfigs { resources = append(resources, &SageMakerNotebookInstanceLifecycleConfig{ svc: svc, Name: lifecycleConfig.NotebookInstanceLifecycleConfigName, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *SageMakerNotebookInstanceLifecycleConfig) Remove() error { _, err := f.svc.DeleteNotebookInstanceLifecycleConfig(&sagemaker.DeleteNotebookInstanceLifecycleConfigInput{ NotebookInstanceLifecycleConfigName: f.Name, }) return err } func (f *SageMakerNotebookInstanceLifecycleConfig) String() string { return *f.Name } func (f *SageMakerNotebookInstanceLifecycleConfig) Properties() types.Properties { properties := types.NewProperties() properties. Set("Name", f.Name) return properties } aws-nuke-2.16.0/resources/sagemaker-notebookinstances.go000066400000000000000000000024241411137415400233630ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sagemaker" ) type SageMakerNotebookInstance struct { svc *sagemaker.SageMaker notebookInstanceName *string } func init() { register("SageMakerNotebookInstance", ListSageMakerNotebookInstances) } func ListSageMakerNotebookInstances(sess *session.Session) ([]Resource, error) { svc := sagemaker.New(sess) resources := []Resource{} params := &sagemaker.ListNotebookInstancesInput{ MaxResults: aws.Int64(30), } for { resp, err := svc.ListNotebookInstances(params) if err != nil { return nil, err } for _, notebookInstance := range resp.NotebookInstances { resources = append(resources, &SageMakerNotebookInstance{ svc: svc, notebookInstanceName: notebookInstance.NotebookInstanceName, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *SageMakerNotebookInstance) Remove() error { _, err := f.svc.DeleteNotebookInstance(&sagemaker.DeleteNotebookInstanceInput{ NotebookInstanceName: f.notebookInstanceName, }) return err } func (f *SageMakerNotebookInstance) String() string { return *f.notebookInstanceName } aws-nuke-2.16.0/resources/sagemaker-userprofiles.go000066400000000000000000000030061411137415400223520ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sagemaker" "github.com/rebuy-de/aws-nuke/pkg/types" ) type SageMakerUserProfile struct { svc *sagemaker.SageMaker domainID *string userProfileName *string } func init() { register("SageMakerUserProfiles", ListSageMakerUserProfiles) } func ListSageMakerUserProfiles(sess *session.Session) ([]Resource, error) { svc := sagemaker.New(sess) resources := []Resource{} params := &sagemaker.ListUserProfilesInput{ MaxResults: aws.Int64(30), } for { resp, err := svc.ListUserProfiles(params) if err != nil { return nil, err } for _, userProfile := range resp.UserProfiles { resources = append(resources, &SageMakerUserProfile{ svc: svc, domainID: userProfile.DomainId, userProfileName: userProfile.UserProfileName, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *SageMakerUserProfile) Remove() error { _, err := f.svc.DeleteUserProfile(&sagemaker.DeleteUserProfileInput{ DomainId: f.domainID, UserProfileName: f.userProfileName, }) return err } func (f *SageMakerUserProfile) String() string { return *f.userProfileName } func (i *SageMakerUserProfile) Properties() types.Properties { properties := types.NewProperties() properties. Set("DomainID", i.domainID). Set("UserProfileName", i.userProfileName) return properties } aws-nuke-2.16.0/resources/secretsmanager-secrets.go000066400000000000000000000027111411137415400223460ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/secretsmanager" "github.com/rebuy-de/aws-nuke/pkg/types" ) type SecretsManagerSecret struct { svc *secretsmanager.SecretsManager ARN *string tags []*secretsmanager.Tag } func init() { register("SecretsManagerSecret", ListSecretsManagerSecrets) } func ListSecretsManagerSecrets(sess *session.Session) ([]Resource, error) { svc := secretsmanager.New(sess) resources := []Resource{} params := &secretsmanager.ListSecretsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListSecrets(params) if err != nil { return nil, err } for _, secrets := range output.SecretList { resources = append(resources, &SecretsManagerSecret{ svc: svc, ARN: secrets.ARN, tags: secrets.Tags, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *SecretsManagerSecret) Remove() error { _, err := f.svc.DeleteSecret(&secretsmanager.DeleteSecretInput{ SecretId: f.ARN, ForceDeleteWithoutRecovery: aws.Bool(true), }) return err } func (f *SecretsManagerSecret) Properties() types.Properties { properties := types.NewProperties() for _, tagValue := range f.tags { properties.SetTag(tagValue.Key, tagValue.Value) } return properties } func (f *SecretsManagerSecret) String() string { return *f.ARN } aws-nuke-2.16.0/resources/securityhub-hub.go000066400000000000000000000017321411137415400210210ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/securityhub" "github.com/rebuy-de/aws-nuke/pkg/types" ) func init() { register("SecurityHub", ListHubs) } func ListHubs(sess *session.Session) ([]Resource, error) { svc := securityhub.New(sess) resources := make([]Resource, 0) resp, err := svc.DescribeHub(nil) if err != nil { if IsAWSError(err, securityhub.ErrCodeInvalidAccessException) { // Security Hub is not enabled for this region return resources, nil } return nil, err } resources = append(resources, &Hub{ svc: svc, id: resp.HubArn, }) return resources, nil } type Hub struct { svc *securityhub.SecurityHub id *string } func (hub *Hub) Properties() types.Properties { properties := types.NewProperties() properties.Set("Arn", hub.id) return properties } func (hub *Hub) Remove() error { _, err := hub.svc.DisableSecurityHub(&securityhub.DisableSecurityHubInput{}) return err } aws-nuke-2.16.0/resources/servicecatalog-portfolio-constraints-attachements.go000066400000000000000000000050401411137415400277240ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/servicecatalog" "github.com/rebuy-de/aws-nuke/pkg/types" log "github.com/sirupsen/logrus" ) type ServiceCatalogConstraintPortfolioAttachment struct { svc *servicecatalog.ServiceCatalog constraintID *string portfolioID *string portfolioName *string } func init() { register("ServiceCatalogConstraintPortfolioAttachment", ListServiceCatalogPrincipalProductAttachments) } func ListServiceCatalogPrincipalProductAttachments(sess *session.Session) ([]Resource, error) { svc := servicecatalog.New(sess) resources := []Resource{} portfolios := []*servicecatalog.PortfolioDetail{} params := &servicecatalog.ListPortfoliosInput{ PageSize: aws.Int64(20), } //List all Portfolios for { resp, err := svc.ListPortfolios(params) if err != nil { if IsAWSError(err, servicecatalog.ErrCodeTagOptionNotMigratedException) { log.Info(err) break } return nil, err } for _, portfolioDetail := range resp.PortfolioDetails { portfolios = append(portfolios, portfolioDetail) } if resp.NextPageToken == nil { break } params.PageToken = resp.NextPageToken } constraintParams := &servicecatalog.ListConstraintsForPortfolioInput{ PageSize: aws.Int64(20), } for _, portfolio := range portfolios { constraintParams.PortfolioId = portfolio.Id resp, err := svc.ListConstraintsForPortfolio(constraintParams) if err != nil { return nil, err } for _, constraintDetail := range resp.ConstraintDetails { resources = append(resources, &ServiceCatalogConstraintPortfolioAttachment{ svc: svc, portfolioID: portfolio.Id, constraintID: constraintDetail.ConstraintId, portfolioName: portfolio.DisplayName, }) } if resp.NextPageToken == nil { break } constraintParams.PageToken = resp.NextPageToken } return resources, nil } func (f *ServiceCatalogConstraintPortfolioAttachment) Remove() error { _, err := f.svc.DeleteConstraint(&servicecatalog.DeleteConstraintInput{ Id: f.constraintID, }) return err } func (f *ServiceCatalogConstraintPortfolioAttachment) Properties() types.Properties { properties := types.NewProperties() properties.Set("PortfolioID", f.portfolioID) properties.Set("ConstraintID", f.constraintID) properties.Set("PortfolioName", f.portfolioName) return properties } func (f *ServiceCatalogConstraintPortfolioAttachment) String() string { return fmt.Sprintf("%s -> %s", *f.constraintID, *f.portfolioID) } aws-nuke-2.16.0/resources/servicecatalog-portfolio-principal-attachements.go000066400000000000000000000047011411137415400273410ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/servicecatalog" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ServiceCatalogPrincipalPortfolioAttachment struct { svc *servicecatalog.ServiceCatalog portfolioID *string principalARN *string portfolioName *string } func init() { register("ServiceCatalogPrincipalPortfolioAttachment", ListServiceCatalogPrincipalPortfolioAttachments) } func ListServiceCatalogPrincipalPortfolioAttachments(sess *session.Session) ([]Resource, error) { svc := servicecatalog.New(sess) resources := []Resource{} portfolios := []*servicecatalog.PortfolioDetail{} params := &servicecatalog.ListPortfoliosInput{ PageSize: aws.Int64(20), } //List all Portfolios for { resp, err := svc.ListPortfolios(params) if err != nil { return nil, err } for _, portfolioDetail := range resp.PortfolioDetails { portfolios = append(portfolios, portfolioDetail) } if resp.NextPageToken == nil { break } params.PageToken = resp.NextPageToken } principalParams := &servicecatalog.ListPrincipalsForPortfolioInput{ PageSize: aws.Int64(20), } for _, portfolio := range portfolios { principalParams.PortfolioId = portfolio.Id resp, err := svc.ListPrincipalsForPortfolio(principalParams) if err != nil { return nil, err } for _, principal := range resp.Principals { resources = append(resources, &ServiceCatalogPrincipalPortfolioAttachment{ svc: svc, principalARN: principal.PrincipalARN, portfolioID: portfolio.Id, portfolioName: portfolio.DisplayName, }) } if resp.NextPageToken == nil { break } principalParams.PageToken = resp.NextPageToken } return resources, nil } func (f *ServiceCatalogPrincipalPortfolioAttachment) Remove() error { _, err := f.svc.DisassociatePrincipalFromPortfolio(&servicecatalog.DisassociatePrincipalFromPortfolioInput{ PrincipalARN: f.principalARN, PortfolioId: f.portfolioID, }) return err } func (f *ServiceCatalogPrincipalPortfolioAttachment) Properties() types.Properties { properties := types.NewProperties() properties.Set("PortfolioID", f.portfolioID) properties.Set("PrincipalARN", f.principalARN) properties.Set("PortfolioName", f.portfolioName) return properties } func (f *ServiceCatalogPrincipalPortfolioAttachment) String() string { return fmt.Sprintf("%s -> %s", *f.principalARN, *f.portfolioID) } aws-nuke-2.16.0/resources/servicecatalog-portfolio-product-attachements.go000066400000000000000000000051551411137415400270440ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/servicecatalog" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ServiceCatalogPortfolioProductAttachment struct { svc *servicecatalog.ServiceCatalog productID *string portfolioID *string portfolioName *string productName *string } func init() { register("ServiceCatalogPortfolioProductAttachment", ListServiceCatalogPortfolioProductAttachments) } func ListServiceCatalogPortfolioProductAttachments(sess *session.Session) ([]Resource, error) { svc := servicecatalog.New(sess) resources := []Resource{} products := make(map[*string]*string) params := &servicecatalog.SearchProductsAsAdminInput{ PageSize: aws.Int64(20), } //List all Products and then search assigned portfolios for { resp, err := svc.SearchProductsAsAdmin(params) if err != nil { return nil, err } for _, productViewDetail := range resp.ProductViewDetails { products[productViewDetail.ProductViewSummary.ProductId] = productViewDetail.ProductViewSummary.Name } if resp.NextPageToken == nil { break } params.PageToken = resp.NextPageToken } portfolioParams := &servicecatalog.ListPortfoliosForProductInput{ PageSize: aws.Int64(20), } for productID, productName := range products { portfolioParams.ProductId = productID resp, err := svc.ListPortfoliosForProduct(portfolioParams) if err != nil { return nil, err } for _, portfolioDetail := range resp.PortfolioDetails { resources = append(resources, &ServiceCatalogPortfolioProductAttachment{ svc: svc, productID: productID, portfolioID: portfolioDetail.Id, portfolioName: portfolioDetail.DisplayName, productName: productName, }) } if resp.NextPageToken == nil { continue } portfolioParams.PageToken = resp.NextPageToken } return resources, nil } func (f *ServiceCatalogPortfolioProductAttachment) Remove() error { _, err := f.svc.DisassociateProductFromPortfolio(&servicecatalog.DisassociateProductFromPortfolioInput{ ProductId: f.productID, PortfolioId: f.portfolioID, }) return err } func (f *ServiceCatalogPortfolioProductAttachment) Properties() types.Properties { properties := types.NewProperties() properties.Set("PortfolioID", f.portfolioID) properties.Set("PortfolioName", f.portfolioName) properties.Set("ProductID", f.productID) properties.Set("ProductName", f.productName) return properties } func (f *ServiceCatalogPortfolioProductAttachment) String() string { return fmt.Sprintf("%s -> %s", *f.productID, *f.portfolioID) } aws-nuke-2.16.0/resources/servicecatalog-portfolio-share-attachements.go000066400000000000000000000044211411137415400264610ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/servicecatalog" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ServiceCatalogPortfolioShareAttachment struct { svc *servicecatalog.ServiceCatalog portfolioID *string accountID *string portfolioName *string } func init() { register("ServiceCatalogPortfolioShareAttachment", ListServiceCatalogPortfolioShareAttachments) } func ListServiceCatalogPortfolioShareAttachments(sess *session.Session) ([]Resource, error) { svc := servicecatalog.New(sess) resources := []Resource{} portfolios := []*servicecatalog.PortfolioDetail{} params := &servicecatalog.ListPortfoliosInput{ PageSize: aws.Int64(20), } //List all Portfolios for { resp, err := svc.ListPortfolios(params) if err != nil { return nil, err } for _, portfolioDetail := range resp.PortfolioDetails { portfolios = append(portfolios, portfolioDetail) } if resp.NextPageToken == nil { break } params.PageToken = resp.NextPageToken } accessParams := &servicecatalog.ListPortfolioAccessInput{} // Get all accounts which have shared access to the portfolio for _, portfolio := range portfolios { accessParams.PortfolioId = portfolio.Id resp, err := svc.ListPortfolioAccess(accessParams) if err != nil { return nil, err } for _, account := range resp.AccountIds { resources = append(resources, &ServiceCatalogPortfolioShareAttachment{ svc: svc, portfolioID: portfolio.Id, accountID: account, portfolioName: portfolio.DisplayName, }) } } return resources, nil } func (f *ServiceCatalogPortfolioShareAttachment) Remove() error { _, err := f.svc.DeletePortfolioShare(&servicecatalog.DeletePortfolioShareInput{ AccountId: f.accountID, PortfolioId: f.portfolioID, }) return err } func (f *ServiceCatalogPortfolioShareAttachment) Properties() types.Properties { properties := types.NewProperties() properties.Set("PortfolioID", f.portfolioID) properties.Set("PortfolioName", f.portfolioName) properties.Set("AccountID", f.accountID) return properties } func (f *ServiceCatalogPortfolioShareAttachment) String() string { return fmt.Sprintf("%s -> %s", *f.portfolioID, *f.accountID) } aws-nuke-2.16.0/resources/servicecatalog-portfolio-tagoptions-attachements.go000066400000000000000000000054241411137415400275520ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/servicecatalog" "github.com/rebuy-de/aws-nuke/pkg/types" log "github.com/sirupsen/logrus" ) type ServiceCatalogTagOptionPortfolioAttachment struct { svc *servicecatalog.ServiceCatalog tagOptionID *string resourceID *string tagOptionKey *string tagOptionValue *string resourceName *string } func init() { register("ServiceCatalogTagOptionPortfolioAttachment", ListServiceCatalogTagOptionPortfolioAttachments) } func ListServiceCatalogTagOptionPortfolioAttachments(sess *session.Session) ([]Resource, error) { svc := servicecatalog.New(sess) resources := []Resource{} tagOptions := []*servicecatalog.TagOptionDetail{} params := &servicecatalog.ListTagOptionsInput{ PageSize: aws.Int64(20), } //List all Tag Options for { resp, err := svc.ListTagOptions(params) if err != nil { if IsAWSError(err, servicecatalog.ErrCodeTagOptionNotMigratedException) { log.Info(err) break } return nil, err } for _, tagOptionDetail := range resp.TagOptionDetails { tagOptions = append(tagOptions, tagOptionDetail) } if resp.PageToken == nil { break } params.PageToken = resp.PageToken } resourceParams := &servicecatalog.ListResourcesForTagOptionInput{ PageSize: aws.Int64(20), } for _, tagOption := range tagOptions { resourceParams.TagOptionId = tagOption.Id resp, err := svc.ListResourcesForTagOption(resourceParams) if err != nil { return nil, err } for _, resourceDetail := range resp.ResourceDetails { resources = append(resources, &ServiceCatalogTagOptionPortfolioAttachment{ svc: svc, tagOptionID: tagOption.Id, resourceID: resourceDetail.Id, resourceName: resourceDetail.Name, tagOptionKey: tagOption.Key, tagOptionValue: tagOption.Value, }) } if resp.PageToken == nil { break } resourceParams.PageToken = resp.PageToken } return resources, nil } func (f *ServiceCatalogTagOptionPortfolioAttachment) Remove() error { _, err := f.svc.DisassociateTagOptionFromResource(&servicecatalog.DisassociateTagOptionFromResourceInput{ TagOptionId: f.tagOptionID, ResourceId: f.resourceID, }) return err } func (f *ServiceCatalogTagOptionPortfolioAttachment) Properties() types.Properties { properties := types.NewProperties() properties.Set("TagOptionID", f.tagOptionID) properties.Set("TagOptionKey", f.tagOptionKey) properties.Set("TagOptionValue", f.tagOptionValue) properties.Set("ResourceID", f.resourceID) properties.Set("ResourceName", f.resourceName) return properties } func (f *ServiceCatalogTagOptionPortfolioAttachment) String() string { return fmt.Sprintf("%s -> %s", *f.tagOptionID, *f.resourceID) } aws-nuke-2.16.0/resources/servicecatalog-portfolios.go000066400000000000000000000031201411137415400230610ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/servicecatalog" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ServiceCatalogPortfolio struct { svc *servicecatalog.ServiceCatalog ID *string displayName *string providerName *string } func init() { register("ServiceCatalogPortfolio", ListServiceCatalogPortfolios) } func ListServiceCatalogPortfolios(sess *session.Session) ([]Resource, error) { svc := servicecatalog.New(sess) resources := []Resource{} params := &servicecatalog.ListPortfoliosInput{ PageSize: aws.Int64(20), } for { resp, err := svc.ListPortfolios(params) if err != nil { return nil, err } for _, portfolioDetail := range resp.PortfolioDetails { resources = append(resources, &ServiceCatalogPortfolio{ svc: svc, ID: portfolioDetail.Id, displayName: portfolioDetail.DisplayName, providerName: portfolioDetail.ProviderName, }) } if resp.NextPageToken == nil { break } params.PageToken = resp.NextPageToken } return resources, nil } func (f *ServiceCatalogPortfolio) Remove() error { _, err := f.svc.DeletePortfolio(&servicecatalog.DeletePortfolioInput{ Id: f.ID, }) return err } func (f *ServiceCatalogPortfolio) Properties() types.Properties { properties := types.NewProperties() properties.Set("ID", f.ID) properties.Set("DisplayName", f.displayName) properties.Set("ProviderName", f.providerName) return properties } func (f *ServiceCatalogPortfolio) String() string { return *f.ID } aws-nuke-2.16.0/resources/servicecatalog-products.go000066400000000000000000000026621411137415400225360ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/servicecatalog" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ServiceCatalogProduct struct { svc *servicecatalog.ServiceCatalog ID *string name *string } func init() { register("ServiceCatalogProduct", ListServiceCatalogProducts) } func ListServiceCatalogProducts(sess *session.Session) ([]Resource, error) { svc := servicecatalog.New(sess) resources := []Resource{} params := &servicecatalog.SearchProductsAsAdminInput{ PageSize: aws.Int64(20), } for { resp, err := svc.SearchProductsAsAdmin(params) if err != nil { return nil, err } for _, productView := range resp.ProductViewDetails { resources = append(resources, &ServiceCatalogProduct{ svc: svc, ID: productView.ProductViewSummary.ProductId, name: productView.ProductViewSummary.Name, }) } if resp.NextPageToken == nil { break } params.PageToken = resp.NextPageToken } return resources, nil } func (f *ServiceCatalogProduct) Remove() error { _, err := f.svc.DeleteProduct(&servicecatalog.DeleteProductInput{ Id: f.ID, }) return err } func (f *ServiceCatalogProduct) Properties() types.Properties { properties := types.NewProperties() properties.Set("ID", f.ID) properties.Set("Name", f.name) return properties } func (f *ServiceCatalogProduct) String() string { return *f.ID } aws-nuke-2.16.0/resources/servicecatalog-provisionedproducts.go000066400000000000000000000037641411137415400250240ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/servicecatalog" "github.com/rebuy-de/aws-nuke/pkg/types" ) type ServiceCatalogProvisionedProduct struct { svc *servicecatalog.ServiceCatalog ID *string terminateToken *string name *string productID *string } func init() { register("ServiceCatalogProvisionedProduct", ListServiceCatalogProvisionedProducts) } func ListServiceCatalogProvisionedProducts(sess *session.Session) ([]Resource, error) { svc := servicecatalog.New(sess) resources := []Resource{} params := &servicecatalog.ScanProvisionedProductsInput{ PageSize: aws.Int64(20), AccessLevelFilter: &servicecatalog.AccessLevelFilter{ Key: aws.String("Account"), Value: aws.String("self"), }, } for { resp, err := svc.ScanProvisionedProducts(params) if err != nil { return nil, err } for _, provisionedProduct := range resp.ProvisionedProducts { resources = append(resources, &ServiceCatalogProvisionedProduct{ svc: svc, ID: provisionedProduct.Id, terminateToken: provisionedProduct.IdempotencyToken, name: provisionedProduct.Name, productID: provisionedProduct.ProductId, }) } if resp.NextPageToken == nil { break } params.PageToken = resp.NextPageToken } return resources, nil } func (f *ServiceCatalogProvisionedProduct) Remove() error { _, err := f.svc.TerminateProvisionedProduct(&servicecatalog.TerminateProvisionedProductInput{ ProvisionedProductId: f.ID, IgnoreErrors: aws.Bool(true), TerminateToken: f.terminateToken, }) return err } func (f *ServiceCatalogProvisionedProduct) Properties() types.Properties { properties := types.NewProperties() properties.Set("ID", f.ID) properties.Set("Name", f.name) properties.Set("ProductID", f.productID) return properties } func (f *ServiceCatalogProvisionedProduct) String() string { return *f.ID } aws-nuke-2.16.0/resources/servicecatalog-tagoptions.go000066400000000000000000000031631411137415400230570ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/servicecatalog" "github.com/rebuy-de/aws-nuke/pkg/types" log "github.com/sirupsen/logrus" ) type ServiceCatalogTagOption struct { svc *servicecatalog.ServiceCatalog ID *string key *string value *string } func init() { register("ServiceCatalogTagOption", ListServiceCatalogTagOptions) } func ListServiceCatalogTagOptions(sess *session.Session) ([]Resource, error) { svc := servicecatalog.New(sess) resources := []Resource{} params := &servicecatalog.ListTagOptionsInput{ PageSize: aws.Int64(20), } for { resp, err := svc.ListTagOptions(params) if err != nil { if IsAWSError(err, servicecatalog.ErrCodeTagOptionNotMigratedException) { log.Info(err) break } return nil, err } for _, tagOptionDetail := range resp.TagOptionDetails { resources = append(resources, &ServiceCatalogTagOption{ svc: svc, ID: tagOptionDetail.Id, key: tagOptionDetail.Key, value: tagOptionDetail.Value, }) } if resp.PageToken == nil { break } params.PageToken = resp.PageToken } return resources, nil } func (f *ServiceCatalogTagOption) Remove() error { _, err := f.svc.DeleteTagOption(&servicecatalog.DeleteTagOptionInput{ Id: f.ID, }) return err } func (f *ServiceCatalogTagOption) Properties() types.Properties { properties := types.NewProperties() properties.Set("ID", f.ID) properties.Set("Key", f.key) properties.Set("Value", f.value) return properties } func (f *ServiceCatalogTagOption) String() string { return *f.ID } aws-nuke-2.16.0/resources/servicediscovery-instances.go000066400000000000000000000036221411137415400232540ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/servicediscovery" ) type ServiceDiscoveryInstance struct { svc *servicediscovery.ServiceDiscovery serviceID *string instanceID *string } func init() { register("ServiceDiscoveryInstance", ListServiceDiscoveryInstances) } func ListServiceDiscoveryInstances(sess *session.Session) ([]Resource, error) { svc := servicediscovery.New(sess) resources := []Resource{} services := []*servicediscovery.ServiceSummary{} params := &servicediscovery.ListServicesInput{ MaxResults: aws.Int64(100), } // Collect all services, using separate for loop // due to multi-service pagination issues for { output, err := svc.ListServices(params) if err != nil { return nil, err } for _, service := range output.Services { services = append(services, service) } if output.NextToken == nil { break } params.NextToken = output.NextToken } //Collect Instances for de-registration for _, service := range services { instanceParams := &servicediscovery.ListInstancesInput{ ServiceId: service.Id, MaxResults: aws.Int64(100), } output, err := svc.ListInstances(instanceParams) if err != nil { return nil, err } for _, instance := range output.Instances { resources = append(resources, &ServiceDiscoveryInstance{ svc: svc, serviceID: service.Id, instanceID: instance.Id, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *ServiceDiscoveryInstance) Remove() error { _, err := f.svc.DeregisterInstance(&servicediscovery.DeregisterInstanceInput{ InstanceId: f.instanceID, ServiceId: f.serviceID, }) return err } func (f *ServiceDiscoveryInstance) String() string { return fmt.Sprintf("%s -> %s", *f.instanceID, *f.serviceID) } aws-nuke-2.16.0/resources/servicediscovery-namespaces.go000066400000000000000000000023501411137415400234010ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/servicediscovery" ) type ServiceDiscoveryNamespace struct { svc *servicediscovery.ServiceDiscovery ID *string } func init() { register("ServiceDiscoveryNamespace", ListServiceDiscoveryNamespaces) } func ListServiceDiscoveryNamespaces(sess *session.Session) ([]Resource, error) { svc := servicediscovery.New(sess) resources := []Resource{} params := &servicediscovery.ListNamespacesInput{ MaxResults: aws.Int64(100), } // Collect all services, using separate for loop // due to multi-service pagination issues for { output, err := svc.ListNamespaces(params) if err != nil { return nil, err } for _, namespace := range output.Namespaces { resources = append(resources, &ServiceDiscoveryNamespace{ svc: svc, ID: namespace.Id, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *ServiceDiscoveryNamespace) Remove() error { _, err := f.svc.DeleteNamespace(&servicediscovery.DeleteNamespaceInput{ Id: f.ID, }) return err } func (f *ServiceDiscoveryNamespace) String() string { return *f.ID } aws-nuke-2.16.0/resources/servicediscovery-services.go000066400000000000000000000023141411137415400231050ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/servicediscovery" ) type ServiceDiscoveryService struct { svc *servicediscovery.ServiceDiscovery ID *string } func init() { register("ServiceDiscoveryService", ListServiceDiscoveryServices) } func ListServiceDiscoveryServices(sess *session.Session) ([]Resource, error) { svc := servicediscovery.New(sess) resources := []Resource{} params := &servicediscovery.ListServicesInput{ MaxResults: aws.Int64(100), } // Collect all services, using separate for loop // due to multi-service pagination issues for { output, err := svc.ListServices(params) if err != nil { return nil, err } for _, service := range output.Services { resources = append(resources, &ServiceDiscoveryService{ svc: svc, ID: service.Id, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *ServiceDiscoveryService) Remove() error { _, err := f.svc.DeleteService(&servicediscovery.DeleteServiceInput{ Id: f.ID, }) return err } func (f *ServiceDiscoveryService) String() string { return *f.ID } aws-nuke-2.16.0/resources/ses-configurationsets.go000066400000000000000000000021361411137415400222340ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ses" ) type SESConfigurationSet struct { svc *ses.SES name *string } func init() { register("SESConfigurationSet", ListSESConfigurationSets) } func ListSESConfigurationSets(sess *session.Session) ([]Resource, error) { svc := ses.New(sess) resources := []Resource{} params := &ses.ListConfigurationSetsInput{ MaxItems: aws.Int64(100), } for { output, err := svc.ListConfigurationSets(params) if err != nil { return nil, err } for _, configurationSet := range output.ConfigurationSets { resources = append(resources, &SESConfigurationSet{ svc: svc, name: configurationSet.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *SESConfigurationSet) Remove() error { _, err := f.svc.DeleteConfigurationSet(&ses.DeleteConfigurationSetInput{ ConfigurationSetName: f.name, }) return err } func (f *SESConfigurationSet) String() string { return *f.name } aws-nuke-2.16.0/resources/ses-identities.go000066400000000000000000000017721411137415400206340ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ses" ) type SESIdentity struct { svc *ses.SES identity *string } func init() { register("SESIdentity", ListSESIdentities) } func ListSESIdentities(sess *session.Session) ([]Resource, error) { svc := ses.New(sess) resources := []Resource{} params := &ses.ListIdentitiesInput{ MaxItems: aws.Int64(100), } for { output, err := svc.ListIdentities(params) if err != nil { return nil, err } for _, identity := range output.Identities { resources = append(resources, &SESIdentity{ svc: svc, identity: identity, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *SESIdentity) Remove() error { _, err := f.svc.DeleteIdentity(&ses.DeleteIdentityInput{ Identity: f.identity, }) return err } func (f *SESIdentity) String() string { return *f.identity } aws-nuke-2.16.0/resources/ses-receiptfilters.go000066400000000000000000000015561411137415400215170ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ses" ) type SESReceiptFilter struct { svc *ses.SES name *string } func init() { register("SESReceiptFilter", ListSESReceiptFilters) } func ListSESReceiptFilters(sess *session.Session) ([]Resource, error) { svc := ses.New(sess) resources := []Resource{} params := &ses.ListReceiptFiltersInput{} output, err := svc.ListReceiptFilters(params) if err != nil { return nil, err } for _, filter := range output.Filters { resources = append(resources, &SESReceiptFilter{ svc: svc, name: filter.Name, }) } return resources, nil } func (f *SESReceiptFilter) Remove() error { _, err := f.svc.DeleteReceiptFilter(&ses.DeleteReceiptFilterInput{ FilterName: f.name, }) return err } func (f *SESReceiptFilter) String() string { return *f.name } aws-nuke-2.16.0/resources/ses-receiptrulesets.go000066400000000000000000000027451411137415400217160ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ses" ) type SESReceiptRuleSet struct { svc *ses.SES name *string activeRuleSet bool } func init() { register("SESReceiptRuleSet", ListSESReceiptRuleSets) } func ListSESReceiptRuleSets(sess *session.Session) ([]Resource, error) { svc := ses.New(sess) resources := []Resource{} params := &ses.ListReceiptRuleSetsInput{} output, err := svc.ListReceiptRuleSets(params) if err != nil { return nil, err } for _, ruleSet := range output.RuleSets { //Check active state ruleSetState := false ruleName := ruleSet.Name activeRuleSetOutput, err := svc.DescribeActiveReceiptRuleSet(&ses.DescribeActiveReceiptRuleSetInput{}) if err != nil { return nil, err } if activeRuleSetOutput.Metadata == nil { ruleSetState = false } else if *ruleName == *activeRuleSetOutput.Metadata.Name { ruleSetState = true } resources = append(resources, &SESReceiptRuleSet{ svc: svc, name: ruleName, activeRuleSet: ruleSetState, }) } return resources, nil } func (f *SESReceiptRuleSet) Remove() error { _, err := f.svc.DeleteReceiptRuleSet(&ses.DeleteReceiptRuleSetInput{ RuleSetName: f.name, }) return err } func (f *SESReceiptRuleSet) String() string { return *f.name } func (f *SESReceiptRuleSet) Filter() error { if f.activeRuleSet == true { return fmt.Errorf("cannot delete active ruleset") } return nil } aws-nuke-2.16.0/resources/ses-templates.go000066400000000000000000000017761411137415400204750ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ses" ) type SESTemplate struct { svc *ses.SES name *string } func init() { register("SESTemplate", ListSESTemplates) } func ListSESTemplates(sess *session.Session) ([]Resource, error) { svc := ses.New(sess) resources := []Resource{} params := &ses.ListTemplatesInput{ MaxItems: aws.Int64(100), } for { output, err := svc.ListTemplates(params) if err != nil { return nil, err } for _, templateMetadata := range output.TemplatesMetadata { resources = append(resources, &SESTemplate{ svc: svc, name: templateMetadata.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *SESTemplate) Remove() error { _, err := f.svc.DeleteTemplate(&ses.DeleteTemplateInput{ TemplateName: f.name, }) return err } func (f *SESTemplate) String() string { return *f.name } aws-nuke-2.16.0/resources/sfn-statemachines.go000066400000000000000000000020501411137415400213050ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sfn" ) type SFNStateMachine struct { svc *sfn.SFN ARN *string } func init() { register("SFNStateMachine", ListSFNStateMachines) } func ListSFNStateMachines(sess *session.Session) ([]Resource, error) { svc := sfn.New(sess) resources := []Resource{} params := &sfn.ListStateMachinesInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListStateMachines(params) if err != nil { return nil, err } for _, stateMachine := range output.StateMachines { resources = append(resources, &SFNStateMachine{ svc: svc, ARN: stateMachine.StateMachineArn, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *SFNStateMachine) Remove() error { _, err := f.svc.DeleteStateMachine(&sfn.DeleteStateMachineInput{ StateMachineArn: f.ARN, }) return err } func (f *SFNStateMachine) String() string { return *f.ARN } aws-nuke-2.16.0/resources/simpledb-domains.go000066400000000000000000000020761411137415400211300ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/simpledb" ) type SimpleDBDomain struct { svc *simpledb.SimpleDB domainName *string } func init() { register("SimpleDBDomain", ListSimpleDBDomains) } func ListSimpleDBDomains(sess *session.Session) ([]Resource, error) { svc := simpledb.New(sess) resources := []Resource{} params := &simpledb.ListDomainsInput{ MaxNumberOfDomains: aws.Int64(100), } for { output, err := svc.ListDomains(params) if err != nil { return nil, err } for _, domainName := range output.DomainNames { resources = append(resources, &SimpleDBDomain{ svc: svc, domainName: domainName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *SimpleDBDomain) Remove() error { _, err := f.svc.DeleteDomain(&simpledb.DeleteDomainInput{ DomainName: f.domainName, }) return err } func (f *SimpleDBDomain) String() string { return *f.domainName } aws-nuke-2.16.0/resources/sns-endpoints.go000066400000000000000000000035441411137415400205060ustar00rootroot00000000000000package 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/sns" ) type SNSEndpoint struct { svc *sns.SNS ARN *string } func init() { register("SNSEndpoint", ListSNSEndpoints) } func ListSNSEndpoints(sess *session.Session) ([]Resource, error) { svc := sns.New(sess) resources := []Resource{} platformApplications := []*sns.PlatformApplication{} platformParams := &sns.ListPlatformApplicationsInput{} for { resp, err := svc.ListPlatformApplications(platformParams) if err != nil { awsErr, ok := err.(awserr.Error) if ok && awsErr.Code() == "InvalidAction" && awsErr.Message() == "Operation (ListPlatformApplications) is not supported in this region" { // AWS answers with InvalidAction on regions that do not // support ListPlatformApplications. break } return nil, err } for _, platformApplication := range resp.PlatformApplications { platformApplications = append(platformApplications, platformApplication) } if resp.NextToken == nil { break } platformParams.NextToken = resp.NextToken } params := &sns.ListEndpointsByPlatformApplicationInput{} for _, platformApplication := range platformApplications { params.PlatformApplicationArn = platformApplication.PlatformApplicationArn resp, err := svc.ListEndpointsByPlatformApplication(params) if err != nil { return nil, err } for _, endpoint := range resp.Endpoints { resources = append(resources, &SNSEndpoint{ svc: svc, ARN: endpoint.EndpointArn, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *SNSEndpoint) Remove() error { _, err := f.svc.DeleteEndpoint(&sns.DeleteEndpointInput{ EndpointArn: f.ARN, }) return err } func (f *SNSEndpoint) String() string { return *f.ARN } aws-nuke-2.16.0/resources/sns-platformapplications.go000066400000000000000000000026341411137415400227350ustar00rootroot00000000000000package 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/sns" ) type SNSPlatformApplication struct { svc *sns.SNS ARN *string } func init() { register("SNSPlatformApplication", ListSNSPlatformApplications) } func ListSNSPlatformApplications(sess *session.Session) ([]Resource, error) { svc := sns.New(sess) resources := []Resource{} params := &sns.ListPlatformApplicationsInput{} for { resp, err := svc.ListPlatformApplications(params) if err != nil { awsErr, ok := err.(awserr.Error) if ok && awsErr.Code() == "InvalidAction" && awsErr.Message() == "Operation (ListPlatformApplications) is not supported in this region" { // AWS answers with InvalidAction on regions that do not // support ListPlatformApplications. break } return nil, err } for _, platformApplication := range resp.PlatformApplications { resources = append(resources, &SNSPlatformApplication{ svc: svc, ARN: platformApplication.PlatformApplicationArn, }) } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } func (f *SNSPlatformApplication) Remove() error { _, err := f.svc.DeletePlatformApplication(&sns.DeletePlatformApplicationInput{ PlatformApplicationArn: f.ARN, }) return err } func (f *SNSPlatformApplication) String() string { return *f.ARN } aws-nuke-2.16.0/resources/sns-subscriptions.go000066400000000000000000000022221411137415400214020ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sns" ) func init() { register("SNSSubscription", ListSNSSubscriptions) } func ListSNSSubscriptions(sess *session.Session) ([]Resource, error) { svc := sns.New(sess) params := &sns.ListSubscriptionsInput{} resources := make([]Resource, 0) for { resp, err := svc.ListSubscriptions(params) if err != nil { return nil, err } for _, subscription := range resp.Subscriptions { if *subscription.SubscriptionArn != "PendingConfirmation" { resources = append(resources, &SNSSubscription{ svc: svc, id: subscription.SubscriptionArn, name: subscription.Owner, }) } } if resp.NextToken == nil { break } params.NextToken = resp.NextToken } return resources, nil } type SNSSubscription struct { svc *sns.SNS id *string name *string } func (subs *SNSSubscription) Remove() error { _, err := subs.svc.Unsubscribe(&sns.UnsubscribeInput{ SubscriptionArn: subs.id, }) return err } func (subs *SNSSubscription) String() string { return fmt.Sprintf("Owner: %s ARN: %s", *subs.name, *subs.id) } aws-nuke-2.16.0/resources/sns-topics.go000066400000000000000000000026731411137415400200060ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sns" "github.com/rebuy-de/aws-nuke/pkg/types" ) type SNSTopic struct { svc *sns.SNS id *string tags []*sns.Tag } func init() { register("SNSTopic", ListSNSTopics) } func ListSNSTopics(sess *session.Session) ([]Resource, error) { svc := sns.New(sess) topics := make([]*sns.Topic, 0) params := &sns.ListTopicsInput{} err := svc.ListTopicsPages(params, func(page *sns.ListTopicsOutput, lastPage bool) bool { for _, out := range page.Topics { topics = append(topics, out) } return true }) if err != nil { return nil, err } resources := make([]Resource, 0) for _, topic := range topics { tags, err := svc.ListTagsForResource(&sns.ListTagsForResourceInput{ ResourceArn: topic.TopicArn, }) if err != nil { continue } resources = append(resources, &SNSTopic{ svc: svc, id: topic.TopicArn, tags: tags.Tags, }) } return resources, nil } func (topic *SNSTopic) Remove() error { _, err := topic.svc.DeleteTopic(&sns.DeleteTopicInput{ TopicArn: topic.id, }) return err } func (topic *SNSTopic) Properties() types.Properties { properties := types.NewProperties() for _, tag := range topic.tags { properties.SetTag(tag.Key, tag.Value) } properties.Set("TopicARN", topic.id) return properties } func (topic *SNSTopic) String() string { return fmt.Sprintf("TopicARN: %s", *topic.id) } aws-nuke-2.16.0/resources/sqs-queues.go000066400000000000000000000014511411137415400200100ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sqs" ) type SQSQueue struct { svc *sqs.SQS queueURL *string } func init() { register("SQSQueue", ListSQSQueues) } func ListSQSQueues(sess *session.Session) ([]Resource, error) { svc := sqs.New(sess) params := &sqs.ListQueuesInput{} resp, err := svc.ListQueues(params) if err != nil { return nil, err } resources := make([]Resource, 0) for _, queue := range resp.QueueUrls { resources = append(resources, &SQSQueue{ svc: svc, queueURL: queue, }) } return resources, nil } func (f *SQSQueue) Remove() error { _, err := f.svc.DeleteQueue(&sqs.DeleteQueueInput{ QueueUrl: f.queueURL, }) return err } func (f *SQSQueue) String() string { return *f.queueURL } aws-nuke-2.16.0/resources/ssm-activations.go000066400000000000000000000020161411137415400210170ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ssm" ) type SSMActivation struct { svc *ssm.SSM ID *string } func init() { register("SSMActivation", ListSSMActivations) } func ListSSMActivations(sess *session.Session) ([]Resource, error) { svc := ssm.New(sess) resources := []Resource{} params := &ssm.DescribeActivationsInput{ MaxResults: aws.Int64(50), } for { output, err := svc.DescribeActivations(params) if err != nil { return nil, err } for _, activation := range output.ActivationList { resources = append(resources, &SSMActivation{ svc: svc, ID: activation.ActivationId, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *SSMActivation) Remove() error { _, err := f.svc.DeleteActivation(&ssm.DeleteActivationInput{ ActivationId: f.ID, }) return err } func (f *SSMActivation) String() string { return *f.ID } aws-nuke-2.16.0/resources/ssm-associations.go000066400000000000000000000022231411137415400211720ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ssm" ) type SSMAssociation struct { svc *ssm.SSM associationID *string instanceID *string } func init() { register("SSMAssociation", ListSSMAssociations) } func ListSSMAssociations(sess *session.Session) ([]Resource, error) { svc := ssm.New(sess) resources := []Resource{} params := &ssm.ListAssociationsInput{ MaxResults: aws.Int64(50), } for { output, err := svc.ListAssociations(params) if err != nil { return nil, err } for _, association := range output.Associations { resources = append(resources, &SSMAssociation{ svc: svc, associationID: association.AssociationId, instanceID: association.InstanceId, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *SSMAssociation) Remove() error { _, err := f.svc.DeleteAssociation(&ssm.DeleteAssociationInput{ AssociationId: f.associationID, }) return err } func (f *SSMAssociation) String() string { return *f.associationID } aws-nuke-2.16.0/resources/ssm-documents.go000066400000000000000000000022531411137415400204770ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ssm" ) type SSMDocument struct { svc *ssm.SSM name *string } func init() { register("SSMDocument", ListSSMDocuments) } func ListSSMDocuments(sess *session.Session) ([]Resource, error) { svc := ssm.New(sess) resources := []Resource{} documentKeyFilter := []*ssm.DocumentKeyValuesFilter{ { Key: aws.String("Owner"), Values: []*string{aws.String("Self")}, }, } params := &ssm.ListDocumentsInput{ MaxResults: aws.Int64(50), Filters: documentKeyFilter, } for { output, err := svc.ListDocuments(params) if err != nil { return nil, err } for _, documentIdentifier := range output.DocumentIdentifiers { resources = append(resources, &SSMDocument{ svc: svc, name: documentIdentifier.Name, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *SSMDocument) Remove() error { _, err := f.svc.DeleteDocument(&ssm.DeleteDocumentInput{ Name: f.name, }) return err } func (f *SSMDocument) String() string { return *f.name } aws-nuke-2.16.0/resources/ssm-maintenancewindows.go000066400000000000000000000021351411137415400223720ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ssm" ) type SSMMaintenanceWindow struct { svc *ssm.SSM ID *string } func init() { register("SSMMaintenanceWindow", ListSSMMaintenanceWindows) } func ListSSMMaintenanceWindows(sess *session.Session) ([]Resource, error) { svc := ssm.New(sess) resources := []Resource{} params := &ssm.DescribeMaintenanceWindowsInput{ MaxResults: aws.Int64(50), } for { output, err := svc.DescribeMaintenanceWindows(params) if err != nil { return nil, err } for _, windowIdentity := range output.WindowIdentities { resources = append(resources, &SSMMaintenanceWindow{ svc: svc, ID: windowIdentity.WindowId, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *SSMMaintenanceWindow) Remove() error { _, err := f.svc.DeleteMaintenanceWindow(&ssm.DeleteMaintenanceWindowInput{ WindowId: f.ID, }) return err } func (f *SSMMaintenanceWindow) String() string { return *f.ID } aws-nuke-2.16.0/resources/ssm-parameters.go000066400000000000000000000030571411137415400206440ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ssm" "github.com/rebuy-de/aws-nuke/pkg/types" ) type SSMParameter struct { svc *ssm.SSM name *string tags []*ssm.Tag } func init() { register("SSMParameter", ListSSMParameters) } func ListSSMParameters(sess *session.Session) ([]Resource, error) { svc := ssm.New(sess) resources := []Resource{} params := &ssm.DescribeParametersInput{ MaxResults: aws.Int64(50), } for { output, err := svc.DescribeParameters(params) if err != nil { return nil, err } for _, parameter := range output.Parameters { tagParams := &ssm.ListTagsForResourceInput{ ResourceId: parameter.Name, ResourceType: aws.String(ssm.ResourceTypeForTaggingParameter), } tagResp, tagErr := svc.ListTagsForResource(tagParams) if tagErr != nil { return nil, tagErr } resources = append(resources, &SSMParameter{ svc: svc, name: parameter.Name, tags: tagResp.TagList, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *SSMParameter) Remove() error { _, err := f.svc.DeleteParameter(&ssm.DeleteParameterInput{ Name: f.name, }) return err } func (f *SSMParameter) String() string { return *f.name } func (f *SSMParameter) Properties() types.Properties { properties := types.NewProperties() for _, tag := range f.tags { properties.SetTag(tag.Key, tag.Value) } properties. Set("Name", f.name) return properties } aws-nuke-2.16.0/resources/ssm-patchbaselines.go000066400000000000000000000040601411137415400214610ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ssm" ) type SSMPatchBaseline struct { svc *ssm.SSM ID *string defaultBaseline *bool } func init() { register("SSMPatchBaseline", ListSSMPatchBaselines) } func ListSSMPatchBaselines(sess *session.Session) ([]Resource, error) { svc := ssm.New(sess) resources := []Resource{} patchBaselineFilter := []*ssm.PatchOrchestratorFilter{ { Key: aws.String("OWNER"), Values: []*string{aws.String("Self")}, }, } params := &ssm.DescribePatchBaselinesInput{ MaxResults: aws.Int64(50), Filters: patchBaselineFilter, } for { output, err := svc.DescribePatchBaselines(params) if err != nil { return nil, err } for _, baselineIdentity := range output.BaselineIdentities { resources = append(resources, &SSMPatchBaseline{ svc: svc, ID: baselineIdentity.BaselineId, defaultBaseline: baselineIdentity.DefaultBaseline, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *SSMPatchBaseline) Remove() error { err := f.DeregisterFromPatchGroups() if err != nil { return err } _, err = f.svc.DeletePatchBaseline(&ssm.DeletePatchBaselineInput{ BaselineId: f.ID, }) return err } func (f *SSMPatchBaseline) DeregisterFromPatchGroups() error { patchBaseLine, err := f.svc.GetPatchBaseline(&ssm.GetPatchBaselineInput{ BaselineId: f.ID, }) if err != nil { return err } for _, patchGroup := range patchBaseLine.PatchGroups { _, err := f.svc.DeregisterPatchBaselineForPatchGroup(&ssm.DeregisterPatchBaselineForPatchGroupInput{ BaselineId: f.ID, PatchGroup: patchGroup, }) if err != nil { return err } } return nil } func (f *SSMPatchBaseline) String() string { return *f.ID } func (f *SSMPatchBaseline) Filter() error { if *f.defaultBaseline { return fmt.Errorf("cannot delete default patch baseline, reassign default first") } return nil } aws-nuke-2.16.0/resources/ssm-resourcedatasyncs.go000066400000000000000000000021411411137415400222330ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ssm" ) type SSMResourceDataSync struct { svc *ssm.SSM name *string } func init() { register("SSMResourceDataSync", ListSSMResourceDataSyncs) } func ListSSMResourceDataSyncs(sess *session.Session) ([]Resource, error) { svc := ssm.New(sess) resources := []Resource{} params := &ssm.ListResourceDataSyncInput{ MaxResults: aws.Int64(50), } for { output, err := svc.ListResourceDataSync(params) if err != nil { return nil, err } for _, resourceDataSyncItem := range output.ResourceDataSyncItems { resources = append(resources, &SSMResourceDataSync{ svc: svc, name: resourceDataSyncItem.SyncName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *SSMResourceDataSync) Remove() error { _, err := f.svc.DeleteResourceDataSync(&ssm.DeleteResourceDataSyncInput{ SyncName: f.name, }) return err } func (f *SSMResourceDataSync) String() string { return *f.name } aws-nuke-2.16.0/resources/storagegateway-fileshares.go000066400000000000000000000022471411137415400230520ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/storagegateway" ) type StorageGatewayFileShare struct { svc *storagegateway.StorageGateway ARN *string } func init() { register("StorageGatewayFileShare", ListStorageGatewayFileShares) } func ListStorageGatewayFileShares(sess *session.Session) ([]Resource, error) { svc := storagegateway.New(sess) resources := []Resource{} params := &storagegateway.ListFileSharesInput{ Limit: aws.Int64(25), } for { output, err := svc.ListFileShares(params) if err != nil { return nil, err } for _, fileShareInfo := range output.FileShareInfoList { resources = append(resources, &StorageGatewayFileShare{ svc: svc, ARN: fileShareInfo.FileShareARN, }) } if output.Marker == nil { break } params.Marker = output.Marker } return resources, nil } func (f *StorageGatewayFileShare) Remove() error { _, err := f.svc.DeleteFileShare(&storagegateway.DeleteFileShareInput{ FileShareARN: f.ARN, ForceDelete: aws.Bool(true), }) return err } func (f *StorageGatewayFileShare) String() string { return *f.ARN } aws-nuke-2.16.0/resources/storagegateway-gateways.go000066400000000000000000000021301411137415400225400ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/storagegateway" ) type StorageGatewayGateway struct { svc *storagegateway.StorageGateway ARN *string } func init() { register("StorageGatewayGateway", ListStorageGatewayGateways) } func ListStorageGatewayGateways(sess *session.Session) ([]Resource, error) { svc := storagegateway.New(sess) resources := []Resource{} params := &storagegateway.ListGatewaysInput{ Limit: aws.Int64(25), } for { output, err := svc.ListGateways(params) if err != nil { return nil, err } for _, gateway := range output.Gateways { resources = append(resources, &StorageGatewayGateway{ svc: svc, ARN: gateway.GatewayARN, }) } if output.Marker == nil { break } params.Marker = output.Marker } return resources, nil } func (f *StorageGatewayGateway) Remove() error { _, err := f.svc.DeleteGateway(&storagegateway.DeleteGatewayInput{ GatewayARN: f.ARN, }) return err } func (f *StorageGatewayGateway) String() string { return *f.ARN } aws-nuke-2.16.0/resources/storagegateway-tapes.go000066400000000000000000000022601411137415400220340ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/storagegateway" ) type StorageGatewayTape struct { svc *storagegateway.StorageGateway tapeARN *string gatewayARN *string } func init() { register("StorageGatewayTape", ListStorageGatewayTapes) } func ListStorageGatewayTapes(sess *session.Session) ([]Resource, error) { svc := storagegateway.New(sess) resources := []Resource{} params := &storagegateway.ListTapesInput{ Limit: aws.Int64(25), } for { output, err := svc.ListTapes(params) if err != nil { return nil, err } for _, tapeInfo := range output.TapeInfos { resources = append(resources, &StorageGatewayTape{ svc: svc, tapeARN: tapeInfo.TapeARN, gatewayARN: tapeInfo.GatewayARN, }) } if output.Marker == nil { break } params.Marker = output.Marker } return resources, nil } func (f *StorageGatewayTape) Remove() error { _, err := f.svc.DeleteTape(&storagegateway.DeleteTapeInput{ TapeARN: f.tapeARN, GatewayARN: f.gatewayARN, }) return err } func (f *StorageGatewayTape) String() string { return *f.tapeARN } aws-nuke-2.16.0/resources/storagegateway-volumes.go000066400000000000000000000021241411137415400224110ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/storagegateway" ) type StorageGatewayVolume struct { svc *storagegateway.StorageGateway ARN *string } func init() { register("StorageGatewayVolume", ListStorageGatewayVolumes) } func ListStorageGatewayVolumes(sess *session.Session) ([]Resource, error) { svc := storagegateway.New(sess) resources := []Resource{} params := &storagegateway.ListVolumesInput{ Limit: aws.Int64(25), } for { output, err := svc.ListVolumes(params) if err != nil { return nil, err } for _, volumeInfo := range output.VolumeInfos { resources = append(resources, &StorageGatewayVolume{ svc: svc, ARN: volumeInfo.VolumeARN, }) } if output.Marker == nil { break } params.Marker = output.Marker } return resources, nil } func (f *StorageGatewayVolume) Remove() error { _, err := f.svc.DeleteVolume(&storagegateway.DeleteVolumeInput{ VolumeARN: f.ARN, }) return err } func (f *StorageGatewayVolume) String() string { return *f.ARN } aws-nuke-2.16.0/resources/transfer-server-user.go000066400000000000000000000041601411137415400220010ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/transfer" "github.com/rebuy-de/aws-nuke/pkg/types" ) type TransferServerUser struct { svc *transfer.Transfer username *string serverID *string tags []*transfer.Tag } func init() { register("TransferServerUser", ListTransferServerUsers) } func ListTransferServerUsers(sess *session.Session) ([]Resource, error) { svc := transfer.New(sess) resources := []Resource{} params := &transfer.ListServersInput{ MaxResults: aws.Int64(50), } for { output, err := svc.ListServers(params) if err != nil { return nil, err } for _, item := range output.Servers { userParams := &transfer.ListUsersInput{ MaxResults: aws.Int64(100), ServerId: item.ServerId, } for { userOutput, err := svc.ListUsers(userParams) if err != nil { return nil, err } for _, user := range userOutput.Users { descOutput, err := svc.DescribeUser(&transfer.DescribeUserInput{ ServerId: item.ServerId, UserName: user.UserName, }) if err != nil { return nil, err } resources = append(resources, &TransferServerUser{ svc: svc, username: user.UserName, serverID: item.ServerId, tags: descOutput.User.Tags, }) } if userOutput.NextToken == nil { break } userParams.NextToken = userOutput.NextToken } } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (ts *TransferServerUser) Remove() error { _, err := ts.svc.DeleteUser(&transfer.DeleteUserInput{ ServerId: ts.serverID, UserName: ts.username, }) return err } func (ts *TransferServerUser) String() string { return fmt.Sprintf("%s -> %s", *ts.serverID, *ts.username) } func (ts *TransferServerUser) Properties() types.Properties { properties := types.NewProperties() for _, tag := range ts.tags { properties.SetTag(tag.Key, tag.Value) } properties. Set("Username", ts.username). Set("ServerID", ts.serverID) return properties } aws-nuke-2.16.0/resources/transfer-server.go000066400000000000000000000036131411137415400210270ustar00rootroot00000000000000package resources import ( "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/transfer" "github.com/rebuy-de/aws-nuke/pkg/types" ) type TransferServer struct { svc *transfer.Transfer serverID *string endpointType *string protocols []string tags []*transfer.Tag } func init() { register("TransferServer", ListTransferServers) } func ListTransferServers(sess *session.Session) ([]Resource, error) { svc := transfer.New(sess) resources := []Resource{} params := &transfer.ListServersInput{ MaxResults: aws.Int64(50), } for { output, err := svc.ListServers(params) if err != nil { return nil, err } for _, item := range output.Servers { descOutput, err := svc.DescribeServer(&transfer.DescribeServerInput{ ServerId: item.ServerId, }) if err != nil { return nil, err } protocols := []string{} for _, protocol := range descOutput.Server.Protocols { protocols = append(protocols, *protocol) } resources = append(resources, &TransferServer{ svc: svc, serverID: item.ServerId, endpointType: item.EndpointType, protocols: protocols, tags: descOutput.Server.Tags, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (ts *TransferServer) Remove() error { _, err := ts.svc.DeleteServer(&transfer.DeleteServerInput{ ServerId: ts.serverID, }) return err } func (ts *TransferServer) String() string { return *ts.serverID } func (ts *TransferServer) Properties() types.Properties { properties := types.NewProperties() for _, tag := range ts.tags { properties.SetTag(tag.Key, tag.Value) } properties. Set("ServerID", ts.serverID). Set("EndpointType", ts.endpointType). Set("Protocols", strings.Join(ts.protocols, ", ")) return properties } aws-nuke-2.16.0/resources/util.go000066400000000000000000000010541411137415400166510ustar00rootroot00000000000000package resources import "github.com/aws/aws-sdk-go/aws/awserr" func UnPtrBool(ptr *bool, def bool) bool { if ptr == nil { return def } return *ptr } func UnPtrString(ptr *string, def string) string { if ptr == nil { return def } return *ptr } func EqualStringPtr(v1, v2 *string) bool { if v1 == nil && v2 == nil { return true } if v1 == nil || v2 == nil { return false } return *v1 == *v2 } func IsAWSError(err error, code string) bool { aerr, ok := err.(awserr.Error) if !ok { return false } return aerr.Code() == code } aws-nuke-2.16.0/resources/waf-rules.go000066400000000000000000000020551411137415400176030ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" ) type WAFRule struct { svc *waf.WAF ID *string } func init() { register("WAFRule", ListWAFRules) } func ListWAFRules(sess *session.Session) ([]Resource, error) { svc := waf.New(sess) resources := []Resource{} params := &waf.ListRulesInput{ Limit: aws.Int64(50), } for { resp, err := svc.ListRules(params) if err != nil { return nil, err } for _, rule := range resp.Rules { resources = append(resources, &WAFRule{ svc: svc, ID: rule.RuleId, }) } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (f *WAFRule) Remove() error { tokenOutput, err := f.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } _, err = f.svc.DeleteRule(&waf.DeleteRuleInput{ RuleId: f.ID, ChangeToken: tokenOutput.ChangeToken, }) return err } func (f *WAFRule) String() string { return *f.ID } aws-nuke-2.16.0/resources/waf-webacl-rule-attachements.go000066400000000000000000000035411411137415400233320ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" ) type WAFWebACLRuleAttachment struct { svc *waf.WAF webACLID *string activatedRule *waf.ActivatedRule } func init() { register("WAFWebACLRuleAttachment", ListWAFWebACLRuleAttachments) } func ListWAFWebACLRuleAttachments(sess *session.Session) ([]Resource, error) { svc := waf.New(sess) resources := []Resource{} webACLs := []*waf.WebACLSummary{} params := &waf.ListWebACLsInput{ Limit: aws.Int64(50), } //List All Web ACL's for { resp, err := svc.ListWebACLs(params) if err != nil { return nil, err } for _, webACL := range resp.WebACLs { webACLs = append(webACLs, webACL) } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } webACLParams := &waf.GetWebACLInput{} for _, webACL := range webACLs { webACLParams.WebACLId = webACL.WebACLId resp, err := svc.GetWebACL(webACLParams) if err != nil { return nil, err } for _, webACLRule := range resp.WebACL.Rules { resources = append(resources, &WAFWebACLRuleAttachment{ svc: svc, webACLID: webACL.WebACLId, activatedRule: webACLRule, }) } } return resources, nil } func (f *WAFWebACLRuleAttachment) Remove() error { tokenOutput, err := f.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } webACLUpdate := &waf.WebACLUpdate{ Action: aws.String("DELETE"), ActivatedRule: f.activatedRule, } _, err = f.svc.UpdateWebACL(&waf.UpdateWebACLInput{ WebACLId: f.webACLID, ChangeToken: tokenOutput.ChangeToken, Updates: []*waf.WebACLUpdate{webACLUpdate}, }) return err } func (f *WAFWebACLRuleAttachment) String() string { return fmt.Sprintf("%s -> %s", *f.webACLID, *f.activatedRule.RuleId) } aws-nuke-2.16.0/resources/waf-webacls.go000066400000000000000000000021131411137415400200640ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" ) type WAFWebACL struct { svc *waf.WAF ID *string } func init() { register("WAFWebACL", ListWAFWebACLs) } func ListWAFWebACLs(sess *session.Session) ([]Resource, error) { svc := waf.New(sess) resources := []Resource{} params := &waf.ListWebACLsInput{ Limit: aws.Int64(50), } for { resp, err := svc.ListWebACLs(params) if err != nil { return nil, err } for _, webACL := range resp.WebACLs { resources = append(resources, &WAFWebACL{ svc: svc, ID: webACL.WebACLId, }) } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (f *WAFWebACL) Remove() error { tokenOutput, err := f.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } _, err = f.svc.DeleteWebACL(&waf.DeleteWebACLInput{ WebACLId: f.ID, ChangeToken: tokenOutput.ChangeToken, }) return err } func (f *WAFWebACL) String() string { return *f.ID } aws-nuke-2.16.0/resources/wafregional-byte-match-set-tuples.go000066400000000000000000000040061411137415400243300ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" "github.com/aws/aws-sdk-go/service/wafregional" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WAFRegionalByteMatchSetIP struct { svc *wafregional.WAFRegional matchSetid *string tuple *waf.ByteMatchTuple } func init() { register("WAFRegionalByteMatchSetIP", ListWAFRegionalByteMatchSetIPs) } func ListWAFRegionalByteMatchSetIPs(sess *session.Session) ([]Resource, error) { svc := wafregional.New(sess) resources := []Resource{} params := &waf.ListByteMatchSetsInput{ Limit: aws.Int64(50), } for { resp, err := svc.ListByteMatchSets(params) if err != nil { return nil, err } for _, set := range resp.ByteMatchSets { details, err := svc.GetByteMatchSet(&waf.GetByteMatchSetInput{ ByteMatchSetId: set.ByteMatchSetId, }) if err != nil { return nil, err } for _, tuple := range details.ByteMatchSet.ByteMatchTuples { resources = append(resources, &WAFRegionalByteMatchSetIP{ svc: svc, matchSetid: set.ByteMatchSetId, tuple: tuple, }) } } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (r *WAFRegionalByteMatchSetIP) Remove() error { tokenOutput, err := r.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } _, err = r.svc.UpdateByteMatchSet(&waf.UpdateByteMatchSetInput{ ChangeToken: tokenOutput.ChangeToken, ByteMatchSetId: r.matchSetid, Updates: []*waf.ByteMatchSetUpdate{ &waf.ByteMatchSetUpdate{ Action: aws.String("DELETE"), ByteMatchTuple: r.tuple, }, }, }) return err } func (r *WAFRegionalByteMatchSetIP) Properties() types.Properties { return types.NewProperties(). Set("ByteMatchSetID", r.matchSetid). Set("FieldToMatchType", r.tuple.FieldToMatch.Type). Set("FieldToMatchData", r.tuple.FieldToMatch.Data). Set("TargetString", r.tuple.TargetString) } aws-nuke-2.16.0/resources/wafregional-byte-match-sets.go000066400000000000000000000027661411137415400232140ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" "github.com/aws/aws-sdk-go/service/wafregional" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WAFRegionalByteMatchSet struct { svc *wafregional.WAFRegional id *string name *string } func init() { register("WAFRegionalByteMatchSet", ListWAFRegionalByteMatchSets) } func ListWAFRegionalByteMatchSets(sess *session.Session) ([]Resource, error) { svc := wafregional.New(sess) resources := []Resource{} params := &waf.ListByteMatchSetsInput{ Limit: aws.Int64(50), } for { resp, err := svc.ListByteMatchSets(params) if err != nil { return nil, err } for _, set := range resp.ByteMatchSets { resources = append(resources, &WAFRegionalByteMatchSet{ svc: svc, id: set.ByteMatchSetId, name: set.Name, }) } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (r *WAFRegionalByteMatchSet) Remove() error { tokenOutput, err := r.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } _, err = r.svc.DeleteByteMatchSet(&waf.DeleteByteMatchSetInput{ ByteMatchSetId: r.id, ChangeToken: tokenOutput.ChangeToken, }) return err } func (r *WAFRegionalByteMatchSet) Properties() types.Properties { return types.NewProperties(). Set("ID", r.id). Set("Name", r.name) } func (r *WAFRegionalByteMatchSet) String() string { return *r.id } aws-nuke-2.16.0/resources/wafregional-ip-set-ips.go000066400000000000000000000034471411137415400221720ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" "github.com/aws/aws-sdk-go/service/wafregional" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WAFRegionalIPSetIP struct { svc *wafregional.WAFRegional ipSetid *string descriptor *waf.IPSetDescriptor } func init() { register("WAFRegionalIPSetIP", ListWAFRegionalIPSetIPs) } func ListWAFRegionalIPSetIPs(sess *session.Session) ([]Resource, error) { svc := wafregional.New(sess) resources := []Resource{} params := &waf.ListIPSetsInput{ Limit: aws.Int64(50), } for { resp, err := svc.ListIPSets(params) if err != nil { return nil, err } for _, set := range resp.IPSets { details, err := svc.GetIPSet(&waf.GetIPSetInput{ IPSetId: set.IPSetId, }) if err != nil { return nil, err } for _, descriptor := range details.IPSet.IPSetDescriptors { resources = append(resources, &WAFRegionalIPSetIP{ svc: svc, ipSetid: set.IPSetId, descriptor: descriptor, }) } } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (r *WAFRegionalIPSetIP) Remove() error { tokenOutput, err := r.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } _, err = r.svc.UpdateIPSet(&waf.UpdateIPSetInput{ ChangeToken: tokenOutput.ChangeToken, IPSetId: r.ipSetid, Updates: []*waf.IPSetUpdate{ &waf.IPSetUpdate{ Action: aws.String("DELETE"), IPSetDescriptor: r.descriptor, }, }, }) return err } func (r *WAFRegionalIPSetIP) Properties() types.Properties { return types.NewProperties(). Set("IPSetID", r.ipSetid). Set("Type", r.descriptor.Type). Set("Value", r.descriptor.Value) } aws-nuke-2.16.0/resources/wafregional-ip-sets.go000066400000000000000000000026161411137415400215610ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" "github.com/aws/aws-sdk-go/service/wafregional" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WAFRegionalIPSet struct { svc *wafregional.WAFRegional id *string name *string } func init() { register("WAFRegionalIPSet", ListWAFRegionalIPSets) } func ListWAFRegionalIPSets(sess *session.Session) ([]Resource, error) { svc := wafregional.New(sess) resources := []Resource{} params := &waf.ListIPSetsInput{ Limit: aws.Int64(50), } for { resp, err := svc.ListIPSets(params) if err != nil { return nil, err } for _, set := range resp.IPSets { resources = append(resources, &WAFRegionalIPSet{ svc: svc, id: set.IPSetId, name: set.Name, }) } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (r *WAFRegionalIPSet) Remove() error { tokenOutput, err := r.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } _, err = r.svc.DeleteIPSet(&waf.DeleteIPSetInput{ IPSetId: r.id, ChangeToken: tokenOutput.ChangeToken, }) return err } func (r *WAFRegionalIPSet) Properties() types.Properties { return types.NewProperties(). Set("ID", r.id). Set("Name", r.name) } func (r *WAFRegionalIPSet) String() string { return *r.id } aws-nuke-2.16.0/resources/wafregional-rate-based-rule-predicates.go000066400000000000000000000040311411137415400252630ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" "github.com/aws/aws-sdk-go/service/wafregional" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WAFRegionalRateBasedRulePredicate struct { svc *wafregional.WAFRegional ruleID *string predicate *waf.Predicate rateLimit *int64 } func init() { register("WAFRegionalRateBasedRulePredicate", ListWAFRegionalRateBasedRulePredicates) } func ListWAFRegionalRateBasedRulePredicates(sess *session.Session) ([]Resource, error) { svc := wafregional.New(sess) resources := []Resource{} params := &waf.ListRateBasedRulesInput{ Limit: aws.Int64(50), } for { resp, err := svc.ListRateBasedRules(params) if err != nil { return nil, err } for _, rule := range resp.Rules { details, err := svc.GetRateBasedRule(&waf.GetRateBasedRuleInput{ RuleId: rule.RuleId, }) if err != nil { return nil, err } for _, predicate := range details.Rule.MatchPredicates { resources = append(resources, &WAFRegionalRateBasedRulePredicate{ svc: svc, ruleID: rule.RuleId, rateLimit: details.Rule.RateLimit, predicate: predicate, }) } } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (r *WAFRegionalRateBasedRulePredicate) Remove() error { tokenOutput, err := r.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } _, err = r.svc.UpdateRateBasedRule(&waf.UpdateRateBasedRuleInput{ ChangeToken: tokenOutput.ChangeToken, RuleId: r.ruleID, RateLimit: r.rateLimit, Updates: []*waf.RuleUpdate{ &waf.RuleUpdate{ Action: aws.String("DELETE"), Predicate: r.predicate, }, }, }) return err } func (r *WAFRegionalRateBasedRulePredicate) Properties() types.Properties { return types.NewProperties(). Set("RuleID", r.ruleID). Set("Type", r.predicate.Type). Set("Negated", r.predicate.Negated). Set("DataID", r.predicate.DataId) } aws-nuke-2.16.0/resources/wafregional-rate-based-rules.go000066400000000000000000000024211411137415400233260ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" "github.com/aws/aws-sdk-go/service/wafregional" ) type WAFRegionalRateBasedRule struct { svc *wafregional.WAFRegional ID *string } func init() { register("WAFRegionalRateBasedRule", ListWAFRegionalRateBasedRules) } func ListWAFRegionalRateBasedRules(sess *session.Session) ([]Resource, error) { svc := wafregional.New(sess) resources := []Resource{} params := &waf.ListRateBasedRulesInput{ Limit: aws.Int64(50), } for { resp, err := svc.ListRateBasedRules(params) if err != nil { return nil, err } for _, rule := range resp.Rules { resources = append(resources, &WAFRegionalRateBasedRule{ svc: svc, ID: rule.RuleId, }) } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (f *WAFRegionalRateBasedRule) Remove() error { tokenOutput, err := f.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } _, err = f.svc.DeleteRateBasedRule(&waf.DeleteRateBasedRuleInput{ RuleId: f.ID, ChangeToken: tokenOutput.ChangeToken, }) return err } func (f *WAFRegionalRateBasedRule) String() string { return *f.ID } aws-nuke-2.16.0/resources/wafregional-regex-match-sets.go000066400000000000000000000030041411137415400233450ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" "github.com/aws/aws-sdk-go/service/wafregional" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WAFRegionalRegexMatchSet struct { svc *wafregional.WAFRegional id *string name *string } func init() { register("WAFRegionalRegexMatchSet", ListWAFRegionalRegexMatchSet) } func ListWAFRegionalRegexMatchSet(sess *session.Session) ([]Resource, error) { svc := wafregional.New(sess) resources := []Resource{} params := &waf.ListRegexMatchSetsInput{ Limit: aws.Int64(50), } for { resp, err := svc.ListRegexMatchSets(params) if err != nil { return nil, err } for _, set := range resp.RegexMatchSets { resources = append(resources, &WAFRegionalRegexMatchSet{ svc: svc, id: set.RegexMatchSetId, name: set.Name, }) } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (r *WAFRegionalRegexMatchSet) Remove() error { tokenOutput, err := r.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } _, err = r.svc.DeleteRegexMatchSet(&waf.DeleteRegexMatchSetInput{ RegexMatchSetId: r.id, ChangeToken: tokenOutput.ChangeToken, }) return err } func (r *WAFRegionalRegexMatchSet) Properties() types.Properties { return types.NewProperties(). Set("ID", r.id). Set("Name", r.name) } func (r *WAFRegionalRegexMatchSet) String() string { return *r.id } aws-nuke-2.16.0/resources/wafregional-regex-match-tuples.go000066400000000000000000000040661411137415400237140ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" "github.com/aws/aws-sdk-go/service/wafregional" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WAFRegionalRegexMatchTuple struct { svc *wafregional.WAFRegional matchSetid *string tuple *waf.RegexMatchTuple } func init() { register("WAFRegionalRegexMatchTuple", ListWAFRegionalRegexMatchTuple) } func ListWAFRegionalRegexMatchTuple(sess *session.Session) ([]Resource, error) { svc := wafregional.New(sess) resources := []Resource{} params := &waf.ListRegexMatchSetsInput{ Limit: aws.Int64(50), } for { resp, err := svc.ListRegexMatchSets(params) if err != nil { return nil, err } for _, set := range resp.RegexMatchSets { regexMatchSet, err := svc.GetRegexMatchSet(&waf.GetRegexMatchSetInput{ RegexMatchSetId: set.RegexMatchSetId, }) if err != nil { return nil, err } for _, tuple := range regexMatchSet.RegexMatchSet.RegexMatchTuples { resources = append(resources, &WAFRegionalRegexMatchTuple{ svc: svc, matchSetid: set.RegexMatchSetId, tuple: tuple, }) } } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (r *WAFRegionalRegexMatchTuple) Remove() error { tokenOutput, err := r.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } _, err = r.svc.UpdateRegexMatchSet(&waf.UpdateRegexMatchSetInput{ ChangeToken: tokenOutput.ChangeToken, RegexMatchSetId: r.matchSetid, Updates: []*waf.RegexMatchSetUpdate{ &waf.RegexMatchSetUpdate{ Action: aws.String("DELETE"), RegexMatchTuple: r.tuple, }, }, }) return err } func (r *WAFRegionalRegexMatchTuple) Properties() types.Properties { return types.NewProperties(). Set("RegexMatchSetID", r.matchSetid). Set("FieldToMatchType", r.tuple.FieldToMatch.Type). Set("FieldToMatchData", r.tuple.FieldToMatch.Data). Set("TextTransformation", r.tuple.TextTransformation) } aws-nuke-2.16.0/resources/wafregional-regex-pattern-sets.go000066400000000000000000000030441411137415400237320ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" "github.com/aws/aws-sdk-go/service/wafregional" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WAFRegionalRegexPatternSet struct { svc *wafregional.WAFRegional id *string name *string } func init() { register("WAFRegionalRegexPatternSet", ListWAFRegionalRegexPatternSet) } func ListWAFRegionalRegexPatternSet(sess *session.Session) ([]Resource, error) { svc := wafregional.New(sess) resources := []Resource{} params := &waf.ListRegexPatternSetsInput{ Limit: aws.Int64(50), } for { resp, err := svc.ListRegexPatternSets(params) if err != nil { return nil, err } for _, set := range resp.RegexPatternSets { resources = append(resources, &WAFRegionalRegexPatternSet{ svc: svc, id: set.RegexPatternSetId, name: set.Name, }) } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (r *WAFRegionalRegexPatternSet) Remove() error { tokenOutput, err := r.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } _, err = r.svc.DeleteRegexPatternSet(&waf.DeleteRegexPatternSetInput{ RegexPatternSetId: r.id, ChangeToken: tokenOutput.ChangeToken, }) return err } func (r *WAFRegionalRegexPatternSet) Properties() types.Properties { return types.NewProperties(). Set("ID", r.id). Set("Name", r.name) } func (r *WAFRegionalRegexPatternSet) String() string { return *r.id } aws-nuke-2.16.0/resources/wafregional-regex-pattern-tuples.go000066400000000000000000000040351411137415400242710ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" "github.com/aws/aws-sdk-go/service/wafregional" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WAFRegionalRegexPatternString struct { svc *wafregional.WAFRegional patternSetid *string patternString *string } func init() { register("WAFRegionalRegexPatternString", ListWAFRegionalRegexPatternString) } func ListWAFRegionalRegexPatternString(sess *session.Session) ([]Resource, error) { svc := wafregional.New(sess) resources := []Resource{} params := &waf.ListRegexPatternSetsInput{ Limit: aws.Int64(50), } for { resp, err := svc.ListRegexPatternSets(params) if err != nil { return nil, err } for _, set := range resp.RegexPatternSets { regexPatternSet, err := svc.GetRegexPatternSet(&waf.GetRegexPatternSetInput{ RegexPatternSetId: set.RegexPatternSetId, }) if err != nil { return nil, err } for _, patternString := range regexPatternSet.RegexPatternSet.RegexPatternStrings { resources = append(resources, &WAFRegionalRegexPatternString{ svc: svc, patternSetid: set.RegexPatternSetId, patternString: patternString, }) } } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (r *WAFRegionalRegexPatternString) Remove() error { tokenOutput, err := r.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } _, err = r.svc.UpdateRegexPatternSet(&waf.UpdateRegexPatternSetInput{ ChangeToken: tokenOutput.ChangeToken, RegexPatternSetId: r.patternSetid, Updates: []*waf.RegexPatternSetUpdate{ &waf.RegexPatternSetUpdate{ Action: aws.String("DELETE"), RegexPatternString: r.patternString, }, }, }) return err } func (r *WAFRegionalRegexPatternString) Properties() types.Properties { return types.NewProperties(). Set("RegexPatternSetID", r.patternSetid). Set("patternString", r.patternString) } aws-nuke-2.16.0/resources/wafregional-rule-predicates.go000066400000000000000000000036351411137415400232670ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" "github.com/aws/aws-sdk-go/service/wafregional" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WAFRegionalRulePredicate struct { svc *wafregional.WAFRegional ruleID *string predicate *waf.Predicate } func init() { register("WAFRegionalRulePredicate", ListWAFRegionalRulePredicates) } func ListWAFRegionalRulePredicates(sess *session.Session) ([]Resource, error) { svc := wafregional.New(sess) resources := []Resource{} params := &waf.ListRulesInput{ Limit: aws.Int64(50), } for { resp, err := svc.ListRules(params) if err != nil { return nil, err } for _, rule := range resp.Rules { details, err := svc.GetRule(&waf.GetRuleInput{ RuleId: rule.RuleId, }) if err != nil { return nil, err } for _, predicate := range details.Rule.Predicates { resources = append(resources, &WAFRegionalRulePredicate{ svc: svc, ruleID: rule.RuleId, predicate: predicate, }) } } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (r *WAFRegionalRulePredicate) Remove() error { tokenOutput, err := r.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } _, err = r.svc.UpdateRule(&waf.UpdateRuleInput{ ChangeToken: tokenOutput.ChangeToken, RuleId: r.ruleID, Updates: []*waf.RuleUpdate{ &waf.RuleUpdate{ Action: aws.String("DELETE"), Predicate: r.predicate, }, }, }) return err } func (r *WAFRegionalRulePredicate) Properties() types.Properties { return types.NewProperties(). Set("RuleID", r.ruleID). Set("Type", r.predicate.Type). Set("Negated", r.predicate.Negated). Set("DataID", r.predicate.DataId) } func (r *WAFRegionalRulePredicate) String() string { return *r.predicate.DataId } aws-nuke-2.16.0/resources/wafregional-rulegroup.go000066400000000000000000000027611411137415400222220ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" "github.com/aws/aws-sdk-go/service/wafregional" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WAFRegionalRuleGroup struct { svc *wafregional.WAFRegional ID *string name *string } func init() { register("WAFRegionalRuleGroup", ListWAFRegionalRuleGroups) } func ListWAFRegionalRuleGroups(sess *session.Session) ([]Resource, error) { svc := wafregional.New(sess) resources := []Resource{} params := &waf.ListRuleGroupsInput{ Limit: aws.Int64(50), } for { resp, err := svc.ListRuleGroups(params) if err != nil { return nil, err } for _, rule := range resp.RuleGroups { resources = append(resources, &WAFRegionalRuleGroup{ svc: svc, ID: rule.RuleGroupId, name: rule.Name, }) } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (f *WAFRegionalRuleGroup) Remove() error { tokenOutput, err := f.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } _, err = f.svc.DeleteRuleGroup(&waf.DeleteRuleGroupInput{ RuleGroupId: f.ID, ChangeToken: tokenOutput.ChangeToken, }) return err } func (f *WAFRegionalRuleGroup) String() string { return *f.ID } func (f *WAFRegionalRuleGroup) Properties() types.Properties { properties := types.NewProperties() properties. Set("ID", f.ID). Set("Name", f.name) return properties } aws-nuke-2.16.0/resources/wafregional-rules.go000066400000000000000000000026531411137415400213300ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" "github.com/aws/aws-sdk-go/service/wafregional" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WAFRegionalRule struct { svc *wafregional.WAFRegional ID *string name *string } func init() { register("WAFRegionalRule", ListWAFRegionalRules) } func ListWAFRegionalRules(sess *session.Session) ([]Resource, error) { svc := wafregional.New(sess) resources := []Resource{} params := &waf.ListRulesInput{ Limit: aws.Int64(50), } for { resp, err := svc.ListRules(params) if err != nil { return nil, err } for _, rule := range resp.Rules { resources = append(resources, &WAFRegionalRule{ svc: svc, ID: rule.RuleId, name: rule.Name, }) } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (f *WAFRegionalRule) Remove() error { tokenOutput, err := f.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } _, err = f.svc.DeleteRule(&waf.DeleteRuleInput{ RuleId: f.ID, ChangeToken: tokenOutput.ChangeToken, }) return err } func (f *WAFRegionalRule) String() string { return *f.ID } func (f *WAFRegionalRule) Properties() types.Properties { properties := types.NewProperties() properties. Set("ID", f.ID). Set("Name", f.name) return properties } aws-nuke-2.16.0/resources/wafregional-webacl-rule-attachments.go000066400000000000000000000037421411137415400247110ustar00rootroot00000000000000package resources import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" "github.com/aws/aws-sdk-go/service/wafregional" ) type WAFRegionalWebACLRuleAttachment struct { svc *wafregional.WAFRegional webACLID *string activatedRule *waf.ActivatedRule } func init() { register("WAFRegionalWebACLRuleAttachment", ListWAFRegionalWebACLRuleAttachments) } func ListWAFRegionalWebACLRuleAttachments(sess *session.Session) ([]Resource, error) { svc := wafregional.New(sess) resources := []Resource{} webACLs := []*waf.WebACLSummary{} params := &waf.ListWebACLsInput{ Limit: aws.Int64(50), } //List All Web ACL's for { resp, err := svc.ListWebACLs(params) if err != nil { return nil, err } for _, webACL := range resp.WebACLs { webACLs = append(webACLs, webACL) } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } webACLParams := &waf.GetWebACLInput{} for _, webACL := range webACLs { webACLParams.WebACLId = webACL.WebACLId resp, err := svc.GetWebACL(webACLParams) if err != nil { return nil, err } for _, webACLRule := range resp.WebACL.Rules { resources = append(resources, &WAFRegionalWebACLRuleAttachment{ svc: svc, webACLID: webACL.WebACLId, activatedRule: webACLRule, }) } } return resources, nil } func (f *WAFRegionalWebACLRuleAttachment) Remove() error { tokenOutput, err := f.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } webACLUpdate := &waf.WebACLUpdate{ Action: aws.String("DELETE"), ActivatedRule: f.activatedRule, } _, err = f.svc.UpdateWebACL(&waf.UpdateWebACLInput{ WebACLId: f.webACLID, ChangeToken: tokenOutput.ChangeToken, Updates: []*waf.WebACLUpdate{webACLUpdate}, }) return err } func (f *WAFRegionalWebACLRuleAttachment) String() string { return fmt.Sprintf("%s -> %s", *f.webACLID, *f.activatedRule.RuleId) } aws-nuke-2.16.0/resources/wafregional-webacls.go000066400000000000000000000027151411137415400216150ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/waf" "github.com/aws/aws-sdk-go/service/wafregional" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WAFRegionalWebACL struct { svc *wafregional.WAFRegional ID *string name *string } func init() { register("WAFRegionalWebACL", ListWAFRegionalWebACLs) } func ListWAFRegionalWebACLs(sess *session.Session) ([]Resource, error) { svc := wafregional.New(sess) resources := []Resource{} params := &waf.ListWebACLsInput{ Limit: aws.Int64(50), } for { resp, err := svc.ListWebACLs(params) if err != nil { return nil, err } for _, webACL := range resp.WebACLs { resources = append(resources, &WAFRegionalWebACL{ svc: svc, ID: webACL.WebACLId, name: webACL.Name, }) } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (f *WAFRegionalWebACL) Remove() error { tokenOutput, err := f.svc.GetChangeToken(&waf.GetChangeTokenInput{}) if err != nil { return err } _, err = f.svc.DeleteWebACL(&waf.DeleteWebACLInput{ WebACLId: f.ID, ChangeToken: tokenOutput.ChangeToken, }) return err } func (f *WAFRegionalWebACL) String() string { return *f.ID } func (f *WAFRegionalWebACL) Properties() types.Properties { properties := types.NewProperties() properties. Set("ID", f.ID). Set("Name", f.name) return properties } aws-nuke-2.16.0/resources/wafv2-ipsets.go000066400000000000000000000035641411137415400202360ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/wafv2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WAFv2IPSet struct { svc *wafv2.WAFV2 id *string name *string lockToken *string scope *string } func init() { register("WAFv2IPSet", ListWAFv2IPSets) } func ListWAFv2IPSets(sess *session.Session) ([]Resource, error) { svc := wafv2.New(sess) resources := []Resource{} params := &wafv2.ListIPSetsInput{ Limit: aws.Int64(50), Scope: aws.String("REGIONAL"), } output, err := getIPSets(svc, params) if err != nil { return []Resource{}, err } resources = append(resources, output...) if *sess.Config.Region == "us-east-1" { params.Scope = aws.String("CLOUDFRONT") output, err := getIPSets(svc, params) if err != nil { return []Resource{}, err } resources = append(resources, output...) } return resources, nil } func getIPSets(svc *wafv2.WAFV2, params *wafv2.ListIPSetsInput) ([]Resource, error) { resources := []Resource{} for { resp, err := svc.ListIPSets(params) if err != nil { return nil, err } for _, set := range resp.IPSets { resources = append(resources, &WAFv2IPSet{ svc: svc, id: set.Id, name: set.Name, lockToken: set.LockToken, scope: params.Scope, }) } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (r *WAFv2IPSet) Remove() error { _, err := r.svc.DeleteIPSet(&wafv2.DeleteIPSetInput{ Id: r.id, Name: r.name, Scope: r.scope, LockToken: r.lockToken, }) return err } func (r *WAFv2IPSet) Properties() types.Properties { return types.NewProperties(). Set("ID", r.id). Set("Name", r.name). Set("Scope", r.scope) } func (r *WAFv2IPSet) String() string { return *r.id } aws-nuke-2.16.0/resources/wafv2-regex-pattern-sets.go000066400000000000000000000040361411137415400224630ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/wafv2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WAFv2RegexPatternSet struct { svc *wafv2.WAFV2 id *string name *string lockToken *string scope *string } func init() { register("WAFv2RegexPatternSet", ListWAFv2RegexPatternSets) } func ListWAFv2RegexPatternSets(sess *session.Session) ([]Resource, error) { svc := wafv2.New(sess) resources := []Resource{} params := &wafv2.ListRegexPatternSetsInput{ Limit: aws.Int64(50), Scope: aws.String("REGIONAL"), } output, err := getRegexPatternSets(svc, params) if err != nil { return []Resource{}, err } resources = append(resources, output...) if *sess.Config.Region == "us-east-1" { params.Scope = aws.String("CLOUDFRONT") output, err := getRegexPatternSets(svc, params) if err != nil { return []Resource{}, err } resources = append(resources, output...) } return resources, nil } func getRegexPatternSets(svc *wafv2.WAFV2, params *wafv2.ListRegexPatternSetsInput) ([]Resource, error) { resources := []Resource{} for { resp, err := svc.ListRegexPatternSets(params) if err != nil { return nil, err } for _, set := range resp.RegexPatternSets { resources = append(resources, &WAFv2RegexPatternSet{ svc: svc, id: set.Id, name: set.Name, lockToken: set.LockToken, scope: params.Scope, }) } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (r *WAFv2RegexPatternSet) Remove() error { _, err := r.svc.DeleteRegexPatternSet(&wafv2.DeleteRegexPatternSetInput{ Id: r.id, Name: r.name, Scope: r.scope, LockToken: r.lockToken, }) return err } func (r *WAFv2RegexPatternSet) Properties() types.Properties { return types.NewProperties(). Set("ID", r.id). Set("Name", r.name). Set("Scope", r.scope) } func (r *WAFv2RegexPatternSet) String() string { return *r.id } aws-nuke-2.16.0/resources/wafv2-rulegroup.go000066400000000000000000000037521411137415400207520ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/wafv2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WAFv2RuleGroup struct { svc *wafv2.WAFV2 ID *string name *string lockToken *string scope *string } func init() { register("WAFv2RuleGroup", ListWAFv2RuleGroups) } func ListWAFv2RuleGroups(sess *session.Session) ([]Resource, error) { svc := wafv2.New(sess) resources := []Resource{} params := &wafv2.ListRuleGroupsInput{ Limit: aws.Int64(50), Scope: aws.String("REGIONAL"), } output, err := getRuleGroups(svc, params) if err != nil { return []Resource{}, err } resources = append(resources, output...) if *sess.Config.Region == "us-east-1" { params.Scope = aws.String("CLOUDFRONT") output, err := getRuleGroups(svc, params) if err != nil { return []Resource{}, err } resources = append(resources, output...) } return resources, nil } func getRuleGroups(svc *wafv2.WAFV2, params *wafv2.ListRuleGroupsInput) ([]Resource, error) { resources := []Resource{} for { resp, err := svc.ListRuleGroups(params) if err != nil { return nil, err } for _, webACL := range resp.RuleGroups { resources = append(resources, &WAFv2RuleGroup{ svc: svc, ID: webACL.Id, name: webACL.Name, lockToken: webACL.LockToken, scope: params.Scope, }) } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (f *WAFv2RuleGroup) Remove() error { _, err := f.svc.DeleteRuleGroup(&wafv2.DeleteRuleGroupInput{ Id: f.ID, Name: f.name, Scope: f.scope, LockToken: f.lockToken, }) return err } func (f *WAFv2RuleGroup) String() string { return *f.ID } func (f *WAFv2RuleGroup) Properties() types.Properties { properties := types.NewProperties() properties. Set("ID", f.ID). Set("Name", f.name). Set("Scope", f.scope) return properties } aws-nuke-2.16.0/resources/wafv2-webacls.go000066400000000000000000000036671411137415400203530ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/wafv2" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WAFv2WebACL struct { svc *wafv2.WAFV2 ID *string name *string lockToken *string scope *string } func init() { register("WAFv2WebACL", ListWAFv2WebACLs) } func ListWAFv2WebACLs(sess *session.Session) ([]Resource, error) { svc := wafv2.New(sess) resources := []Resource{} params := &wafv2.ListWebACLsInput{ Limit: aws.Int64(50), Scope: aws.String("REGIONAL"), } output, err := getWebACLs(svc, params) if err != nil { return []Resource{}, err } resources = append(resources, output...) if *sess.Config.Region == "us-east-1" { params.Scope = aws.String("CLOUDFRONT") output, err := getWebACLs(svc, params) if err != nil { return []Resource{}, err } resources = append(resources, output...) } return resources, nil } func getWebACLs(svc *wafv2.WAFV2, params *wafv2.ListWebACLsInput) ([]Resource, error) { resources := []Resource{} for { resp, err := svc.ListWebACLs(params) if err != nil { return nil, err } for _, webACL := range resp.WebACLs { resources = append(resources, &WAFv2WebACL{ svc: svc, ID: webACL.Id, name: webACL.Name, lockToken: webACL.LockToken, scope: params.Scope, }) } if resp.NextMarker == nil { break } params.NextMarker = resp.NextMarker } return resources, nil } func (f *WAFv2WebACL) Remove() error { _, err := f.svc.DeleteWebACL(&wafv2.DeleteWebACLInput{ Id: f.ID, Name: f.name, Scope: f.scope, LockToken: f.lockToken, }) return err } func (f *WAFv2WebACL) String() string { return *f.ID } func (f *WAFv2WebACL) Properties() types.Properties { properties := types.NewProperties() properties. Set("ID", f.ID). Set("Name", f.name). Set("Scope", f.scope) return properties } aws-nuke-2.16.0/resources/worklink-fleets.go000066400000000000000000000030141411137415400210120ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/worklink" "github.com/rebuy-de/aws-nuke/pkg/types" ) type WorkLinkFleet struct { svc *worklink.WorkLink fleetARN *string fleetName *string fleetCompanyCode *string fleetDisplayName *string } func init() { register("WorkLinkFleet", ListWorkLinkFleets) } func ListWorkLinkFleets(sess *session.Session) ([]Resource, error) { svc := worklink.New(sess) resources := []Resource{} params := &worklink.ListFleetsInput{ MaxResults: aws.Int64(100), } for { output, err := svc.ListFleets(params) if err != nil { return nil, err } for _, fleet := range output.FleetSummaryList { resources = append(resources, &WorkLinkFleet{ svc: svc, fleetARN: fleet.FleetArn, fleetName: fleet.FleetName, fleetCompanyCode: fleet.CompanyCode, fleetDisplayName: fleet.DisplayName, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *WorkLinkFleet) Properties() types.Properties { properties := types.NewProperties() properties.Set("CompanyCode", f.fleetCompanyCode) properties.Set("DisplayName", f.fleetDisplayName) return properties } func (f *WorkLinkFleet) Remove() error { _, err := f.svc.DeleteFleet(&worklink.DeleteFleetInput{ FleetArn: f.fleetARN, }) return err } func (f *WorkLinkFleet) String() string { return *f.fleetName } aws-nuke-2.16.0/resources/workspaces-workspaces.go000066400000000000000000000030011411137415400222260ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/workspaces" ) type WorkSpacesWorkspace struct { svc *workspaces.WorkSpaces workspaceID *string } func init() { register("WorkSpacesWorkspace", ListWorkSpacesWorkspaces) } func ListWorkSpacesWorkspaces(sess *session.Session) ([]Resource, error) { svc := workspaces.New(sess) resources := []Resource{} params := &workspaces.DescribeWorkspacesInput{ Limit: aws.Int64(25), } for { output, err := svc.DescribeWorkspaces(params) if err != nil { return nil, err } for _, workspace := range output.Workspaces { resources = append(resources, &WorkSpacesWorkspace{ svc: svc, workspaceID: workspace.WorkspaceId, }) } if output.NextToken == nil { break } params.NextToken = output.NextToken } return resources, nil } func (f *WorkSpacesWorkspace) Remove() error { stopRequest := &workspaces.StopRequest{ WorkspaceId: f.workspaceID, } terminateRequest := &workspaces.TerminateRequest{ WorkspaceId: f.workspaceID, } _, err := f.svc.StopWorkspaces(&workspaces.StopWorkspacesInput{ StopWorkspaceRequests: []*workspaces.StopRequest{stopRequest}, }) if err != nil { return err } _, err = f.svc.TerminateWorkspaces(&workspaces.TerminateWorkspacesInput{ TerminateWorkspaceRequests: []*workspaces.TerminateRequest{terminateRequest}, }) return err } func (f *WorkSpacesWorkspace) String() string { return *f.workspaceID } aws-nuke-2.16.0/resources/xray-group.go000066400000000000000000000026051411137415400200140ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/xray" "github.com/rebuy-de/aws-nuke/pkg/types" ) type XRayGroup struct { svc *xray.XRay groupName *string groupARN *string } func init() { register("XRayGroup", ListXRayGroups) } func ListXRayGroups(sess *session.Session) ([]Resource, error) { svc := xray.New(sess) resources := []Resource{} // Get X-Ray Groups var xrayGroups []*xray.GroupSummary err := svc.GetGroupsPages( &xray.GetGroupsInput{}, func(page *xray.GetGroupsOutput, lastPage bool) bool { for _, group := range page.Groups { if *group.GroupName != "Default" { // Ignore the Default group as it cannot be removed xrayGroups = append(xrayGroups, group) } } return true }, ) if err != nil { return nil, err } for _, group := range xrayGroups { resources = append(resources, &XRayGroup{ svc: svc, groupName: group.GroupName, groupARN: group.GroupARN, }) } return resources, nil } func (f *XRayGroup) Remove() error { _, err := f.svc.DeleteGroup(&xray.DeleteGroupInput{ GroupARN: f.groupARN, // Only allowed to pass GroupARN _or_ GroupName to delete request }) return err } func (f *XRayGroup) Properties() types.Properties { properties := types.NewProperties() properties. Set("GroupName", f.groupName). Set("GroupARN", f.groupARN) return properties } aws-nuke-2.16.0/resources/xray-samplingrule.go000066400000000000000000000026451411137415400213660ustar00rootroot00000000000000package resources import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/xray" "github.com/rebuy-de/aws-nuke/pkg/types" ) type XRaySamplingRule struct { svc *xray.XRay ruleName *string ruleARN *string } func init() { register("XRaySamplingRule", ListXRaySamplingRules) } func ListXRaySamplingRules(sess *session.Session) ([]Resource, error) { svc := xray.New(sess) resources := []Resource{} var xraySamplingRules []*xray.SamplingRule err := svc.GetSamplingRulesPages( &xray.GetSamplingRulesInput{}, func(page *xray.GetSamplingRulesOutput, lastPage bool) bool { for _, rule := range page.SamplingRuleRecords { if *rule.SamplingRule.RuleName != "Default" { xraySamplingRules = append(xraySamplingRules, rule.SamplingRule) } } return true }, ) if err != nil { return nil, err } for _, rule := range xraySamplingRules { resources = append(resources, &XRaySamplingRule{ svc: svc, ruleName: rule.RuleName, ruleARN: rule.RuleARN, }) } return resources, nil } func (f *XRaySamplingRule) Remove() error { _, err := f.svc.DeleteSamplingRule(&xray.DeleteSamplingRuleInput{ RuleARN: f.ruleARN, // Specify ruleARN or ruleName, not both }) return err } func (f *XRaySamplingRule) Properties() types.Properties { properties := types.NewProperties() properties. Set("RuleName", f.ruleName). Set("RuleARN", f.ruleARN) return properties } aws-nuke-2.16.0/tools/000077500000000000000000000000001411137415400144735ustar00rootroot00000000000000aws-nuke-2.16.0/tools/tools.go000066400000000000000000000002521411137415400161610ustar00rootroot00000000000000// +build tools package main // https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module import ( _ "github.com/golang/mock/mockgen" )