diff --git a/MODULE.bazel b/MODULE.bazel index c24e16f..3186eb4 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -9,13 +9,15 @@ bazel_dep(name = "rules_go", version = "0.49.0", repo_name = "io_bazel_rules_go" bazel_dep(name = "gazelle", version = "0.38.0", repo_name = "bazel_gazelle") go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk") -go_sdk.download(version = "1.22.6") +go_sdk.download(version = "1.23.2") go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps") go_deps.from_file(go_mod = "//:go.mod") use_repo( go_deps, + "com_github_dgraph_io_badger_v4", "com_github_go_resty_resty_v2", + "com_github_hashicorp_hcl_v2", "com_github_hashicorp_vault_client_go", "com_github_spf13_cobra", "com_github_stretchr_testify", @@ -36,3 +38,13 @@ use_repo( go_deps.gazelle_override( path = "github.com/go-resty/resty/v2", ) + +# Disable Protobuf BUILD file generation for BadgerDB, since +# they'll most likely fail the build since we do not have a C/CXX +# toolchain registered +go_deps.gazelle_override( + directives = [ + "gazelle:proto disable_global", + ], + path = "github.com/dgraph-io/badger/v4", +) diff --git a/cmd/waltr/BUILD.bazel b/cmd/waltr/BUILD.bazel index 401aa72..56a0328 100644 --- a/cmd/waltr/BUILD.bazel +++ b/cmd/waltr/BUILD.bazel @@ -16,6 +16,7 @@ go_library( deps = [ "//internal/waltr/app", "//internal/waltr/cmd", + "//pkg/kv", "//pkg/stamp", ], ) diff --git a/cmd/waltr/main.go b/cmd/waltr/main.go index 9401023..86f91e2 100644 --- a/cmd/waltr/main.go +++ b/cmd/waltr/main.go @@ -3,8 +3,8 @@ package main import ( "github.com/fmjstudios/gopskit/internal/waltr/app" "github.com/fmjstudios/gopskit/internal/waltr/cmd" + "github.com/fmjstudios/gopskit/pkg/kv" _ "github.com/fmjstudios/gopskit/pkg/stamp" - "golang.org/x/sync/errgroup" "log" "os" ) @@ -14,21 +14,17 @@ func main() { if err != nil { log.Fatalf("could not initialize waltr application kernel: %v", err) } + defer func(KV *kv.Database) { + err := KV.Close() + if err != nil { + log.Fatalf("could not shut down waltr database connection: %v", err) + } + }(kern.KV) cmdRoot := cmd.NewRootCommand(kern) if err := cmdRoot.Execute(); err != nil { kern.Log.Fatalf("%s exited with error: %v\n", kern.Name, err) } - g := new(errgroup.Group) - g.Go(func() error { - return kern.KV.Close() - }) - - err = g.Wait() - if err != nil { - log.Fatalf("could not shut down waltr database connection: %v", err) - } - os.Exit(0) } diff --git a/go.mod b/go.mod index 4ebf3c2..8ec5168 100644 --- a/go.mod +++ b/go.mod @@ -1,17 +1,19 @@ module github.com/fmjstudios/gopskit -go 1.22.6 +go 1.23.2 require ( + github.com/dgraph-io/badger/v4 v4.3.0 github.com/go-resty/resty/v2 v2.14.0 + github.com/hashicorp/hcl/v2 v2.22.0 github.com/hashicorp/vault-client-go v0.4.3 github.com/spf13/cobra v1.8.1 github.com/stretchr/testify v1.9.0 github.com/vmware-labs/yaml-jsonpath v0.3.2 go.uber.org/zap v1.27.0 - golang.org/x/mod v0.20.0 + golang.org/x/mod v0.21.0 golang.org/x/sync v0.8.0 - golang.org/x/text v0.17.0 + golang.org/x/text v0.19.0 gopkg.in/yaml.v3 v3.0.1 k8s.io/api v0.31.0 k8s.io/apimachinery v0.31.0 @@ -21,10 +23,11 @@ require ( require ( github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect + github.com/agext/levenshtein v1.2.3 // indirect + github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/blang/semver/v4 v4.0.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/dgraph-io/badger/v4 v4.3.0 // indirect github.com/dgraph-io/ristretto v0.1.2-0.20240116140435-c67e07994f91 // indirect github.com/dprotaso/go-yit v0.0.0-20240618133044-5a0af90af097 // indirect github.com/dustin/go-humanize v1.0.1 // indirect @@ -60,6 +63,7 @@ require ( github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect + github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/moby/spdystream v0.4.0 // indirect github.com/moby/term v0.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect @@ -74,14 +78,16 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/x448/float16 v0.8.4 // indirect github.com/xlab/treeprint v1.2.0 // indirect + github.com/zclconf/go-cty v1.15.0 // indirect go.opencensus.io v0.24.0 // indirect go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/net v0.28.0 // indirect + golang.org/x/net v0.30.0 // indirect golang.org/x/oauth2 v0.22.0 // indirect - golang.org/x/sys v0.25.0 // indirect - golang.org/x/term v0.23.0 // indirect + golang.org/x/sys v0.26.0 // indirect + golang.org/x/term v0.25.0 // indirect golang.org/x/time v0.6.0 // indirect + golang.org/x/tools v0.26.0 // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect diff --git a/go.sum b/go.sum index 4573c95..bbedcec 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,10 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= +github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= +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/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= @@ -25,6 +29,8 @@ github.com/dgraph-io/badger/v4 v4.3.0 h1:lcsCE1/1qrRhqP+zYx6xDZb8n7U+QlwNicpc676 github.com/dgraph-io/badger/v4 v4.3.0/go.mod h1:Sc0T595g8zqAQRDf44n+z3wG4BOqLwceaFntt8KPxUM= github.com/dgraph-io/ristretto v0.1.2-0.20240116140435-c67e07994f91 h1:Pux6+xANi0I7RRo5E1gflI4EZ2yx3BGZ75JkAIvGEOA= github.com/dgraph-io/ristretto v0.1.2-0.20240116140435-c67e07994f91/go.mod h1:swkazRqnUf1N62d0Nutz7KIj2UKqsm/H8tD0nBJAXqM= +github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y= +github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dprotaso/go-yit v0.0.0-20191028211022-135eb7262960/go.mod h1:9HQzr9D/0PGwMEbC3d5AB7oi67+h4TsQqItC1GVYG58= github.com/dprotaso/go-yit v0.0.0-20240618133044-5a0af90af097 h1:f5nA5Ys8RXqFXtKc0XofVRiuwNTuJzPIwTmbjLz9vj8= github.com/dprotaso/go-yit v0.0.0-20240618133044-5a0af90af097/go.mod h1:FTAVyH6t+SlS97rv6EXRVuBDLkQqcIe/xQw9f4IFUI4= @@ -60,6 +66,8 @@ github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8Wd github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= +github.com/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/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= @@ -123,6 +131,8 @@ github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5O github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 h1:kes8mmyCpxJsI7FTwtzRqEy9CdjCtrXrXGuOpxEA7Ts= github.com/hashicorp/go-secure-stdlib/strutil v0.1.2/go.mod h1:Gou2R9+il93BqX25LAKCLuM+y9U2T4hlwvT1yprcna4= +github.com/hashicorp/hcl/v2 v2.22.0 h1:hkZ3nCtqeJsDhPRFz5EA9iwcG1hNWGePOTw6oyul12M= +github.com/hashicorp/hcl/v2 v2.22.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA= github.com/hashicorp/vault-client-go v0.4.3 h1:zG7STGVgn/VK6rnZc0k8PGbfv2x/sJExRKHSUg3ljWc= github.com/hashicorp/vault-client-go v0.4.3/go.mod h1:4tDw7Uhq5XOxS1fO+oMtotHL7j4sB9cp0T7U6m4FzDY= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -156,6 +166,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +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/moby/spdystream v0.4.0 h1:Vy79D6mHeJJjiPdFEL2yku1kl0chZpJfZcPpb16BRl8= github.com/moby/spdystream v0.4.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= @@ -232,6 +244,10 @@ github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +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= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.starlark.net v0.0.0-20230525235612-a134d8f9ddca h1:VdD38733bfYv5tUZwEIskMM93VanwNIi5bIKnDrJdEY= @@ -261,8 +277,8 @@ golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= -golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +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.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -284,8 +300,8 @@ golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= -golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= -golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +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/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= @@ -326,8 +342,8 @@ golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= -golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +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/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -338,8 +354,8 @@ golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= -golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU= -golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= +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.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.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -350,8 +366,8 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= -golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U= golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -367,8 +383,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= -golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= -golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= +golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= +golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/internal/waltr/app/BUILD.bazel b/internal/waltr/app/BUILD.bazel index 40b9142..d701c0c 100644 --- a/internal/waltr/app/BUILD.bazel +++ b/internal/waltr/app/BUILD.bazel @@ -9,11 +9,13 @@ go_library( "//pkg/core", "//pkg/fs", "//pkg/kube", + "//pkg/kv", "//pkg/log", "//pkg/proc", "//pkg/stamp", "@com_github_hashicorp_vault_client_go//:vault-client-go", "@com_github_spf13_cobra//:cobra", + "@org_uber_go_zap//:zap", ], ) diff --git a/internal/waltr/app/app.go b/internal/waltr/app/app.go index 72fd188..fb0b65f 100644 --- a/internal/waltr/app/app.go +++ b/internal/waltr/app/app.go @@ -8,6 +8,7 @@ import ( "github.com/fmjstudios/gopskit/pkg/log" "github.com/fmjstudios/gopskit/pkg/proc" "github.com/spf13/cobra" + "go.uber.org/zap" "path/filepath" "time" @@ -44,7 +45,7 @@ func New(opts ...Opt) (*State, error) { return nil, err } - lgr := log.New() + lgr := log.New(log.WithCustomConfig(zap.NewDevelopmentConfig())) defer func() { err = lgr.Sync() }() @@ -64,13 +65,14 @@ func New(opts ...Opt) (*State, error) { // embedded BadgerDB database dbpath := filepath.Join(platf.Data, "data") + fmt.Println("Creating BadgerDB database at:", dbpath) db, err := kv.New(dbpath) if err != nil { return nil, err } // enforce HTTPS - va := fmt.Sprintf("https://127.0.0.1:%s", kube.DefaultLocalPort) + va := fmt.Sprintf("http://127.0.0.1:%s", kube.DefaultLocalPort) vc, err := vault.New(vault.WithAddress(va), vault.WithRequestTimeout(60*time.Second), vault.WithTLS(vault.TLSConfiguration{ InsecureSkipVerify: true, })) diff --git a/internal/waltr/cmd/BUILD.bazel b/internal/waltr/cmd/BUILD.bazel index 07fc178..d38b648 100644 --- a/internal/waltr/cmd/BUILD.bazel +++ b/internal/waltr/cmd/BUILD.bazel @@ -21,6 +21,8 @@ go_library( "//pkg/helpers", "//pkg/proc", "//pkg/tools", + "@com_github_hashicorp_hcl_v2//gohcl", + "@com_github_hashicorp_hcl_v2//hclparse", "@com_github_hashicorp_vault_client_go//:vault-client-go", "@com_github_hashicorp_vault_client_go//schema", "@com_github_spf13_cobra//:cobra", diff --git a/internal/waltr/cmd/cmd.go b/internal/waltr/cmd/cmd.go index 1e122f1..a90d030 100644 --- a/internal/waltr/cmd/cmd.go +++ b/internal/waltr/cmd/cmd.go @@ -42,6 +42,7 @@ func NewRootCommand(waltr *app.State) *cobra.Command { CompletionOptions: cobra.CompletionOptions{ HiddenDefaultCmd: true, }, + SilenceUsage: true, } // Kubernetes Flags diff --git a/internal/waltr/cmd/init.go b/internal/waltr/cmd/init.go index e059d9c..af178b2 100644 --- a/internal/waltr/cmd/init.go +++ b/internal/waltr/cmd/init.go @@ -9,6 +9,8 @@ import ( "github.com/fmjstudios/gopskit/pkg/core" "github.com/fmjstudios/gopskit/pkg/proc" "github.com/fmjstudios/gopskit/pkg/tools" + "github.com/hashicorp/hcl/v2/gohcl" + "github.com/hashicorp/hcl/v2/hclparse" "github.com/hashicorp/vault-client-go/schema" "github.com/spf13/cobra" corev1 "k8s.io/api/core/v1" @@ -72,6 +74,8 @@ func NewInitCommand() func(app *app.State) *cobra.Command { } } + // pod has to run first + cmdutil.WaitUntilRunning(app, p) if err := cmdutil.DisableAshHistory(app, p); err != nil { app.Log.Errorf("could not disable Ash Shell history for Pod: %s. Error: %v", p.Name, err) } @@ -97,13 +101,15 @@ func NewInitCommand() func(app *app.State) *cobra.Command { // auto-unseal cannot be configured without this key val, ok := cm.Data["extraconfig-from-values.hcl"] if ok { - for _, v := range cmdutil.KnownUnsealTypes { - if strings.Contains(val, v) { - needsUnseal = false - highAvailability = true // must be true if auto-unseal is set - } + var cfg cmdutil.VaultConfig + hcp := hclparse.NewParser() + f, err := hcp.ParseHCL([]byte(val), "example.hcl") + err = gohcl.DecodeBody(f.Body, nil, &cfg) + if err != nil { + return fmt.Errorf("vault has invalid configuration. Error: %v", err) } + needsUnseal = cfg.Seal == nil if !needsUnseal { app.Log.Info("found custom chart configuration enabling Auto-Unseal! skipping" + " unseal steps") @@ -192,6 +198,19 @@ func NewInitCommand() func(app *app.State) *cobra.Command { app.Log.Info("secret-file unset. only writing Vault Token to cache path!") } + // write to Database + err = app.KV.Set("token", []byte(data.Data.RootToken)) + if err != nil { + defer cancel() + return err + } + + err = app.KV.Set("unseal-keys", []byte(strings.Join(data.Data.Keys, ","))) + if err != nil { + defer cancel() + return err + } + // always write backup json file to cache path err = cmdutil.WriteCredentials(app, environment, creds) if err != nil { diff --git a/internal/waltr/cmd/test.go b/internal/waltr/cmd/test.go index 18e1da7..368662c 100644 --- a/internal/waltr/cmd/test.go +++ b/internal/waltr/cmd/test.go @@ -86,6 +86,19 @@ func NewTestCommand() func(app *app.State) *cobra.Command { } app.Log.Info(fmt.Sprintf("https://%s:%d", svc.Spec.ClusterIP, svc.Spec.Ports[0].Port)) + // DB test + token, err := app.KV.Get("token") + if err != nil { + return fmt.Errorf("could not retrieve token: %v", err) + } + fmt.Printf("Vault Root Token: %s\n", token) + + unsealKeys, err := app.KV.Get("unseal-keys") + if err != nil { + return fmt.Errorf("could not retrieve unseal keys: %v", err) + } + fmt.Printf("Vault Unseal Keys: %s\n", unsealKeys) + return nil }, } diff --git a/internal/waltr/util/BUILD.bazel b/internal/waltr/util/BUILD.bazel index 75e75bf..bbcff1c 100644 --- a/internal/waltr/util/BUILD.bazel +++ b/internal/waltr/util/BUILD.bazel @@ -13,6 +13,7 @@ go_library( "//pkg/core", "//pkg/fs", "//pkg/helpers", + "@com_github_hashicorp_hcl_v2//:hcl", "@io_k8s_api//core/v1:core", "@io_k8s_apimachinery//pkg/apis/meta/v1:meta", ], diff --git a/internal/waltr/util/vault.go b/internal/waltr/util/vault.go index cbf7a46..b8f3555 100644 --- a/internal/waltr/util/vault.go +++ b/internal/waltr/util/vault.go @@ -8,6 +8,7 @@ import ( "github.com/fmjstudios/gopskit/pkg/core" "github.com/fmjstudios/gopskit/pkg/fs" "github.com/fmjstudios/gopskit/pkg/helpers" + "github.com/hashicorp/hcl/v2" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "path/filepath" @@ -15,10 +16,17 @@ import ( "time" ) -var ( - KnownUnsealTypes = []string{"seal \"alicloudkms\"", "seal \"awskms\"", "seal \"azurekeyvault\"", - "seal \"gcpckms\"", "seal \"ocikms\"", "seal \"pkcs11\"", "seal \"transit\""} -) +type VaultConfig struct { + DisableMLock bool `hcl:"disable_mlock"` + UI bool `hcl:"ui"` + Seal *SealConfig `hcl:"seal,block"` + Remain hcl.Body `hcl:",remain"` +} + +type SealConfig struct { + Type string `hcl:"type,label"` + Remain hcl.Body `hcl:",remain"` +} // Credentials is a custom type which is used to write and load Vault credentials to and from a file type Credentials struct { diff --git a/pkg/core/BUILD.bazel b/pkg/core/BUILD.bazel index 312ca11..80bc148 100644 --- a/pkg/core/BUILD.bazel +++ b/pkg/core/BUILD.bazel @@ -24,6 +24,7 @@ go_library( deps = [ "//pkg/fs", "//pkg/kube", + "//pkg/kv", "//pkg/log", "//pkg/proc", "//pkg/stamp", diff --git a/pkg/fs/paths.go b/pkg/fs/paths.go index 152e626..f3275fd 100644 --- a/pkg/fs/paths.go +++ b/pkg/fs/paths.go @@ -148,10 +148,12 @@ func Paths(opts ...Opt) (*PlatformPaths, error) { wg.Done() }() } + wg.Wait() // wait for configuration to finish g := new(errgroup.Group) // async init g.Go(func() error { + p.updateConfigPaths() err := p.configure() if err != nil { return err @@ -171,9 +173,6 @@ func Paths(opts ...Opt) (*PlatformPaths, error) { return nil, err } - // wait for non-failable options - wg.Wait() - return p, nil } @@ -235,7 +234,7 @@ func (p *PlatformPaths) configure() error { return err } - if p.AppName, err = p.determineDataDir(); err != nil { + if p.Data, err = p.determineDataDir(); err != nil { return err } @@ -294,6 +293,15 @@ func (p *PlatformPaths) determineCacheDir() (string, error) { return path, nil } +// updateConfigPaths ensures we use the updated names for the configuration paths, +// whenever an Opt has updated the value post-initialization +func (p *PlatformPaths) updateConfigPaths() { + p.ConfigPaths = []string{ + fmt.Sprintf("/etc/%s/%s.%s", p.AppName, p.AppName, p.ConfigTypes[0]), + fmt.Sprintf("./%s.%s", p.AppName, p.ConfigTypes[0]), + } +} + // findConfigFile tries to find a configuration file within the specified ConfigPaths and // marks the file as existing within the Exists map, if found. func (p *PlatformPaths) findConfigFile(ctx context.Context) error { diff --git a/pkg/kv/BUILD.bazel b/pkg/kv/BUILD.bazel new file mode 100644 index 0000000..a9cdc94 --- /dev/null +++ b/pkg/kv/BUILD.bazel @@ -0,0 +1,24 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "kv", + srcs = [ + "kv.go", + "op.go", + "types.go", + ], + importpath = "github.com/fmjstudios/gopskit/pkg/kv", + visibility = ["//visibility:public"], + deps = [ + "//pkg/fs", + "//pkg/helpers", + "@com_github_dgraph_io_badger_v4//:badger", + "@org_golang_x_sync//errgroup", + ], +) + +alias( + name = "go_default_library", + actual = ":kv", + visibility = ["//visibility:public"], +) diff --git a/pkg/kv/op.go b/pkg/kv/op.go index e184b23..66d1488 100644 --- a/pkg/kv/op.go +++ b/pkg/kv/op.go @@ -198,7 +198,7 @@ func (d *Database) Close() error { d.lock.Lock() defer d.lock.Unlock() - doneC := make(chan struct{}, 1) + doneC := make(chan struct{}) go d.gc(doneC) <-doneC diff --git a/pkg/log/log.go b/pkg/log/log.go index 3bf04f4..b1e30ed 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -113,9 +113,9 @@ func New(opts ...Option) *Logger { // WithCustomConfig overrides the entire DefaultConfig configuration, replacing the reference with a new zap.Config // object which will be used to configure the Logger -func WithCustomConfig(cfg *zap.Config) Option { +func WithCustomConfig(cfg zap.Config) Option { return func(config *zap.Config) { - config = cfg + config = &cfg } }