From 6c34c3acbd938a9c0ed70bc350fb92c0c3f6b048 Mon Sep 17 00:00:00 2001 From: Michael Lacore Date: Tue, 8 Oct 2024 12:32:57 -0700 Subject: [PATCH] Create build and release pipeline (#14) * Create main.yml * Adding workflow files from mass CLI, + codeowners * adding pre-commit-config file * fixing lint * adding golangci-lint config file * adding goreleaser, end-of-file-fixer ignore for testdata * refactoring from linting * precommit fixes * update golangci lint config * fixing misspelling * changing require to assert which doesn't care about JSON object order --- .github/CODEOWNERS | 2 + .github/workflows/lint.yaml | 26 + .github/workflows/main.yml | 28 + .github/workflows/pre-commit.yaml | 19 + .github/workflows/test.yaml | 21 + .golangci.yaml | 249 +++++++ .goreleaser.yaml | 51 ++ .pre-commit-config.yaml | 24 + Makefile | 2 +- README.md | 2 +- go.mod | 52 +- go.sum | 124 ++-- pkg/bicep/biceptoschema.go | 70 +- pkg/bicep/biceptoschema_test.go | 4 +- pkg/bicep/schematobicep.go | 12 +- pkg/bicep/testdata/simple.json | 670 +++++++++--------- pkg/helm/helmtoschema.go | 17 +- pkg/opentofu/schematotofu.go | 2 +- .../testdata/opentofu/simple/schema.json | 362 +++++----- pkg/opentofu/testdata/schemas/default.json | 10 +- .../testdata/schemas/dependencies.json | 42 +- pkg/opentofu/testdata/schemas/dynamics.json | 2 +- pkg/opentofu/testdata/schemas/simple.json | 14 +- .../testdata/schemas/topleveldep.json | 40 +- pkg/opentofu/tofutoschema.go | 19 +- pkg/schema/marshal.go | 1 - pkg/schema/testdata/schema.json | 2 +- pkg/schema/types.go | 8 +- 28 files changed, 1171 insertions(+), 704 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/lint.yaml create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/pre-commit.yaml create mode 100644 .github/workflows/test.yaml create mode 100644 .golangci.yaml create mode 100644 .goreleaser.yaml create mode 100644 .pre-commit-config.yaml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..a0ba85d --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +* @chrisghill +* @mclacore diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..2ba2ba3 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,26 @@ +# adapted from https://github.com/golangci/golangci-lint-action +name: golangci-lint + +on: + push: + branches: [main] + pull_request: + branches: [main] +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + pull-requests: read +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v5 + with: + go-version: 1.22 + - uses: actions/checkout@v4 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: v1.56.2 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..c75da2c --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,28 @@ +name: Generate release-artifacts +on: + push: + # Pattern matched against refs/tags + tags: + - '*' + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - run: git fetch --force --tags + - uses: actions/setup-go@v5 + with: + go-version: 1.22 + - uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: v1.24.0 + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml new file mode 100644 index 0000000..2d840ea --- /dev/null +++ b/.github/workflows/pre-commit.yaml @@ -0,0 +1,19 @@ +name: pre-commit + +on: + pull_request: + push: + branches: [main] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v2 + - uses: pre-commit/action@v2.0.3 + env: + # this check prevents devs from commit to main. + # however, we don't want it to fail on commits to main in CI. + # we use the golangci-lint gh action in lint.yaml because it generates useful comments. + SKIP: no-commit-to-branch,golangci-lint diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..d385681 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,21 @@ +name: Test + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.22 + - name: Build + run: go build -v ./... + - name: Test + run: go test -v ./... diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..f2b29ab --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,249 @@ +## Golden config for golangci-lint v1.46.2 +# +# This is the best config for golangci-lint based on my experience and opinion. +# It is very strict, but not extremely strict. +# Feel free to adopt and change it for your needs. + +run: + # Timeout for analysis, e.g. 30s, 5m. + # Default: 1m + timeout: 3m + +# This file contains only configs which differ from defaults. +# All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml +linters-settings: + cyclop: + # The maximal code complexity to report. + # Default: 10 + max-complexity: 30 + # The maximal average package complexity. + # If it's higher than 0.0 (float) the check is enabled + # Default: 0.0 + package-average: 10.0 + + errcheck: + # Report about not checking of errors in type assertions: `a := b.(MyStruct)`. + # Such cases aren't reported by default. + # Default: false + check-type-assertions: true + + funlen: + # Checks the number of lines in a function. + # If lower than 0, disable the check. + # Default: 60 + lines: 100 + # Checks the number of statements in a function. + # If lower than 0, disable the check. + # Default: 40 + statements: 51 + + gocognit: + # Minimal code complexity to report + # Default: 30 (but we recommend 10-20) + min-complexity: 20 + + gocritic: + # Settings passed to gocritic. + # The settings key is the name of a supported gocritic checker. + # The list of supported checkers can be find in https://go-critic.github.io/overview. + settings: + captLocal: + # Whether to restrict checker to params only. + # Default: true + paramsOnly: false + underef: + # Whether to skip (*x).method() calls where x is a pointer receiver. + # Default: true + skipRecvDeref: false + + gomodguard: + blocked: + # List of blocked modules. + # Default: [] + modules: + - github.com/golang/protobuf: + recommendations: + - google.golang.org/protobuf + reason: "see https://developers.google.com/protocol-buffers/docs/reference/go/faq#modules" + - github.com/satori/go.uuid: + recommendations: + - github.com/google/uuid + reason: "satori's package is not maintained" + - github.com/gofrs/uuid: + recommendations: + - github.com/google/uuid + reason: "see recommendation from dev-infra team: https://confluence.gtforge.com/x/gQI6Aw" + + govet: + # Enable all analyzers. + # Default: false + enable-all: true + # Disable analyzers by name. + # Run `go tool vet help` to see all analyzers. + # Default: [] + disable: + - fieldalignment # too strict + # Settings per analyzer. + settings: + shadow: + # Whether to be strict about shadowing; can be noisy. + # Default: false + strict: true + + nakedret: + # Make an issue if func has more lines of code than this setting, and it has naked returns. + # Default: 30 + max-func-lines: 0 + + nolintlint: + # Exclude following linters from requiring an explanation. + # Default: [] + allow-no-explanation: [funlen, gocognit, lll] + # Enable to require an explanation of nonzero length after each nolint directive. + # Default: false + require-explanation: false + # Enable to require nolint directives to mention the specific linter being suppressed. + # Default: false + require-specific: true + + rowserrcheck: + # database/sql is always checked + # Default: [] + packages: + - github.com/jmoiron/sqlx + + tenv: + # The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures. + # Otherwise, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked. + # Default: false + all: true + +linters: + enable: + - gomoddirectives + - errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases + - gosimple # Linter for Go source code that specializes in simplifying a code + - govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string + - ineffassign # Detects when assignments to existing variables are not used + - staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks + - typecheck # Like the front-end of a Go compiler, parses and type-checks Go code + - unused # Checks Go code for unused constants, variables, functions and types + - asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers + - bidichk # Checks for dangerous unicode character sequences + - bodyclose # checks whether HTTP response body is closed successfully + - contextcheck # check the function whether use a non-inherited context + - cyclop # checks function and package cyclomatic complexity + - dupl # Tool for code clone detection + - durationcheck # check for two durations multiplied together + - errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error. + - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. + # - execinquery # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds + # - exhaustive # check exhaustiveness of enum switch statements + # - exportloopref # checks for pointers to enclosing loop variables (deprecated) + # - forbidigo # Forbids identifiers + - funlen # Tool for detection of long functions + # - gochecknoglobals # check that no global variables exist + # - gochecknoinits # Checks that no init functions are present in Go code + - gocognit # Computes and checks the cognitive complexity of functions + # - goconst # Finds repeated strings that could be replaced by a constant + - gocritic # Provides diagnostics that check for bugs, performance and style issues. + - gocyclo # Computes and checks the cyclomatic complexity of functions + # - godot # Check if comments end in a period + - goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. + # - gomnd # An analyzer to detect magic numbers. + # - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. + - gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. + - goprintffuncname # Checks that printf-like functions are named with f at the end + - gosec # Inspects source code for security problems + # - lll # Reports long lines + - makezero # Finds slice declarations with non-zero initial length + - nakedret # Finds naked returns in functions greater than a specified function length + # - nestif # Reports deeply nested if statements + - nilerr # Finds the code that returns nil even if it checks that the error is not nil. + - nilnil # Checks that there is no simultaneous return of nil error and an invalid value. + - noctx # noctx finds sending http request without context.Context + - nolintlint # Reports ill-formed or insufficient nolint directives + # - nonamedreturns # Reports all named returns + # - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. + - predeclared # find code that shadows one of Go's predeclared identifiers + - promlinter # Check Prometheus metrics naming via promlint + # - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. + - rowserrcheck # checks whether Err of rows is checked successfully + - sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed. + - stylecheck # Stylecheck is a replacement for golint + - tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 + - testpackage # linter that makes you use a separate _test package + - tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes + - unconvert # Remove unnecessary type conversions + - unparam # Reports unused function parameters + - wastedassign # wastedassign finds wasted assignment statements. + - whitespace # Tool for detection of leading and trailing whitespace + ## you may want to enable + #- decorder # check declaration order and count of types, constants, variables and functions + #- exhaustruct # Checks if all structure fields are initialized + #- goheader # Checks is file header matches to pattern + #- ireturn # Accept Interfaces, Return Concrete Types + #- prealloc # [premature optimization, but can be used in some cases] Finds slice declarations that could potentially be preallocated + #- varnamelen # [great idea, but too many false positives] checks that the length of a variable's name matches its scope + #- wrapcheck # Checks that errors returned from external packages are wrapped + ## disabled + #- containedctx # containedctx is a linter that detects struct contained context.Context field + #- depguard # [replaced by gomodguard] Go linter that checks if package imports are in a list of acceptable packages + #- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) + #- errchkjson # [don't see profit + I'm against of omitting errors like in the first example https://github.com/breml/errchkjson] Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted. + #- forcetypeassert # [replaced by errcheck] finds forced type assertions + #- gci # Gci controls golang package import order and makes it always deterministic. + - godox # Tool for detection of FIXME, TODO and other comment keywords + #- goerr113 # [too strict] Golang linter to check the errors handling expressions + #- gofmt # [replaced by goimports] Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification + #- gofumpt # [replaced by goimports, gofumports is not available yet] Gofumpt checks whether code was gofumpt-ed. + #- grouper # An analyzer to analyze expression groups. + #- ifshort # Checks that your code uses short syntax for if-statements whenever possible + #- importas # Enforces consistent import aliases + #- maintidx # maintidx measures the maintainability index of each function. + #- misspell # [useless] Finds commonly misspelled English words in comments + #- nlreturn # [too strict and mostly code is not more readable] nlreturn checks for a new line before return and branch statements to increase code clarity + #- paralleltest # [too many false positives] paralleltest detects missing usage of t.Parallel() method in your Go test + #- tagliatelle # Checks the struct tags. + #- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers + #- wsl # [too strict and mostly code is not more readable] Whitespace Linter - Forces you to use empty lines! + ## deprecated + #- exhaustivestruct # [deprecated, replaced by exhaustruct] Checks if all struct's fields are initialized + #- golint # [deprecated, replaced by revive] Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes + #- interfacer # [deprecated] Linter that suggests narrower interface types + #- maligned # [deprecated, replaced by govet fieldalignment] Tool to detect Go structs that would take less memory if their fields were sorted + #- scopelint # [deprecated, replaced by exportloopref] Scopelint checks for unpinned variables in go programs + +issues: + # Maximum count of issues with the same text. + # Set to 0 to disable. + # Default: 3 + max-same-issues: 50 + + # exclude: + + exclude-rules: + # Allow unused params at the cobra command level + # - linters: [revive] + # text: "unused-parameter: parameter ('cmd'|'args') seems to be unused, consider removing or renaming it as _" + - source: "^//\\s*go:generate\\s" + linters: [lll] + # Allow TODO for now + - source: "(noinspection|TODO)" + linters: [godox] + - source: "//noinspection" + linters: [gocritic] + - source: "^\\s+if _, ok := err\\.\\([^.]+\\.InternalError\\); ok {" + linters: [errorlint] + - path: "_test\\.go" + linters: + # - revive + - bodyclose + - dupl + - funlen + - goconst + - gosec + - noctx + - wrapcheck + - gocognit + - cyclop diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..1170452 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,51 @@ +release: + # If set to auto, will mark the release as not ready for production in case there is an indicator for this in the + # tag e.g. v1.0.0-rc1 .If set to true, will mark the release as not ready for production. + prerelease: auto + +builds: + - id: linux-build + binary: airlock + env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 + - arm64 + # commented these out so i work on implementing them with airlock + # ldflags: &build-ldflags | + # -X github.com/massdriver-cloud/mass/pkg/version.version={{.Version}} + # -X github.com/massdriver-cloud/mass/pkg/version.gitSHA={{.FullCommit}} + + - id: darwin-build + binary: airlock + env: + - CGO_ENABLED=0 + goos: + - darwin + goarch: + - amd64 + - arm64 + ldflags: *build-ldflags + +archives: + - id: linux-archives + builds: + - linux-build + name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}" + + - id: darwin-archives + builds: + - darwin-build + name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}" + +checksum: + name_template: 'checksums.txt' + +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..f4884be --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,24 @@ +fail_fast: false + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.2.0 + hooks: + - id: trailing-whitespace + - id: check-merge-conflict + - id: check-json + exclude: .devcontainer/ + - id: pretty-format-json + args: + - --autofix + - --no-sort-keys + - --indent=4 + exclude: .devcontainer/ + - id: end-of-file-fixer + - id: detect-aws-credentials + args: + - --allow-missing-credentials + - id: no-commit-to-branch + args: + - -b + - main diff --git a/Makefile b/Makefile index 12c1f33..ebda9fb 100644 --- a/Makefile +++ b/Makefile @@ -43,4 +43,4 @@ install.macos: build.macos .PHONY: install.linux install.linux: build.linux - cp -f bin/airlock-linux-amd64 ${INSTALL_PATH}/airlock \ No newline at end of file + cp -f bin/airlock-linux-amd64 ${INSTALL_PATH}/airlock diff --git a/README.md b/README.md index 8235231..590560c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![License](https://img.shields.io/github/license/massdriver-cloud/airlock)](https://github.com/massdriver-cloud/airlock/blob/master/LICENSE) ## Overview -Generate JSON Schema from various sources (OpenTofu, Helm) +Generate JSON Schema from various sources (OpenTofu, Helm) ## Getting Started diff --git a/go.mod b/go.mod index 2bda70e..477e6e8 100644 --- a/go.mod +++ b/go.mod @@ -1,35 +1,37 @@ module github.com/massdriver-cloud/airlock -go 1.22.4 +go 1.23.1 -toolchain go1.22.5 +toolchain go1.23.2 require ( - github.com/Checkmarx/kics/v2 v2.1.1 - github.com/charmbracelet/glamour v0.6.0 - github.com/hashicorp/hcl/v2 v2.20.1 + github.com/Checkmarx/kics/v2 v2.1.3 + github.com/charmbracelet/glamour v0.8.0 + github.com/hashicorp/hcl/v2 v2.22.0 github.com/massdriver-cloud/terraform-config-inspect v0.0.1 - github.com/spf13/cobra v1.8.0 + github.com/spf13/cobra v1.8.1 github.com/stretchr/testify v1.9.0 github.com/wk8/go-ordered-map/v2 v2.1.8 github.com/xeipuuv/gojsonschema v1.2.0 - github.com/zclconf/go-cty v1.14.4 + github.com/zclconf/go-cty v1.15.0 gopkg.in/yaml.v3 v3.0.1 ) require ( github.com/agext/levenshtein v1.2.3 // indirect - github.com/alecthomas/chroma v0.10.0 // indirect + github.com/alecthomas/chroma/v2 v2.14.0 // indirect github.com/antlr4-go/antlr/v4 v4.13.1 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect - github.com/aymanbagabas/go-osc52 v1.0.3 // indirect + github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymerick/douceur v0.2.0 // indirect github.com/bahlo/generic-list-go v0.2.0 // indirect github.com/buger/jsonparser v1.1.1 // indirect + github.com/charmbracelet/lipgloss v0.13.0 // indirect + github.com/charmbracelet/x/ansi v0.3.2 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/dlclark/regexp2 v1.4.0 // indirect + github.com/dlclark/regexp2 v1.11.4 // indirect github.com/google/go-cmp v0.6.0 // indirect - github.com/gorilla/css v1.0.0 // indirect + github.com/gorilla/css v1.0.1 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/kr/pretty v0.3.1 // indirect @@ -37,12 +39,11 @@ require ( github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mattn/go-runewidth v0.0.15 // indirect - github.com/microcosm-cc/bluemonday v1.0.21 // indirect + github.com/mattn/go-runewidth v0.0.16 // indirect + github.com/microcosm-cc/bluemonday v1.0.27 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/muesli/reflow v0.3.0 // indirect - github.com/muesli/termenv v0.13.0 // indirect - github.com/olekukonko/tablewriter v0.0.5 // indirect + github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/rs/zerolog v1.33.0 // indirect @@ -50,15 +51,16 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect - github.com/yuin/goldmark v1.5.2 // indirect - github.com/yuin/goldmark-emoji v1.0.1 // indirect - golang.org/x/crypto v0.24.0 // indirect - golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 // indirect - golang.org/x/mod v0.18.0 // indirect - golang.org/x/net v0.26.0 // indirect - golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.21.0 // indirect - golang.org/x/text v0.16.0 // indirect - golang.org/x/tools v0.22.0 // indirect + github.com/yuin/goldmark v1.7.4 // indirect + github.com/yuin/goldmark-emoji v1.0.3 // indirect + golang.org/x/crypto v0.28.0 // indirect + golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect + golang.org/x/mod v0.21.0 // indirect + golang.org/x/net v0.30.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.26.0 // indirect + golang.org/x/term v0.25.0 // indirect + golang.org/x/text v0.19.0 // indirect + golang.org/x/tools v0.25.0 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect ) diff --git a/go.sum b/go.sum index e06b214..ef9e2ff 100644 --- a/go.sum +++ b/go.sum @@ -1,43 +1,57 @@ -github.com/Checkmarx/kics/v2 v2.1.1 h1:eLvKQic07zKdkxR+x/PQhLBbc7e2P+fqbGvKNygB2IY= -github.com/Checkmarx/kics/v2 v2.1.1/go.mod h1:v6zQxOcztKolSvgI3BLnfO4Nw3c2B4QXlMzj4wQO4pg= +github.com/Checkmarx/kics/v2 v2.1.3 h1:X+53sjAq9suwzCmZwdGqpBkIgcL1vp5KYqNEbA0woAs= +github.com/Checkmarx/kics/v2 v2.1.3/go.mod h1:66f8m0G8klx4G15sQhuOserSxcni6QpjGiMmXLaIFos= github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= -github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek= -github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s= +github.com/alecthomas/assert/v2 v2.7.0 h1:QtqSACNS3tF7oasA8CU6A6sXZSBDqnm7RfpLl9bZqbE= +github.com/alecthomas/assert/v2 v2.7.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= +github.com/alecthomas/chroma/v2 v2.14.0 h1:R3+wzpnUArGcQz7fCETQBzO5n9IMNi13iIs46aU4V9E= +github.com/alecthomas/chroma/v2 v2.14.0/go.mod h1:QolEbTfmUHIMVpBqxeDnNBj2uoeI4EbYP4i6n68SG4I= +github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc= +github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ= github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw= github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= -github.com/aymanbagabas/go-osc52 v1.0.3 h1:DTwqENW7X9arYimJrPeGZcV0ln14sGMt3pHZspWD+Mg= -github.com/aymanbagabas/go-osc52 v1.0.3/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4= +github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= +github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= +github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8= +github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA= github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= -github.com/charmbracelet/glamour v0.6.0 h1:wi8fse3Y7nfcabbbDuwolqTqMQPMnVPeZhDM273bISc= -github.com/charmbracelet/glamour v0.6.0/go.mod h1:taqWV4swIMMbWALc0m7AfE9JkPSU8om2538k9ITBxOc= +github.com/charmbracelet/glamour v0.8.0 h1:tPrjL3aRcQbn++7t18wOpgLyl8wrOHUEDS7IZ68QtZs= +github.com/charmbracelet/glamour v0.8.0/go.mod h1:ViRgmKkf3u5S7uakt2czJ272WSg2ZenlYEZXT2x7Bjw= +github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw= +github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY= +github.com/charmbracelet/x/ansi v0.3.2 h1:wsEwgAN+C9U06l9dCVMX0/L3x7ptvY1qmjMwyfE6USY= +github.com/charmbracelet/x/ansi v0.3.2/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= +github.com/charmbracelet/x/exp/golden v0.0.0-20240806155701-69247e0abc2a h1:G99klV19u0QnhiizODirwVksQB91TJKV/UaTnACcG30= +github.com/charmbracelet/x/exp/golden v0.0.0-20240806155701-69247e0abc2a/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= -github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E= -github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= +github.com/dlclark/regexp2 v1.11.4 h1:rPYF9/LECdNymJufQKmri9gV604RvvABwgOA8un7yAo= +github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= 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/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY= -github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c= +github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8= +github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hashicorp/hcl/v2 v2.20.1 h1:M6hgdyz7HYt1UN9e61j+qKJBqR3orTWbI1HKBJEdxtc= -github.com/hashicorp/hcl/v2 v2.20.1/go.mod h1:TZDqQ4kNKCbh1iJp99FdPiUaVDDUPivbqxZulxDYqL4= +github.com/hashicorp/hcl/v2 v2.22.0 h1:hkZ3nCtqeJsDhPRFz5EA9iwcG1hNWGePOTw6oyul12M= +github.com/hashicorp/hcl/v2 v2.22.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA= +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= +github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= @@ -57,21 +71,17 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/ github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= -github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= -github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/microcosm-cc/bluemonday v1.0.21 h1:dNH3e4PSyE4vNX+KlRGHT5KrSvjeUkoNPwEORjffHJg= -github.com/microcosm-cc/bluemonday v1.0.21/go.mod h1:ytNkv4RrDrLJ2pqlsSI46O6IVXmZOBBD4SaJyDwwTkM= +github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= +github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk= +github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= -github.com/muesli/termenv v0.13.0 h1:wK20DRpJdDX8b7Ek2QfhvqhRQFZ237RGRO0RQ/Iqdy0= -github.com/muesli/termenv v0.13.0/go.mod h1:sP1+uffeLaEYpyOTb8pLCUctGcGLnoFjSn4YJK5e2bc= -github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= -github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= +github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a h1:2MaM6YC3mGu54x+RKAA6JiFFHlHDY1UbkxqppT7wYOg= +github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a/go.mod h1:hxSnBBYLK21Vtq/PHd0S2FYCxBXzBua8ov5s1RobyRQ= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -89,13 +99,12 @@ github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWR github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sosedoff/ansible-vault-go v0.2.0 h1:XqkBdqbXgTuFQ++NdrZvSdUTNozeb6S3V5x7FVs17vg= github.com/sosedoff/ansible-vault-go v0.2.0/go.mod h1:wMU54HNJfY0n0KIgbpA9m15NBfaUDlJrAsaZp0FwzkI= -github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= -github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc= @@ -107,43 +116,38 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.5.2 h1:ALmeCk/px5FSm1MAcFBAsVKZjDuMVj8Tm7FFIlMJnqU= -github.com/yuin/goldmark v1.5.2/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -github.com/yuin/goldmark-emoji v1.0.1 h1:ctuWEyzGBwiucEqxzwe0SOYDXPAucOrE9NQC18Wa1os= -github.com/yuin/goldmark-emoji v1.0.1/go.mod h1:2w1E6FEWLcDQkoTE+7HU6QF1F6SLlNGjRIBbIZQFqkQ= -github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8= -github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= -github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI= -github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= -golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 h1:LoYXNGAShUG3m/ehNk4iFctuhGX/+R1ZpfJ4/ia80JM= -golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI= -golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= -golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= -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-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= +github.com/yuin/goldmark v1.7.4 h1:BDXOHExt+A7gwPCJgPIIq7ENvceR7we7rOS9TNoLZeg= +github.com/yuin/goldmark v1.7.4/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= +github.com/yuin/goldmark-emoji v1.0.3 h1:aLRkLHOuBR2czCY4R8olwMjID+tENfhyFDMCRhbIQY4= +github.com/yuin/goldmark-emoji v1.0.3/go.mod h1:tTkZEbwu5wkPmgTcitqddVxY9osFZiavD+r4AzQrh1U= +github.com/zclconf/go-cty v1.15.0 h1:tTCRWxsexYUmtt/wVxgDClUe+uQusuI443uL6e+5sXQ= +github.com/zclconf/go-cty v1.15.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= +github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo= +github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM= +golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= +golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= +golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk= +golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY= +golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= +golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= +golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= +golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA= -golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24= +golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE= +golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/bicep/biceptoschema.go b/pkg/bicep/biceptoschema.go index b3181ba..e220b12 100644 --- a/pkg/bicep/biceptoschema.go +++ b/pkg/bicep/biceptoschema.go @@ -44,25 +44,25 @@ func BicepToSchema(templatePath string) (*schema.Schema, error) { } for name, value := range doc[0]["parameters"].(map[string]interface{}) { - bicepParam := bicepParam{} + param := bicepParam{} // marshal to json and unmarshal into custom struct to make bicep param easier to access - bytes, err := json.Marshal(value) - if err != nil { - return nil, err + bytes, marshalErr := json.Marshal(value) + if marshalErr != nil { + return nil, marshalErr } - err = json.Unmarshal(bytes, &bicepParam) - if err != nil { - return nil, err + unmarshalErr := json.Unmarshal(bytes, ¶m) + if unmarshalErr != nil { + return nil, unmarshalErr } property := new(schema.Schema) property.Title = name - property.Description = bicepParam.Metadata.Description + property.Description = param.Metadata.Description - err = parseBicepParam(property, bicepParam) - if err != nil { - return nil, err + parseErr := parseBicepParam(property, param) + if parseErr != nil { + return nil, parseErr } params.Properties.Set(name, property) @@ -97,8 +97,13 @@ func parseIntParam(sch *schema.Schema, bicepParam bicepParam) error { sch.Type = "integer" sch.Default = bicepParam.DefaultValue - if bicepParam.AllowedValues != nil && len(bicepParam.AllowedValues) == 1 { - sch.Enum = bicepParam.AllowedValues[0].([]interface{}) + allowedVals := bicepParam.AllowedValues + if len(allowedVals) == 1 { + assertedEnum, ok := allowedVals[0].([]interface{}) + if !ok { + return fmt.Errorf("unable to cast %v to []interface{}", allowedVals) + } + sch.Enum = assertedEnum } if bicepParam.MinValue != nil { @@ -125,8 +130,13 @@ func parseStringParam(sch *schema.Schema, bicepParam bicepParam, secure bool) er sch.Format = "password" } - if bicepParam.AllowedValues != nil && len(bicepParam.AllowedValues) == 1 { - sch.Enum = bicepParam.AllowedValues[0].([]interface{}) + allowedVals := bicepParam.AllowedValues + if len(allowedVals) == 1 { + assertedEnum, ok := allowedVals[0].([]interface{}) + if !ok { + return fmt.Errorf("unable to cast %v to []interface{}", allowedVals) + } + sch.Enum = assertedEnum } sch.MinLength = bicepParam.MinLength @@ -142,7 +152,10 @@ func parseArrayParam(sch *schema.Schema, bicepParam bicepParam) error { sch.MaxItems = bicepParam.MaxLength if bicepParam.DefaultValue != nil && len(bicepParam.DefaultValue.([]interface{})) != 0 { - parseArrayType(sch, bicepParam.DefaultValue.([]interface{})) + err := parseArrayType(sch, bicepParam.DefaultValue.([]interface{})) + if err != nil { + return err + } } return nil } @@ -151,7 +164,10 @@ func parseObjectParam(sch *schema.Schema, bicepParam bicepParam) error { sch.Type = "object" if bicepParam.DefaultValue != nil && len(bicepParam.DefaultValue.(map[string]interface{})) > 1 { - parseObjectType(sch, bicepParam.DefaultValue.(map[string]interface{})) + err := parseObjectType(sch, bicepParam.DefaultValue.(map[string]interface{})) + if err != nil { + return err + } } return nil } @@ -180,10 +196,16 @@ func parseObjectType(sch *schema.Schema, objValue map[string]interface{}) error property.Default = value case reflect.Slice: property.Type = "array" - parseArrayType(property, value.([]interface{})) + err := parseArrayType(property, value.([]interface{})) + if err != nil { + return err + } case reflect.Map: property.Type = "object" - parseObjectType(property, value.(map[string]interface{})) + err := parseObjectType(property, value.(map[string]interface{})) + if err != nil { + return err + } default: return errors.New("unknown type: " + reflect.TypeOf(value).String()) } @@ -213,10 +235,16 @@ func parseArrayType(sch *schema.Schema, value []interface{}) error { sch.Default = value case reflect.Slice: items.Type = "array" - parseArrayType(items, elem.([]interface{})) + err := parseArrayType(items, elem.([]interface{})) + if err != nil { + return err + } case reflect.Map: items.Type = "object" - parseObjectType(items, elem.(map[string]interface{})) + err := parseObjectType(items, elem.(map[string]interface{})) + if err != nil { + return err + } default: return errors.New("unknown type: " + reflect.TypeOf(elem).String()) } diff --git a/pkg/bicep/biceptoschema_test.go b/pkg/bicep/biceptoschema_test.go index be1c3f3..0d9db18 100644 --- a/pkg/bicep/biceptoschema_test.go +++ b/pkg/bicep/biceptoschema_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/massdriver-cloud/airlock/pkg/bicep" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" ) func TestBicepToSchema(t *testing.T) { @@ -178,7 +178,7 @@ func TestBicepToSchema(t *testing.T) { t.Fatalf("%d, unexpected error", err) } - require.JSONEq(t, tc.want, string(bytes)) + assert.JSONEq(t, tc.want, string(bytes)) }) } } diff --git a/pkg/bicep/schematobicep.go b/pkg/bicep/schematobicep.go index b555470..35bcc49 100644 --- a/pkg/bicep/schematobicep.go +++ b/pkg/bicep/schematobicep.go @@ -11,7 +11,7 @@ import ( "github.com/massdriver-cloud/airlock/pkg/schema" ) -var indent string = " " +var indent = " " func SchemaToBicep(in io.Reader) ([]byte, error) { inBytes, err := io.ReadAll(in) @@ -81,15 +81,15 @@ func renderBicep(val interface{}, prefix string) (string, error) { case reflect.Bool: return fmt.Sprintf("%v", val), nil case reflect.Slice: - assertedVal, asserArrErr := val.([]interface{}) - if asserArrErr != true { + assertedVal, assertArrErr := val.([]interface{}) + if !assertArrErr { return "", fmt.Errorf("unable to convert value into array: %v", val) } return parseArray(assertedVal, prefix) case reflect.Map: - assertedVal, asserObjErr := val.(map[string]interface{}) - if asserObjErr != true { + assertedVal, assertObjErr := val.(map[string]interface{}) + if !assertObjErr { return "", fmt.Errorf("unable to convert value into object: %v", val) } @@ -124,7 +124,7 @@ func writeDescription(sch *schema.Schema, buf *bytes.Buffer) { } func writeAllowedParams(sch *schema.Schema, buf *bytes.Buffer) error { - if sch.Enum != nil && len(sch.Enum) > 0 { + if len(sch.Enum) > 0 { renderedVal, err := renderBicep(sch.Enum, "") if err != nil { return err diff --git a/pkg/bicep/testdata/simple.json b/pkg/bicep/testdata/simple.json index 830ead6..fdbc116 100644 --- a/pkg/bicep/testdata/simple.json +++ b/pkg/bicep/testdata/simple.json @@ -1,345 +1,345 @@ { - "required": [ - "stringtest", - "integertest", - "numbertest", - "booltest", - "arraytest", - "objecttest", - "nestedtest", - "enumtest" - ], - "properties": { - "stringtest": { - "type": "string" - }, - "integertest": { - "type": "integer" - }, - "numbertest": { - "type": "number" - }, - "booltest": { - "type": "boolean" - }, - "arraytest": { - "type": "array", - "items": { - "type": "string" - } - }, - "objecttest": { - "type": "object", - "required": [ - "foo" - ], - "properties": { - "foo": { - "type": "string" - }, - "bar": { - "type": "integer" - } - } - }, - "nestedtest": { - "type": "object", - "required": [ - "top" - ], - "properties": { - "top": { - "type": "object", - "required": [ - "nested" - ], - "properties": { - "nested": { - "type": "string" - } - } - } - } - }, - "enumtest": { - "type": "string", - "enum": [ - "foo", - "bar" - ] - }, - "enumtestints": { - "type": "integer", - "enum": [ - 1, - 2 - ] - }, - "enumtestbools": { - "type": "boolean", - "enum": [ - true, - false - ] - }, - "enumtestarrays": { - "type": "array", - "items": { - "type": "string" - }, - "enum": [ - [ - "foo", - "bar" - ], - [ - "baz", - "qux" - ] - ] - }, - "enumobjecttest": { - "type": "object", - "enum": [ - { - "foo": "bar" - }, - { - "baz": "qux" - } - ] - }, - "descriptiontest": { - "type": "string", - "description": "This is a description" - }, - "descriptionenumtest": { - "type": "string", - "description": "This is a new description", - "enum": [ - "foo", - "bar", - "baz" - ] - }, - "minvaluetest": { - "type": "integer", - "minimum": 5 - }, - "maxvaluetest": { - "type": "integer", - "maximum": 10 - }, - "minmaxvaluetest": { - "type": "integer", - "minimum": 5, - "maximum": 10 - }, - "minlengthstringtest": { - "type": "string", - "minLength": 5 - }, - "maxlengthstringtest": { - "type": "string", - "maxLength": 10 - }, - "minmaxlengthstringtest": { - "type": "string", - "minLength": 5, - "maxLength": 10 - }, - "minlengtharraytest": { - "type": "array", - "items": { - "type": "string" - }, - "minItems": 2 - }, - "maxlengtharraytest": { - "type": "array", - "items": { - "type": "string" - }, - "maxItems": 5 - }, - "minmaxlengtharraytest": { - "type": "array", - "items": { - "type": "string" - }, - "minItems": 2, - "maxItems": 5 - }, - "defaultstringtest": { - "type": "string", - "default": "foo" - }, - "defaultintegertest": { - "type": "integer", - "default": 5 - }, - "defaultbooltest": { - "type": "boolean", - "default": true - }, - "defaultarraytest": { - "type": "array", - "items": { - "type": "string" - }, - "default": [ - "foo", - "bar" - ] - }, - "defaultobjecttest": { - "type": "object", - "required": [ - "bar", - "foo" - ], - "properties": { - "bar": { - "type": "string" - }, - "foo": { - "type": "integer" - } - }, - "default": { - "bar": "baz", - "foo": 5 - } - }, - "defaultspaceobjecttest": { - "type": "object", - "required": [ - "foo", - "lorem" - ], - "properties": { - "foo": { - "type": "string" - }, - "lorem": { - "type": "string" - } - }, - "default": { - "foo": "bar baz", - "lorem": "ipsum" - } - }, - "defaultarrayobjecttest": { - "type": "array", - "items": { - "type": "object", - "required": [ - "bar", - "foo" - ], - "properties": { - "bar": { + "required": [ + "stringtest", + "integertest", + "numbertest", + "booltest", + "arraytest", + "objecttest", + "nestedtest", + "enumtest" + ], + "properties": { + "stringtest": { "type": "string" - }, - "foo": { + }, + "integertest": { "type": "integer" - } - } - }, - "default": [ - { - "bar": "baz", - "foo": 5 - }, - { - "bar": "qux", - "foo": 10 - } - ] - }, - "defaultnestedarraytest": { - "type": "array", - "items": { - "type": "array", - "items": { - "type": "array", - "items": { - "type": "string" - } - } - }, - "default": [ - [ - [ - "foo" - ], - [ - "bar" - ] - ], - [ - [ - "baz" - ], - [ - "qux" - ] - ] - ] - }, - "defaultnestedobjecttest": { - "type": "object", - "required": [ - "foo", - "quid" - ], - "properties": { - "foo": { - "type": "object", - "required": [ - "bar" - ], - "properties": { - "bar": { - "type": "object", - "required": [ + }, + "numbertest": { + "type": "number" + }, + "booltest": { + "type": "boolean" + }, + "arraytest": { + "type": "array", + "items": { + "type": "string" + } + }, + "objecttest": { + "type": "object", + "required": [ + "foo" + ], + "properties": { + "foo": { + "type": "string" + }, + "bar": { + "type": "integer" + } + } + }, + "nestedtest": { + "type": "object", + "required": [ + "top" + ], + "properties": { + "top": { + "type": "object", + "required": [ + "nested" + ], + "properties": { + "nested": { + "type": "string" + } + } + } + } + }, + "enumtest": { + "type": "string", + "enum": [ + "foo", + "bar" + ] + }, + "enumtestints": { + "type": "integer", + "enum": [ + 1, + 2 + ] + }, + "enumtestbools": { + "type": "boolean", + "enum": [ + true, + false + ] + }, + "enumtestarrays": { + "type": "array", + "items": { + "type": "string" + }, + "enum": [ + [ + "foo", + "bar" + ], + [ + "baz", + "qux" + ] + ] + }, + "enumobjecttest": { + "type": "object", + "enum": [ + { + "foo": "bar" + }, + { + "baz": "qux" + } + ] + }, + "descriptiontest": { + "type": "string", + "description": "This is a description" + }, + "descriptionenumtest": { + "type": "string", + "description": "This is a new description", + "enum": [ + "foo", + "bar", "baz" - ], - "properties": { - "baz": { - "type": "string" + ] + }, + "minvaluetest": { + "type": "integer", + "minimum": 5 + }, + "maxvaluetest": { + "type": "integer", + "maximum": 10 + }, + "minmaxvaluetest": { + "type": "integer", + "minimum": 5, + "maximum": 10 + }, + "minlengthstringtest": { + "type": "string", + "minLength": 5 + }, + "maxlengthstringtest": { + "type": "string", + "maxLength": 10 + }, + "minmaxlengthstringtest": { + "type": "string", + "minLength": 5, + "maxLength": 10 + }, + "minlengtharraytest": { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 2 + }, + "maxlengtharraytest": { + "type": "array", + "items": { + "type": "string" + }, + "maxItems": 5 + }, + "minmaxlengtharraytest": { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 2, + "maxItems": 5 + }, + "defaultstringtest": { + "type": "string", + "default": "foo" + }, + "defaultintegertest": { + "type": "integer", + "default": 5 + }, + "defaultbooltest": { + "type": "boolean", + "default": true + }, + "defaultarraytest": { + "type": "array", + "items": { + "type": "string" + }, + "default": [ + "foo", + "bar" + ] + }, + "defaultobjecttest": { + "type": "object", + "required": [ + "bar", + "foo" + ], + "properties": { + "bar": { + "type": "string" + }, + "foo": { + "type": "integer" } - } + }, + "default": { + "bar": "baz", + "foo": 5 } - } - }, - "quid": { - "type": "object", - "required": [ - "pro" - ], - "properties": { - "pro": { - "type": "string" + }, + "defaultspaceobjecttest": { + "type": "object", + "required": [ + "foo", + "lorem" + ], + "properties": { + "foo": { + "type": "string" + }, + "lorem": { + "type": "string" + } + }, + "default": { + "foo": "bar baz", + "lorem": "ipsum" } - } - } - }, - "default": { - "foo": { - "bar": { - "baz": "qux" - } - }, - "quid": { - "pro": "quo" + }, + "defaultarrayobjecttest": { + "type": "array", + "items": { + "type": "object", + "required": [ + "bar", + "foo" + ], + "properties": { + "bar": { + "type": "string" + }, + "foo": { + "type": "integer" + } + } + }, + "default": [ + { + "bar": "baz", + "foo": 5 + }, + { + "bar": "qux", + "foo": 10 + } + ] + }, + "defaultnestedarraytest": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "default": [ + [ + [ + "foo" + ], + [ + "bar" + ] + ], + [ + [ + "baz" + ], + [ + "qux" + ] + ] + ] + }, + "defaultnestedobjecttest": { + "type": "object", + "required": [ + "foo", + "quid" + ], + "properties": { + "foo": { + "type": "object", + "required": [ + "bar" + ], + "properties": { + "bar": { + "type": "object", + "required": [ + "baz" + ], + "properties": { + "baz": { + "type": "string" + } + } + } + } + }, + "quid": { + "type": "object", + "required": [ + "pro" + ], + "properties": { + "pro": { + "type": "string" + } + } + } + }, + "default": { + "foo": { + "bar": { + "baz": "qux" + } + }, + "quid": { + "pro": "quo" + } + } + }, + "securestringtest": { + "type": "string", + "format": "password" } - } - }, - "securestringtest": { - "type": "string", - "format": "password" } - } } diff --git a/pkg/helm/helmtoschema.go b/pkg/helm/helmtoschema.go index 1fc6971..e69105d 100644 --- a/pkg/helm/helmtoschema.go +++ b/pkg/helm/helmtoschema.go @@ -8,7 +8,7 @@ import ( "github.com/massdriver-cloud/airlock/pkg/schema" orderedmap "github.com/wk8/go-ordered-map/v2" - "gopkg.in/yaml.v3" + yaml "gopkg.in/yaml.v3" ) type nullError struct{} @@ -41,15 +41,13 @@ func HelmToSchema(valuesPath string) (*schema.Schema, error) { return sch, nil } -func parseNameNode(schema *schema.Schema, node *yaml.Node) error { +func parseNameNode(schema *schema.Schema, node *yaml.Node) { schema.Title = node.Value description := strings.TrimLeft(node.HeadComment, "# \t") if len(description) > 0 { schema.Description = description } - - return nil } func parseValueNode(schema *schema.Schema, node *yaml.Node) error { @@ -76,18 +74,17 @@ func parseValueNode(schema *schema.Schema, node *yaml.Node) error { func nodeToProperty(name, value *yaml.Node) (*schema.Schema, error) { sch := new(schema.Schema) - if err := parseNameNode(sch, name); err != nil { - return nil, err - } + parseNameNode(sch, name) err := parseValueNode(sch, value) if err != nil { + //nolint:errorlint if _, ok := err.(*nullError); ok { - fmt.Printf("Warning: Skipping field %s. Reason: %v\n", sch.Title, err) + fmt.Printf("warning: skipping field %s\n reason: %v\n", sch.Title, err) + //nolint:nilnil return nil, nil - } else { - return nil, err } + return nil, err } return sch, nil diff --git a/pkg/opentofu/schematotofu.go b/pkg/opentofu/schematotofu.go index e4f5967..1196bde 100644 --- a/pkg/opentofu/schematotofu.go +++ b/pkg/opentofu/schematotofu.go @@ -113,7 +113,7 @@ func convertMap(node *schema.Schema) hclwrite.Tokens { } // if there is exactly 1 patternProperty specification (and no other dynamic is set), we can interpret as a map - if node.PatternProperties != nil && len(node.PatternProperties) == 1 && additionalPropertiesIsFalseOrNull { + if len(node.PatternProperties) == 1 && additionalPropertiesIsFalseOrNull { for _, patternProp := range node.PatternProperties { return hclwrite.TokensForFunctionCall("map", typeExprTokens(patternProp, false)) } diff --git a/pkg/opentofu/testdata/opentofu/simple/schema.json b/pkg/opentofu/testdata/opentofu/simple/schema.json index 037a068..d64aae2 100644 --- a/pkg/opentofu/testdata/opentofu/simple/schema.json +++ b/pkg/opentofu/testdata/opentofu/simple/schema.json @@ -1,202 +1,202 @@ { - "required": [ - "nodescription", - "testbool", - "testemptybool", - "testlist", - "testmap", - "testnestedobject", - "testnumber", - "testobject", - "testset", - "teststring" - ], - "properties": { - "teststring": { - "title": "teststring", - "type": "string", - "description": "An example string variable", - "default": "string value" - }, - "testnumber": { - "title": "testnumber", - "type": "number", - "description": "An example number variable", - "default": 20 - }, - "testbool": { - "title": "testbool", - "type": "boolean", - "description": "An example bool variable", - "default": false - }, - "testemptybool": { - "title": "testemptybool", - "type": "boolean", - "description": "An example empty bool variable", - "default": false - }, - "testobject": { - "title": "testobject", - "type": "object", - "properties": { - "name": { - "title": "name", - "type": "string" + "required": [ + "nodescription", + "testbool", + "testemptybool", + "testlist", + "testmap", + "testnestedobject", + "testnumber", + "testobject", + "testset", + "teststring" + ], + "properties": { + "teststring": { + "title": "teststring", + "type": "string", + "description": "An example string variable", + "default": "string value" }, - "address": { - "title": "address", - "type": "string" + "testnumber": { + "title": "testnumber", + "type": "number", + "description": "An example number variable", + "default": 20 }, - "age": { - "title": "age", - "type": "number" - } - }, - "required": [ - "name" - ], - "description": "An example object variable", - "default": { - "name": "Bob", - "address": "123 Bob St." - } - }, - "testnestedobject": { - "title": "testnestedobject", - "description": "An example nested object variable", - "type": "object", - "required": [ - "name" - ], - "properties": { - "name": { - "title": "name", - "type": "string" - }, - "address": { - "title": "address", - "type": "string", - "default": "123 Bob St." + "testbool": { + "title": "testbool", + "type": "boolean", + "description": "An example bool variable", + "default": false }, - "age": { - "title": "age", - "type": "number", - "default": 30 + "testemptybool": { + "title": "testemptybool", + "type": "boolean", + "description": "An example empty bool variable", + "default": false }, - "dead": { - "title": "dead", - "type": "boolean", - "default": false - }, - "phones": { - "title": "phones", - "type": "object", - "default": { - "home": "987-654-3210" - }, - "required": [ - "home" - ], - "properties": { - "home": { - "title": "home", - "type": "string" + "testobject": { + "title": "testobject", + "type": "object", + "properties": { + "name": { + "title": "name", + "type": "string" + }, + "address": { + "title": "address", + "type": "string" + }, + "age": { + "title": "age", + "type": "number" + } }, - "work": { - "title": "work", - "type": "string", - "default": "123-456-7891" + "required": [ + "name" + ], + "description": "An example object variable", + "default": { + "name": "Bob", + "address": "123 Bob St." } - } }, - "children": { - "title": "children", - "type": "array", - "default": [ - { - "name": "bob", - "occupation": { - "company": "none", - "experience": 2, - "manager": true - } - } - ], - "items": { + "testnestedobject": { + "title": "testnestedobject", + "description": "An example nested object variable", "type": "object", "required": [ - "name" + "name" ], "properties": { - "name": { - "title": "name", - "type": "string" - }, - "occupation": { - "title": "occupation", - "type": "object", - "default": { - "company": "Massdriver", - "experience": 1, - "manager": false - }, - "required": [ - "company" - ], - "properties": { - "company": { - "title": "company", + "name": { + "title": "name", "type": "string" - }, - "experience": { - "title": "experience", + }, + "address": { + "title": "address", + "type": "string", + "default": "123 Bob St." + }, + "age": { + "title": "age", "type": "number", - "default": 0 - }, - "manager": { - "title": "manager", + "default": 30 + }, + "dead": { + "title": "dead", "type": "boolean", "default": false - } + }, + "phones": { + "title": "phones", + "type": "object", + "default": { + "home": "987-654-3210" + }, + "required": [ + "home" + ], + "properties": { + "home": { + "title": "home", + "type": "string" + }, + "work": { + "title": "work", + "type": "string", + "default": "123-456-7891" + } + } + }, + "children": { + "title": "children", + "type": "array", + "default": [ + { + "name": "bob", + "occupation": { + "company": "none", + "experience": 2, + "manager": true + } + } + ], + "items": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "title": "name", + "type": "string" + }, + "occupation": { + "title": "occupation", + "type": "object", + "default": { + "company": "Massdriver", + "experience": 1, + "manager": false + }, + "required": [ + "company" + ], + "properties": { + "company": { + "title": "company", + "type": "string" + }, + "experience": { + "title": "experience", + "type": "number", + "default": 0 + }, + "manager": { + "title": "manager", + "type": "boolean", + "default": false + } + } + } + } + } } - } } - } + }, + "testlist": { + "title": "testlist", + "type": "array", + "description": "An example list variable", + "items": { + "type": "string" + } + }, + "testset": { + "title": "testset", + "type": "array", + "uniqueItems": true, + "description": "An example set variable", + "items": { + "type": "string" + } + }, + "testmap": { + "title": "testmap", + "type": "object", + "description": "An example map variable", + "propertyNames": { + "pattern": "^.*$" + }, + "additionalProperties": { + "type": "string" + } + }, + "nodescription": { + "title": "nodescription", + "type": "string" } - } - }, - "testlist": { - "title": "testlist", - "type": "array", - "description": "An example list variable", - "items": { - "type": "string" - } - }, - "testset": { - "title": "testset", - "type": "array", - "uniqueItems": true, - "description": "An example set variable", - "items": { - "type": "string" - } - }, - "testmap": { - "title": "testmap", - "type": "object", - "description": "An example map variable", - "propertyNames": { - "pattern": "^.*$" - }, - "additionalProperties": { - "type": "string" - } - }, - "nodescription": { - "title": "nodescription", - "type": "string" } - } } diff --git a/pkg/opentofu/testdata/schemas/default.json b/pkg/opentofu/testdata/schemas/default.json index 0550d8b..b77f905 100644 --- a/pkg/opentofu/testdata/schemas/default.json +++ b/pkg/opentofu/testdata/schemas/default.json @@ -21,7 +21,9 @@ }, "arraytest": { "type": "array", - "default": ["foo"], + "default": [ + "foo" + ], "items": { "type": "string" } @@ -31,7 +33,9 @@ "default": { "foo": "bar" }, - "required": ["foo"], + "required": [ + "foo" + ], "properties": { "foo": { "type": "string" @@ -46,4 +50,4 @@ "required": [ "requiredtest" ] -} \ No newline at end of file +} diff --git a/pkg/opentofu/testdata/schemas/dependencies.json b/pkg/opentofu/testdata/schemas/dependencies.json index 13f3e1d..ab876eb 100644 --- a/pkg/opentofu/testdata/schemas/dependencies.json +++ b/pkg/opentofu/testdata/schemas/dependencies.json @@ -5,7 +5,9 @@ "properties": { "single": { "type": "object", - "required": ["foo"], + "required": [ + "foo" + ], "properties": { "foo": { "type": "boolean" @@ -16,26 +18,30 @@ }, "dependencies": { "foo": { - "oneOf": [{ - "properties": { - "foo": { - "const": false - } - } - }, - { - "properties": { - "foo": { - "const": true - }, - "baz": { - "type": "string" + "oneOf": [ + { + "properties": { + "foo": { + "const": false + } } }, - "required": ["baz"] - }] + { + "properties": { + "foo": { + "const": true + }, + "baz": { + "type": "string" + } + }, + "required": [ + "baz" + ] + } + ] } } } } -} \ No newline at end of file +} diff --git a/pkg/opentofu/testdata/schemas/dynamics.json b/pkg/opentofu/testdata/schemas/dynamics.json index 30c5c26..8ebf753 100644 --- a/pkg/opentofu/testdata/schemas/dynamics.json +++ b/pkg/opentofu/testdata/schemas/dynamics.json @@ -39,4 +39,4 @@ } } } -} \ No newline at end of file +} diff --git a/pkg/opentofu/testdata/schemas/simple.json b/pkg/opentofu/testdata/schemas/simple.json index 9905b6e..5a1cf01 100644 --- a/pkg/opentofu/testdata/schemas/simple.json +++ b/pkg/opentofu/testdata/schemas/simple.json @@ -29,7 +29,9 @@ }, "objecttest": { "type": "object", - "required": ["foo"], + "required": [ + "foo" + ], "properties": { "foo": { "type": "string" @@ -41,11 +43,15 @@ }, "nestedtest": { "type": "object", - "required": ["top"], + "required": [ + "top" + ], "properties": { "top": { "type": "object", - "required": ["nested"], + "required": [ + "nested" + ], "properties": { "nested": { "type": "string" @@ -55,4 +61,4 @@ } } } -} \ No newline at end of file +} diff --git a/pkg/opentofu/testdata/schemas/topleveldep.json b/pkg/opentofu/testdata/schemas/topleveldep.json index 99f709c..da16913 100644 --- a/pkg/opentofu/testdata/schemas/topleveldep.json +++ b/pkg/opentofu/testdata/schemas/topleveldep.json @@ -5,28 +5,32 @@ "properties": { "single": { "type": "string" - } + } }, "dependencies": { "single": { - "oneOf": [{ - "properties": { - "single": { - "const": "something" - } - } - }, - { - "properties": { - "single": { - "const": "somethingelse" - }, - "foo": { - "type": "string" + "oneOf": [ + { + "properties": { + "single": { + "const": "something" + } } }, - "required": ["foo"] - }] + { + "properties": { + "single": { + "const": "somethingelse" + }, + "foo": { + "type": "string" + } + }, + "required": [ + "foo" + ] + } + ] } } -} \ No newline at end of file +} diff --git a/pkg/opentofu/tofutoschema.go b/pkg/opentofu/tofutoschema.go index e27cfe7..306ac47 100644 --- a/pkg/opentofu/tofutoschema.go +++ b/pkg/opentofu/tofutoschema.go @@ -6,7 +6,7 @@ import ( "fmt" "slices" - "github.com/hashicorp/hcl/v2" + hcl "github.com/hashicorp/hcl/v2" "github.com/hashicorp/hcl/v2/ext/typeexpr" "github.com/hashicorp/hcl/v2/hclsyntax" "github.com/massdriver-cloud/airlock/pkg/schema" @@ -54,12 +54,9 @@ func variableToSchema(variable *tfconfig.Variable) (*schema.Schema, error) { variable.Name: defaults, } } - err = hydrateSchemaFromNameTypeAndDefaults(schema, variable.Name, variableType, topLevelDefault) - if err != nil { - return nil, err - } + hydrateSchemaFromNameTypeAndDefaults(schema, variable.Name, variableType, topLevelDefault) - schema.Description = string(variable.Description) + schema.Description = variable.Description if variable.Default != nil { schema.Default = variable.Default @@ -84,7 +81,7 @@ func variableTypeStringToCtyType(variableType string) (cty.Type, *typeexpr.Defau return ty, defaults, nil } -func hydrateSchemaFromNameTypeAndDefaults(sch *schema.Schema, name string, ty cty.Type, defaults *typeexpr.Defaults) error { +func hydrateSchemaFromNameTypeAndDefaults(sch *schema.Schema, name string, ty cty.Type, defaults *typeexpr.Defaults) { sch.Title = name if defaults != nil { @@ -93,6 +90,7 @@ func hydrateSchemaFromNameTypeAndDefaults(sch *schema.Schema, name string, ty ct } } + //nolint:gocritic if ty.IsPrimitiveType() { hydratePrimitiveSchema(sch, ty) } else if ty.IsMapType() { @@ -104,7 +102,6 @@ func hydrateSchemaFromNameTypeAndDefaults(sch *schema.Schema, name string, ty ct } else if ty.IsSetType() { hydrateSetSchema(sch, name, ty, defaults) } - return nil } func hydratePrimitiveSchema(sch *schema.Schema, ty cty.Type) { @@ -158,14 +155,14 @@ func ctyValueToInterface(val cty.Value) interface{} { if err != nil { // Should never happen, since all possible known // values have a JSON mapping. - panic(fmt.Errorf("failed to serialize default value as JSON: %s", err)) + panic(fmt.Errorf("failed to serialize default value as JSON: %w", err)) } var def interface{} err = json.Unmarshal(valJSON, &def) if err != nil { // Again should never happen, because valJSON is // guaranteed valid by ctyjson.Marshal. - panic(fmt.Errorf("failed to re-parse default value from JSON: %s", err)) + panic(fmt.Errorf("failed to re-parse default value from JSON: %w", err)) } removeNullKeys(def) return def @@ -193,7 +190,7 @@ func removeNullKeys(defVal interface{}) { delete(assertedDefVal, key) continue } - if valObj, ok := assertedDefVal[key].(map[string]interface{}); ok { + if valObj, objOk := assertedDefVal[key].(map[string]interface{}); objOk { removeNullKeys(valObj) } } diff --git a/pkg/schema/marshal.go b/pkg/schema/marshal.go index 6e5091d..7418450 100644 --- a/pkg/schema/marshal.go +++ b/pkg/schema/marshal.go @@ -45,7 +45,6 @@ func (s *Schema) UnmarshalJSON(data []byte) error { return err } s.AdditionalProperties = &addPropSchema - } else { // additionalProperties is bool s.AdditionalProperties = addPropBool diff --git a/pkg/schema/testdata/schema.json b/pkg/schema/testdata/schema.json index 2d2fbc0..22446b7 100644 --- a/pkg/schema/testdata/schema.json +++ b/pkg/schema/testdata/schema.json @@ -25,4 +25,4 @@ } } } -} \ No newline at end of file +} diff --git a/pkg/schema/types.go b/pkg/schema/types.go index 2bc9bdd..d4ceb63 100644 --- a/pkg/schema/types.go +++ b/pkg/schema/types.go @@ -11,11 +11,11 @@ import ( type Schema struct { // RFC draft-bhutton-json-schema-00 Version string `json:"$schema,omitempty"` // section 8.1.1 - //ID ID `json:"$id,omitempty"` // section 8.2.1 + // ID ID `json:"$id,omitempty"` // section 8.2.1 Anchor string `json:"$anchor,omitempty"` // section 8.2.2 Ref string `json:"$ref,omitempty"` // section 8.2.3.1 DynamicRef string `json:"$dynamicRef,omitempty"` // section 8.2.3.2 - //Definitions Definitions `json:"$defs,omitempty"` // section 8.2.4 + // Definitions Definitions `json:"$defs,omitempty"` // section 8.2.4 Comments string `json:"$comment,omitempty"` // section 8.3 // RFC draft-bhutton-json-schema-00 section 10.2.1 (Sub-schemas with logic) AllOf []*Schema `json:"allOf,omitempty"` // section 10.2.1.1 @@ -32,12 +32,12 @@ type Schema struct { Items *Schema `json:"items,omitempty"` // section 10.3.1.2 (replaces additionalItems) Contains *Schema `json:"contains,omitempty"` // section 10.3.1.3 // RFC draft-bhutton-json-schema-00 section 10.3.2 (sub-schemas) - //Properties map[string]*Schema `json:"properties,omitempty"` // section 10.3.2.1 + // Properties map[string]*Schema `json:"properties,omitempty"` // section 10.3.2.1 Properties *orderedmap.OrderedMap[string, *Schema] `json:"properties,omitempty"` PatternProperties map[string]*Schema `json:"patternProperties,omitempty"` // section 10.3.2.2 AdditionalPropertiesRaw *json.RawMessage `json:"additionalProperties,omitempty"` // section 10.3.2.3 AdditionalProperties interface{} `json:"-"` - //AdditionalProperties *Schema `json:"additionalProperties,omitempty"` // section 10.3.2.3 + // AdditionalProperties *Schema `json:"additionalProperties,omitempty"` // section 10.3.2.3 PropertyNames *Schema `json:"propertyNames,omitempty"` // section 10.3.2.4 // RFC draft-bhutton-json-schema-validation-00, section 6 Type string `json:"type,omitempty"` // section 6.1.1