diff --git a/.codeclimate.yml b/.codeclimate.yml deleted file mode 100644 index ea45cf1d1..000000000 --- a/.codeclimate.yml +++ /dev/null @@ -1,17 +0,0 @@ -version: "2" -checks: - return-statements: - config: - threshold: 6 -plugins: - gofmt: - enabled: true - golint: - enabled: true - govet: - enabled: true - -exclude_patterns: - - "!**/**.go" - - "**/*_test.go" - - "resource/resource_list.go" diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 5286f7f65..5b773c6a8 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -13,3 +13,14 @@ updates: - "aelsabbahy" open-pull-requests-limit: 0 + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + day: "saturday" + + - package-ecosystem: "pip" + directory: "/docs" + schedule: + interval: "weekly" + day: "saturday" diff --git a/.github/workflows/docker-goss.yaml b/.github/workflows/docker-goss.yaml new file mode 100644 index 000000000..78e07bdcd --- /dev/null +++ b/.github/workflows/docker-goss.yaml @@ -0,0 +1,98 @@ +name: Docker image for Goss + +on: + push: + branches: + - master + tags: + - "v*" + workflow_dispatch: + +env: + PLATFORMS: "linux/amd64,linux/arm64" + +jobs: + goss: + name: Build and push Docker image + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + security-events: write # To upload Trivy sarif files + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ghcr.io/${{ github.repository_owner }}/goss + + - name: Get latest git tag + uses: actions-ecosystem/action-get-latest-tag@v1 + id: get-latest-tag + + - name: Set short git commit SHA + run: | + calculatedSha=$(git rev-parse --short ${{ github.sha }}) + echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV + + - name: Get the current version of Go from project. + run: echo "GO_VERSION_FROM_PROJECT=$(go mod edit -json | jq -r .Go)" >> $GITHUB_ENV + + - name: Build master goss image + if: github.ref_name == 'master' + uses: docker/build-push-action@v5 + with: + build-args: | + GO_VERSION=${{ env.GO_VERSION_FROM_PROJECT }} + GOSS_VERSION=${{ steps.get-latest-tag.outputs.tag }}-${{ github.ref_name }}+${{ env.COMMIT_SHORT_SHA }} + context: . + push: true + tags: | + ghcr.io/${{ github.repository_owner }}/goss:master + labels: ${{ steps.meta.outputs.labels }} + platforms: ${{ env.PLATFORMS }} + + - name: Build release goss image + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') + uses: docker/build-push-action@v5 + with: + build-args: | + GO_VERSION=${{ env.GO_VERSION_FROM_PROJECT }} + GOSS_VERSION=${{ github.ref_name }} + context: . + push: true + tags: | + ghcr.io/${{ github.repository_owner }}/goss:latest + ghcr.io/${{ github.repository_owner }}/goss:${{ github.ref_name }} + labels: ${{ steps.meta.outputs.labels }} + platforms: ${{ env.PLATFORMS }} + + - name: Run Trivy vulnerability scanner + uses: aquasecurity/trivy-action@master + with: + image-ref: ghcr.io/${{ github.repository_owner }}/goss:master + format: "sarif" + output: "trivy-results.sarif" + + - name: Upload Trivy scan results to GitHub Security tab + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: "trivy-results.sarif" diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 6a80c4abd..f7a871e6c 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -7,7 +7,7 @@ on: pull_request: paths: - mkdocs.yml - - docs/ + - docs/** - README.md - LICENSE - extras/**/README.md @@ -20,28 +20,31 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: DavidAnson/markdownlint-cli2-action@v13 + - uses: DavidAnson/markdownlint-cli2-action@v16 with: globs: | docs/**/*.md + README.md + extras/**/README.md + .github/CONTRIBUTING.md build: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: - python-version: "3.11" + python-version: "3.12" cache: 'pip' - name: Install dependencies run: | pip install --upgrade pip - pip install --requirement docs/requirements.pip + pip install --requirement docs/requirements.txt - name: Build documentation run: mkdocs build # To remove if not using github pages - name: Upload artifact - uses: actions/upload-pages-artifact@v2 + uses: actions/upload-pages-artifact@v3 with: path: site diff --git a/.github/workflows/golangci.yaml b/.github/workflows/golangci.yaml new file mode 100644 index 000000000..dde4b4d41 --- /dev/null +++ b/.github/workflows/golangci.yaml @@ -0,0 +1,41 @@ +name: Golang ci +on: + # don't build any branch other than master (and prs) when git pushed + pull_request: {} + push: + branches: + - master + - "/^v\\d+\\.\\d+(\\.\\d+)?(-\\S*)?$/" + paths-ignore: + - "**/*.md" + +permissions: + contents: read + pull-requests: read + +jobs: + lint: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.59 + + coverage: + name: coverage + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Unit tests and coverage + run: make cov diff --git a/.github/workflows/preview-docs.yaml b/.github/workflows/preview-docs.yaml index e2aebafa7..37a47a597 100644 --- a/.github/workflows/preview-docs.yaml +++ b/.github/workflows/preview-docs.yaml @@ -5,7 +5,7 @@ on: - opened paths: - mkdocs.yml - - docs/ + - docs/** - README.md - LICENSE - extras/**/README.md diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 000000000..52977cfd6 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,16 @@ +linters: + # Disable all linters. + # Default: false + disable-all: true + # Enable specific linter + # https://golangci-lint.run/usage/linters/#enabled-by-default + enable: + # default linter + # - errcheck # there are to many failures at the moment + - gosimple + - govet + - ineffassign + - staticcheck + - unused + # custom linter + - gofmt diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 3166424d8..015eb5de8 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -16,4 +16,4 @@ mkdocs: # Optionally declare the Python requirements required to build your docs python: install: - - requirements: docs/requirements.pip + - requirements: docs/requirements.txt diff --git a/.travis.yml b/.travis.yml index 7d1886919..f18455cba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,4 @@ --- -env: - global: - - secure: IH/xOtRl9rcek+YTz1s2lv2njdV1gob0AY21/kGhqUBH2sdztQ/02CteGz5E0c+LfqoUYQglLsejVCNLXQJI39CyZRzysB1wlVOz7YIPNaOLATtMGg0/8Mb7dpeqAV1u3agIi87q3ims1EkmGE9UGNj/qL75oTXBiozEfkbcsheH3Ju9CcO0i006UlNqAG4T++l1JZ4kPmr1r5eNjRu52oWQrlxaOYpZJGnT3qjxkvxcnI/Pgiem0+2aZ7Yluu0lA7UCFWyORoDRUz4pQR3uDG4ADPG4WcpJ601LDZyWtS7EOXVBgWZX9vV9ZVx63nK5w0W8NN6PQOuz0niN9iwR+FsShrPIsh6P9wVZfGifwXK4g2FL2XMBRuZCsQfrpRY6JbnuyGeMqN53ta95y0Yv4H65UQ7bulr4Lnic4+W52G/fl1VUYX8Bts+ecUydIu+afcDZ6GkpVLEURjaek99uO5ewHH7lfVAOQv4wUP8GFUyLXJumJZHvMzyiAXsTHdUZdm+Ap8EPzWFYYnMxySU39MEkIvhfG47X6sA7zAppuoNwd8vU4ZaxSdsme2InUSalETGJZ7ohL+M/tkTMyuyq8uLMRuwscNdgcCjGaHM19NQMrv4nsPmmzTeiDRoFk2wad07Mgsjy07esxw52rs3zAsa37+h74GYFWYo523AiYjw= - language: go go: @@ -31,18 +27,9 @@ before_install: # bash from macOS is too old to have readarray. Install newer version. - if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then HOMEBREW_NO_AUTO_UPDATE=1 brew install bash; fi -install: - - ./ci/install.sh - -before_script: - - ./ci/before-build.sh - script: - ./ci/build.sh -after_script: - - ./ci/after-build.sh - deploy: provider: releases api_key: diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..93a143a3d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +ARG GO_VERSION=1.21 + +FROM docker.io/golang:${GO_VERSION}-alpine AS base + +ARG GOSS_VERSION=v0.0.0 +WORKDIR /build + +RUN --mount=target=. \ + CGO_ENABLED=0 go build \ + -ldflags "-X github.com/goss-org/goss/util.Version=${GOSS_VERSION} -s -w" \ + -o "/release/goss" \ + ./cmd/goss + +FROM alpine:3.19 + +COPY --from=base /release/* /usr/bin/ + +RUN mkdir /goss +VOLUME /goss diff --git a/Makefile b/Makefile index 6bbbb5780..a4d9008c2 100644 --- a/Makefile +++ b/Makefile @@ -35,10 +35,10 @@ htmlcov: go test -v -coverpkg=./... -coverprofile=c.out ./... go tool cover -html ./c.out - lint: $(info INFO: Starting build $@) - golint $(pkgs) || true + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59 + golangci-lint run --timeout 5m $(pkgs) || true vet: $(info INFO: Starting build $@) @@ -148,10 +148,10 @@ $(PYTHON): $(info Creating virtualenv in $(VENV)) @python -m venv $(VENV) -$(DOCS_DEPS): $(PYTHON) docs/requirements.pip +$(DOCS_DEPS): $(PYTHON) docs/requirements.txt $(info Installing dependencies) @pip install --upgrade pip - @pip install --requirement docs/requirements.pip + @pip install --requirement docs/requirements.txt @touch $(DOCS_DEPS) docs/setup: $(DOCS_DEPS) diff --git a/README.md b/README.md index 02ede20cb..cc5d40434 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ asciicast -**Note:** For testing docker containers see the [dgoss](https://github.com/goss-org/goss/tree/master/extras/dgoss) wrapper. +**Note:** For testing containers see the [dgoss](https://github.com/goss-org/goss/tree/master/extras/dgoss) wrapper. Also, user submitted wrapper scripts for Kubernetes [kgoss](https://github.com/goss-org/goss/tree/master/extras/kgoss) and Docker Compose [dcgoss](https://github.com/goss-org/goss/tree/master/extras/dcgoss). @@ -95,6 +95,10 @@ make build [Full Documentation](https://github.com/goss-org/goss/blob/e73553f9c3065ac297499dafb4f8abef6acb24ad/docs/manual.md) +## Using the container image + +[Using the Goss container image](docs/container_image.md) + ## Quick start diff --git a/ci/after-build.sh b/ci/after-build.sh deleted file mode 100755 index 8970a6375..000000000 --- a/ci/after-build.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -os_name="$(go env GOOS)" - -if [[ "${os_name}" != "windows" ]]; then - ./cc-test-reporter after-build --exit-code "${TRAVIS_TEST_RESULT}" -d -fi diff --git a/ci/before-build.sh b/ci/before-build.sh deleted file mode 100755 index 0c5475d4f..000000000 --- a/ci/before-build.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -os_name="$(go env GOOS)" - -if [[ "${os_name}" != "windows" ]]; then - ./cc-test-reporter before-build -fi diff --git a/ci/install.sh b/ci/install.sh deleted file mode 100755 index 8dea0dab3..000000000 --- a/ci/install.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -os_name="$(go env GOOS)" - -go get -u golang.org/x/lint/golint - -if [[ "${os_name}" != "windows" ]]; then - curl -L "https://codeclimate.com/downloads/test-reporter/test-reporter-latest-${os_name}-amd64" > "./cc-test-reporter" - chmod +x "./cc-test-reporter" -fi diff --git a/cmd/goss/goss.go b/cmd/goss/goss.go index 670094248..0c6a061a2 100644 --- a/cmd/goss/goss.go +++ b/cmd/goss/goss.go @@ -18,8 +18,6 @@ import ( "github.com/urfave/cli" ) -var version string - // converts a cli context into a goss Config func newRuntimeConfigFromCLI(c *cli.Context) *util.Config { cfg := &util.Config{ @@ -69,7 +67,7 @@ func timeoutFlag(value time.Duration) cli.DurationFlag { func main() { app := cli.NewApp() app.EnableBashCompletion = true - app.Version = version + app.Version = util.Version app.Name = "goss" app.Usage = "Quick and Easy server validation" app.Flags = []cli.Flag{ @@ -425,14 +423,6 @@ func addAlphaFlagIfNeeded(app *cli.App) { } } -const msgFormat string = `WARNING: goss for this platform (%q) is alpha-quality, work-in-progress and community-supported. - -You should not expect everything to work. Treat linux as the canonical behaviour to expect. - -Please see https://github.com/goss-org/goss/tree/master/docs/platform-feature-parity.md to set your expectations and see progress. -Please file issues via https://github.com/goss-org/goss/issues/new/choose -Pull requests and bug reports very welcome.` - func fatalAlphaIfNeeded(c *cli.Context) { if runtime.GOOS == "darwin" || runtime.GOOS == "windows" { if c.GlobalString("use-alpha") != "1" { diff --git a/docs/.pages b/docs/.pages index 67373453b..bed10fe4c 100644 --- a/docs/.pages +++ b/docs/.pages @@ -2,6 +2,7 @@ nav: - Home: index.md - installation.md - quickstart.md + - container_image.md - Command Reference: cli.md - The gossfile: gossfile.md - migrations.md diff --git a/docs/cli.md b/docs/cli.md index d7b1bf62e..f72b0bfb4 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -62,12 +62,12 @@ GLOBAL OPTIONS: ## Commands Commands are the actions goss can run. -- [add](#add): add a single test for a resource -- [autoadd](#autoadd): automatically add multiple tests for a resource -- [render](#render): renders and outputs the gossfile, importing all included gossfiles -- [serve](#serve): serves the gossfile validation as an HTTP endpoint on a specified address and port, +* [add](#add): add a single test for a resource +* [autoadd](#autoadd): automatically add multiple tests for a resource +* [render](#render): renders and outputs the gossfile, importing all included gossfiles +* [serve](#serve): serves the gossfile validation as an HTTP endpoint on a specified address and port, so you can use your gossfile as a health report for the host -- [validate](#validate): runs the goss test suite on your server +* [validate](#validate): runs the goss test suite on your server ### `add` @@ -123,22 +123,22 @@ A sub-command *resource type* has to be provided when running `add`. Automatically [adds](#add) all **existing** resources matching the provided argument. Will automatically add the following matching resources: -- `file` - only if argument contains `/` -- `group` -- `package` -- `port` -- `process` - Also adding any ports it's listening to (if run as root) -- `service` -- `user` +* `file` - only if argument contains `/` +* `group` +* `package` +* `port` +* `process` - Also adding any ports it's listening to (if run as root) +* `service` +* `user` Will **NOT** automatically add: -- `addr` -- `command` - for safety -- `dns` -- `http` -- `interface` -- `kernel-param` -- `mount` +* `addr` +* `command` - for safety +* `dns` +* `http` +* `interface` +* `kernel-param` +* `mount` !!! example ```console diff --git a/docs/container_image.md b/docs/container_image.md new file mode 100644 index 000000000..ba12d30f7 --- /dev/null +++ b/docs/container_image.md @@ -0,0 +1,53 @@ +# Goss container image + +## Dockerfiles + +* [latest](https://github.com/goss-org/goss/blob/master/Dockerfile) + +## Using the base image + +This is a simple alpine image with Goss preinstalled on it. +Can be used as a base image for your projects to allow for easy health checking. + +### Mount example + +Create the container + +```sh +docker run --name goss ghcr.io/goss-org/goss goss +``` + +Create your container and mount goss + +```sh +docker run --rm -it --volumes-from goss --name weby nginx +``` + +Run goss inside your container + +```sh +docker exec weby /goss/goss autoadd nginx +``` + +### HEALTHCHECK example + +```dockerfile +FROM ghcr.io/goss-org/goss:latest + +COPY goss/ /goss/ +HEALTHCHECK --interval=1s --timeout=6s CMD goss -g /goss/goss.yaml validate + +# your stuff.. +``` + +### Startup delay example + +```dockerfile +FROM ghcr.io/goss-org/goss:latest + +COPY goss/ /goss/ + +# Alternatively, the -r option can be set +# using the GOSS_RETRY_TIMEOUT env variable +CMD goss -g /goss/goss.yaml validate -r 5m && exec real_comand.. +``` diff --git a/docs/containers/docker-compose.md b/docs/containers/docker-compose.md index 9219adf97..3955acc5a 100644 --- a/docs/containers/docker-compose.md +++ b/docs/containers/docker-compose.md @@ -1 +1,2 @@ + --8<-- "extras/dcgoss/README.md" diff --git a/docs/containers/docker.md b/docs/containers/docker.md index 07daf5c87..e17d0e635 100644 --- a/docs/containers/docker.md +++ b/docs/containers/docker.md @@ -1 +1,2 @@ + --8<-- "extras/dgoss/README.md" diff --git a/docs/containers/kubernetes.md b/docs/containers/kubernetes.md index b696d2f54..83a0bbb53 100644 --- a/docs/containers/kubernetes.md +++ b/docs/containers/kubernetes.md @@ -1 +1,2 @@ + --8<-- "extras/kgoss/README.md" diff --git a/docs/contributing.md b/docs/contributing.md index 0c7bc9cbf..1a1055c5e 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -1 +1,2 @@ + --8<-- ".github/CONTRIBUTING.md" diff --git a/docs/gossfile.md b/docs/gossfile.md index 31f259adf..a463c2ceb 100644 --- a/docs/gossfile.md +++ b/docs/gossfile.md @@ -918,6 +918,27 @@ Available functions: `toUpper` : Changes piped input to UPPERCASE + `findStringSubmatch regex string` + : Returns map[string]interface{} with the names of the parenthesized subexpressions, like `(?P[a-z])` + + {{ $regexDBrc := "\\'mysql:\\/\\/(?P[a-z0-9]+):(?P[a-z0-9]+)@localhost\\/(?Proundcube_[a-z0-9]+)\\';"}} + + {{ $rcConf := readFile /home/user/roundcube/config.inc.php | findStringSubmatch $regexDBrc }} + {{ $UserDBrc := get $rcConf "login" }} + {{ $PassDBrc := get $rcConf "password" }} + {{ $DBrc := get $rcConf "database" }} + + If not exists named parenthesized subexps, returns stringfied array string: + + {{ $regexDBrc := "\\'mysql:\\/\\/([a-z0-9]+):([a-z0-9]+)@localhost\\/(roundcube_[a-z0-9]+)\\';"}} + + {{ $rcConf := readFile /home/user/roundcube/config.inc.php | findStringSubmatch $regexDBrc }} + {{ $UserDBrc := get $rcConf "1" }} + {{ $PassDBrc := get $rcConf "2" }} + {{ $DBrc := get $rcConf "3" }} + + NOTE: stringfied string array begins with "1" ("0" is all the string matched) + !!! warning gossfiles containing text/template `{{}}` controls will no longer work with `goss add/autoadd`. diff --git a/docs/license.md b/docs/license.md index f409d4523..e47f1b546 100644 --- a/docs/license.md +++ b/docs/license.md @@ -1 +1,2 @@ + --8<-- "LICENSE" diff --git a/docs/migrations.md b/docs/migrations.md index f6981f4c0..9b4ef5ec4 100644 --- a/docs/migrations.md +++ b/docs/migrations.md @@ -16,8 +16,8 @@ user: - root ``` -Goss v0.4.x, will fail with the above as group "root" is only in the slice once. However, with goss v0.4.x the array may contain -matchers. The test below is valid for v0.4.x but not valid for v0.3.x +Goss v0.4.x, will fail with the above as group "root" is only in the slice once. However, with goss v0.4.x the array may +contain matchers. The test below is valid for v0.4.x but not valid for v0.3.x ```yaml user: diff --git a/docs/requirements.pip b/docs/requirements.txt similarity index 58% rename from docs/requirements.pip rename to docs/requirements.txt index cfa4c09da..7e1b447f5 100644 --- a/docs/requirements.pip +++ b/docs/requirements.txt @@ -1,6 +1,6 @@ -mkdocs-material==9.5.3 +mkdocs-material==9.5.23 mkdocs-macros-plugin==1.0.5 mkdocs-awesome-pages-plugin==2.9.2 +mkdocs-exclude==1.0.2 mdx-breakless-lists==1.0.1 -pygments==2.17.2 - +pygments==2.18.0 diff --git a/extras/dcgoss/README.md b/extras/dcgoss/README.md index 06d64498a..9eedf65ec 100644 --- a/extras/dcgoss/README.md +++ b/extras/dcgoss/README.md @@ -1,6 +1,7 @@ # dcgoss -dcgoss is a convenience wrapper around goss that aims to bring the simplicity of goss to docker-compose managed containers. It is based on `dgoss`. +dcgoss is a convenience wrapper around goss that aims to bring the simplicity of goss to docker-compose managed +containers. It is based on `dgoss`. ## Usage @@ -8,7 +9,9 @@ dcgoss is a convenience wrapper around goss that aims to bring the simplicity of ### Run -Run is used to validate a docker container defined in `docker-compose.yml`. It expects both a `docker-compose.yml` and `goss.yaml` file to exist in the directory it was invoked from. Container configuration is used from the compose file, for example: +Run is used to validate a docker container defined in `docker-compose.yml`. It expects both a `docker-compose.yml` +and `goss.yaml` file to exist in the directory it was invoked from. Container configuration is used from the +compose file, for example: **run:** @@ -43,7 +46,7 @@ The following environment variables can be set to change the behavior of dcgoss. #### DEBUG Enables debug output of `dcgoss`. - + When running in debug mode, the tmp dir with the container output will not be cleaned up. **Default:** empty @@ -54,7 +57,7 @@ When running in debug mode, the tmp dir with the container output will not be cl #### GOSS_PATH -Location of the goss binary to use. +Location of the goss binary to use. **Default:** `$(which goss)` @@ -104,8 +107,9 @@ If unset (or empty), the `--vars` flag is omitted, which is the normal behavior. #### GOSS_FILES_STRATEGY -Strategy used for copying goss files into the docker container. -If set to `'mount'` a volume with goss files is mounted and log output is streamed into the container as `/goss/docker_output.log` file. +Strategy used for copying goss files into the docker container. +If set to `'mount'` a volume with goss files is mounted and log output is streamed into the container as +`/goss/docker_output.log` file. Other strategy is `'cp'` which uses `'docker cp'` command to copy goss files into docker container. With the `'cp'` strategy you lose the ability to write tests or waits against the docker output. The `'cp'` strategy is required especially when docker daemon is not on the local machine. @@ -114,7 +118,8 @@ The `'cp'` strategy is required especially when docker daemon is not on the loca ## Debugging test runs -When debugging test execution its beneficual to set both `DEBUG=true` and `GOSS_WAIT_OPTS=-r 60s -s 5s` (without the redirect to `/dev/null`). +When debugging test execution its beneficual to set both `DEBUG=true` and `GOSS_WAIT_OPTS=-r 60s -s 5s` +(without the redirect to `/dev/null`). **Example:** diff --git a/extras/dgoss/README.md b/extras/dgoss/README.md index beedc739e..ebe7fd3fd 100644 --- a/extras/dgoss/README.md +++ b/extras/dgoss/README.md @@ -1,12 +1,14 @@ # dgoss -dgoss is a convenience wrapper around goss that aims to bring the simplicity of goss to docker containers. +dgoss is a convenience wrapper around goss that aims to bring the simplicity of goss to containers. ## Examples and Tutorials -* [blog tutorial](https://medium.com/@aelsabbahy/tutorial-how-to-test-your-docker-image-in-half-a-second-bbd13e06a4a9) - Introduction to dgoss tutorial +* [blog tutorial](https://medium.com/@aelsabbahy/tutorial-how-to-test-your-docker-image-in-half-a-second-bbd13e06a4a9) - +Introduction to dgoss tutorial * [video tutorial](https://youtu.be/PEHz5EnZ-FM) - Same as above, but in video format -* [dgoss-examples](https://github.com/aelsabbahy/dgoss-examples) - Repo containing examples of using dgoss to validate docker images +* [dgoss-examples](https://github.com/aelsabbahy/dgoss-examples) - Repo containing examples of using dgoss to validate +container images ## Installation @@ -29,6 +31,9 @@ curl -L https://github.com/goss-org/goss/releases/download/v0.3.6/goss-linux-amd # Set your GOSS_PATH to the above location export GOSS_PATH=~/Downloads/goss-linux-amd64 +# Set DGOSS_TEMP_DIR to the tmp directory in your home, since /tmp is private on Mac OSX +export DGOSS_TEMP_DIR=~/tmp + # Use dgoss dgoss edit ... dgoss run ... @@ -40,9 +45,10 @@ dgoss run ... ### Run -Run is used to validate a docker container. +Run is used to validate a container. It expects a `./goss.yaml` file to exist in the directory it was invoked from. -In most cases one can just substitute the docker command for the dgoss command, for example: +In most cases one can just substitute the runtime command (`docker` or `podman`) +for the dgoss command, for example: **run:** @@ -56,13 +62,15 @@ In most cases one can just substitute the docker command for the dgoss command, * Run the container with the flags you specified. * Stream the containers log output into the container as `/goss/docker_output.log` - * This allows writing tests or waits against the docker output + * This allows writing tests or waits against the container output * (optional) Run `goss` with `$GOSS_WAIT_OPTS` if `./goss_wait.yaml` file exists in the current dir * Run `goss` with `$GOSS_OPTS` using `./goss.yaml` ### Edit -Edit will launch a docker container, install goss, and drop the user into an interactive shell. Once the user quits the interactive shell, any `goss.yaml` or `goss_wait.yaml` are copied out into the current directory. This allows the user to leverage the `goss add|autoadd` commands to write tests as they would on a regular machine. +Edit will launch a container, install goss, and drop the user into an interactive shell. +Once the user quits the interactive shell, any `goss.yaml` or `goss_wait.yaml` are copied out into the current directory. +This allows the user to leverage the `goss add|autoadd` commands to write tests as they would on a regular machine. **Example:** @@ -96,23 +104,39 @@ Time to sleep after running container (and optionally `goss_wait.yaml`) and befo Location of the goss yaml files. (Default: `.`) +#### GOSS_ADDITIONAL_COPY_PATH + +Colon-seperated list of additional directories to copy to container. + +By default dgoss copies `goss.yaml` from the current working directory and +nothing else. You may need other files like scripts and configurations copied +as well. Specify `GOSS_ADDITIONAL_COPY_PATH` similar to `$PATH` as colon seperated +list of directories for each additional directory you'd like to recursively copy. +These will be copied as directories next to `goss.yaml` in the temporary +directory `DGOSS_TEMP_DIR`. (Default: `''`) + #### GOSS_VARS The name of the variables file relative to `GOSS_FILES_PATH` to copy into the -docker container and use for valiation (i.e. `dgoss run`) and copy out of the -docker container when writing tests (i.e. `dgoss edit`). If set, the +container and use for valiation (i.e. `dgoss run`) and copy out of the +container when writing tests (i.e. `dgoss edit`). If set, the `--vars` flag is passed to `goss validate` commands inside the container. If unset (or empty), the `--vars` flag is omitted, which is the normal behavior. (Default: `''`). #### GOSS_FILES_STRATEGY -Strategy used for copying goss files into the docker container. If set to `'mount'` a volume with goss files is mounted and log output is streamed into the container as `/goss/docker_output.log` file. Other strategy is `'cp'` which uses `'docker cp'` command to copy goss files into docker container. With the `'cp'` strategy you lose the ability to write tests or waits against the docker output. The `'cp'` strategy is required especially when docker daemon is not on the local machine. +Strategy used for copying goss files into the container. If set to `'mount'` a volume with goss files is mounted +and log output is streamed into the container as `/goss/docker_output.log` file. Other strategy is `'cp'` which uses +`'docker cp'` command to copy goss files into container. With the `'cp'` strategy you lose the ability to write +tests or waits against the container output. The `'cp'` strategy is required especially when container daemon is not on the +local machine. (Default `'mount'`) #### CONTAINER_LOG_OUTPUT -Location of the file that contains tested container logs. Logs are retained only if the variable is set to a non-empty string. (Default `''`) +Location of the file that contains tested container logs. Logs are retained only if the variable is set to a non-empty +string. (Default `''`) #### DGOSS_TEMP_DIR @@ -120,4 +144,5 @@ Location of the temporary directory used by dgoss. (Default `'$(mktemp -d /tmp/t #### CONTAINER_RUNTIME -Container runtime to use - `docker` or `podman`. Defaults to `docker`. Note that `podman` requires a run command to keep the container running. This defaults to `sleep infinity` in case only an image is passed to `dgoss` commands. +Container runtime to use - `docker` or `podman`. Defaults to `docker`. Note that `podman` requires a run command to keep +the container running. This defaults to `sleep infinity` in case only an image is passed to `dgoss` commands. diff --git a/extras/dgoss/dgoss b/extras/dgoss/dgoss index deefb7a74..962d429c9 100755 --- a/extras/dgoss/dgoss +++ b/extras/dgoss/dgoss @@ -36,6 +36,12 @@ run(){ [[ -e "${GOSS_FILES_PATH}/${GOSS_FILE:-goss.yaml}" ]] && cp "${GOSS_FILES_PATH}/${GOSS_FILE:-goss.yaml}" "$tmp_dir/goss.yaml" && chmod 644 "$tmp_dir/goss.yaml" [[ -e "${GOSS_FILES_PATH}/goss_wait.yaml" ]] && cp "${GOSS_FILES_PATH}/goss_wait.yaml" "$tmp_dir" && chmod 644 "$tmp_dir/goss_wait.yaml" [[ -n "${GOSS_VARS}" ]] && [[ -e "${GOSS_FILES_PATH}/${GOSS_VARS}" ]] && cp "${GOSS_FILES_PATH}/${GOSS_VARS}" "$tmp_dir" && chmod 644 "$tmp_dir/${GOSS_VARS}" + if [ -n "$GOSS_ADDITIONAL_COPY_PATH" ]; then + for dir in "$(echo "$GOSS_ADDITIONAL_COPY_PATH" | sed 's/:/ /g')"; do + cp -r ${dir} "${tmp_dir}/" + chmod -R 755 "$tmp_dir/$(basename ${dir})" + done + fi # Switch between mount or cp files strategy GOSS_FILES_STRATEGY=${GOSS_FILES_STRATEGY:="mount"} diff --git a/extras/kgoss/README.md b/extras/kgoss/README.md index ae3cbb047..eb9f14d47 100644 --- a/extras/kgoss/README.md +++ b/extras/kgoss/README.md @@ -23,10 +23,10 @@ You can manually install kgoss and goss by going through the Web UI, getting the files and putting them in the right path. To get each of them: * **kgoss**: Run `curl -sSLO - https://raw.githubusercontent.com/goss-org/goss/master/extras/kgoss/kgoss`. + https://raw.githubusercontent.com/goss-org/goss/master/extras/kgoss/kgoss`. * **goss**: Download the `goss-linux-amd64` asset from and rename it `goss`. Place it - in your HOME directory, e.g. C:\\Users\\ on Windows; or set the + in your HOME directory, e.g. `C:\Users\` on Windows; or set the environment variable `GOSS_PATH` to its path. ### Automatic / CLI @@ -96,7 +96,7 @@ To find `goss.yaml` in another directory specify that directory's path in `GOSS_ ### Run -The `run` command is used to validate a docker container. It expects a +The `run` command is used to validate a container. It expects a `./goss.yaml` file to exist in the directory it was invoked from. **Example:** @@ -111,7 +111,7 @@ The `run` command is used to validate a docker container. It expects a ### Edit -Edit will launch a docker container, install goss, and drop the user into an +Edit will launch a container, install goss, and drop the user into an interactive shell. Once the user quits the interactive shell, any `goss.yaml` or `goss_wait.yaml` are copied out into the current directory. This allows the user to leverage the `goss add|autoadd` commands to write tests as they would diff --git a/go.mod b/go.mod index 497d77921..959bbba8f 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/miekg/dns v1.1.58 github.com/moby/sys/mountinfo v0.7.1 github.com/oleiade/reflections v1.0.1 - github.com/onsi/gomega v1.31.1 + github.com/onsi/gomega v1.33.1 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/pmezard/go-difflib v1.0.0 github.com/prometheus/client_golang v1.19.0 @@ -49,12 +49,13 @@ require ( github.com/spf13/cast v1.6.0 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect - golang.org/x/crypto v0.21.0 // indirect + golang.org/x/crypto v0.23.0 // indirect golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect - golang.org/x/mod v0.16.0 // indirect - golang.org/x/net v0.22.0 // indirect - golang.org/x/sys v0.18.0 // indirect - golang.org/x/text v0.14.0 // indirect - golang.org/x/tools v0.18.0 // indirect + golang.org/x/mod v0.17.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect + golang.org/x/tools v0.20.0 // indirect google.golang.org/protobuf v1.33.0 // indirect ) diff --git a/go.sum b/go.sum index 683010c5a..6f024b4cc 100644 --- a/go.sum +++ b/go.sum @@ -26,14 +26,14 @@ github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= -github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= -github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= -github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= -github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= +github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 h1:k7nVchz72niMH6YLQNvHSdIE7iqsQxK1P41mySCvssg= +github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -70,10 +70,10 @@ github.com/moby/sys/mountinfo v0.7.1 h1:/tTvQaSJRr2FshkhXiIpux6fQ2Zvc4j7tAhMTStA github.com/moby/sys/mountinfo v0.7.1/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI= github.com/oleiade/reflections v1.0.1 h1:D1XO3LVEYroYskEsoSiGItp9RUxG6jWnCVvrqH0HHQM= github.com/oleiade/reflections v1.0.1/go.mod h1:rdFxbxq4QXVZWj0F+e9jqjDkc7dbp97vkRixKo2JR60= -github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY= -github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM= -github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo= -github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0= +github.com/onsi/ginkgo/v2 v2.17.2 h1:7eMhcy3GimbsA3hEnVKdw/PQM9XN9krpKVXsZdph0/g= +github.com/onsi/ginkgo/v2 v2.17.2/go.mod h1:nP2DPOQoNsQmsVyv5rDA8JkXQoCs6goXIvr/PRJ1eCc= +github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk= +github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0= github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -82,8 +82,6 @@ github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7km github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k= github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos= github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8= -github.com/prometheus/common v0.49.0 h1:ToNTdK4zSnPVJmh698mGFkDor9wBI/iGaJy5dbH1EgI= -github.com/prometheus/common v0.49.0/go.mod h1:Kxm+EULxRbUkjGU6WFsQqo3ORzB4tyKvlWFOE9mB2sE= github.com/prometheus/common v0.50.0 h1:YSZE6aa9+luNa2da6/Tik0q0A5AbR+U003TItK57CPQ= github.com/prometheus/common v0.50.0/go.mod h1:wHFBCEVWVmHMUpg7pYcOm2QUR/ocQdYSJVQJKnHc3xQ= github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= @@ -124,25 +122,23 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= -golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= -golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ= golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= -golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= -golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= -golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= -golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= -golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -151,8 +147,8 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= @@ -160,16 +156,14 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= -golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= +golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY= +golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= -google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/integration-tests/Dockerfile_alpine3 b/integration-tests/Dockerfile_alpine3 index 153bc0c68..c573021ee 100644 --- a/integration-tests/Dockerfile_alpine3 +++ b/integration-tests/Dockerfile_alpine3 @@ -1,9 +1,10 @@ -FROM alpine:3.12 +FROM alpine:3.19 MAINTAINER Ahmed # install apache2 and remove un-needed services RUN apk update && \ - apk add openrc apache2 bash ca-certificates tinyproxy && \ + apk add --no-cache openrc apache2=2.4.59-r0 bash ca-certificates tinyproxy && \ + sed -i 's/Listen 80/Listen 0.0.0.0:80/g' /etc/apache2/httpd.conf && \ rc-update add apache2 && \ rc-update add tinyproxy && \ rm -rf /etc/init.d/networking /etc/init.d/hwdrivers /var/cache/apk/* /tmp/* diff --git a/integration-tests/Dockerfile_alpine3.md5 b/integration-tests/Dockerfile_alpine3.md5 index 0526fed52..f4bdce743 100644 --- a/integration-tests/Dockerfile_alpine3.md5 +++ b/integration-tests/Dockerfile_alpine3.md5 @@ -1 +1 @@ -f2b97c4629a92aa7f9b378b49f6e1b42 Dockerfile_alpine3 +f9c8c187e94693c4625a8c8d01fae3bf Dockerfile_alpine3 diff --git a/integration-tests/Dockerfile_trusty.md5 b/integration-tests/Dockerfile_trusty.md5 index 7e049058a..5a2c288f6 100644 --- a/integration-tests/Dockerfile_trusty.md5 +++ b/integration-tests/Dockerfile_trusty.md5 @@ -1 +1 @@ -5117819dc7907aa1100e2ff0f2edb68f Dockerfile_trusty +ac8c8df3415c0eecdbedc322480e696e Dockerfile_trusty diff --git a/integration-tests/goss/alpine3/goss-aa-expected.yaml b/integration-tests/goss/alpine3/goss-aa-expected.yaml index 2d95f3e6b..ea7c1180b 100644 --- a/integration-tests/goss/alpine3/goss-aa-expected.yaml +++ b/integration-tests/goss/alpine3/goss-aa-expected.yaml @@ -2,7 +2,7 @@ package: apache2: installed: true versions: - - 2.4.46-r1 + - 2.4.59-r0 service: apache2: enabled: true diff --git a/integration-tests/goss/alpine3/goss-expected.yaml b/integration-tests/goss/alpine3/goss-expected.yaml index 0953e91d8..b3fc9f83e 100644 --- a/integration-tests/goss/alpine3/goss-expected.yaml +++ b/integration-tests/goss/alpine3/goss-expected.yaml @@ -13,7 +13,7 @@ package: apache2: installed: true versions: - - 2.4.46-r1 + - 2.4.59-r0 foobar: installed: false vim-tiny: diff --git a/integration-tests/goss/goss-shared.yaml b/integration-tests/goss/goss-shared.yaml index 7966a7167..220ec4e8c 100644 --- a/integration-tests/goss/goss-shared.yaml +++ b/integration-tests/goss/goss-shared.yaml @@ -204,7 +204,9 @@ http: request-headers: - "Foo: bar" headers: ["Content-Type: application/json"] - body: ['"Foo": "bar"'] + body: + - '"Foo": "bar"' + - '"User-Agent": "goss/0.0.0"' http://httpbin/headers?host: status: 200 timeout: 60000 diff --git a/integration-tests/goss/vars.yaml b/integration-tests/goss/vars.yaml index 6ad4e545b..3b2ec891e 100644 --- a/integration-tests/goss/vars.yaml +++ b/integration-tests/goss/vars.yaml @@ -2,7 +2,7 @@ alpine3: proxy: http://127.0.0.1:8888 packages: - apache2: "2.4.46-r1" + apache2: "2.4.59-r0" services: apache2: [sysinit] arch: diff --git a/matchers/have_patterns.go b/matchers/have_patterns.go index fd7c92897..cf2bcd139 100644 --- a/matchers/have_patterns.go +++ b/matchers/have_patterns.go @@ -146,14 +146,6 @@ func (m *HavePatternsMatcher) NegatedFailureResult(actual interface{}) MatcherRe } } -func appendMissingStrings(message string, missingElements []string) string { - if len(missingElements) == 0 { - return message - } - return fmt.Sprintf("%s\nthe missing elements were\n%s", message, - format.Object(missingElements, 1)) -} - type patternMatcher interface { Match(string) bool Pattern() string diff --git a/matchers/type_conversion.go b/matchers/type_conversion.go index 0d425bb4f..29fb96db8 100644 --- a/matchers/type_conversion.go +++ b/matchers/type_conversion.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "strconv" "strings" @@ -108,7 +107,7 @@ func (t ReaderToString) Transform(i interface{}) (interface{}, error) { return nil, fmt.Errorf("Expected io.reader, Got:%s", format.Object(i, 1)) } - b, err := ioutil.ReadAll(r) + b, err := io.ReadAll(r) if err != nil { return "", err } diff --git a/mkdocs.yml b/mkdocs.yml index 547aaaa90..7156db5e6 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -46,6 +46,9 @@ plugins: - awesome-pages - macros: render_by_default: false + - exclude: + glob: + - requirements.txt markdown_extensions: - abbr @@ -78,14 +81,12 @@ markdown_extensions: check_paths: true - pymdownx.superfences -copyright: Copyright © 2015 - 2023 Ahmed Elsabbahy +copyright: Copyright © 2015 - 2024 Ahmed Elsabbahy extra: social: - icon: fontawesome/brands/github - link: https://github.com/gooss-org/goss - - icon: simple/codeclimate - link: https://codeclimate.com/github/goss-org/goss + link: https://github.com/goss-org/goss - icon: simple/travisci link: https://travis-ci.org/goss-org/goss - icon: fontawesome/brands/medium diff --git a/outputs/json.go b/outputs/json.go index 0d7063d0c..c2413aaf4 100644 --- a/outputs/json.go +++ b/outputs/json.go @@ -24,8 +24,7 @@ func (r Json) ValidOptions() []*formatOption { func (r Json) Output(w io.Writer, results <-chan []resource.TestResult, outConfig util.OutputConfig) (exitCode int) { - var pretty bool - pretty = util.IsValueInList(foPretty, outConfig.FormatOptions) + var pretty bool = util.IsValueInList(foPretty, outConfig.FormatOptions) includeRaw := !util.IsValueInList(foExcludeRaw, outConfig.FormatOptions) sort := util.IsValueInList(foSort, outConfig.FormatOptions) diff --git a/outputs/junit.go b/outputs/junit.go index 3e7de6ead..d50e3677e 100644 --- a/outputs/junit.go +++ b/outputs/junit.go @@ -34,8 +34,7 @@ func (r JUnit) Output(w io.Writer, results <-chan []resource.TestResult, // ISO8601 timeformat timestamp := time.Now().Format(time.RFC3339) - var summary map[int]string - summary = make(map[int]string) + var summary map[int]string = make(map[int]string) var startTime time.Time var endTime time.Time diff --git a/outputs/nagios.go b/outputs/nagios.go index d91776dba..2940d2235 100644 --- a/outputs/nagios.go +++ b/outputs/nagios.go @@ -31,8 +31,7 @@ func (r Nagios) Output(w io.Writer, results <-chan []resource.TestResult, var startTime time.Time var endTime time.Time - var summary map[int]string - summary = make(map[int]string) + var summary map[int]string = make(map[int]string) for resultGroup := range results { for _, testResult := range resultGroup { diff --git a/outputs/rspecish.go b/outputs/rspecish.go index cdeae891f..7fb5f2f9f 100644 --- a/outputs/rspecish.go +++ b/outputs/rspecish.go @@ -43,15 +43,15 @@ func (r Rspecish) Output(w io.Writer, results <-chan []resource.TestResult, switch testResult.Result { case resource.SUCCESS: logTrace("TRACE", "SUCCESS", testResult, false) - fmt.Fprintf(w, green(".")) + fmt.Fprint(w, green(".")) case resource.SKIP: logTrace("TRACE", "SKIP", testResult, false) - fmt.Fprintf(w, yellow("S")) + fmt.Fprint(w, yellow("S")) failedOrSkippedGroup = append(failedOrSkippedGroup, testResult) skipped++ case resource.FAIL: logTrace("TRACE", "FAIL", testResult, false) - fmt.Fprintf(w, red("F")) + fmt.Fprint(w, red("F")) failedOrSkippedGroup = append(failedOrSkippedGroup, testResult) failed++ } diff --git a/outputs/tap.go b/outputs/tap.go index 341e2a0ef..a5d6166ca 100644 --- a/outputs/tap.go +++ b/outputs/tap.go @@ -27,8 +27,7 @@ func (r Tap) Output(w io.Writer, results <-chan []resource.TestResult, testCount := 0 failed := 0 - var summary map[int]string - summary = make(map[int]string) + var summary map[int]string = make(map[int]string) for resultGroup := range results { for _, testResult := range resultGroup { diff --git a/release-build.sh b/release-build.sh index 0e1f7bfbb..2922fdac9 100755 --- a/release-build.sh +++ b/release-build.sh @@ -22,7 +22,7 @@ fi output="${output_dir}/${output_fname}" GOOS="${os}" GOARCH="${arch}" CGO_ENABLED=0 go build \ - -ldflags "-X main.version=${version_stamp} -s -w" \ + -ldflags "-X github.com/goss-org/goss/util.Version=${version_stamp} -s -w" \ -o "${output}" \ github.com/goss-org/goss/cmd/goss diff --git a/resource/addr.go b/resource/addr.go index 2347583e9..f98eb630f 100644 --- a/resource/addr.go +++ b/resource/addr.go @@ -20,6 +20,8 @@ type Addr struct { Skip bool `json:"skip,omitempty" yaml:"skip,omitempty"` } +type idKey struct{} + const ( AddrResourceKey = "addr" AddResourceName = "Addr" @@ -51,7 +53,7 @@ func (a *Addr) GetAddress() string { } func (a *Addr) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", a.ID()) + ctx := context.WithValue(context.Background(), idKey{}, a.ID()) skip := a.Skip if a.Timeout == 0 { diff --git a/resource/command.go b/resource/command.go index 79a1671e7..365867d24 100644 --- a/resource/command.go +++ b/resource/command.go @@ -49,7 +49,7 @@ func (c *Command) GetExec() string { } func (c *Command) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", c.ID()) + ctx := context.WithValue(context.Background(), idKey{}, c.ID()) skip := c.Skip if c.Timeout == 0 { diff --git a/resource/dns.go b/resource/dns.go index bd3274d99..6cd114002 100644 --- a/resource/dns.go +++ b/resource/dns.go @@ -52,7 +52,7 @@ func (d *DNS) GetResolve() string { } func (d *DNS) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", d.ID()) + ctx := context.WithValue(context.Background(), idKey{}, d.ID()) skip := d.Skip if d.Timeout == 0 { d.Timeout = 500 diff --git a/resource/file.go b/resource/file.go index 97356a193..6b3c94c4c 100644 --- a/resource/file.go +++ b/resource/file.go @@ -61,7 +61,7 @@ func (f *File) GetPath() string { } func (f *File) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", f.ID()) + ctx := context.WithValue(context.Background(), idKey{}, f.ID()) skip := f.Skip sysFile := sys.NewFile(ctx, f.GetPath(), sys, util.Config{}) diff --git a/resource/group.go b/resource/group.go index 7ca928108..cfd71a3a3 100644 --- a/resource/group.go +++ b/resource/group.go @@ -47,7 +47,7 @@ func (g *Group) GetGroupname() string { } func (g *Group) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", g.ID()) + ctx := context.WithValue(context.Background(), idKey{}, g.ID()) skip := g.Skip sysgroup := sys.NewGroup(ctx, g.GetGroupname(), sys, util.Config{}) diff --git a/resource/http.go b/resource/http.go index b9a1006de..bbd820098 100644 --- a/resource/http.go +++ b/resource/http.go @@ -63,7 +63,7 @@ func (r *HTTP) getURL() string { } func (u *HTTP) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", u.ID()) + ctx := context.WithValue(context.Background(), idKey{}, u.ID()) skip := u.Skip if u.Timeout == 0 { u.Timeout = 5000 diff --git a/resource/interface.go b/resource/interface.go index 14921d133..68e3fa3d6 100644 --- a/resource/interface.go +++ b/resource/interface.go @@ -50,7 +50,7 @@ func (i *Interface) GetName() string { } func (i *Interface) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", i.ID()) + ctx := context.WithValue(context.Background(), idKey{}, i.ID()) skip := i.Skip sysInterface := sys.NewInterface(ctx, i.GetName(), sys, util.Config{}) diff --git a/resource/kernel_param.go b/resource/kernel_param.go index 494597a96..7f50270bd 100644 --- a/resource/kernel_param.go +++ b/resource/kernel_param.go @@ -50,7 +50,7 @@ func (k *KernelParam) GetName() string { } func (k *KernelParam) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", k.ID()) + ctx := context.WithValue(context.Background(), idKey{}, k.ID()) skip := k.Skip sysKernelParam := sys.NewKernelParam(ctx, k.GetName(), sys, util.Config{}) diff --git a/resource/mount.go b/resource/mount.go index 401c172ec..4410cbb2f 100644 --- a/resource/mount.go +++ b/resource/mount.go @@ -54,7 +54,7 @@ func (m *Mount) GetMountPoint() string { } func (m *Mount) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", m.ID()) + ctx := context.WithValue(context.Background(), idKey{}, m.ID()) skip := m.Skip if m.Timeout == 0 { diff --git a/resource/package.go b/resource/package.go index f8afffcb5..6d393a1b2 100644 --- a/resource/package.go +++ b/resource/package.go @@ -47,7 +47,7 @@ func (p *Package) GetName() string { } func (p *Package) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", p.ID()) + ctx := context.WithValue(context.Background(), idKey{}, p.ID()) skip := p.Skip sysPkg := sys.NewPackage(ctx, p.GetName(), sys, util.Config{}) diff --git a/resource/port.go b/resource/port.go index 70f72ae93..02c32859c 100644 --- a/resource/port.go +++ b/resource/port.go @@ -47,7 +47,7 @@ func (p *Port) GetPort() string { } func (p *Port) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", p.ID()) + ctx := context.WithValue(context.Background(), idKey{}, p.ID()) skip := p.Skip sysPort := sys.NewPort(ctx, p.GetPort(), sys, util.Config{}) diff --git a/resource/process.go b/resource/process.go index 9012760e9..c7413d7ef 100644 --- a/resource/process.go +++ b/resource/process.go @@ -46,7 +46,7 @@ func (p *Process) GetComm() string { } func (p *Process) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", p.ID()) + ctx := context.WithValue(context.Background(), idKey{}, p.ID()) skip := p.Skip sysProcess := sys.NewProcess(ctx, p.GetComm(), sys, util.Config{}) diff --git a/resource/resource.go b/resource/resource.go index bff257e02..104972ad5 100644 --- a/resource/resource.go +++ b/resource/resource.go @@ -5,11 +5,9 @@ import ( "os" "path/filepath" "strconv" - "strings" "sync" "github.com/goss-org/goss/system" - "github.com/oleiade/reflections" ) type Resource interface { @@ -66,18 +64,6 @@ func deprecateAtoI(depr any, desc string) any { return float64(i) } -func validAttrs(i any, t string) (map[string]bool, error) { - validAttrs := make(map[string]bool) - tags, err := reflections.Tags(i, t) - if err != nil { - return nil, err - } - for _, v := range tags { - validAttrs[strings.Split(v, ",")[0]] = true - } - return validAttrs, nil -} - func shouldSkip(results []TestResult) bool { if len(results) < 1 { return false diff --git a/resource/resource_list.go b/resource/resource_list.go index e3aedb633..61b381596 100644 --- a/resource/resource_list.go +++ b/resource/resource_list.go @@ -18,7 +18,7 @@ import ( type AddrMap map[string]*Addr func (r AddrMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Addr, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewAddr(ctx, sr, sys, config) res, err := NewAddr(sysres, config) if err != nil { @@ -33,13 +33,13 @@ func (r AddrMap) AppendSysResource(sr string, sys *system.System, config util.Co } func (r AddrMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Addr, system.Addr, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewAddr(ctx, sr, sys, util.Config{}) res, err := NewAddr(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -119,7 +119,7 @@ func (ret *AddrMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type CommandMap map[string]*Command func (r CommandMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Command, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewCommand(ctx, sr, sys, config) res, err := NewCommand(sysres, config) if err != nil { @@ -134,13 +134,13 @@ func (r CommandMap) AppendSysResource(sr string, sys *system.System, config util } func (r CommandMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Command, system.Command, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewCommand(ctx, sr, sys, util.Config{}) res, err := NewCommand(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -220,7 +220,7 @@ func (ret *CommandMap) UnmarshalYAML(unmarshal func(v interface{}) error) error type DNSMap map[string]*DNS func (r DNSMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*DNS, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewDNS(ctx, sr, sys, config) res, err := NewDNS(sysres, config) if err != nil { @@ -235,13 +235,13 @@ func (r DNSMap) AppendSysResource(sr string, sys *system.System, config util.Con } func (r DNSMap) AppendSysResourceIfExists(sr string, sys *system.System) (*DNS, system.DNS, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewDNS(ctx, sr, sys, util.Config{}) res, err := NewDNS(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -321,7 +321,7 @@ func (ret *DNSMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type FileMap map[string]*File func (r FileMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*File, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewFile(ctx, sr, sys, config) res, err := NewFile(sysres, config) if err != nil { @@ -336,13 +336,13 @@ func (r FileMap) AppendSysResource(sr string, sys *system.System, config util.Co } func (r FileMap) AppendSysResourceIfExists(sr string, sys *system.System) (*File, system.File, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewFile(ctx, sr, sys, util.Config{}) res, err := NewFile(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -422,7 +422,7 @@ func (ret *FileMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type GossfileMap map[string]*Gossfile func (r GossfileMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Gossfile, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewGossfile(ctx, sr, sys, config) res, err := NewGossfile(sysres, config) if err != nil { @@ -437,13 +437,13 @@ func (r GossfileMap) AppendSysResource(sr string, sys *system.System, config uti } func (r GossfileMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Gossfile, system.Gossfile, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewGossfile(ctx, sr, sys, util.Config{}) res, err := NewGossfile(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -523,7 +523,7 @@ func (ret *GossfileMap) UnmarshalYAML(unmarshal func(v interface{}) error) error type GroupMap map[string]*Group func (r GroupMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Group, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewGroup(ctx, sr, sys, config) res, err := NewGroup(sysres, config) if err != nil { @@ -538,13 +538,13 @@ func (r GroupMap) AppendSysResource(sr string, sys *system.System, config util.C } func (r GroupMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Group, system.Group, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewGroup(ctx, sr, sys, util.Config{}) res, err := NewGroup(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -624,7 +624,7 @@ func (ret *GroupMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type PackageMap map[string]*Package func (r PackageMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Package, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewPackage(ctx, sr, sys, config) res, err := NewPackage(sysres, config) if err != nil { @@ -639,13 +639,13 @@ func (r PackageMap) AppendSysResource(sr string, sys *system.System, config util } func (r PackageMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Package, system.Package, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewPackage(ctx, sr, sys, util.Config{}) res, err := NewPackage(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -725,7 +725,7 @@ func (ret *PackageMap) UnmarshalYAML(unmarshal func(v interface{}) error) error type PortMap map[string]*Port func (r PortMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Port, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewPort(ctx, sr, sys, config) res, err := NewPort(sysres, config) if err != nil { @@ -740,13 +740,13 @@ func (r PortMap) AppendSysResource(sr string, sys *system.System, config util.Co } func (r PortMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Port, system.Port, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewPort(ctx, sr, sys, util.Config{}) res, err := NewPort(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -826,7 +826,7 @@ func (ret *PortMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type ProcessMap map[string]*Process func (r ProcessMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Process, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewProcess(ctx, sr, sys, config) res, err := NewProcess(sysres, config) if err != nil { @@ -841,13 +841,13 @@ func (r ProcessMap) AppendSysResource(sr string, sys *system.System, config util } func (r ProcessMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Process, system.Process, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewProcess(ctx, sr, sys, util.Config{}) res, err := NewProcess(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -927,7 +927,7 @@ func (ret *ProcessMap) UnmarshalYAML(unmarshal func(v interface{}) error) error type ServiceMap map[string]*Service func (r ServiceMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Service, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewService(ctx, sr, sys, config) res, err := NewService(sysres, config) if err != nil { @@ -942,13 +942,13 @@ func (r ServiceMap) AppendSysResource(sr string, sys *system.System, config util } func (r ServiceMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Service, system.Service, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewService(ctx, sr, sys, util.Config{}) res, err := NewService(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -1028,7 +1028,7 @@ func (ret *ServiceMap) UnmarshalYAML(unmarshal func(v interface{}) error) error type UserMap map[string]*User func (r UserMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*User, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewUser(ctx, sr, sys, config) res, err := NewUser(sysres, config) if err != nil { @@ -1043,13 +1043,13 @@ func (r UserMap) AppendSysResource(sr string, sys *system.System, config util.Co } func (r UserMap) AppendSysResourceIfExists(sr string, sys *system.System) (*User, system.User, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewUser(ctx, sr, sys, util.Config{}) res, err := NewUser(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -1129,7 +1129,7 @@ func (ret *UserMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type KernelParamMap map[string]*KernelParam func (r KernelParamMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*KernelParam, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewKernelParam(ctx, sr, sys, config) res, err := NewKernelParam(sysres, config) if err != nil { @@ -1144,13 +1144,13 @@ func (r KernelParamMap) AppendSysResource(sr string, sys *system.System, config } func (r KernelParamMap) AppendSysResourceIfExists(sr string, sys *system.System) (*KernelParam, system.KernelParam, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewKernelParam(ctx, sr, sys, util.Config{}) res, err := NewKernelParam(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -1230,7 +1230,7 @@ func (ret *KernelParamMap) UnmarshalYAML(unmarshal func(v interface{}) error) er type MountMap map[string]*Mount func (r MountMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Mount, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewMount(ctx, sr, sys, config) res, err := NewMount(sysres, config) if err != nil { @@ -1245,13 +1245,13 @@ func (r MountMap) AppendSysResource(sr string, sys *system.System, config util.C } func (r MountMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Mount, system.Mount, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewMount(ctx, sr, sys, util.Config{}) res, err := NewMount(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -1331,7 +1331,7 @@ func (ret *MountMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type InterfaceMap map[string]*Interface func (r InterfaceMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Interface, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewInterface(ctx, sr, sys, config) res, err := NewInterface(sysres, config) if err != nil { @@ -1346,13 +1346,13 @@ func (r InterfaceMap) AppendSysResource(sr string, sys *system.System, config ut } func (r InterfaceMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Interface, system.Interface, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewInterface(ctx, sr, sys, util.Config{}) res, err := NewInterface(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -1432,7 +1432,7 @@ func (ret *InterfaceMap) UnmarshalYAML(unmarshal func(v interface{}) error) erro type HTTPMap map[string]*HTTP func (r HTTPMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*HTTP, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewHTTP(ctx, sr, sys, config) res, err := NewHTTP(sysres, config) if err != nil { @@ -1447,13 +1447,13 @@ func (r HTTPMap) AppendSysResource(sr string, sys *system.System, config util.Co } func (r HTTPMap) AppendSysResourceIfExists(sr string, sys *system.System) (*HTTP, system.HTTP, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewHTTP(ctx, sr, sys, util.Config{}) res, err := NewHTTP(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { diff --git a/resource/resource_list_genny.go b/resource/resource_list_genny.go index a483bc4ea..fccdea348 100644 --- a/resource/resource_list_genny.go +++ b/resource/resource_list_genny.go @@ -26,7 +26,7 @@ type ResourceType generic.Type type ResourceTypeMap map[string]*ResourceType func (r ResourceTypeMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*ResourceType, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewResourceType(ctx, sr, sys, config) res, err := NewResourceType(sysres, config) if err != nil { @@ -41,13 +41,13 @@ func (r ResourceTypeMap) AppendSysResource(sr string, sys *system.System, config } func (r ResourceTypeMap) AppendSysResourceIfExists(sr string, sys *system.System) (*ResourceType, system.ResourceType, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewResourceType(ctx, sr, sys, util.Config{}) res, err := NewResourceType(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { diff --git a/resource/service.go b/resource/service.go index 2285c3e1f..2f35e9d3d 100644 --- a/resource/service.go +++ b/resource/service.go @@ -48,7 +48,7 @@ func (s *Service) GetName() string { } func (s *Service) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", s.ID()) + ctx := context.WithValue(context.Background(), idKey{}, s.ID()) skip := s.Skip sysservice := sys.NewService(ctx, s.GetName(), sys, util.Config{}) diff --git a/resource/user.go b/resource/user.go index 3895f8067..c1b64b06f 100644 --- a/resource/user.go +++ b/resource/user.go @@ -51,7 +51,7 @@ func (u *User) GetUsername() string { } func (u *User) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", u.ID()) + ctx := context.WithValue(context.Background(), idKey{}, u.ID()) skip := u.Skip sysuser := sys.NewUser(ctx, u.GetUsername(), sys, util.Config{}) diff --git a/resource/validate.go b/resource/validate.go index c7abb4428..720c7b7d5 100644 --- a/resource/validate.go +++ b/resource/validate.go @@ -41,10 +41,6 @@ func HumanOutcomes() map[int]string { return humanOutcomes } -const ( - maxScanTokenSize = 10 * 1024 * 1024 -) - type ValidateError string func (g ValidateError) Error() string { return string(g) } diff --git a/serve.go b/serve.go index 3adb34270..d30973adf 100644 --- a/serve.go +++ b/serve.go @@ -85,7 +85,7 @@ func (h healthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { log.Printf("[TRACE] %v: requesting health probe", r.RemoteAddr) resp := h.processAndEnsureCached(negotiatedContentType, outputer) - w.Header().Set(http.CanonicalHeaderKey("Content-Type"), negotiatedContentType) + w.Header().Set(http.CanonicalHeaderKey("Content-Type"), negotiatedContentType) //nolint:gosimple w.WriteHeader(resp.statusCode) logBody := "" if resp.statusCode != http.StatusOK { diff --git a/serve_test.go b/serve_test.go index b29fe3baf..8b19d048d 100644 --- a/serve_test.go +++ b/serve_test.go @@ -66,7 +66,7 @@ func TestServeWithNoContentNegotiation(t *testing.T) { t.Logf("testName %q log output:\n%s", testName, logOutput.String()) assert.Equal(t, tc.expectedHTTPStatus, rr.Code) if tc.expectedContentType != "" { - assert.Equal(t, []string{tc.expectedContentType}, rr.HeaderMap["Content-Type"]) + assert.Equal(t, tc.expectedContentType, rr.Result().Header.Get("Content-Type")) } }) } @@ -173,7 +173,7 @@ func TestServeNegotiatingContent(t *testing.T) { t.Logf("testName %q log output:\n%s", testName, logOutput.String()) assert.Equal(t, tc.expectedHTTPStatus, rr.Code) if tc.expectedContentType != "" { - assert.Equal(t, []string{tc.expectedContentType}, rr.HeaderMap["Content-Type"]) + assert.Equal(t, tc.expectedContentType, rr.Result().Header.Get("Content-Type")) } }) } @@ -297,11 +297,9 @@ func TestServeCacheNegotiatingContent(t *testing.T) { func makeRequest(t *testing.T, config *util.Config, headers map[string][]string) *http.Request { req, err := http.NewRequest("GET", config.Endpoint, nil) require.NoError(t, err) - if headers != nil { - for header, vals := range headers { - for _, v := range vals { - req.Header.Add(header, v) - } + for header, vals := range headers { + for _, v := range vals { + req.Header.Add(header, v) } } return req diff --git a/system/file.go b/system/file.go index 6927d910f..a6f1efaef 100644 --- a/system/file.go +++ b/system/file.go @@ -38,14 +38,13 @@ type hashFuncType string const ( md5Hash hashFuncType = "md5" - sha256Hash = "sha256" - sha512Hash = "sha512" + sha256Hash hashFuncType = "sha256" + sha512Hash hashFuncType = "sha512" ) type DefFile struct { path string realPath string - fi os.FileInfo loaded bool err error } @@ -167,7 +166,7 @@ func realPath(path string) (string, error) { if f == "~" { usr, err = user.Current() } else { - usr, err = user.Lookup(f[1:len(f)]) + usr, err = user.Lookup(f[1:]) } if err != nil { return "", err diff --git a/system/http.go b/system/http.go index cdbf589cf..d5e5abec7 100644 --- a/system/http.go +++ b/system/http.go @@ -16,6 +16,9 @@ import ( "github.com/goss-org/goss/util" ) +const USER_AGENT_HEADER_PREFIX = "user-agent:" +const DEFAULT_USER_AGENT_PREFIX = "goss/" + type HTTP interface { HTTP() string Status() (int, error) @@ -47,6 +50,11 @@ type DefHTTP struct { func NewDefHTTP(_ context.Context, httpStr string, system *System, config util.Config) HTTP { headers := http.Header{} + + if !hasUserAgentHeader(config.RequestHeader) { + config.RequestHeader = append(config.RequestHeader, fmt.Sprintf("%s %s%s", USER_AGENT_HEADER_PREFIX, DEFAULT_USER_AGENT_PREFIX, util.Version)) + } + for _, r := range config.RequestHeader { str := strings.SplitN(r, ": ", 2) headers.Add(str[0], str[1]) @@ -209,3 +217,12 @@ func (u *DefHTTP) Body() (io.Reader, error) { return u.resp.Body, nil } + +func hasUserAgentHeader(headers []string) bool { + for _, header := range headers { + if strings.HasPrefix(strings.ToLower(header), USER_AGENT_HEADER_PREFIX) { + return true + } + } + return false +} diff --git a/system/kernel_param.go b/system/kernel_param.go index 867e08f65..c7b6e29f8 100644 --- a/system/kernel_param.go +++ b/system/kernel_param.go @@ -14,8 +14,7 @@ type KernelParam interface { } type DefKernelParam struct { - key string - value string + key string } func NewDefKernelParam(_ context.Context, key string, system *System, config util.Config) KernelParam { diff --git a/system/service.go b/system/service.go index df2a43dc7..bdb280702 100644 --- a/system/service.go +++ b/system/service.go @@ -11,8 +11,5 @@ type Service interface { } func invalidService(s string) bool { - if strings.ContainsRune(s, '/') { - return true - } - return false + return strings.ContainsRune(s, '/') } diff --git a/template.go b/template.go index 1d524eacd..8621ce9d4 100644 --- a/template.go +++ b/template.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "regexp" + "strconv" "strings" "text/template" @@ -76,11 +77,37 @@ func regexMatch(re, s string) (bool, error) { return compiled.MatchString(s), nil } +// return named parenthesized subexpresions, if received, or stringfied (Sprig "get" need strings) keys like array +func findStringSubmatch(pattern, input string) map[string]interface{} { + re := regexp.MustCompile(pattern) + els := re.FindStringSubmatch(input) + + elsMap := make(map[string]interface{}) + elsMapNamed := make(map[string]interface{}) + + // create always elsMaps but returns elsMapNamed if exists named parenthesized subexps + for i := 0; i < len(els); i++ { + // convert i to string according returned (https://github.com/goss-org/goss/pull/895#issuecomment-2075716706) + elsMap[strconv.Itoa(i)] = els[i] + + if re.SubexpNames()[i] != "" { + elsMapNamed[re.SubexpNames()[i]] = els[i] + } + } + + // returns elsMapNamed if exists named parenthesized subexps + if len(elsMapNamed) > 0 { + return elsMapNamed + } + return elsMap +} + var funcMap = template.FuncMap{ - "mkSlice": mkSlice, - "readFile": readFile, - "getEnv": getEnv, - "regexMatch": regexMatch, - "toUpper": strings.ToUpper, - "toLower": strings.ToLower, + "mkSlice": mkSlice, + "readFile": readFile, + "getEnv": getEnv, + "regexMatch": regexMatch, + "toUpper": strings.ToUpper, + "toLower": strings.ToLower, + "findStringSubmatch": findStringSubmatch, } diff --git a/util/build.go b/util/build.go new file mode 100644 index 000000000..9deff372a --- /dev/null +++ b/util/build.go @@ -0,0 +1,3 @@ +package util + +var Version string diff --git a/util/config.go b/util/config.go index 8c0a68d19..3be5fa84e 100644 --- a/util/config.go +++ b/util/config.go @@ -271,7 +271,7 @@ func ValidateSections(unmarshal func(any) error, i any, whitelist map[string]boo typ := reflect.TypeOf(i) typs := strings.Split(typ.String(), ".")[1] for id, v := range toValidate { - for k, _ := range v { + for k := range v { if !whitelist[k] { return fmt.Errorf("invalid Attribute for %s:%s: %s", typs, id, k) } @@ -295,7 +295,7 @@ func WhitelistAttrs(i any, format format) (map[string]bool, error) { func IsValueInList(value string, list []string) bool { for _, v := range list { - if strings.ToLower(v) == strings.ToLower(value) { + if strings.EqualFold(v, value) { return true } }