From 3a1ab7bad874e9b51d15be48a305793a1a0591f4 Mon Sep 17 00:00:00 2001 From: purpleclay Date: Tue, 10 Oct 2023 08:17:26 +0100 Subject: [PATCH 1/6] initial pass at aligning dns53 to other projects --- .../dependency-review.yml => .deepsource.toml | 27 +++-- .github/dependabot.yml | 2 +- .github/workflows/ci.yml | 99 +++++-------------- ...dependabot-merge.yml => code-security.yml} | 49 +++++---- .github/workflows/docs.yml | 22 +++-- .github/workflows/{uplift.yml => nsv.yml} | 20 ++-- .github/workflows/release.yml | 54 ++++++---- .../{git-secrets.yml => shellcheck.yml} | 30 +++--- .golangci.yml | 48 ++++++--- LICENSE | 2 +- Taskfile.yaml | 94 ++++++++++-------- go.mod | 2 +- go.sum | 5 + sonar-project.properties | 20 ---- 14 files changed, 238 insertions(+), 236 deletions(-) rename .github/workflows/dependency-review.yml => .deepsource.toml (77%) rename .github/workflows/{dependabot-merge.yml => code-security.yml} (63%) rename .github/workflows/{uplift.yml => nsv.yml} (75%) rename .github/workflows/{git-secrets.yml => shellcheck.yml} (67%) delete mode 100644 sonar-project.properties diff --git a/.github/workflows/dependency-review.yml b/.deepsource.toml similarity index 77% rename from .github/workflows/dependency-review.yml rename to .deepsource.toml index f2a3186..bf26972 100644 --- a/.github/workflows/dependency-review.yml +++ b/.deepsource.toml @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Purple Clay +# Copyright (c) 2022 - 2023 Purple Clay # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -17,20 +17,19 @@ # 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. +version = 1 -name: dependency-review -on: - pull_request: +test_patterns = [ + "**/*_test.go" +] -permissions: - contents: read +[[analyzers]] +name = "go" +enabled = true -jobs: - dependency-review: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 + [analyzers.meta] + import_root = "github.com/purpleclay/dns53" - - name: Dependency Review - uses: actions/dependency-review-action@v3 +[[analyzers]] +name = "secret" +enabled = true diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 11e59f1..d6d434a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Purple Clay +# Copyright (c) 2022 - 2023 Purple Clay # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0fa4b0d..d7ee90d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Purple Clay +# Copyright (c) 2022 - 2023 Purple Clay # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -29,87 +29,34 @@ on: - "go.mod" - "go.sum" pull_request: + branches: + - main paths: + - .github/workflows/ci.yml - "**/*.go" - "*.go" - "go.mod" - "go.sum" + +permissions: + contents: read + jobs: - ci: + # By splitting testing into its own job will ensure the needs: clause for + # static-analysis runs without waiting on the entire matrix. Jobs that run + # against macos and windows are considerably slower + test: + uses: purpleclay/github/.github/workflows/go-test.yml@main strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.os }} - steps: - - name: Set Git Line Endings - run: | - git config --global core.autocrlf false - git config --global core.eol lf - if: matrix.os == 'windows-latest' - - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup Go - uses: actions/setup-go@v4 - with: - go-version: 1.19 - - - name: Cache Go - uses: actions/cache@v3 - with: - path: | - ~/go/pkg/mod - ~/.cache/go-build - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - - name: Install Task - uses: arduino/setup-task@v1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - - - name: Test - run: task test - - - name: Build - run: task build - - # All static checks from this point should run on linux as it is the - # fastest platform - - name: Integration Test - if: matrix.os == 'ubuntu-latest' - run: task integration-test - - # Temporary workaround until the golangci-lint GitHub action supports 1.19 - - name: Install golangci-lint - if: matrix.os == 'ubuntu-latest' - run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest - - - name: Lint Code - if: matrix.os == 'ubuntu-latest' - run: task lint - - - name: misspell - if: matrix.os == 'ubuntu-latest' - uses: reviewdog/action-misspell@v1 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - locale: "UK" - exclude: | - ./go.mod - ./go.sum - ./.goreleaser.yml - ./Taskfile.yaml - ./.github/workflows/** - ./CODE_OF_CONDUCT.md - - - name: SonarCloud Scan - if: matrix.os == 'ubuntu-latest' - uses: SonarSource/sonarcloud-github-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + go-version: ${{ vars.GO_VERSION }} + secrets: + github-token: ${{ secrets.GITHUB_TOKEN }} + + lint: + uses: purpleclay/github/.github/workflows/golangci-lint.yml@main + with: + version: ${{ vars.GOLANGCI_LINT_VERSION }} + go-version: ${{ vars.GO_VERSION }} diff --git a/.github/workflows/dependabot-merge.yml b/.github/workflows/code-security.yml similarity index 63% rename from .github/workflows/dependabot-merge.yml rename to .github/workflows/code-security.yml index 72e95ba..d4a5a62 100644 --- a/.github/workflows/dependabot-merge.yml +++ b/.github/workflows/code-security.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Purple Clay +# Copyright (c) 2022 - 2023 Purple Clay # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -18,26 +18,35 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -name: dependabot-merge -on: pull_request +name: code-security +on: + push: + branches: + - main + paths: + - "**/*.go" + - "*.go" + - "go.mod" + - "go.sum" + pull_request: + branches: + - main + paths: + - "**/*.go" + - "*.go" + - "go.mod" + - "go.sum" permissions: - contents: write + actions: read + contents: read + security-events: write jobs: - dependabot: - runs-on: ubuntu-latest - if: ${{ github.actor == 'dependabot[bot]' }} - steps: - - name: Fetch Metadata - id: metadata - uses: dependabot/fetch-metadata@v1.6.0 - with: - github-token: "${{ secrets.GITHUB_TOKEN }}" - - # Will only merge if all checks pass and approvals are present - - name: Auto-merge PR - run: gh pr merge --auto --squash "$PR_URL" - env: - PR_URL: ${{ github.event.pull_request.html_url }} - GH_TOKEN: ${{ secrets.GH_AUTOMERGE }} + security-checks: + if: ${{ github.actor != 'dependabot[bot]' }} + uses: purpleclay/github/.github/workflows/code-security.yml@main + with: + go-version: ${{ vars.GO_VERSION }} + secrets: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 562e9cc..1e4ce13 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Purple Clay +# Copyright (c) 2022 - 2023 Purple Clay # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -33,6 +33,10 @@ on: - "docs/**" - "mkdocs.yml" workflow_dispatch: + +permissions: + contents: write + jobs: build-docs: runs-on: ubuntu-latest @@ -49,12 +53,12 @@ jobs: username: ${{ github.repository_owner }} password: ${{ secrets.GH_GHCR }} - - run: docker pull ghcr.io/purpleclay/mkdocs-material-insiders + - run: docker pull ghcr.io/purpleclay/mkdocs-material-insiders:${{ vars.MKDOCS_MATERIAL_INSIDERS_VERSION }} - name: Build + run: docker run --rm -i -v ${PWD}:/docs ghcr.io/purpleclay/mkdocs-material-insiders:${{ vars.MKDOCS_MATERIAL_INSIDERS_VERSION }} build env: - GH_TOKEN: ${{ secrets.GH_MKDOCS }} - run: docker run --rm -i -e GH_TOKEN=${GH_TOKEN} -v ${PWD}:/docs ghcr.io/purpleclay/mkdocs-material-insiders build + CI: true - name: HTML Test uses: wjdp/htmltest-action@master @@ -63,7 +67,7 @@ jobs: config: htmltest.yml - name: Patch mkdocs.yml Site URL - if: startsWith(github.ref, 'refs/tags/v') || ${{ github.event_name == 'workflow_dispatch' }} + if: ${{ startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch') }} uses: jacobtomlinson/gha-find-replace@v3 with: find: 'site_url: ""' @@ -72,7 +76,7 @@ jobs: include: mkdocs.yml - name: Patch mkdocs.yml Edit URI - if: startsWith(github.ref, 'refs/tags/v') || ${{ github.event_name == 'workflow_dispatch' }} + if: ${{ startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch') }} uses: jacobtomlinson/gha-find-replace@v3 with: find: 'edit_uri: ""' @@ -81,7 +85,7 @@ jobs: include: mkdocs.yml - name: Deploy documentation - if: startsWith(github.ref, 'refs/tags/v') || ${{ github.event_name == 'workflow_dispatch' }} + if: ${{ startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch') }} + run: docker run --rm -i -v ${PWD}:/docs ghcr.io/purpleclay/mkdocs-material-insiders:${{ vars.MKDOCS_MATERIAL_INSIDERS_VERSION }} gh-deploy --force env: - GH_TOKEN: ${{ secrets.GH_MKDOCS }} - run: docker run --rm -i -e GH_TOKEN=${GH_TOKEN} -v ${PWD}:/docs ghcr.io/purpleclay/mkdocs-material-insiders gh-deploy --force + CI: true diff --git a/.github/workflows/uplift.yml b/.github/workflows/nsv.yml similarity index 75% rename from .github/workflows/uplift.yml rename to .github/workflows/nsv.yml index 0f069b2..984fcbe 100644 --- a/.github/workflows/uplift.yml +++ b/.github/workflows/nsv.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Purple Clay +# Copyright (c) 2023 Purple Clay # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -18,23 +18,27 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -name: uplift +name: nsv on: workflow_dispatch: jobs: - uplift: + nsv: runs-on: ubuntu-latest + permissions: + contents: write steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - token: ${{ secrets.GH_UPLIFT }} + token: ${{ secrets.GH_NSV }} - - name: Release - uses: gembaadvantage/uplift-action@v2.0.1 + - name: Tag + uses: purpleclay/nsv-action@v1 with: - args: release --skip-changelog + token: ${{ secrets.GH_NSV }} env: - GITHUB_TOKEN: ${{ secrets.GH_UPLIFT }} + GPG_PRIVATE_KEY: "${{ secrets.GPG_PRIVATE_KEY }}" + GPG_PASSPHRASE: "${{ secrets.GPG_PASSPHRASE }}" + GPG_TRUST_LEVEL: "${{ secrets.GPG_TRUST_LEVEL }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 509919a..dee75f0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Purple Clay +# Copyright (c) 2022 - 2023 Purple Clay # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -23,16 +23,18 @@ on: push: tags: - "v*.*.*" + +permissions: + actions: read + contents: write + id-token: write + packages: write + jobs: goreleaser: runs-on: ubuntu-latest - permissions: - actions: read - contents: read - id-token: write - packages: write steps: - - name: Checkout + - name: Git Clone uses: actions/checkout@v4 with: fetch-depth: 0 @@ -40,16 +42,8 @@ jobs: - name: Setup Go uses: actions/setup-go@v4 with: - go-version: 1.19 - - - uses: actions/cache@v3 - with: - path: | - ~/go/pkg/mod - ~/.cache/go-build - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- + go-version: ${{ vars.GO_VERSION }} + cache: true - name: Install Cosign uses: sigstore/cosign-installer@main @@ -57,11 +51,35 @@ jobs: - name: Download Syft uses: anchore/sbom-action/download-syft@v0 + - uses: docker/setup-qemu-action@v3 + + - uses: docker/setup-buildx-action@v3 + + - name: DockerHub Login + uses: docker/login-action@v3 + with: + username: ${{ secrets.GH_DOCKER_USERNAME }} + password: ${{ secrets.GH_DOCKER_PASSWORD }} + + - name: GHCR Login + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: GitLab Login + uses: docker/login-action@v3 + with: + registry: registry.gitlab.com + username: ${{ secrets.GL_DOCKER_USERNAME }} + password: ${{ secrets.GL_DOCKER_PASSWORD }} + - name: GoReleaser uses: goreleaser/goreleaser-action@v5 with: version: latest - args: release --rm-dist + args: release --clean env: GITHUB_TOKEN: ${{ secrets.GH_GORELEASER }} FURY_TOKEN: ${{ secrets.GH_FURY_TOKEN }} diff --git a/.github/workflows/git-secrets.yml b/.github/workflows/shellcheck.yml similarity index 67% rename from .github/workflows/git-secrets.yml rename to .github/workflows/shellcheck.yml index 8ba4703..c904d62 100644 --- a/.github/workflows/git-secrets.yml +++ b/.github/workflows/shellcheck.yml @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Purple Clay +# Copyright (c) 2022 - 2023 Purple Clay # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -18,31 +18,31 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -name: git-secrets +name: shellcheck on: push: branches: - main + paths: + - "scripts/**" pull_request: + branches: + - main + paths: + - "scripts/**" permissions: contents: read jobs: - git-secrets: + shellcheck: runs-on: ubuntu-latest - if: ${{ github.actor != 'dependabot[bot]' }} + name: shellcheck steps: - - name: Checkout + - name: Checkout repository uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: GitGuardian - uses: GitGuardian/gg-shield-action@master - env: - GITHUB_PUSH_BEFORE_SHA: ${{ github.event.before }} - GITHUB_PUSH_BASE_SHA: ${{ github.event.base }} - GITHUB_PULL_BASE_SHA: ${{ github.event.pull_request.base.sha }} - GITHUB_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} - GITGUARDIAN_API_KEY: ${{ secrets.GH_GITGUARDIAN_KEY }} + - name: ShellCheck + uses: ludeeus/action-shellcheck@master + with: + scandir: './scripts' diff --git a/.golangci.yml b/.golangci.yml index d782e52..e209e57 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,21 +1,47 @@ -run: - timeout: 2m +# Copyright (c) 2022 - 2023 Purple Clay +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# in the Software without restriction, including without limitation the rights +# 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. linters: disable-all: true enable: - - dupl + - errname + - forbidigo + - godox + - goerr113 - gofumpt - - goimports - - gosimple - - govet - - ineffassign + - ireturn - misspell - - nakedret + - musttag - revive - - staticcheck + - tagliatelle + - thelper - unused linters-settings: - dupl: - threshold: 400 + forbidigo: + forbid: + - 'ioutil\.*' + tagliatelle: + case: + use-field-name: false + rules: + json: snake + toml: snake + yaml: snake diff --git a/LICENSE b/LICENSE index 70734d5..eee5d44 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Purple Clay +Copyright (c) 2022 - 2023 Purple Clay Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Taskfile.yaml b/Taskfile.yaml index 8d01a8d..6c85072 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -1,11 +1,26 @@ -# https://taskfile.dev +# Copyright (c) 2023 Purple Clay +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# in the Software without restriction, including without limitation the rights +# 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. version: "3" vars: - BINDIR: bin - BINNAME: dns53 - REPORTDIR: reports GIT_COMMIT: sh: git rev-parse HEAD GIT_SHA: @@ -22,58 +37,53 @@ tasks: default: desc: Runs all of the default tasks cmds: - - task: lint - - task: test - - task: integration-test - - task: build + - task: ci - build: - desc: Build the dns53 binary + ci: + desc: Run all CI tasks cmds: - - go build -ldflags '-s -w {{.LDFLAGS}}' . + - task: deps + - task: unit-test + - task: integration-test + - task: lint + - task: build - reports-dir: - desc: Creates the report directory if it doesn't exist + deps: + desc: Install all dependencies cmds: - - mkdir -p {{.REPORTDIR}} - status: - - test -d {{.REPORTDIR}} + - go mod tidy - test: - desc: Run the tests - deps: [reports-dir] + unit-test: + desc: Run the unit tests + vars: + TEST_FORMAT: '{{default "" .TEST_FORMAT}}' + COVER_PROFILE: '{{default "coverage.out" .COVER_PROFILE}}' + TEST_OPTIONS: '{{default "-short -race -vet=off -shuffle=on" .TEST_OPTIONS}}' cmds: - - go test -short -race -vet=off -p 1 -covermode=atomic -coverprofile={{.REPORTDIR}}/unittest.out -json ./... | tee {{.REPORTDIR}}/unittest.json + - go test {{.TEST_OPTIONS}} -covermode=atomic -coverprofile={{.COVER_PROFILE}} {{.TEST_FORMAT}} ./... integration-test: desc: Run the integration tests - deps: [reports-dir] + vars: + TEST_FORMAT: '{{default "" .TEST_FORMAT}}' + COVER_PROFILE: '{{default "integrationtest.out" .COVER_PROFILE}}' + TEST_OPTIONS: '{{default "-short -race -vet=off -shuffle=on" .TEST_OPTIONS}}' cmds: - - go test -run=Integration -race -vet=off -p 1 -covermode=atomic -coverprofile={{.REPORTDIR}}/integrationtest.out -json ./... | tee {{.REPORTDIR}}/integrationtest.json + - go test -run=Integration {{.TEST_OPTIONS}} -covermode=atomic -coverprofile={{.COVER_PROFILE}} {{.TEST_FORMAT}} ./... lint: - desc: Lint the code using golangci - deps: [reports-dir] + desc: Lint the code using golangci-lint + vars: + REPORT_FORMAT: '{{default "colored-line-number" .REPORT_FORMAT}}' cmds: - - golangci-lint run --timeout 5m0s --out-format checkstyle | tee {{.REPORTDIR}}/golangci-lint.xml + - golangci-lint run --timeout 5m0s --out-format {{.REPORT_FORMAT}} + + build: + desc: Build the binary + cmds: + - go build -ldflags '-s -w {{.LDFLAGS}}' . format: - desc: Format the code using Gofumpt + desc: Format the code using gofumpt cmds: - gofumpt -w -l . - - clean: - desc: Delete all artefacts from recent build - cmds: - - task: remove-binary - - task: remove-reports - - remove-binary: - desc: Delete an existing built binary - cmds: - - rm -f ./{{.BINNAME}} - - remove-reports: - desc: Delete an existing reports directory - cmds: - - rm -rf {{.REPORTDIR}} diff --git a/go.mod b/go.mod index 34be34f..348b01a 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/purpleclay/dns53 -go 1.19 +go 1.21 require ( github.com/aws/aws-sdk-go-v2 v1.21.1 diff --git a/go.sum b/go.sum index 37ae4b2..5c2d150 100644 --- a/go.sum +++ b/go.sum @@ -148,6 +148,7 @@ github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiE github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= +github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 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= @@ -180,6 +181,7 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/charmbracelet/bubbles v0.16.1 h1:6uzpAAaT9ZqKssntbvZMlksWHruQLNxg49H5WdeuYSY= github.com/charmbracelet/bubbles v0.16.1/go.mod h1:2QCp9LFlEsBQMvIYERr7Ww2H2bA7xen1idUDIzm/+Xc= github.com/charmbracelet/bubbletea v0.24.2 h1:uaQIKx9Ai6Gdh5zpTbGiWpytMU+CfsPp06RaW2cx/SY= @@ -464,6 +466,7 @@ github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= @@ -547,6 +550,7 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-containerregistry v0.5.1/go.mod h1:Ct15B4yir3PLOP5jsy0GNeYVaIZs/MK/Jz5any1wFW0= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -678,6 +682,7 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/linuxkit/virtsock v0.0.0-20201010232012-f8cee7dfc7a3/go.mod h1:3r6x7q95whyfWQpmGZTu3gk3v2YkMi05HEzl7Tf7YEo= diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index ad51fbc..0000000 --- a/sonar-project.properties +++ /dev/null @@ -1,20 +0,0 @@ -sonar.projectKey=purpleclay_dns53 -sonar.organization=purpleclay -sonar.projectDescription=Dynamic DNS within Amazon Route53. Expose your EC2 quickly, easily and privately - -sonar.sources=. -sonar.exclusions=**/*_test.go - -sonar.tests=. -sonar.test.inclusions=**/*_test.go - -sonar.coverage.exclusions=**/mock.go,**/stub.go,internal/tui/**/* - -sonar.links.homepage=https://docs.purpleclay.dev/dns53/ -sonar.links.ci=https://github.com/purpleclay/dns53/actions -sonar.links.scm=https://github.com/purpleclar/dns53 -sonar.links.issue=https://github.com/purpleclar/dns53/issues - -sonar.go.golangci-lint.reportPaths=reports/golangci-lint.xml -sonar.go.tests.reportPaths=reports/unittest.json,reports/integrationtest.json -sonar.go.coverage.reportPaths=reports/unittest.out,reports/integrationtest.out \ No newline at end of file From 2ac6d840a8768e270fa2f3fc490e196d54553ff7 Mon Sep 17 00:00:00 2001 From: purpleclay Date: Wed, 11 Oct 2023 05:44:11 +0100 Subject: [PATCH 2/6] first pass at fixing linting errors --- cmd/root.go | 10 ++-- cmd/root_test.go | 54 +++++++++---------- cmd/version.go | 6 +-- internal/ec2/ec2mock/mock.go | 10 ++-- internal/imds/imdsstub/stub.go | 22 ++++---- internal/r53/r53mock/mock.go | 10 ++-- .../tui/components/errorpanel/errorpanel.go | 2 +- .../components/filteredlist/filteredlist.go | 4 +- internal/tui/components/footer/footer.go | 4 +- 9 files changed, 63 insertions(+), 59 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 2897ed8..3dafc5d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -46,11 +46,11 @@ import ( ) const ( - longDesc = `Dynamic DNS within Amazon Route 53. Expose your EC2 quickly, easily, and privately within a Route + longDesc = `Dynamic DNS within Amazon Route 53. Expose your EC2 quickly, easily, and privately within a Route 53 Private Hosted Zone (PHZ). -Your EC2 will be exposed through a dynamically generated resource record that will automatically -be deleted when dns53 exits. Let dns53 name your resource record for you, or customise it to your needs. +Your EC2 will be exposed through a dynamically generated resource record that will automatically +be deleted when dns53 exits. Let dns53 name your resource record for you, or customise it to your needs. Built using Bubbletea 🧋` examples = ` # Launch the TUI and use the wizard to select a PHZ @@ -128,7 +128,7 @@ func (c *Command) Execute(args []string) error { rootCmd := &cobra.Command{ Use: "dns53", - Short: `Dynamic DNS within Amazon Route 53. Expose your EC2 quickly, easily and privately within a Route + Short: `Dynamic DNS within Amazon Route 53. Expose your EC2 quickly, easily and privately within a Route 53 Private Hosted Zone (PHZ)`, Long: longDesc, Example: examples, @@ -282,7 +282,7 @@ func autoAttachToZone(ctx *globalContext, name, vpc, region string) (autoAttachm region: region, } - zone, err := ctx.r53Client.ByName(ctx, "dns53") + zone, err := ctx.r53Client.ByName(ctx, name) if err != nil { return attachment, err } diff --git a/cmd/root_test.go b/cmd/root_test.go index a163264..a967b15 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -154,45 +154,45 @@ func TestCleanTagsAppendsToMap(t *testing.T) { } func TestRootCommand(t *testing.T) { - // options := []globalContextOption{ - // withIMDSClient(imds.NewFromAPI(imdsstub.New(t))), - // withSkipTea(), - // } + options := []globalContextOption{ + withIMDSClient(imds.NewFromAPI(imdsstub.New(t))), + withSkipTea(), + } - // cmd := newWithOptions(options...) - // err := cmd.Execute([]string{}) + cmd := newWithOptions(options...) + err := cmd.Execute([]string{}) - // require.NoError(t, err) - // assert.Equal(t, cmd.ctx.teaModelOptions.PhzID, "") - // assert.Equal(t, cmd.ctx.teaModelOptions.DomainName, "") + require.NoError(t, err) + assert.Equal(t, cmd.ctx.teaModelOptions.HostedZoneID, "") + assert.Equal(t, cmd.ctx.teaModelOptions.DomainName, "") } func TestRootCommandWithPrivateHostedZoneID(t *testing.T) { - // options := []globalContextOption{ - // withIMDSClient(imds.NewFromAPI(imdsstub.New(t))), - // withSkipTea(), - // } + options := []globalContextOption{ + withIMDSClient(imds.NewFromAPI(imdsstub.New(t))), + withSkipTea(), + } - // cmd := newWithOptions(options...) - // err := cmd.Execute([]string{"--phz-id", "Z00000000001"}) + cmd := newWithOptions(options...) + err := cmd.Execute([]string{"--phz-id", "Z00000000001"}) - // require.NoError(t, err) - // assert.Equal(t, cmd.ctx.teaModelOptions.PhzID, "Z00000000001") - // assert.Equal(t, cmd.ctx.teaModelOptions.DomainName, "") + require.NoError(t, err) + assert.Equal(t, cmd.ctx.teaModelOptions.HostedZoneID, "Z00000000001") + assert.Equal(t, cmd.ctx.teaModelOptions.DomainName, "") } func TestRootCommandWithCustomDomain(t *testing.T) { - // options := []globalContextOption{ - // withIMDSClient(imds.NewFromAPI(imdsstub.New(t))), - // withSkipTea(), - // } + options := []globalContextOption{ + withIMDSClient(imds.NewFromAPI(imdsstub.New(t))), + withSkipTea(), + } - // cmd := newWithOptions(options...) - // err := cmd.Execute([]string{"--domain-name", "custom.{{.Name}}"}) + cmd := newWithOptions(options...) + err := cmd.Execute([]string{"--domain-name", "custom.{{.Name}}"}) - // require.NoError(t, err) - // assert.Equal(t, cmd.ctx.teaModelOptions.PhzID, "") - // assert.Equal(t, cmd.ctx.teaModelOptions.DomainName, "custom.stub-ec2") + require.NoError(t, err) + assert.Equal(t, cmd.ctx.teaModelOptions.HostedZoneID, "") + assert.Equal(t, cmd.ctx.teaModelOptions.DomainName, "custom.stub-ec2") } func TestRootCommandAutoAttachToZone(t *testing.T) { diff --git a/cmd/version.go b/cmd/version.go index 7967024..fdf26c3 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -45,9 +45,9 @@ var ( // BuildInfo contains build time information about the application type BuildInfo struct { Version string `json:"version,omitempty"` - GitBranch string `json:"gitBranch,omitempty"` - GitCommit string `json:"gitCommit,omitempty"` - BuildDate string `json:"buildDate,omitempty"` + GitBranch string `json:"git_branch,omitempty"` + GitCommit string `json:"git_commit,omitempty"` + BuildDate string `json:"build_date,omitempty"` Go GoDetails `json:"go,omitempty"` } diff --git a/internal/ec2/ec2mock/mock.go b/internal/ec2/ec2mock/mock.go index d8c99e8..45bd5e1 100644 --- a/internal/ec2/ec2mock/mock.go +++ b/internal/ec2/ec2mock/mock.go @@ -39,14 +39,14 @@ func (m *ClientAPI) ModifyInstanceMetadataOptions(ctx context.Context, params *e return args.Get(0).(*ec2.ModifyInstanceMetadataOptionsOutput), args.Error(1) } -func New(t testing.TB) *ClientAPI { - t.Helper() +func New(tb testing.TB) *ClientAPI { + tb.Helper() mock := &ClientAPI{} - mock.Mock.Test(t) + mock.Mock.Test(tb) - t.Cleanup(func() { - mock.AssertExpectations(t) + tb.Cleanup(func() { + mock.AssertExpectations(tb) }) return mock diff --git a/internal/imds/imdsstub/stub.go b/internal/imds/imdsstub/stub.go index 57251ee..29f5e72 100644 --- a/internal/imds/imdsstub/stub.go +++ b/internal/imds/imdsstub/stub.go @@ -46,16 +46,19 @@ var defaultMetadata = map[string]string{ } type Client struct { - t testing.TB + tb testing.TB metadata map[string]string err error } -func New(t testing.TB) *Client { - return &Client{t: t, metadata: defaultMetadata} +func New(tb testing.TB) *Client { + tb.Helper() + return &Client{tb: tb, metadata: defaultMetadata} } -func NewWithoutTags(t testing.TB) *Client { +func NewWithoutTags(tb testing.TB) *Client { + tb.Helper() + // Remove all traces of tags from the default metadata noTags := defaultMetadata noTags[""] = "local-ipv4\nmac\nplacement-region\nplacement/availability-zone\ninstance-id" @@ -63,15 +66,16 @@ func NewWithoutTags(t testing.TB) *Client { delete(noTags, "tags/instance/Name") delete(noTags, "tags/instance/Environment") - return &Client{t: t, metadata: noTags} + return &Client{tb: tb, metadata: noTags} } -func NewWithError(t testing.TB, err error) *Client { - return &Client{t: t, err: err} +func NewWithError(tb testing.TB, err error) *Client { + tb.Helper() + return &Client{tb: tb, err: err} } -func (c *Client) GetMetadata(ctx context.Context, params *imds.GetMetadataInput, optFns ...func(*imds.Options)) (*imds.GetMetadataOutput, error) { - c.t.Helper() +func (c *Client) GetMetadata(_ context.Context, params *imds.GetMetadataInput, _ ...func(*imds.Options)) (*imds.GetMetadataOutput, error) { + c.tb.Helper() if c.err != nil { return &imds.GetMetadataOutput{}, c.err diff --git a/internal/r53/r53mock/mock.go b/internal/r53/r53mock/mock.go index 2512370..683dae4 100644 --- a/internal/r53/r53mock/mock.go +++ b/internal/r53/r53mock/mock.go @@ -74,14 +74,14 @@ func (m *ClientAPI) DisassociateVPCFromHostedZone(ctx context.Context, params *r return args.Get(0).(*route53.DisassociateVPCFromHostedZoneOutput), args.Error(1) } -func New(t testing.TB) *ClientAPI { - t.Helper() +func New(tb testing.TB) *ClientAPI { + tb.Helper() mock := &ClientAPI{} - mock.Mock.Test(t) + mock.Mock.Test(tb) - t.Cleanup(func() { - mock.AssertExpectations(t) + tb.Cleanup(func() { + mock.AssertExpectations(tb) }) return mock diff --git a/internal/tui/components/errorpanel/errorpanel.go b/internal/tui/components/errorpanel/errorpanel.go index 29354b5..bfab175 100644 --- a/internal/tui/components/errorpanel/errorpanel.go +++ b/internal/tui/components/errorpanel/errorpanel.go @@ -81,7 +81,7 @@ func (m Model) RaiseError(reason string, cause error) Model { return m } -func (m Model) Resize(width, height int) Model { +func (m Model) Resize(width, _ int) Model { // Restrict the error panel to be 3/4 the width of the containing component m.width = int(float32(width) * 0.75) return m diff --git a/internal/tui/components/filteredlist/filteredlist.go b/internal/tui/components/filteredlist/filteredlist.go index 7f3a1a2..7220f2a 100644 --- a/internal/tui/components/filteredlist/filteredlist.go +++ b/internal/tui/components/filteredlist/filteredlist.go @@ -29,7 +29,7 @@ import ( "github.com/purpleclay/dns53/internal/tui/theme" ) -func New(tems []list.Item, width, height int) list.Model { +func New(items []list.Item, width, height int) list.Model { delegate := list.NewDefaultDelegate() // Override the colours within the existing styles @@ -48,7 +48,7 @@ func New(tems []list.Item, width, height int) list.Model { Underline(true). Bold(true) - filteredList := list.New([]list.Item{}, delegate, width, height) + filteredList := list.New(items, delegate, width, height) // Override the colours within the existing styles filteredList.Styles.FilterPrompt = filteredList.Styles.FilterPrompt. diff --git a/internal/tui/components/footer/footer.go b/internal/tui/components/footer/footer.go index 5ec68e2..5abcd14 100644 --- a/internal/tui/components/footer/footer.go +++ b/internal/tui/components/footer/footer.go @@ -60,7 +60,7 @@ func (m Model) Init() tea.Cmd { return nil } -func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m Model) Update(_ tea.Msg) (tea.Model, tea.Cmd) { return m, nil } @@ -78,7 +78,7 @@ func (m Model) View() string { return b.String() } -func (m Model) Resize(width, height int) components.Model { +func (m Model) Resize(width, _ int) components.Model { m.width = width return m } From 8e88d193c7208b108d265d1776d9717a022b5ea6 Mon Sep 17 00:00:00 2001 From: purpleclay Date: Wed, 11 Oct 2023 05:55:28 +0100 Subject: [PATCH 3/6] fix static analysis issues --- cmd/root.go | 4 ++-- internal/tui/components/errorpanel/errorpanel.go | 4 ++-- internal/tui/components/footer/footer.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 3dafc5d..223feb8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -194,7 +194,7 @@ func (c *Command) Execute(args []string) error { p := tea.NewProgram(tui.New(c.ctx.teaModelOptions), tea.WithOutput(c.ctx.out), tea.WithAltScreen()) if !c.ctx.skipTea { - err = p.Start() + _, err = p.Run() } return err @@ -221,7 +221,7 @@ func (c *Command) Execute(args []string) error { } func awsConfig(opts *globalOptions) (aws.Config, error) { - optsFn := []func(*config.LoadOptions) error{} + var optsFn []func(*config.LoadOptions) error if opts.awsProfile != "" { optsFn = append(optsFn, config.WithSharedConfigProfile(opts.awsProfile)) } diff --git a/internal/tui/components/errorpanel/errorpanel.go b/internal/tui/components/errorpanel/errorpanel.go index bfab175..f5555de 100644 --- a/internal/tui/components/errorpanel/errorpanel.go +++ b/internal/tui/components/errorpanel/errorpanel.go @@ -43,11 +43,11 @@ func New() Model { } } -func (m Model) Init() tea.Cmd { +func (Model) Init() tea.Cmd { return nil } -func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m Model) Update(_ tea.Msg) (tea.Model, tea.Cmd) { return m, nil } diff --git a/internal/tui/components/footer/footer.go b/internal/tui/components/footer/footer.go index 5abcd14..1ab8047 100644 --- a/internal/tui/components/footer/footer.go +++ b/internal/tui/components/footer/footer.go @@ -56,7 +56,7 @@ func New(keymap help.KeyMap) Model { } } -func (m Model) Init() tea.Cmd { +func (Model) Init() tea.Cmd { return nil } From cbb4f91ceb8746969ceb642e56895a88c026347b Mon Sep 17 00:00:00 2001 From: purpleclay Date: Wed, 11 Oct 2023 06:16:47 +0100 Subject: [PATCH 4/6] fix further linter issues --- .golangci.yml | 7 +++++++ cmd/tag_test.go | 11 ----------- internal/ec2/ec2_test.go | 12 ------------ internal/tui/components/header/header.go | 6 +++--- 4 files changed, 10 insertions(+), 26 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index e209e57..8bf7eac 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -35,6 +35,13 @@ linters: - unused linters-settings: + ireturn: + allow: + - tea.Msg + - pages.Model + - bubbletea.Model + - components.Model + - error forbidigo: forbid: - 'ioutil\.*' diff --git a/cmd/tag_test.go b/cmd/tag_test.go index 84c1e41..87f1863 100644 --- a/cmd/tag_test.go +++ b/cmd/tag_test.go @@ -57,14 +57,3 @@ func TestTagsCommand(t *testing.T) { assert.Contains(t, table, "| Environment | dev | {{.Tags.Environment}} | {{index .Tags \"Environment\"}} |\n") assert.True(t, strings.HasSuffix(table, "+-------------+----------+-----------------------+-------------------------------+\n")) } - -func TestTagsCommandIMDSError(t *testing.T) { - ctx := &globalContext{ - imdsClient: imds.NewFromAPI(imdsstub.NewWithError(t, errors.New("error"))), - } - - cmd := newTagsCommand() - err := cmd.ExecuteContext(ctx) - - require.Error(t, err) -} diff --git a/internal/ec2/ec2_test.go b/internal/ec2/ec2_test.go index a69ad7f..d6ad8d1 100644 --- a/internal/ec2/ec2_test.go +++ b/internal/ec2/ec2_test.go @@ -24,7 +24,6 @@ package ec2_test import ( "context" - "errors" "testing" awsec2 "github.com/aws/aws-sdk-go-v2/service/ec2" @@ -71,14 +70,3 @@ func TestToggleInstanceMetadataTags(t *testing.T) { }) } } - -func TestToggleInstanceMetadataTagsError(t *testing.T) { - api := ec2mock.New(t) - api.On("ModifyInstanceMetadataOptions", mock.Anything, mock.Anything, mock.Anything). - Return(&awsec2.ModifyInstanceMetadataOptionsOutput{}, errors.New("error")) - - client := ec2.NewFromAPI(api) - err := client.ToggleInstanceMetadataTags(context.Background(), "12345", ec2.InstanceMetadataToggleEnabled) - - assert.Error(t, err) -} diff --git a/internal/tui/components/header/header.go b/internal/tui/components/header/header.go index 23727d2..fda4d80 100644 --- a/internal/tui/components/header/header.go +++ b/internal/tui/components/header/header.go @@ -47,11 +47,11 @@ func New(name, version, description string) Model { } } -func (m Model) Init() tea.Cmd { +func (Model) Init() tea.Cmd { return nil } -func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m Model) Update(_ tea.Msg) (tea.Model, tea.Cmd) { return m, nil } @@ -80,7 +80,7 @@ func (m Model) View() string { return b.String() } -func (m Model) Resize(width, height int) components.Model { +func (m Model) Resize(width, _ int) components.Model { m.width = width return m } From d48d4a53502259650073aa8e999dea29462703a4 Mon Sep 17 00:00:00 2001 From: purpleclay Date: Wed, 11 Oct 2023 06:26:12 +0100 Subject: [PATCH 5/6] temporarily exclude goerr113 linter errors --- cmd/imds.go | 1 + cmd/imds_test.go | 2 ++ cmd/root.go | 1 + cmd/root_test.go | 3 +++ cmd/tag_test.go | 1 - internal/imds/imdsstub/stub.go | 1 + 6 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/imds.go b/cmd/imds.go index 4f47005..b52d7b7 100644 --- a/cmd/imds.go +++ b/cmd/imds.go @@ -42,6 +42,7 @@ func (t *toggleSetting) String() string { return string(*t) } +//nolint:goerr113 func (t *toggleSetting) Set(v string) error { setting := strings.ToLower(v) diff --git a/cmd/imds_test.go b/cmd/imds_test.go index 95d8b7d..f31b690 100644 --- a/cmd/imds_test.go +++ b/cmd/imds_test.go @@ -135,6 +135,7 @@ func TestIMDSCommandFlagIsRequired(t *testing.T) { assert.Contains(t, err.Error(), `"instance-metadata-tags" not set`) } +//nolint:goerr113 func TestIMDSCommandIMDSClientError(t *testing.T) { ctx := &globalContext{ imdsClient: imds.NewFromAPI(imdsstub.NewWithError(t, errors.New("error"))), @@ -147,6 +148,7 @@ func TestIMDSCommandIMDSClientError(t *testing.T) { require.Error(t, err) } +//nolint:goerr113 func TestIMDSCommandEC2ClientError(t *testing.T) { mockEC2 := ec2mock.New(t) mockEC2.On("ModifyInstanceMetadataOptions", mock.Anything, mock.Anything, mock.Anything). diff --git a/cmd/root.go b/cmd/root.go index 223feb8..083b3fe 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -233,6 +233,7 @@ func awsConfig(opts *globalOptions) (aws.Config, error) { return config.LoadDefaultConfig(context.Background(), optsFn...) } +//nolint:goerr113 func resolveDomainName(domain string, metadata imds.Metadata) (string, error) { dmn := strings.ReplaceAll(domain, " ", "") diff --git a/cmd/root_test.go b/cmd/root_test.go index a967b15..e12919f 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -260,6 +260,7 @@ func TestRootCommandAutoAttachToZoneExisting(t *testing.T) { require.NoError(t, err) } +//nolint:goerr113 func TestRootCommandAutoAttachToZoneSearchError(t *testing.T) { errMsg := "failed to search" @@ -280,6 +281,7 @@ func TestRootCommandAutoAttachToZoneSearchError(t *testing.T) { m.AssertNotCalled(t, "AssociateVPCWithHostedZone") } +//nolint:goerr113 func TestRootCommandAutoAttachToZoneCreationError(t *testing.T) { errMsg := "failed to create" @@ -300,6 +302,7 @@ func TestRootCommandAutoAttachToZoneCreationError(t *testing.T) { require.EqualError(t, err, errMsg) } +//nolint:goerr113 func TestRootCommandAutoAttachToZoneAssociationError(t *testing.T) { errMsg := "failed to associate" diff --git a/cmd/tag_test.go b/cmd/tag_test.go index 87f1863..3659d14 100644 --- a/cmd/tag_test.go +++ b/cmd/tag_test.go @@ -24,7 +24,6 @@ package cmd import ( "bytes" - "errors" "strings" "testing" diff --git a/internal/imds/imdsstub/stub.go b/internal/imds/imdsstub/stub.go index 29f5e72..7f72479 100644 --- a/internal/imds/imdsstub/stub.go +++ b/internal/imds/imdsstub/stub.go @@ -74,6 +74,7 @@ func NewWithError(tb testing.TB, err error) *Client { return &Client{tb: tb, err: err} } +//nolint:goerr113 func (c *Client) GetMetadata(_ context.Context, params *imds.GetMetadataInput, _ ...func(*imds.Options)) (*imds.GetMetadataOutput, error) { c.tb.Helper() From cf8f9f83f1bdaf728b0bb969198420b058603491 Mon Sep 17 00:00:00 2001 From: purpleclay Date: Wed, 11 Oct 2023 06:30:57 +0100 Subject: [PATCH 6/6] remove sonarcloud links from readme --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 660bfc0..cf71380 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,6 @@ https://user-images.githubusercontent.com/106762954/200760788-f0d78147-9e3f-4f7d [![License MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](/LICENSE) [![Go Report Card](https://goreportcard.com/badge/github.com/purpleclay/dns53?style=flat-square)](https://goreportcard.com/report/github.com/purpleclay/dns53) [![Go Version](https://img.shields.io/github/go-mod/go-version/purpleclay/dns53.svg?style=flat-square)](go.mod) -[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=purpleclay_dns53&metric=coverage)](https://sonarcloud.io/summary/new_code?id=purpleclay_dns53) -[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=purpleclay_dns53&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=purpleclay_dns53) ## Documentation