diff --git a/.gitignore b/.gitignore index e99ac8f..b711704 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,25 @@ .* +*.zip +*.tar +*.out *.log +/bin/ +/tmp/ + +## Git +!.gitkeep +!.gitignore + +## GitHub !.github/ -!.husky/ + +## Editorconfig !.editorconfig -!.gitignore + +## Husky +!.husky/ +!.husky.yaml + +## Golang !.golangci.yml !.goreleaser.yml -!.husky.yaml -!.yamllint.yaml -/bin/ -/coverage.out -/coverage.html -/tmp/ diff --git a/.golangci.yml b/.golangci.yml index f9f768e..1385e27 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,63 +1,200 @@ run: timeout: 5m - skip-dirs: - - tmp + +issues: + exclude-dirs: + - 'bin' + - 'tmp' linters-settings: + # https://golangci-lint.run/usage/linters/#misspell + misspell: + mode: restricted + # https://golangci-lint.run/usage/linters/#asasalint + asasalint: + ignore-test: true + # https://golangci-lint.run/usage/linters/#exhaustive + exhaustive: + default-signifies-exhaustive: true + # https://golangci-lint.run/usage/linters/#predeclared + predeclared: + ignore: "new,error" + # https://golangci-lint.run/usage/linters/#gocritic gocritic: disabled-checks: - ifElseChain - commentFormatting + # https://golangci-lint.run/usage/linters/#testifylint + testifylint: + disable: + - float-compare + # https://golangci-lint.run/usage/linters/#gosec gosec: - excludes: - - G204 + confidence: medium + excludes: [G204] + # https://golangci-lint.run/usage/linters/#importas + importas: + no-unaliased: true + # https://golangci-lint.run/usage/linters/#gomoddirectives + gomoddirectives: + replace-local: true + # https://golangci-lint.run/usage/linters/#revive + revive: + ignore-generated-header: true + enable-all-rules: true + rules: + - name: line-length-limit + disabled: true + - name: cognitive-complexity + disabled: true + - name: unused-parameter + disabled: true + - name: add-constant + disabled: true + - name: cyclomatic + disabled: true + - name: function-length + disabled: true + - name: function-result-limit + disabled: true + - name: flag-parameter + disabled: true + - name: unused-receiver + disabled: true + - name: argument-limit + disabled: true + - name: max-control-nesting + disabled: true + - name: comment-spacings + disabled: true + - name: struct-tag + arguments: + - "json,inline" + - "yaml,squash" + - name: unhandled-error + arguments: + - "fmt.Printf" + - "fmt.Println" + # TODO remove + - name: deep-exit + disabled: true + - name: empty-block + disabled: true + - name: nested-structs + disabled: true + - name: unhandled-error + disabled: true + - name: indent-error-flow + disabled: true linters: + disable-all: true enable: - # Enabled by default linters: - - errcheck - - gosimple - - govet - - ineffassign - - staticcheck + ## Enabled by default linters: + - errcheck # errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false] + - gosimple # (megacheck) Linter for Go source code that specializes in simplifying code [fast: false, auto-fix: false] + - govet # (vet, vetshadow) Vet examines Go source code and reports suspicious constructs. It is roughly the same as 'go vet' and uses its passes. [fast: false, auto-fix: false] + - ineffassign # Detects when assignments to existing variables are not used [fast: true, auto-fix: false] + - staticcheck # (megacheck) It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary. The author of staticcheck doesn't support or approve the use of staticcheck as a library inside golangci-lint. [fast: false, auto-fix: false] + - unused # (megacheck) Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false] - # Disabled by default linters: - - asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false] + ## Disabled by your configuration linters: + - asasalint # check for pass []any as any in variadic func(...any) [fast: false, auto-fix: false] + - asciicheck # checks that all code identifiers does not have non-ASCII symbols in the name [fast: true, auto-fix: false] - bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false] - #- dupl # Tool for code clone detection [fast: true, auto-fix: false] + - bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false] + - containedctx # containedctx is a linter that detects struct contained context.Context field [fast: false, auto-fix: false] + - contextcheck # check whether the function uses a non-inherited context [fast: false, auto-fix: false] + - copyloopvar # (go >= 1.22) copyloopvar is a linter detects places where loop variables are copied [fast: true, auto-fix: false] + - decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false] + - durationcheck # check for two durations multiplied together [fast: false, auto-fix: false] + - errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and reports occations, where the check for the returned error can be omitted. [fast: false, auto-fix: false] + - errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, auto-fix: false] + - 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. [fast: false, auto-fix: false] + #- exhaustive # check exhaustiveness of enum switch statements [fast: false, auto-fix: false] + - exportloopref # checks for pointers to enclosing loop variables [fast: false, auto-fix: false] + #- forbidigo # Forbids identifiers [fast: false, auto-fix: false] - forcetypeassert # finds forced type assertions [fast: true, auto-fix: false] - #- gochecknoinits # Checks that no init functions are present in Go code [fast: true, auto-fix: false] - #- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false] - - gocritic # Provides diagnostics that check for bugs, performance and style issues. [fast: false, auto-fix: false] - - goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true] + - gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. [fast: true, auto-fix: false] + - gochecksumtype # Run exhaustiveness checks on Go "sum types" [fast: false, auto-fix: false] + - goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false] + - gocritic # Provides diagnostics that check for bugs, performance and style issues. [fast: false, auto-fix: true] + - gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true] + - goheader # Checks is file header matches to pattern [fast: true, auto-fix: true] + - goimports # Check import statements are formatted according to the 'goimport' command. Reformat imports in autofix mode. [fast: true, auto-fix: true] #- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. [fast: true, auto-fix: false] - 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. [fast: true, auto-fix: false] - - goprintffuncname # Checks that printf-like functions are named with `f` at the end [fast: true, auto-fix: false] - - gosec # (gas): Inspects source code for security problems [fast: false, auto-fix: false] - - grouper # An analyzer to analyze expression groups. [fast: true, auto-fix: false] + - goprintffuncname # Checks that printf-like functions are named with `f` at the end. [fast: true, auto-fix: false] + - gosec # (gas) Inspects source code for security problems [fast: false, auto-fix: false] + - gosmopolitan # Report certain i18n/l10n anti-patterns in your Go codebase [fast: false, auto-fix: false] + - grouper # Analyze expression groups. [fast: true, auto-fix: false] - importas # Enforces consistent import aliases [fast: false, auto-fix: false] - - maintidx # maintidx measures the maintainability index of each function. [fast: true, auto-fix: false] - #- makezero # Finds slice declarations with non-zero initial length [fast: false, auto-fix: false] - - misspell # Finds commonly misspelled English words in comments [fast: true, auto-fix: true] - - nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false] - #- nestif # Reports deeply nested if statements [fast: true, auto-fix: false] + - inamedparam # reports interfaces with unnamed method parameters [fast: true, auto-fix: false] + - intrange # (go >= 1.22) intrange is a linter to find places where for loops could make use of an integer range. [fast: true, auto-fix: false] + - loggercheck # (logrlint) Checks key value pairs for common logger libraries (kitlog,klog,logr,zap). [fast: false, auto-fix: false] + - makezero # Finds slice declarations with non-zero initial length [fast: false, auto-fix: false] + - misspell # Finds commonly misspelled English words [fast: true, auto-fix: true] + - mirror # reports wrong mirror patterns of bytes/strings usage [fast: false, auto-fix: true] + - musttag # enforce field tags in (un)marshaled structs [fast: false, auto-fix: false] + - nakedret # Checks that functions with naked returns are not longer than a maximum size (can be zero). [fast: true, auto-fix: false] - nilerr # Finds the code that returns nil even if it checks that the error is not nil. [fast: false, auto-fix: false] - nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value. [fast: false, auto-fix: false] - - noctx # noctx finds sending http request without context.Context [fast: false, auto-fix: false] - - nolintlint # Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: false] - #- nonamedreturns # Reports all named returns [fast: false, auto-fix: false] + - noctx # Finds sending http request without context.Context [fast: false, auto-fix: false] + - nolintlint # Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: true] + - nonamedreturns # Reports all named returns [fast: false, auto-fix: false] - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. [fast: true, auto-fix: false] - - prealloc # Finds slice declarations that could potentially be pre-allocated [fast: true, auto-fix: false] - #- predeclared # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false] + #- paralleltest # Detects missing usage of t.Parallel() method in your Go test [fast: false, auto-fix: false] + - predeclared # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false] - promlinter # Check Prometheus metrics naming via promlint [fast: true, auto-fix: false] - #- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false] - #- tagliatelle # Checks the struct tags. [fast: true, auto-fix: false] + #- reassign # Checks that package variables are not reassigned [fast: false, auto-fix: false] + - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false] + - rowserrcheck # checks whether Rows.Err of rows is checked successfully [fast: false, auto-fix: false] + - spancheck # Checks for mistakes with OpenTelemetry/Census spans. [fast: false, auto-fix: false] + - sqlclosecheck # Checks that sql.Rows, sql.Stmt, sqlx.NamedStmt, pgx.Query are closed. [fast: false, auto-fix: false] + - stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false] + - tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 [fast: false, auto-fix: false] + - testableexamples # linter checks if examples are testable (have an expected output) [fast: true, auto-fix: false] + - testifylint # Checks usage of github.com/stretchr/testify. [fast: false, auto-fix: false] - testpackage # linter that makes you use a separate _test package [fast: true, auto-fix: false] - - thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false] + - thelper # thelper detects tests helpers which is not start with t.Helper() method. [fast: false, auto-fix: false] + - tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes. [fast: false, auto-fix: false] - unconvert # Remove unnecessary type conversions [fast: false, auto-fix: false] - - unparam # Reports unused function parameters [fast: false, auto-fix: false] - usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. [fast: true, auto-fix: false] - - wastedassign # wastedassign finds wasted assignment statements. [fast: false, auto-fix: false] - - whitespace # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true] - disable: - - unused + - wastedassign # Finds wasted assignment statements [fast: false, auto-fix: false] + - whitespace # Whitespace is a linter that checks for unnecessary newlines at the start and end of functions, if, for, etc. [fast: true, auto-fix: true] + + ## Don't enable + #- cyclop # checks function and package cyclomatic complexity [fast: false, auto-fix: false] + #- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false] + #- dupl # Tool for code clone detection [fast: true, auto-fix: false] + #- dupword # checks for duplicate words in the source code [fast: true, auto-fix: false] + #- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false] + #- err113 # Go linter to check the errors handling expressions [fast: false, auto-fix: false] + #- exhaustruct # Checks if all structure fields are initialized [fast: false, auto-fix: false] + #- gci # Gci controls Go package import order and makes it always deterministic. [fast: true, auto-fix: true] + #- gochecknoglobals # Check that no global variables exist. [fast: false, auto-fix: false] + #- gochecknoinits # Checks that no init functions are present in Go code [fast: true, auto-fix: false] + #- gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false] + #- godot # Check if comments end in a period [fast: true, auto-fix: true] + #- godox # Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false] + #- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true] + #- funlen # Tool for detection of long functions [fast: true, auto-fix: false] + #- ginkgolinter # enforces standards of using ginkgo and gomega [fast: false, auto-fix: false] + #- gocognit # Computes and checks the cognitive complexity of functions [fast: true, auto-fix: false] + #- interfacebloat # A linter that checks the number of methods inside an interface. [fast: true, auto-fix: false] + #- lll # Reports long lines [fast: true, auto-fix: false] + #- ireturn # Accept Interfaces, Return Concrete Types [fast: false, auto-fix: false] + #- maintidx # maintidx measures the maintainability index of each function. [fast: true, auto-fix: false] + #- nestif # Reports deeply nested if statements [fast: true, auto-fix: false] + #- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity [fast: true, auto-fix: false] + #- perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. [fast: false, auto-fix: false] + #- prealloc # Finds slice declarations that could potentially be pre-allocated [fast: true, auto-fix: false] + #- protogetter # Reports direct reads from proto message fields when getters should be used [fast: false, auto-fix: true] + #- sloglint # ensure consistent code style when using log/slog [fast: false, auto-fix: false] + #- tagalign # check that struct tags are well aligned [fast: true, auto-fix: true] + #- tagliatelle # Checks the struct tags. [fast: true, auto-fix: false] + #- unparam # Reports unused function parameters [fast: false, auto-fix: false] + #- varnamelen # checks that the length of a variable's name matches its scope [fast: false, auto-fix: false] + #- wrapcheck # Checks that errors returned from external packages are wrapped [fast: false, auto-fix: false] + #- wsl # add or remove empty lines [fast: true, auto-fix: false] + #- zerologlint # Detects the wrong usage of `zerolog` that a user forgets to dispatch with `Send` or `Msg` [fast: false, auto-fix: false] diff --git a/cmd/actions/postrenderer.go b/cmd/actions/postrenderer.go index 82aa536..156750d 100644 --- a/cmd/actions/postrenderer.go +++ b/cmd/actions/postrenderer.go @@ -19,7 +19,6 @@ var postRendererCmd = &cobra.Command{ Example: " squadron template storefinder frontend backend --namespace demo", Args: cobra.MinimumNArgs(0), RunE: func(cmd *cobra.Command, args []string) error { - // this does the trick r, err := io.ReadAll(cmd.InOrStdin()) if err != nil { diff --git a/cmd/actions/root.go b/cmd/actions/root.go index 2c7ecd0..6429ccb 100644 --- a/cmd/actions/root.go +++ b/cmd/actions/root.go @@ -71,7 +71,7 @@ func Execute() { } // parseExtraArgs ... -func parseExtraArgs(args []string) (out []string, extraArgs []string) { +func parseExtraArgs(args []string) (out []string, extraArgs []string) { //nolint:nonamedreturns for i, arg := range args { if strings.HasPrefix(arg, "--") && i > 0 { return args[:i], args[i:] @@ -82,7 +82,7 @@ func parseExtraArgs(args []string) (out []string, extraArgs []string) { return args, nil } -func parseSquadronAndUnitNames(args []string) (squadron string, units []string) { +func parseSquadronAndUnitNames(args []string) (squadron string, units []string) { //nolint:nonamedreturns if len(args) == 0 { return "", nil } diff --git a/go.mod b/go.mod index 269210d..3d37bb9 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,9 @@ module github.com/foomo/squadron go 1.22.0 -toolchain go1.22.2 +toolchain go1.22.5 + +replace github.com/miracl/conflate v1.2.1 => github.com/runz0rd/conflate v1.2.2-0.20210920145208-fa48576ef06d require ( github.com/1Password/connect-sdk-go v1.5.3 @@ -17,21 +19,22 @@ require ( golang.org/x/sync v0.7.0 gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.1 - k8s.io/api v0.30.2 + k8s.io/api v0.30.3 ) require ( atomicgo.dev/cursor v0.2.0 // indirect atomicgo.dev/keyboard v0.2.9 // indirect atomicgo.dev/schedule v0.1.0 // indirect - github.com/BurntSushi/toml v1.2.0 // indirect + github.com/BurntSushi/toml v1.4.0 // indirect github.com/containerd/console v1.0.3 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dlclark/regexp2 v1.4.0 // indirect github.com/ghodss/yaml v1.0.0 // indirect - github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/logr v1.4.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/google/gofuzz v1.2.0 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/gookit/color v1.5.4 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/json-iterator/go v1.1.12 // indirect @@ -51,16 +54,14 @@ require ( github.com/xeipuuv/gojsonschema v1.2.0 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect go.uber.org/atomic v1.10.0 // indirect - golang.org/x/net v0.23.0 // indirect - golang.org/x/sys v0.18.0 // indirect - golang.org/x/term v0.18.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/net v0.26.0 // indirect + golang.org/x/sys v0.21.0 // indirect + golang.org/x/term v0.21.0 // indirect + golang.org/x/text v0.16.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect - k8s.io/apimachinery v0.30.2 // indirect + k8s.io/apimachinery v0.30.3 // indirect k8s.io/klog/v2 v2.120.1 // indirect k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect ) - -replace github.com/miracl/conflate v1.2.1 => github.com/runz0rd/conflate v1.2.2-0.20210920145208-fa48576ef06d diff --git a/go.sum b/go.sum index 7423ad8..586a45d 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ atomicgo.dev/schedule v0.1.0/go.mod h1:xeUa3oAkiuHYh8bKiQBRojqAMq3PXXbJujjb0hw8p github.com/1Password/connect-sdk-go v1.5.3 h1:KyjJ+kCKj6BwB2Y8tPM1Ixg5uIS6HsB0uWA8U38p/Uk= github.com/1Password/connect-sdk-go v1.5.3/go.mod h1:5rSymY4oIYtS4G3t0oMkGAXBeoYiukV3vkqlnEjIDJs= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= -github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= +github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/HdrHistogram/hdrhistogram-go v1.1.2 h1:5IcZpTvzydCQeHzK4Ef/D5rrSqwxob0t8PQPMybUNFM= github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo= github.com/MarvinJWendt/testza v0.1.0/go.mod h1:7AxNvlfeHP7Z/hDQ5JtE3OKYT3XFUeLCDE2DQninSqs= @@ -35,8 +35,8 @@ 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/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -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-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -45,8 +45,8 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ= github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo= github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0= @@ -157,8 +157,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY 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.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= -golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +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.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -179,22 +179,22 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.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.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-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= -golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= +golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= +golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= 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.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -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.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.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= @@ -221,10 +221,10 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/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= -k8s.io/api v0.30.2 h1:+ZhRj+28QT4UOH+BKznu4CBgPWgkXO7XAvMcMl0qKvI= -k8s.io/api v0.30.2/go.mod h1:ULg5g9JvOev2dG0u2hig4Z7tQ2hHIuS+m8MNZ+X6EmI= -k8s.io/apimachinery v0.30.2 h1:fEMcnBj6qkzzPGSVsAZtQThU62SmQ4ZymlXRC5yFSCg= -k8s.io/apimachinery v0.30.2/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= +k8s.io/api v0.30.3 h1:ImHwK9DCsPA9uoU3rVh4QHAHHK5dTSv1nxJUapx8hoQ= +k8s.io/api v0.30.3/go.mod h1:GPc8jlzoe5JG3pb0KJCSLX5oAFIW3/qNJITlDj8BH04= +k8s.io/apimachinery v0.30.3 h1:q1laaWCmrszyQuSQCfNB8cFgCuDAoPszKY4ucAjDwHc= +k8s.io/apimachinery v0.30.3/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc= k8s.io/klog/v2 v2.120.1 h1:QXU6cPEOIslTGvZaXvFWiP9VKyeet3sawzTOvdXb4Vw= k8s.io/klog/v2 v2.120.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI= diff --git a/internal/config/config.go b/internal/config/config.go index 32426d4..020211a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -11,7 +11,7 @@ type Config struct { // Version of the schema Version string `yaml:"version,omitempty"` // Global values to be injected into all squadron values - Global map[string]interface{} `yaml:"global,omitempty"` + Global map[string]any `yaml:"global,omitempty"` // Global builds that can be referenced as dependencies Builds map[string]Build `yaml:"builds,omitempty"` // Squadron definitions diff --git a/internal/config/unit.go b/internal/config/unit.go index 24005a1..311d706 100644 --- a/internal/config/unit.go +++ b/internal/config/unit.go @@ -15,21 +15,21 @@ import ( ) type Unit struct { - Chart helm.Dependency `yaml:"chart,omitempty"` - Kustomize string `yaml:"kustomize,omitempty"` - Tags Tags `yaml:"tags,omitempty"` - Builds map[string]Build `yaml:"builds,omitempty"` - Values map[string]interface{} `yaml:"values,omitempty"` + Chart helm.Dependency `yaml:"chart,omitempty"` + Kustomize string `yaml:"kustomize,omitempty"` + Tags Tags `yaml:"tags,omitempty"` + Builds map[string]Build `yaml:"builds,omitempty"` + Values map[string]any `yaml:"values,omitempty"` } // ------------------------------------------------------------------------------------------------ // ~ Public methods // ------------------------------------------------------------------------------------------------ -func (u *Unit) ValuesYAML(global map[string]interface{}) ([]byte, error) { +func (u *Unit) ValuesYAML(global map[string]any) ([]byte, error) { values := u.Values if values == nil { - values = map[string]interface{}{} + values = map[string]any{} } if global != nil { if _, ok := values["global"]; !ok { @@ -69,7 +69,7 @@ func (u *Unit) Push(ctx context.Context, squadron, unit string, args []string) ( return "", nil } -func (u *Unit) Template(ctx context.Context, name, squadron, unit, namespace string, global map[string]interface{}, helmArgs []string) ([]byte, error) { +func (u *Unit) Template(ctx context.Context, name, squadron, unit, namespace string, global map[string]any, helmArgs []string) ([]byte, error) { var ret bytes.Buffer valueBytes, err := u.ValuesYAML(global) if err != nil { diff --git a/internal/helm/chart.go b/internal/helm/chart.go index 3186e2a..52a2f6a 100644 --- a/internal/helm/chart.go +++ b/internal/helm/chart.go @@ -31,7 +31,7 @@ func (c *Chart) AddDependency(alias string, cd Dependency) { c.Dependencies = append(c.Dependencies, cd) } -func (c *Chart) Generate(chartPath string, overrides interface{}) error { +func (c *Chart) Generate(chartPath string, overrides any) error { // generate Chart.yaml if err := util.GenerateYaml(path.Join(chartPath, chartFile), c); err != nil { return err diff --git a/internal/helm/doc.go b/internal/helm/doc.go index de7cfab..aa5b86f 100644 --- a/internal/helm/doc.go +++ b/internal/helm/doc.go @@ -1,9 +1,9 @@ package helm import ( - "fmt" "os" + "github.com/pkg/errors" "gopkg.in/yaml.v3" ) @@ -18,10 +18,10 @@ func loadChart(path string) (*Chart, error) { c := Chart{} file, err := os.ReadFile(path) if err != nil { - return nil, fmt.Errorf("error while opening file: %v", err) + return nil, errors.Wrap(err, "error while opening file") } if err := yaml.Unmarshal(file, &c); err != nil { - return nil, fmt.Errorf("error while unmarshalling template file: %s", err) + return nil, errors.Wrap(err, "error while unmarshalling template file") } return &c, nil } diff --git a/internal/template/default.go b/internal/template/default.go index 100e199..4046cb2 100644 --- a/internal/template/default.go +++ b/internal/template/default.go @@ -1,13 +1,13 @@ package template -func defaultValue(value string, def interface{}) interface{} { +func defaultValue(value string, def any) any { if value == "" { return def } return value } -func defaultIndexValue(v map[string]interface{}, index string, def interface{}) interface{} { +func defaultIndexValue(v map[string]any, index string, def any) any { var ok bool if _, ok = v[index]; ok { return v[index] diff --git a/internal/template/file.go b/internal/template/file.go index 004d885..256556c 100644 --- a/internal/template/file.go +++ b/internal/template/file.go @@ -8,7 +8,7 @@ import ( "github.com/pkg/errors" ) -func file(ctx context.Context, templateVars interface{}, errorOnMissing bool) func(v string) (string, error) { +func file(ctx context.Context, templateVars any, errorOnMissing bool) func(v string) (string, error) { return func(v string) (string, error) { if v == "" { return "", nil diff --git a/internal/template/onepassword.go b/internal/template/onepassword.go index 3d9603a..2b9b09c 100644 --- a/internal/template/onepassword.go +++ b/internal/template/onepassword.go @@ -10,6 +10,7 @@ import ( "os/exec" "regexp" "strings" + "sync" "text/template" "github.com/1Password/connect-sdk-go/connect" @@ -27,7 +28,7 @@ var ErrOnePasswordNotSignedIn = errors.New("not signed in") func onePasswordConnectGet(client connect.Client, vaultUUID, itemUUID string) (map[string]string, error) { var item *onepassword.Item - if onePasswordUUID.Match([]byte(itemUUID)) { + if onePasswordUUID.MatchString(itemUUID) { if v, err := client.GetItem(itemUUID, vaultUUID); err != nil { return nil, err } else { @@ -51,7 +52,7 @@ func onePasswordConnectGet(client connect.Client, vaultUUID, itemUUID string) (m func onePasswordConnectGetDocument(client connect.Client, vaultUUID, itemUUID string) (string, error) { var item *onepassword.Item - if onePasswordUUID.Match([]byte(itemUUID)) { + if onePasswordUUID.MatchString(itemUUID) { if v, err := client.GetItem(itemUUID, vaultUUID); err != nil { return "", err } else { @@ -79,16 +80,20 @@ func onePasswordConnectGetDocument(client connect.Client, vaultUUID, itemUUID st return strings.Trim(string(res), "\n"), nil } +var onePasswordGetLock sync.Mutex + func onePasswordGet(ctx context.Context, account, vaultUUID, itemUUID string) (map[string]string, error) { + onePasswordGetLock.Lock() + defer onePasswordGetLock.Unlock() var v struct { Vault struct { ID string `json:"id"` } `json:"vault"` Fields []struct { - ID string `json:"id"` - Type string `json:"type"` // CONCEALED, STRING - Label string `json:"label"` - Value interface{} `json:"value"` + ID string `json:"id"` + Type string `json:"type"` // CONCEALED, STRING + Label string `json:"label"` + Value any `json:"value"` } `json:"fields"` } if res, err := exec.CommandContext(ctx, "op", "item", "get", itemUUID, "--vault", vaultUUID, "--account", account, "--format", "json").CombinedOutput(); err != nil && strings.Contains(string(res), "You are not currently signed in") { @@ -115,7 +120,11 @@ func onePasswordGet(ctx context.Context, account, vaultUUID, itemUUID string) (m } } +var onePasswordGetDocumentLock sync.Mutex + func onePasswordGetDocument(ctx context.Context, account, vaultUUID, itemUUID string) (string, error) { + onePasswordGetDocumentLock.Lock() + defer onePasswordGetDocumentLock.Unlock() res, err := exec.CommandContext(ctx, "op", "document", "get", itemUUID, "--vault", vaultUUID, "--account", account).CombinedOutput() if err != nil && strings.Contains(string(res), "You are not currently signed in") { return "", ErrOnePasswordNotSignedIn @@ -164,30 +173,50 @@ func isServiceAccount() bool { return os.Getenv("OP_SERVICE_ACCOUNT_TOKEN") != "" } +var onePasswordInitLock sync.Mutex + func onePasswordInit(ctx context.Context, account string) error { - if onePasswordCache == nil { - onePasswordCache = map[string]map[string]string{} - if _, err := exec.LookPath("op"); err != nil { - pterm.Warning.Println("Your templates includes a call to 1Password, please install it:") - pterm.Warning.Println("https://support.1password.com/command-line-getting-started/#set-up-the-command-line-tool") - return errors.Wrap(err, "failed to lookup op") - } else if _, err := exec.CommandContext(ctx, "op", "account", "get", "--account", account).CombinedOutput(); err == nil { - // do nothing - } else if os.Getenv(fmt.Sprintf("OP_SESSION_%s", account)) == "" { - if err := onePasswordSignIn(ctx, account); err != nil { - return errors.Wrap(err, "failed to sign in") - } + onePasswordInitLock.Lock() + defer onePasswordInitLock.Unlock() + + // validate cache + if onePasswordCache != nil { + return nil + } + + onePasswordCache = map[string]map[string]string{} + + // validate env + if isConnect() || isServiceAccount() { + return nil + } + + // validate executeable + if _, err := exec.LookPath("op"); err != nil { + pterm.Warning.Println("Your templates includes a call to 1Password, please install it:") + pterm.Warning.Println("https://support.1password.com/command-line-getting-started/#set-up-the-command-line-tool") + return errors.Wrap(err, "failed to lookup op") + } + + // validate auth + if _, err := exec.CommandContext(ctx, "op", "account", "get", "--account", account).CombinedOutput(); err == nil { + return nil + } + + // validate auth env + if os.Getenv(fmt.Sprintf("OP_SESSION_%s", account)) == "" { + if err := onePasswordSignIn(ctx, account); err != nil { + return errors.Wrap(err, "failed to sign in") } } + return nil } -func onePassword(ctx context.Context, templateVars interface{}, errorOnMissing bool) func(account, vaultUUID, itemUUID, field string) (string, error) { +func onePassword(ctx context.Context, templateVars any, errorOnMissing bool) func(account, vaultUUID, itemUUID, field string) (string, error) { return func(account, vaultUUID, itemUUID, field string) (string, error) { - // validate command - if isConnect() || isServiceAccount() { - onePasswordCache = map[string]map[string]string{} - } else if err := onePasswordInit(ctx, account); err != nil { + // init + if err := onePasswordInit(ctx, account); err != nil { return "", err } // render uuid & field params @@ -205,27 +234,19 @@ func onePassword(ctx context.Context, templateVars interface{}, errorOnMissing b // create cache key cacheKey := strings.Join([]string{account, vaultUUID, itemUUID}, "#") - if isConnect() { - if _, ok := onePasswordCache[cacheKey]; !ok { - if client, err := connect.NewClientFromEnvironment(); err != nil { + if _, ok := onePasswordCache[cacheKey]; !ok { + if isConnect() { + client, err := connect.NewClientFromEnvironment() + if err != nil { return "", err - } else if res, err := onePasswordConnectGet(client, vaultUUID, itemUUID); err != nil { + } + if res, err := onePasswordConnectGet(client, vaultUUID, itemUUID); err != nil { return "", err } else { onePasswordCache[cacheKey] = res } - } - } else { - if _, ok := onePasswordCache[cacheKey]; !ok { - if res, err := onePasswordGet(ctx, account, vaultUUID, itemUUID); !errors.Is(err, ErrOnePasswordNotSignedIn) { - if err != nil { - return "", err - } else { - onePasswordCache[cacheKey] = res - } - } else if err := onePasswordSignIn(ctx, account); err != nil { - return "", errors.Wrap(err, "failed to sign in second time") - } else if res, err = onePasswordGet(ctx, account, vaultUUID, itemUUID); err != nil { + } else { + if res, err := onePasswordGet(ctx, account, vaultUUID, itemUUID); err != nil { return "", err } else { onePasswordCache[cacheKey] = res @@ -241,14 +262,13 @@ func onePassword(ctx context.Context, templateVars interface{}, errorOnMissing b } } -func onePasswordDocument(ctx context.Context, templateVars interface{}, errorOnMissing bool) func(account, vaultUUID, itemUUID string) (string, error) { +func onePasswordDocument(ctx context.Context, templateVars any, errorOnMissing bool) func(account, vaultUUID, itemUUID string) (string, error) { return func(account, vaultUUID, itemUUID string) (string, error) { - // validate command - if isConnect() || isServiceAccount() { - onePasswordCache = map[string]map[string]string{} - } else if err := onePasswordInit(ctx, account); err != nil { + // init + if err := onePasswordInit(ctx, account); err != nil { return "", err } + // render uuid & field params if value, err := onePasswordRender("op", itemUUID, templateVars, errorOnMissing); err != nil { return "", err @@ -259,8 +279,8 @@ func onePasswordDocument(ctx context.Context, templateVars interface{}, errorOnM // create cache key cacheKey := strings.Join([]string{account, vaultUUID, itemUUID}, "#") - if isConnect() { - if _, ok := onePasswordCache[cacheKey]; !ok { + if _, ok := onePasswordCache[cacheKey]; !ok { + if isConnect() { if client, err := connect.NewClientFromEnvironment(); err != nil { return "", err } else if res, err := onePasswordConnectGetDocument(client, vaultUUID, itemUUID); err != nil { @@ -268,18 +288,8 @@ func onePasswordDocument(ctx context.Context, templateVars interface{}, errorOnM } else { onePasswordCache[cacheKey] = map[string]string{"document": res} } - } - } else { - if _, ok := onePasswordCache[cacheKey]; !ok { - if res, err := onePasswordGetDocument(ctx, account, vaultUUID, itemUUID); !errors.Is(err, ErrOnePasswordNotSignedIn) { - if err != nil { - return "", err - } else { - onePasswordCache[cacheKey] = map[string]string{"document": res} - } - } else if err := onePasswordSignIn(ctx, account); err != nil { - return "", errors.Wrap(err, "failed to sign in second time") - } else if res, err = onePasswordGetDocument(ctx, account, vaultUUID, itemUUID); err != nil { + } else { + if res, err := onePasswordGetDocument(ctx, account, vaultUUID, itemUUID); err != nil { return "", err } else { onePasswordCache[cacheKey] = map[string]string{"document": res} @@ -295,7 +305,7 @@ func onePasswordDocument(ctx context.Context, templateVars interface{}, errorOnM } } -func onePasswordRender(name, text string, data interface{}, errorOnMissing bool) (string, error) { +func onePasswordRender(name, text string, data any, errorOnMissing bool) (string, error) { var opts []string if !errorOnMissing { opts = append(opts, "missingkey=error") diff --git a/internal/template/template.go b/internal/template/template.go index e374b18..d135148 100644 --- a/internal/template/template.go +++ b/internal/template/template.go @@ -6,7 +6,7 @@ import ( "text/template" ) -func ExecuteFileTemplate(ctx context.Context, text string, templateVars interface{}, errorOnMissing bool) ([]byte, error) { +func ExecuteFileTemplate(ctx context.Context, text string, templateVars any, errorOnMissing bool) ([]byte, error) { funcMap := template.FuncMap{ "env": env, "envDefault": envDefault, diff --git a/internal/template/vars.go b/internal/template/vars.go index f81d37f..1ab9cd7 100644 --- a/internal/template/vars.go +++ b/internal/template/vars.go @@ -1,7 +1,7 @@ package template -type Vars map[string]interface{} +type Vars map[string]any -func (tv *Vars) Add(name string, value interface{}) { +func (tv *Vars) Add(name string, value any) { (*tv)[name] = value } diff --git a/internal/util/kube.go b/internal/util/kube.go index f3bc75b..f03079a 100644 --- a/internal/util/kube.go +++ b/internal/util/kube.go @@ -7,7 +7,7 @@ import ( "os" "strings" - v1 "k8s.io/api/apps/v1" + k8s "k8s.io/api/apps/v1" ) type KubeCmd struct { @@ -85,12 +85,12 @@ func (c KubeCmd) DeleteService(service string) *Cmd { return c.Args("delete", "service", service) } -func (c KubeCmd) GetDeployment(ctx context.Context, deployment string) (*v1.Deployment, error) { +func (c KubeCmd) GetDeployment(ctx context.Context, deployment string) (*k8s.Deployment, error) { out, err := c.Args("get", "deployment", deployment, "-o", "json").Run(ctx) if err != nil { return nil, err } - var d v1.Deployment + var d k8s.Deployment if err := json.Unmarshal([]byte(out), &d); err != nil { return nil, err } @@ -127,7 +127,7 @@ func (c KubeCmd) GetPods(ctx context.Context, selectors map[string]string) ([]st return parseResources(out, "pod/") } -func (c KubeCmd) GetContainers(deployment v1.Deployment) []string { +func (c KubeCmd) GetContainers(deployment k8s.Deployment) []string { containers := make([]string, len(deployment.Spec.Template.Spec.Containers)) for i, c := range deployment.Spec.Template.Spec.Containers { containers[i] = c.Name diff --git a/internal/util/strings.go b/internal/util/strings.go index 7c85a50..e54053a 100644 --- a/internal/util/strings.go +++ b/internal/util/strings.go @@ -4,8 +4,8 @@ import ( "strings" ) -func ToSnakeCaseKeys(in interface{}) { - if value, ok := in.(map[string]interface{}); ok { +func ToSnakeCaseKeys(in any) { + if value, ok := in.(map[string]any); ok { for k, v := range value { if strings.Contains(k, "-") { value[strings.ReplaceAll(k, "-", "_")] = v diff --git a/internal/util/yaml.go b/internal/util/yaml.go index 29f2ce4..e78deba 100644 --- a/internal/util/yaml.go +++ b/internal/util/yaml.go @@ -6,7 +6,7 @@ import ( yamlv2 "gopkg.in/yaml.v2" ) -func GenerateYaml(path string, data interface{}) (err error) { +func GenerateYaml(path string, data any) (err error) { out, marshalErr := yamlv2.Marshal(data) if marshalErr != nil { return marshalErr @@ -21,5 +21,5 @@ func GenerateYaml(path string, data interface{}) (err error) { } }() _, err = file.Write(out) - return + return err } diff --git a/squadron.go b/squadron.go index 23e417c..a0bc834 100644 --- a/squadron.go +++ b/squadron.go @@ -147,7 +147,7 @@ func (sq *Squadron) RenderConfig(ctx context.Context) error { pterm.Debug.Println("rendering config") var tv templatex.Vars - var vars map[string]interface{} + var vars map[string]any if err := yaml.Unmarshal([]byte(sq.config), &vars); err != nil { return err } @@ -239,8 +239,6 @@ func (sq *Squadron) BuildDependencies(ctx context.Context, buildArgs []string, p dependencies := sq.c.BuildDependencies() for name, dependency := range dependencies { i := i + 1 - name := name - dependency := dependency wg.Go(func() error { pterm.Info.Printfln("[%d/%d] Building dependency `%s`", i, len(dependencies), name) pterm.FgGray.Printfln("└ %s:%s", dependency.Image, dependency.Tag) @@ -408,9 +406,9 @@ func (sq *Squadron) Status(ctx context.Context, helmArgs []string, parallel int) LastDeployed string `json:"last_deployed"` Description string `json:"description"` } `json:"info"` - deployedBy string `json:"-"` - gitCommit string `json:"-"` - gitBranch string `json:"-"` + deployedBy string `json:"-"` //nolint:revive + gitCommit string `json:"-"` //nolint:revive + gitBranch string `json:"-"` //nolint:revive } wg, ctx := errgroup.WithContext(ctx) @@ -528,7 +526,6 @@ func (sq *Squadron) UpdateLocalDependencies(ctx context.Context, parallel int) e wg.SetLimit(parallel) for repository := range repositories { - repository := repository wg.Go(func() error { pterm.Debug.Printfln("running helm dependency update for %s", repository) if out, err := util.NewHelmCommand().