From a55dc7fd5cd852da99a4df3a1d9c83a61d7db42f Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 1 Jul 2024 14:59:29 +0200 Subject: [PATCH 01/23] chore: squashing commits --- .gitignore | 1 + .vscode/launch.json | 18 ++ cmd/gitops/main.go | 55 ++++- cmd/gitops/templating.go | 23 -- cmd/gitops/vault.go | 2 - go.mod | 40 ++-- go.sum | 131 ++++++++---- internal/finalizer/finalizer.go | 14 ++ internal/git/clone.go | 40 ++++ .../kubernetes}/kubernetes.go | 13 +- internal/patch/patch.go | 198 ++++++++++++++++++ internal/patch/patch_test.go | 123 +++++++++++ internal/secret/diff.go | 147 ++++++------- internal/secret/loader.go | 2 +- internal/secret/secret.go | 20 +- internal/secret/secret_test.go | 4 +- internal/templating/templating.go | 53 ++--- internal/templating/templating_test.go | 62 ++---- .../util.go => internal/util/application.go | 29 +-- 19 files changed, 700 insertions(+), 275 deletions(-) delete mode 100644 cmd/gitops/templating.go delete mode 100644 cmd/gitops/vault.go create mode 100644 internal/finalizer/finalizer.go create mode 100644 internal/git/clone.go rename {cmd/gitops => internal/kubernetes}/kubernetes.go (96%) create mode 100644 internal/patch/patch.go create mode 100644 internal/patch/patch_test.go rename cmd/gitops/util.go => internal/util/application.go (54%) diff --git a/.gitignore b/.gitignore index 95577b6..ee2e538 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ homebrew-gitops/ .gitops-state.yaml +sandbox/ # Ignore "main" binary main diff --git a/.vscode/launch.json b/.vscode/launch.json index 52f487c..18136ca 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,24 @@ "mode": "auto", "program": "cmd/gitops", "args": ["secrets", "a", "k8s", "-auto-approve"] + }, + { + "name": "gitops patch test", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "cmd/gitops", + "args": [ + "--verbose", + "patch", + "--basicauth", + "mparten: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", + "--repo", + "https://git.i.mercedes-benz.com/itocg-smb-devops/cluster", + "applications/int/service-userandroles-v3/values.yaml", + "service-tomcat.service.image.tag", + "3.1.2.42" + ] } ] } diff --git a/cmd/gitops/main.go b/cmd/gitops/main.go index 7db7625..4bbd96c 100644 --- a/cmd/gitops/main.go +++ b/cmd/gitops/main.go @@ -4,8 +4,12 @@ import ( "os" "github.com/TwiN/go-color" + "github.com/mxcd/gitops-cli/internal/finalizer" "github.com/mxcd/gitops-cli/internal/k8s" + "github.com/mxcd/gitops-cli/internal/kubernetes" + "github.com/mxcd/gitops-cli/internal/patch" "github.com/mxcd/gitops-cli/internal/state" + "github.com/mxcd/gitops-cli/internal/templating" "github.com/mxcd/gitops-cli/internal/util" log "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" @@ -89,7 +93,7 @@ func main() { }, Action: func(c *cli.Context) error { initApplication(c) - return applyKubernetes(c) + return kubernetes.ApplyKubernetes(c) }, }, { @@ -114,7 +118,7 @@ func main() { Action: func(c *cli.Context) error { initApplication(c) - return planKubernetes(c) + return kubernetes.PlanKubernetes(c) }, }, }, @@ -124,7 +128,7 @@ func main() { Usage: "Test the templating of secrets", Action: func(c *cli.Context) error { initApplication(c) - return testTemplating(c) + return templating.TestTemplating(c) }, }, }, @@ -146,7 +150,7 @@ func main() { for _, cluster := range clusters { println(color.InBlue(cluster.Name), " => ", cluster.ConfigFile) } - return exitApplication(c, true) + return finalizer.ExitApplication(c, true) }, }, { @@ -170,7 +174,7 @@ func main() { if err != nil { return err } - return exitApplication(c, true) + return finalizer.ExitApplication(c, true) }, }, { @@ -185,7 +189,7 @@ func main() { if err != nil { return err } - return exitApplication(c, true) + return finalizer.ExitApplication(c, true) }, }, { @@ -198,11 +202,39 @@ func main() { for _, clusterClient := range clusterClients { clusterClient.PrettyPrint() } - return exitApplication(c, false) + return finalizer.ExitApplication(c, false) }, }, }, }, + { + Name: "patch", + Usage: "Patch a single file in a GitOps cluster repository", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "repo", + Value: "", + Usage: "Repo to be used for the patch", + EnvVars: []string{"GITOPS_REPO"}, + }, + &cli.StringFlag{ + Name: "branch", + Value: "main", + Usage: "Branch to be used for the patch", + EnvVars: []string{"GITOPS_BRANCH"}, + }, + &cli.StringFlag{ + Name: "basicauth", + Value: "", + Usage: "BasicAuth for authenticating against the GitOps repository", + EnvVars: []string{"GITOPS_BASICAUTH"}, + }, + }, + Action: func(c *cli.Context) error { + initApplication(c) + return patch.Patch(c) + }, + }, }, } @@ -211,3 +243,12 @@ func main() { log.Fatal(err) } } + +func initApplication(c *cli.Context) error { + util.PrintLogo(c) + util.SetLogLevel(c) + util.SetCliContext(c) + util.GetRootDir() + err := state.LoadState(c) + return err +} diff --git a/cmd/gitops/templating.go b/cmd/gitops/templating.go deleted file mode 100644 index 8f113b9..0000000 --- a/cmd/gitops/templating.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import ( - "github.com/mxcd/gitops-cli/internal/util" - log "github.com/sirupsen/logrus" - "github.com/urfave/cli/v2" -) - -func testTemplating(c *cli.Context) error { - secretFiles, err := util.GetSecretFiles() - if err != nil { - log.Fatal(err) - } - for _, secretFile := range secretFiles { - log.Debug(secretFile) - decryptedFile, err := util.DecryptFile(secretFile) - if err != nil { - log.Fatal(err) - } - log.Trace(string(decryptedFile)) - } - return nil -} \ No newline at end of file diff --git a/cmd/gitops/vault.go b/cmd/gitops/vault.go deleted file mode 100644 index c9ecbf5..0000000 --- a/cmd/gitops/vault.go +++ /dev/null @@ -1,2 +0,0 @@ -package main - diff --git a/go.mod b/go.mod index 2adebd1..04218ec 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/mxcd/gitops-cli go 1.19 require ( + github.com/go-git/go-git/v5 v5.11.0 github.com/google/uuid v1.1.2 github.com/schollz/progressbar/v3 v3.13.0 github.com/sirupsen/logrus v1.9.0 @@ -14,28 +15,43 @@ require ( ) require ( + dario.cat/mergo v1.0.0 // indirect + github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/cloudflare/circl v1.3.3 // indirect + github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/emicklei/go-restful/v3 v3.9.0 // indirect - github.com/go-logr/logr v1.2.3 // indirect + github.com/emirpasic/gods v1.18.1 // indirect + github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect + github.com/go-git/go-billy/v5 v5.5.0 // indirect + github.com/go-logr/logr v1.2.4 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.20.0 // indirect github.com/go-openapi/swag v0.19.14 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/google/gnostic v0.5.7-v3refs // indirect - github.com/google/go-cmp v0.5.9 // indirect + github.com/google/go-cmp v0.6.0 // indirect github.com/google/gofuzz v1.1.0 // indirect - github.com/hashicorp/vault-client-go v0.2.0 // indirect github.com/imdario/mergo v0.3.6 // indirect + github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect + github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/mailru/easyjson v0.7.6 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/onsi/ginkgo/v2 v2.11.0 // indirect + github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/sergi/go-diff v1.1.0 // indirect + github.com/skeema/knownhosts v1.2.1 // indirect github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect + github.com/xanzy/ssh-agent v0.3.3 // indirect + golang.org/x/mod v0.12.0 // indirect + golang.org/x/tools v0.13.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect + gopkg.in/warnings.v0 v0.1.2 // indirect k8s.io/klog/v2 v2.80.1 // indirect k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect @@ -58,7 +74,7 @@ require ( github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect github.com/Azure/go-autorest/logger v0.2.1 // indirect github.com/Azure/go-autorest/tracing v0.6.0 // indirect - github.com/ProtonMail/go-crypto v0.0.0-20220407094043-a94812496cf5 // indirect + github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect github.com/TwiN/go-color v1.4.0 github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f github.com/armon/go-metrics v0.3.10 // indirect @@ -71,7 +87,7 @@ require ( github.com/fatih/color v1.13.0 // indirect github.com/golang-jwt/jwt/v4 v4.3.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/golang/protobuf v1.5.2 // indirect + github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/googleapis/gax-go/v2 v2.2.0 // indirect github.com/goware/prefixer v0.0.0-20160118172347-395022866408 // indirect @@ -113,17 +129,17 @@ require ( github.com/rivo/uniseg v0.4.3 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect - github.com/stretchr/testify v1.8.2 + github.com/stretchr/testify v1.8.4 github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect go.mozilla.org/gopgagent v0.0.0-20170926210634-4d7ea76ff71a // indirect go.opencensus.io v0.23.0 // indirect go.uber.org/atomic v1.9.0 // indirect - golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect - golang.org/x/net v0.7.0 // indirect + golang.org/x/crypto v0.16.0 // indirect + golang.org/x/net v0.19.0 // indirect golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect - golang.org/x/sys v0.6.0 // indirect - golang.org/x/term v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/term v0.15.0 // indirect + golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.3.0 // indirect google.golang.org/api v0.74.0 // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/go.sum b/go.sum index b8c5dc4..9312fb7 100644 --- a/go.sum +++ b/go.sum @@ -48,6 +48,8 @@ cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0Zeo cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/age v1.0.0 h1:V6q14n0mqYU3qKFkZ6oOaF9oXneOviS3ubXsSVBRSzc= filippo.io/age v1.0.0/go.mod h1:PaX+Si/Sd5G8LgfCwldsSba3H1DDQZhIhFGkhbHaBq8= @@ -81,11 +83,13 @@ github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBp github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= -github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA= +github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/ProtonMail/go-crypto v0.0.0-20220407094043-a94812496cf5 h1:cSHEbLj0GZeHM1mWG84qEnGFojNEQ83W7cwaPRjcwXU= -github.com/ProtonMail/go-crypto v0.0.0-20220407094043-a94812496cf5/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo= +github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg= +github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= github.com/TwiN/go-color v1.4.0 h1:fNbOwOrvup5oj934UragnW0B1WKaAkkB85q19Y7h4ng= github.com/TwiN/go-color v1.4.0/go.mod h1:0QTVEPlu+AoCyTrho7bXbVkrCkVpdQr7YF7PYWEtSxM= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -94,6 +98,7 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f h1:NNJE6p4LchkmNfNskDUaSbrwxZzr7t2/lj2aS+q4oF0= github.com/andybalholm/crlf v0.0.0-20171020200849-670099aa064f/go.mod h1:k8feO4+kXDxro6ErPXBRTJ/ro2mf0SsFG8s7doP9kJE= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/go-metrics v0.3.9/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb4QAOwNTFc= github.com/armon/go-metrics v0.3.10 h1:FR+drcQStOe+32sYyJYyZ7FIdgoGGBnwLl+flodp8Uo= @@ -101,6 +106,7 @@ github.com/armon/go-metrics v0.3.10/go.mod h1:4O98XIr/9W0sxpJ8UaYkvjk10Iff7SnFrb github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/aws/aws-sdk-go v1.43.43 h1:1L06qzQvl4aC3Skfh5rV7xVhGHjIZoHcqy16NoyQ1o4= github.com/aws/aws-sdk-go v1.43.43/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= @@ -109,6 +115,7 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= +github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs= github.com/cenkalti/backoff/v3 v3.2.2 h1:cfUAAO3yvKMYKPrvhDuHSwQnhZNk/RMHKdZqKTxfm6M= @@ -122,6 +129,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= +github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= @@ -134,6 +143,8 @@ github.com/containerd/continuity v0.2.2 h1:QSqfxcn8c+12slxwu00AtzXrsami0MJb/MQs9 github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= +github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -142,8 +153,11 @@ github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/ github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= +github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= github.com/emicklei/go-restful/v3 v3.9.0 h1:XwGDlfxEnQZzuopoqxwSEllNcCOM9DhhFyhFIIGKwxE= github.com/emicklei/go-restful/v3 v3.9.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= +github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -163,7 +177,15 @@ github.com/frankban/quicktest v1.10.0/go.mod h1:ui7WezCLWMWxVWr1GETZY3smRy0G4KWq github.com/frankban/quicktest v1.13.0 h1:yNZif1OkDfNoDfb9zZa9aXIpejNR4F23Wely0c+Qdqk= github.com/frankban/quicktest v1.13.0/go.mod h1:qLE0fzW0VuyUAJgPU19zByoIr0HtCHN/r/VLSOOIySU= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= github.com/go-asn1-ber/asn1-ber v1.3.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= +github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= +github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= +github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= +github.com/go-git/go-git/v5 v5.11.0 h1:XIZc1p+8YzypNr34itUfSvYJcv+eYdTnTvOZ2vD3cA4= +github.com/go-git/go-git/v5 v5.11.0/go.mod h1:6GFcX2P3NM7FPBfpePbpLd21XxsgdAt+lKqXmCUiUCY= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -173,8 +195,8 @@ github.com/go-ldap/ldap/v3 v3.1.10/go.mod h1:5Zun81jBTabRaI8lzN7E1JjyEl1g6zI6u9p github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= -github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= @@ -184,6 +206,7 @@ github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh github.com/go-openapi/swag v0.19.14 h1:gm3vOOXfiuw5i9p5N9xJvfjvuofpyvLA9Wr6QfK5Fng= github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-test/deep v1.0.2 h1:onZX1rnHT3Wv6cqNgYyFOOlgVKJrksuCMCRvJStbMYw= github.com/go-test/deep v1.0.2/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -224,8 +247,9 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -246,8 +270,8 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g= github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -268,6 +292,7 @@ github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= @@ -304,8 +329,6 @@ github.com/hashicorp/go-plugin v1.4.3 h1:DXmvivbWD5qdiBts9TpBC7BYL1Aia5sxbRgQB+v github.com/hashicorp/go-plugin v1.4.3/go.mod h1:5fGEH17QVwTTcR0zV7yhDPLLmFX9YSZ38b18Udy6vYQ= github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= -github.com/hashicorp/go-retryablehttp v0.7.0 h1:eu1EI/mbirUgP5C8hVsTNaGZreBDlYiwC1FZWkvQPQ4= -github.com/hashicorp/go-retryablehttp v0.7.0/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/go-retryablehttp v0.7.2 h1:AcYqCvkpalPnPF2pn0KamgwamS42TqUDDYFRKq/RAd0= github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5Oi2viEzc= @@ -336,8 +359,6 @@ github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+l github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= 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/vault-client-go v0.2.0 h1:Zzf5D2kj7QmBZE2ZTdril1aJlujMptPatxslTkdDF+U= -github.com/hashicorp/vault-client-go v0.2.0/go.mod h1:C9rbJeHeI1Dy/MXXd5YLrzRfAH27n6mARnhpvaW/8gk= github.com/hashicorp/vault/api v1.5.0 h1:Bp6yc2bn7CWkOrVIzFT/Qurzx528bdavF3nz590eu28= github.com/hashicorp/vault/api v1.5.0/go.mod h1:LkMdrZnWNrFaQyYYazWVn7KshilfDidgVBq6YiTq/bM= github.com/hashicorp/vault/sdk v0.4.1 h1:3SaHOJY687jY1fnB61PtL0cOkKItphrbLmux7T92HBo= @@ -351,6 +372,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28= github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= +github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE= github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74= @@ -368,14 +391,16 @@ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1 github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw= +github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= +github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -434,13 +459,13 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= -github.com/onsi/ginkgo/v2 v2.4.0 h1:+Ig9nvqgS5OBSACXNk15PLdp0U9XPYROt9CFzVdFGIs= -github.com/onsi/gomega v1.23.0 h1:/oxKu9c2HVap+F3PfKort2Hw5DEU+HGlW8n+tguWsys= +github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU= +github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM= +github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM= github.com/opencontainers/runc v1.1.0 h1:O9+X96OcDjkmmZyfaG996kV7yq8HsoU2h1XRRQcefG8= @@ -450,6 +475,8 @@ github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144T github.com/pierrec/lz4 v2.5.2+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM= github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= +github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -474,6 +501,7 @@ github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw= github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= @@ -481,32 +509,35 @@ github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkB github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= github.com/schollz/progressbar/v3 v3.13.0 h1:9TeeWRcjW2qd05I8Kf9knPkW4vLM/hYoa6z9ABvxje8= github.com/schollz/progressbar/v3 v3.13.0/go.mod h1:ZBYnSuLAX2LU8P8UiKN/KgF2DY58AJC8yfVYLPC8Ly4= +github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= +github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ= +github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= 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/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/urfave/cli/v2 v2.25.0 h1:ykdZKuQey2zq0yin/l7JOm9Mh+pg72ngYMeB0ABn6q8= github.com/urfave/cli/v2 v2.25.0/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= +github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= +github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -514,6 +545,7 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.mozilla.org/gopgagent v0.0.0-20170926210634-4d7ea76ff71a h1:N7VD+PwpJME2ZfQT8+ejxwA4Ow10IkGbU0MGf94ll8k= go.mozilla.org/gopgagent v0.0.0-20170926210634-4d7ea76ff71a/go.mod h1:YDKUvO0b//78PaaEro6CAPH6NqohCmL2Cwju5XI2HoE= go.mozilla.org/sops/v3 v3.7.3 h1:CYx02LnWTATWv6NqWJIt4JCKVKSnGV+MsRiDpvwWQhg= @@ -535,12 +567,14 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA= -golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= +golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -551,8 +585,6 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug= -golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -578,6 +610,10 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 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= @@ -620,8 +656,12 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= +golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -653,6 +693,9 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -669,6 +712,7 @@ golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -691,6 +735,7 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -714,18 +759,25 @@ golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 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.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= -golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= +golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -735,14 +787,15 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/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 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.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/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 h1:M73Iuj3xbbb9Uk1DYhzydthsj6oOd6l9bpuFcNoUvTs= -golang.org/x/time v0.0.0-20220224211638-0e9765cccd65/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -798,6 +851,10 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +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 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= 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= @@ -970,8 +1027,8 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= @@ -982,6 +1039,8 @@ gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= gopkg.in/urfave/cli.v1 v1.20.0 h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0= gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0= +gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= +gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/internal/finalizer/finalizer.go b/internal/finalizer/finalizer.go new file mode 100644 index 0000000..79a95aa --- /dev/null +++ b/internal/finalizer/finalizer.go @@ -0,0 +1,14 @@ +package finalizer + +import ( + "github.com/mxcd/gitops-cli/internal/state" + "github.com/urfave/cli/v2" +) + +func ExitApplication(c *cli.Context, writeState bool) error { + var err error + if writeState { + err = state.GetState().Save(c) + } + return err +} diff --git a/internal/git/clone.go b/internal/git/clone.go new file mode 100644 index 0000000..ce5233a --- /dev/null +++ b/internal/git/clone.go @@ -0,0 +1,40 @@ +package git + +import ( + "fmt" + "time" + + "github.com/go-git/go-billy/v5/memfs" + git "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing" + "github.com/go-git/go-git/v5/plumbing/transport" + "github.com/go-git/go-git/v5/storage/memory" + log "github.com/sirupsen/logrus" +) + +type GitOpsCloneOptions struct { + Repository string + Branch string + FilePath string + Auth transport.AuthMethod +} + +func Clone(options *GitOpsCloneOptions) (*git.Repository, error) { + startTime := time.Now() + repo, err := git.Clone(memory.NewStorage(), memfs.New(), &git.CloneOptions{ + URL: options.Repository, + Auth: options.Auth, + Depth: 1, + ReferenceName: plumbing.ReferenceName(fmt.Sprintf("refs/heads/%s", options.Branch)), + SingleBranch: true, + Tags: git.NoTags, + // Progress: os.Stdout, + }) + if err != nil { + log.Error(err) + return nil, err + } + log.Debug("Cloned repository ", options.Repository, " on branch ", options.Branch, " in ", time.Since(startTime)) + + return repo, nil +} diff --git a/cmd/gitops/kubernetes.go b/internal/kubernetes/kubernetes.go similarity index 96% rename from cmd/gitops/kubernetes.go rename to internal/kubernetes/kubernetes.go index 694e6a1..161356f 100644 --- a/cmd/gitops/kubernetes.go +++ b/internal/kubernetes/kubernetes.go @@ -1,4 +1,4 @@ -package main +package kubernetes import ( "fmt" @@ -6,6 +6,7 @@ import ( "github.com/TwiN/go-color" "github.com/google/uuid" + "github.com/mxcd/gitops-cli/internal/finalizer" "github.com/mxcd/gitops-cli/internal/k8s" "github.com/mxcd/gitops-cli/internal/plan" "github.com/mxcd/gitops-cli/internal/secret" @@ -17,7 +18,7 @@ import ( k8sErrors "k8s.io/apimachinery/pkg/api/errors" ) -func applyKubernetes(c *cli.Context) error { +func ApplyKubernetes(c *cli.Context) error { p, err := createKubernetesPlan(c) if err != nil { return err @@ -26,7 +27,7 @@ func applyKubernetes(c *cli.Context) error { // exit if there is nothing to do if p.NothingToDo() { println(color.InGreen("No changes to apply.")) - exitApplication(c, true) + finalizer.ExitApplication(c, true) return nil } @@ -55,11 +56,11 @@ func applyKubernetes(c *cli.Context) error { println("") println(color.InGreen("All changes applied.")) - exitApplication(c, true) + finalizer.ExitApplication(c, true) return nil } -func planKubernetes(c *cli.Context) error { +func PlanKubernetes(c *cli.Context) error { clusterLimitString := getClusterLimit(c) p, err := createKubernetesPlan(c) @@ -78,7 +79,7 @@ func planKubernetes(c *cli.Context) error { applyString := fmt.Sprintf("gitops secrets%s apply kubernetes %s", dirLimitString, clusterLimitString) println(color.InBold("use"), color.InGreen(color.InBold(applyString)), color.InBold("to apply these changes to your cluster")) } - exitApplication(c, false) + finalizer.ExitApplication(c, false) return nil } diff --git a/internal/patch/patch.go b/internal/patch/patch.go new file mode 100644 index 0000000..ae8c78f --- /dev/null +++ b/internal/patch/patch.go @@ -0,0 +1,198 @@ +package patch + +import ( + "bytes" + "errors" + "io" + "strings" + + "github.com/go-git/go-git/v5/plumbing/transport" + "github.com/go-git/go-git/v5/plumbing/transport/http" + "github.com/mxcd/gitops-cli/internal/git" + log "github.com/sirupsen/logrus" + "github.com/urfave/cli/v2" + "gopkg.in/yaml.v3" +) + +func Patch(c *cli.Context) error { + branch := c.String("branch") + basicAuth := c.String("basicauth") + + var auth transport.AuthMethod = nil + + if basicAuth != "" { + split := strings.Split(basicAuth, ":") + if len(split) != 2 { + return errors.New("invalid basic auth string") + } + auth = &http.BasicAuth{ + Username: split[0], + Password: split[1], + } + } + + repository := c.String("repo") + if repository == "" { + return errors.New("no repository specified") + } + + filePath := c.Args().First() + if filePath == "" { + return errors.New("no file specified for patching") + } + + selector := c.Args().Get(1) + value := c.Args().Get(2) + + repo, err := git.Clone(&git.GitOpsCloneOptions{ + Repository: repository, + Branch: branch, + Auth: auth, + }) + + if err != nil { + return err + } + + worktree, err := repo.Worktree() + if err != nil { + log.Error("Failed to get worktree: ", err) + return err + } + + file, err := worktree.Filesystem.Open(filePath) + if err != nil { + log.Error("Failed to open file: ", err) + return err + } + defer file.Close() + + // Read the contents of the file + fileContents, err := io.ReadAll(file) + if err != nil { + log.Error("Failed to read file: ", err) + return err + } + + log.Debug("Read file ", filePath, ":\n", string(fileContents)) + + // TODO patch single file + var fileData yaml.Node + err = yaml.Unmarshal(fileContents, &fileData) + if err != nil { + panic(err) + } + log.Debug("File data: ", fileData) + + patchedData, err := patchYamlData(&fileData, selector, value) + if err != nil { + return err + } + log.Debug("Patched file data: ", patchedData) + + patchedFileContents, err := yaml.Marshal(patchedData) + if err != nil { + return err + } + log.Debug("Patched file contents: ", string(patchedFileContents)) + + // TODO commit and push + + return err +} + +func patchYamlString(yamlString string, selector string, value string) (string, error) { + var fileData yaml.Node + err := yaml.Unmarshal([]byte(yamlString), &fileData) + if err != nil { + return "", err + } + + var patchedData *yaml.Node + if strings.HasPrefix(selector, ".") { + selector = selector[1:] + patchedData, err = patchYamlData(&fileData, selector, value) + if err != nil { + return "", err + } + } else { + patchedData, err = patchYamlDataWithSearch(&fileData, selector, value) + if err != nil { + return "", err + } + } + + var b bytes.Buffer + yamlEncoder := yaml.NewEncoder(&b) + yamlEncoder.SetIndent(2) + err = yamlEncoder.Encode(patchedData) + if err != nil { + return "", err + } + + return b.String(), nil +} + +func patchYamlData(data *yaml.Node, selector string, value string) (*yaml.Node, error) { + selectorParts := strings.Split(selector, ".") + + if err := findAndPatchNode(data, selectorParts, value); err != nil { + return nil, err + } + return data, nil +} + +func findAndPatchNode(node *yaml.Node, selectorParts []string, value string) error { + if len(selectorParts) == 0 { + node.Value = value + return nil + } + + for i, child := range node.Content { + if child.Kind == yaml.MappingNode { + for j := 0; j < len(child.Content); j += 2 { + keyNode := child.Content[j] + valueNode := child.Content[j+1] + if keyNode.Value == selectorParts[0] { + return findAndPatchNode(valueNode, selectorParts[1:], value) + } + } + } else if child.Kind == yaml.ScalarNode { + if child.Value == selectorParts[0] { + return findAndPatchNode(node.Content[i+1], selectorParts[1:], value) + } + } + } + + return errors.New("selector not found") +} + +func patchYamlDataWithSearch(data *yaml.Node, selector string, value string) (*yaml.Node, error) { + if err := findAndPatchNodeWithSearch(data, selector, value); err != nil { + return nil, err + } + return data, nil +} + +func findAndPatchNodeWithSearch(node *yaml.Node, selector string, value string) error { + if node.Kind == yaml.MappingNode { + for i := 0; i < len(node.Content); i += 2 { + keyNode := node.Content[i] + valueNode := node.Content[i+1] + if keyNode.Kind == yaml.ScalarNode && keyNode.Value == selector { + valueNode.Value = value + return nil + } + if err := findAndPatchNodeWithSearch(valueNode, selector, value); err == nil { + return nil + } + } + } else if node.Kind == yaml.SequenceNode || node.Kind == yaml.DocumentNode { + for _, child := range node.Content { + if err := findAndPatchNodeWithSearch(child, selector, value); err == nil { + return nil + } + } + } + return errors.New("key not found") +} diff --git a/internal/patch/patch_test.go b/internal/patch/patch_test.go new file mode 100644 index 0000000..ef68d3a --- /dev/null +++ b/internal/patch/patch_test.go @@ -0,0 +1,123 @@ +package patch + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +type TestCase struct { + originalYaml string + selector string + value string + expectedYaml string +} + +var testCases = []TestCase{ + { + originalYaml: `foo: bar +`, + selector: ".foo", + value: "baz", + expectedYaml: `foo: baz +`, + }, + { + originalYaml: `some: + nested: + structure: + foo: bar +`, + selector: ".some.nested.structure.foo", + value: "baz", + expectedYaml: `some: + nested: + structure: + foo: baz +`, + }, + { + originalYaml: `some: + nested: + # some comment + structure: + foo: bar +`, + selector: ".some.nested.structure.foo", + value: "baz", + expectedYaml: `some: + nested: + # some comment + structure: + foo: baz +`, + }, + { + originalYaml: `some: + nested: + # some comment + structure: + foo: bar +`, + selector: "foo", + value: "baz", + expectedYaml: `some: + nested: + # some comment + structure: + foo: baz +`, + }, + { + originalYaml: `some: + nested: + # some comment + structure: + - fizz: buzz + - foo: bar +`, + selector: "foo", + value: "baz", + expectedYaml: `some: + nested: + # some comment + structure: + - fizz: buzz + - foo: baz +`, + }, + { + originalYaml: `some: + nested: + # some comment + fizz: + buzz: bar + structure: + foo: bar +`, + selector: ".some.nested.structure.foo", + value: "baz", + expectedYaml: `some: + nested: + # some comment + fizz: + buzz: bar + structure: + foo: baz +`, + }, +} + +func TestYamlPatching(t *testing.T) { + test := func(testCase TestCase) { + + pathedYamlString, err := patchYamlString(testCase.originalYaml, testCase.selector, testCase.value) + assert.NoError(t, err) + + assert.Equal(t, testCase.expectedYaml, pathedYamlString, "Patched data should be equal to expected data") + } + + for _, testCase := range testCases { + test(testCase) + } +} diff --git a/internal/secret/diff.go b/internal/secret/diff.go index ae5d9d8..bd9e430 100644 --- a/internal/secret/diff.go +++ b/internal/secret/diff.go @@ -8,16 +8,17 @@ import ( ) type SecretDiffType string + var SecretDiffTypeUnchanged SecretDiffType = "unchanged" var SecretDiffTypeAdded SecretDiffType = "added" var SecretDiffTypeRemoved SecretDiffType = "removed" var SecretDiffTypeChanged SecretDiffType = "changed" type SecretDiffEntry struct { - Type SecretDiffType - Key string - OldValue string - NewValue string + Type SecretDiffType + Key string + OldValue string + NewValue string Sensitive bool } type SecretDiff struct { @@ -38,15 +39,15 @@ type SecretDiff struct { func CompareSecrets(oldSecret *Secret, newSecret *Secret) *SecretDiff { diffEntries := []SecretDiffEntry{} - + // if both secrets are nil, they are equal if oldSecret == nil && newSecret == nil { return &SecretDiff{ - Equal: true, - Type: SecretDiffTypeUnchanged, - Name: "", + Equal: true, + Type: SecretDiffTypeUnchanged, + Name: "", Namespace: "", - Entries: diffEntries, + Entries: diffEntries, } } @@ -54,19 +55,19 @@ func CompareSecrets(oldSecret *Secret, newSecret *Secret) *SecretDiff { if oldSecret == nil && newSecret != nil { for key, value := range newSecret.Data { diffEntries = append(diffEntries, SecretDiffEntry{ - Type: SecretDiffTypeAdded, - Key: fmt.Sprintf("data.%s", key), - OldValue: "", - NewValue: value, + Type: SecretDiffTypeAdded, + Key: fmt.Sprintf("data.%s", key), + OldValue: "", + NewValue: value, Sensitive: true, }) } return &SecretDiff{ - Equal: false, - Type: SecretDiffTypeAdded, - Name: newSecret.Name, + Equal: false, + Type: SecretDiffTypeAdded, + Name: newSecret.Name, Namespace: newSecret.Namespace, - Entries: diffEntries, + Entries: diffEntries, } } @@ -74,68 +75,68 @@ func CompareSecrets(oldSecret *Secret, newSecret *Secret) *SecretDiff { if oldSecret != nil && newSecret == nil { for key, value := range oldSecret.Data { diffEntries = append(diffEntries, SecretDiffEntry{ - Type: SecretDiffTypeRemoved, - Key: fmt.Sprintf("data.%s", key), - OldValue: value, - NewValue: "", + Type: SecretDiffTypeRemoved, + Key: fmt.Sprintf("data.%s", key), + OldValue: value, + NewValue: "", Sensitive: true, }) } return &SecretDiff{ - Equal: false, - Type: SecretDiffTypeRemoved, - Name: oldSecret.Name, + Equal: false, + Type: SecretDiffTypeRemoved, + Name: oldSecret.Name, Namespace: oldSecret.Namespace, - Entries: diffEntries, + Entries: diffEntries, } } - + if oldSecret.TargetType != newSecret.TargetType { diffEntries = append(diffEntries, SecretDiffEntry{ - Type: SecretDiffTypeChanged, - Key: "targetType", - OldValue: string(oldSecret.TargetType), - NewValue: string(newSecret.TargetType), + Type: SecretDiffTypeChanged, + Key: "targetType", + OldValue: string(oldSecret.TargetType), + NewValue: string(newSecret.TargetType), Sensitive: false, }) } if oldSecret.Target != newSecret.Target { diffEntries = append(diffEntries, SecretDiffEntry{ - Type: SecretDiffTypeChanged, - Key: "target", - OldValue: string(oldSecret.Target), - NewValue: string(newSecret.Target), + Type: SecretDiffTypeChanged, + Key: "target", + OldValue: string(oldSecret.Target), + NewValue: string(newSecret.Target), Sensitive: false, }) } if oldSecret.Name != newSecret.Name { diffEntries = append(diffEntries, SecretDiffEntry{ - Type: SecretDiffTypeChanged, - Key: "name", - OldValue: oldSecret.Name, - NewValue: newSecret.Name, + Type: SecretDiffTypeChanged, + Key: "name", + OldValue: oldSecret.Name, + NewValue: newSecret.Name, Sensitive: false, }) } if oldSecret.Namespace != newSecret.Namespace { diffEntries = append(diffEntries, SecretDiffEntry{ - Type: SecretDiffTypeChanged, - Key: "namespace", - OldValue: oldSecret.Namespace, - NewValue: newSecret.Namespace, + Type: SecretDiffTypeChanged, + Key: "namespace", + OldValue: oldSecret.Namespace, + NewValue: newSecret.Namespace, Sensitive: false, }) } if oldSecret.Type != newSecret.Type { diffEntries = append(diffEntries, SecretDiffEntry{ - Type: SecretDiffTypeChanged, - Key: "type", - OldValue: oldSecret.Type, - NewValue: newSecret.Type, + Type: SecretDiffTypeChanged, + Key: "type", + OldValue: oldSecret.Type, + NewValue: newSecret.Type, Sensitive: false, }) } @@ -144,20 +145,20 @@ func CompareSecrets(oldSecret *Secret, newSecret *Secret) *SecretDiff { // check if key is in new secret if _, ok := newSecret.Data[key]; !ok { diffEntries = append(diffEntries, SecretDiffEntry{ - Type: SecretDiffTypeRemoved, - Key: fmt.Sprintf("data.%s", key), - OldValue: value, - NewValue: "", + Type: SecretDiffTypeRemoved, + Key: fmt.Sprintf("data.%s", key), + OldValue: value, + NewValue: "", Sensitive: true, }) } else { // check if value is equal if value != newSecret.Data[key] { diffEntries = append(diffEntries, SecretDiffEntry{ - Type: SecretDiffTypeChanged, - Key: fmt.Sprintf("data.%s", key), - OldValue: value, - NewValue: newSecret.Data[key], + Type: SecretDiffTypeChanged, + Key: fmt.Sprintf("data.%s", key), + OldValue: value, + NewValue: newSecret.Data[key], Sensitive: true, }) } @@ -168,10 +169,10 @@ func CompareSecrets(oldSecret *Secret, newSecret *Secret) *SecretDiff { // check if key is in old secret if _, ok := oldSecret.Data[key]; !ok { diffEntries = append(diffEntries, SecretDiffEntry{ - Type: SecretDiffTypeAdded, - Key: fmt.Sprintf("data.%s", key), - OldValue: "", - NewValue: value, + Type: SecretDiffTypeAdded, + Key: fmt.Sprintf("data.%s", key), + OldValue: "", + NewValue: value, Sensitive: true, }) } @@ -180,28 +181,28 @@ func CompareSecrets(oldSecret *Secret, newSecret *Secret) *SecretDiff { var diffName = "" if oldSecret != nil { diffName = oldSecret.Name - } else if newSecret != nil{ + } else if newSecret != nil { diffName = newSecret.Name } var diffNamespace = "" if oldSecret != nil { diffNamespace = oldSecret.Namespace - } else if newSecret != nil{ + } else if newSecret != nil { diffNamespace = newSecret.Namespace } - diff := SecretDiff { - Name: diffName, + diff := SecretDiff{ + Name: diffName, Namespace: diffNamespace, - Entries: diffEntries, + Entries: diffEntries, } - + if len(diffEntries) > 0 { - diff.Type = SecretDiffTypeChanged; + diff.Type = SecretDiffTypeChanged diff.Equal = false } else { - diff.Type = SecretDiffTypeUnchanged; + diff.Type = SecretDiffTypeUnchanged diff.Equal = true } @@ -238,12 +239,12 @@ func (d *SecretDiff) Print() { return } switch d.Type { - case SecretDiffTypeAdded: - println(color.InGreen(combinedSecretName), color.InGreen(": "), color.InBold(color.InGreen("add"))) - case SecretDiffTypeRemoved: - println(color.InRed(combinedSecretName), color.InRed(": "), color.InBold(color.InRed("remove"))) - case SecretDiffTypeChanged: - println(color.InYellow(combinedSecretName), color.InYellow(": "), color.InBold(color.InYellow("change"))) + case SecretDiffTypeAdded: + println(color.InGreen(combinedSecretName), color.InGreen(": "), color.InBold(color.InGreen("add"))) + case SecretDiffTypeRemoved: + println(color.InRed(combinedSecretName), color.InRed(": "), color.InBold(color.InRed("remove"))) + case SecretDiffTypeChanged: + println(color.InYellow(combinedSecretName), color.InYellow(": "), color.InBold(color.InYellow("change"))) } printDetailedChanges() } @@ -255,4 +256,4 @@ func (d *SecretDiff) GetEntry(key string) *SecretDiffEntry { } } return nil -} \ No newline at end of file +} diff --git a/internal/secret/loader.go b/internal/secret/loader.go index d2c970b..60974cf 100644 --- a/internal/secret/loader.go +++ b/internal/secret/loader.go @@ -52,7 +52,7 @@ func LoadLocalSecretsLimited(targetTypeFilter SecretTargetType, directoryLimit s ) for _, secretFileName := range secretFileNames { bar.Add(1) - secret, err := FromPath(secretFileName, directoryLimit) + secret, err := FromPath(secretFileName) if err != nil { bar.Finish() return nil, err diff --git a/internal/secret/secret.go b/internal/secret/secret.go index adcb38f..db896a7 100644 --- a/internal/secret/secret.go +++ b/internal/secret/secret.go @@ -47,7 +47,6 @@ type Secret struct { } type SecretTargetType string - var SecretTargetTypeVault SecretTargetType = "vault" var SecretTargetTypeKubernetes SecretTargetType = "k8s" var SecretTargetTypeAll SecretTargetType = "all" @@ -58,7 +57,7 @@ type SecretFile struct { Name string `yaml:"name,omitempty"` Namespace string `yaml:"namespace" default:"default"` Type string `yaml:"type" default:"Opaque"` - Data map[string]string `yaml:"data"` + Data map[string]string `yaml:"data"` ID string `yaml:"id,omitempty"` } @@ -66,7 +65,7 @@ type TemplateData struct { Values map[interface{}]interface{} } -func (s *Secret) Load(directoryLimit string) error { +func (s *Secret) Load() error { if s.Path == "" { return errors.New("secret path is empty") } @@ -79,7 +78,7 @@ func (s *Secret) Load(directoryLimit string) error { // execute templating on the secret file data data := TemplateData{ - Values: templating.GetValuesForPath(s.Path, directoryLimit), + Values: templating.GetValuesForPath(s.Path), } stringData := string(decryptedFileContent) tmpl, err := template.New(s.Path).Parse(stringData) @@ -104,7 +103,7 @@ func (s *Secret) Load(directoryLimit string) error { yaml.UnmarshalStrict(s.BinaryData, &secretFile) s.TargetType = secretFile.TargetType - + if secretFile.Target != "" { s.Target = secretFile.Target } else { @@ -129,13 +128,13 @@ func (s *Secret) Load(directoryLimit string) error { } else { s.Type = "Opaque" } - + s.Data = secretFile.Data if util.GetCliContext().Bool("print") { s.PrettyPrint() } - + return nil } @@ -161,15 +160,16 @@ func (s *Secret) PrettyPrint() { } } -func FromPath(path string, directoryLimit string) (*Secret, error) { - s := Secret{ +func FromPath(path string) (*Secret, error) { + s := Secret { Path: path, } - err := s.Load(directoryLimit) + err := s.Load() if err != nil { return nil, err } return &s, nil } + diff --git a/internal/secret/secret_test.go b/internal/secret/secret_test.go index cf6be66..9aa0e62 100644 --- a/internal/secret/secret_test.go +++ b/internal/secret/secret_test.go @@ -12,7 +12,7 @@ func TestLoadSecret1(t *testing.T) { secret := Secret { Path: f, } - err := secret.Load("") + err := secret.Load() if err != nil { t.Error(err) @@ -31,7 +31,7 @@ func TestLoadSecret2(t *testing.T) { secret := Secret { Path: f, } - err := secret.Load("") + err := secret.Load() if err != nil { t.Error(err) diff --git a/internal/templating/templating.go b/internal/templating/templating.go index e7b8e06..c7a61d8 100644 --- a/internal/templating/templating.go +++ b/internal/templating/templating.go @@ -8,6 +8,7 @@ import ( "strings" log "github.com/sirupsen/logrus" + "github.com/urfave/cli/v2" "github.com/mxcd/gitops-cli/internal/util" "gopkg.in/yaml.v2" @@ -25,22 +26,17 @@ type TemplateValuesPath struct { var loaded = false -func LoadValues(directoryLimit string) error { +func LoadValues() error { log.Trace("Loading values files") secretFiles, err := util.GetSecretFiles() if err != nil { return err } var valuesFiles []string - for _, secretFileName := range secretFiles { - if !strings.HasSuffix(secretFileName, "values.gitops.secret.enc.yaml") && !strings.HasSuffix(secretFileName, "values.gitops.secret.enc.yml") { - continue + for _, secretFile := range secretFiles { + if strings.HasSuffix(secretFile, "values.gitops.secret.enc.yaml") || strings.HasSuffix(secretFile, "values.gitops.secret.enc.yml") { + valuesFiles = append(valuesFiles, secretFile) } - if !valuesFileApplicable(secretFileName, directoryLimit) { - log.Trace("Skipping values file due to directory filter: ", secretFileName) - continue - } - valuesFiles = append(valuesFiles, secretFileName) } for _, valuesFile := range valuesFiles { @@ -107,9 +103,9 @@ func (t TemplateValues) merge() { } } -func GetValuesForPath(path string, directoryLimit string) map[interface{}]interface{} { +func GetValuesForPath(path string) map[interface{}]interface{} { if !loaded { - err := LoadValues(directoryLimit) + err := LoadValues() if err != nil { log.Panic(err) } @@ -134,31 +130,18 @@ func GetValuesForPath(path string, directoryLimit string) map[interface{}]interf return values } -func valuesFileApplicable(secretFile, directoryLimit string) bool { - secretFile = filepath.Clean(secretFile) - directoryLimit = filepath.Clean(directoryLimit) - - if directoryLimit == "." { - return true +func TestTemplating(c *cli.Context) error { + secretFiles, err := util.GetSecretFiles() + if err != nil { + log.Fatal(err) } - - secretFileParentDir := filepath.Dir(secretFile) - secretFileDirectoryElements := strings.Split(secretFileParentDir, string(filepath.Separator)) - directoryLimitElements := strings.Split(directoryLimit, string(filepath.Separator)) - - if len(secretFileDirectoryElements) <= len(directoryLimitElements) { - for i, secretFileDirectoryElement := range secretFileDirectoryElements { - if secretFileDirectoryElement != directoryLimitElements[i] { - return false - } - } - } else { - for i, directoryLimitElement := range directoryLimitElements { - if directoryLimitElement != secretFileDirectoryElements[i] { - return false - } + for _, secretFile := range secretFiles { + log.Debug(secretFile) + decryptedFile, err := util.DecryptFile(secretFile) + if err != nil { + log.Fatal(err) } + log.Trace(string(decryptedFile)) } - - return true + return nil } diff --git a/internal/templating/templating_test.go b/internal/templating/templating_test.go index 53e0f5a..cab727f 100644 --- a/internal/templating/templating_test.go +++ b/internal/templating/templating_test.go @@ -9,18 +9,18 @@ import ( func TestMapMerge1(t *testing.T) { a := map[interface{}]interface{}{ - "foo": "bar", + "foo": "bar", "fizz": "buzz", } b := map[interface{}]interface{}{ "fizz": "fizz", } c := map[interface{}]interface{}{ - "foo": "bar", + "foo": "bar", "fizz": "fizz", } d := mergeMaps(a, b) - assert.Equal(t, c, d, "Maps should be equal") + assert.Equal(t, c, d, "Maps should be equal") } func TestMapMerge2(t *testing.T) { @@ -39,7 +39,7 @@ func TestMapMerge2(t *testing.T) { "d": "4", } d := mergeMaps(a, b) - assert.Equal(t, c, d, "Maps should be equal") + assert.Equal(t, c, d, "Maps should be equal") } func TestMapMerge3(t *testing.T) { @@ -55,7 +55,7 @@ func TestMapMerge3(t *testing.T) { "b": 42, } d := mergeMaps(a, b) - assert.Equal(t, c, d, "Maps should be equal") + assert.Equal(t, c, d, "Maps should be equal") } func TestMapMerge4(t *testing.T) { @@ -71,7 +71,7 @@ func TestMapMerge4(t *testing.T) { "b": []interface{}{"2", "3"}, } d := mergeMaps(a, b) - assert.Equal(t, c, d, "Maps should be equal") + assert.Equal(t, c, d, "Maps should be equal") } func TestTemplateValuesMerge(t *testing.T) { @@ -159,57 +159,31 @@ func TestTemplateValuesMerge(t *testing.T) { assert.Equal(t, expectedMergedTemplateValues, templateValues, "TemplateValues should be equal") } + func TestValuesFileLoading(t *testing.T) { c := util.GetDummyCliContext() util.SetCliContext(c) util.ComputeRootDir(c) - - LoadValues("") - + + LoadValues() + valuesSet1 := map[interface{}]interface{}{ - "namespace": "gitops-dev", - "stage": "dev", + "namespace": "gitops-dev", + "stage": "dev", "databaseUsername": "my-very-strong-username", "databasePassword": "my-very-strong-password", } - mergedValues1 := GetValuesForPath("test_assets/implicit-name.gitops.secret.enc.yml", "") + mergedValues1 := GetValuesForPath("test_assets/implicit-name.gitops.secret.enc.yml") assert.Equal(t, valuesSet1, mergedValues1, "Values should be equal") valuesSet2 := map[interface{}]interface{}{ - "namespace": "gitops-dev", - "stage": "sub-dev", + "namespace": "gitops-dev", + "stage": "sub-dev", "databaseUsername": "my-very-strong-username", "databasePassword": "my-very-strong-password", - "key": "fooo", + "key": "fooo", } - mergedValues2 := GetValuesForPath("test_assets/subdirectory/subdir-secret.gitops.secret.enc.yml", "") + mergedValues2 := GetValuesForPath("test_assets/subdirectory/subdir-secret.gitops.secret.enc.yml") assert.Equal(t, valuesSet2, mergedValues2, "Values should be equal") -} - -func TestIsInParentPath(t *testing.T) { - tests := []struct { - name string - path1 string - path2 string - expected bool - }{ - {"Direct Parent", "a/b/c.txt", "a/b/d/", true}, - {"Grandparent", "a/b/c.txt", "a/b/d/e/", true}, - {"Not a Parent", "a/b/c.txt", "f/g/h/", false}, - {"Same Directory", "a/b/c.txt", "a/b/", true}, - {"Root Directory", "c.txt", "/", false}, - {"Path2 is Parent", "a/b/c/d.txt", "a/b/c", true}, - {"Nested under filter", "a/b/c/d.txt", "a/", true}, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - result := valuesFileApplicable(tt.path1, tt.path2) - - if result != tt.expected { - t.Errorf("isInParentPath(%q, %q) = %v; expected %v", tt.path1, tt.path2, result, tt.expected) - } - }) - } -} +} \ No newline at end of file diff --git a/cmd/gitops/util.go b/internal/util/application.go similarity index 54% rename from cmd/gitops/util.go rename to internal/util/application.go index 2af6233..2bae75d 100644 --- a/cmd/gitops/util.go +++ b/internal/util/application.go @@ -1,32 +1,13 @@ -package main +package util import ( - "github.com/mxcd/gitops-cli/internal/state" - "github.com/mxcd/gitops-cli/internal/util" log "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) -func initApplication(c *cli.Context) error { - printLogo(c) - setLogLevel(c) - util.SetCliContext(c) - util.GetRootDir() - err := state.LoadState(c) - return err -} - -func exitApplication(c *cli.Context, writeState bool) error { - var err error - if writeState { - err = state.GetState().Save(c) - } - return err -} - -func setLogLevel(c *cli.Context) { +func SetLogLevel(c *cli.Context) { log.SetLevel(log.InfoLevel) - + if c.Bool("verbose") { log.SetLevel(log.DebugLevel) } @@ -36,7 +17,7 @@ func setLogLevel(c *cli.Context) { } } -func printLogo(c *cli.Context) { +func PrintLogo(c *cli.Context) { if c.Bool("no-logo") { return } @@ -48,4 +29,4 @@ func printLogo(c *cli.Context) { println("/_/ \\__, /_/\\__/\\____/ .___/____/") println(" /____/ /_/") println("") -} \ No newline at end of file +} From f837be9f19d094c25e106473d7275884e872ab47 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 1 Jul 2024 14:59:40 +0200 Subject: [PATCH 02/23] chore: squashing commits --- .gitignore | 2 ++ .vscode/launch.json | 34 ---------------------------------- 2 files changed, 2 insertions(+), 34 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.gitignore b/.gitignore index ee2e538..e63b9a2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ homebrew-gitops/ .gitops-state.yaml sandbox/ +.vscode/launch.json + # Ignore "main" binary main # Ignore "gitops" binary diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 18136ca..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "gitops secrets apply k8s", - "type": "go", - "request": "launch", - "mode": "auto", - "program": "cmd/gitops", - "args": ["secrets", "a", "k8s", "-auto-approve"] - }, - { - "name": "gitops patch test", - "type": "go", - "request": "launch", - "mode": "auto", - "program": "cmd/gitops", - "args": [ - "--verbose", - "patch", - "--basicauth", - "mparten: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", - "--repo", - "https://git.i.mercedes-benz.com/itocg-smb-devops/cluster", - "applications/int/service-userandroles-v3/values.yaml", - "service-tomcat.service.image.tag", - "3.1.2.42" - ] - } - ] -} From e868631bb97866c81c75fb41dcc5053af3d514f4 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 26 Jan 2025 01:55:45 +0100 Subject: [PATCH 03/23] feat(wip): git patcher --- .github/workflows/build.yml | 2 +- .github/workflows/golang-tests.yml | 2 +- .gitignore | 4 + cmd/gitops/main.go | 16 +- hack/soft-serve/docker-compose.yml | 14 ++ hack/soft-serve/fixtures/values.yaml | 7 + hack/soft-serve/start.sh | 48 ++++ hack/soft-serve/stop.sh | 21 ++ internal/git/clone.go | 78 +++++-- internal/git/git.go | 57 +++++ internal/patch/method_git.go | 186 ++++++++++++++++ internal/patch/method_git_test.go | 31 +++ internal/patch/patch.go | 208 +++++------------- internal/yaml/patcher.go | 105 +++++++++ .../patch_test.go => yaml/patcher_test.go} | 6 +- tapes/plan/plan-k8s.tape | 69 ++++++ 16 files changed, 673 insertions(+), 181 deletions(-) create mode 100644 hack/soft-serve/docker-compose.yml create mode 100644 hack/soft-serve/fixtures/values.yaml create mode 100755 hack/soft-serve/start.sh create mode 100755 hack/soft-serve/stop.sh create mode 100644 internal/git/git.go create mode 100644 internal/patch/method_git.go create mode 100644 internal/patch/method_git_test.go create mode 100644 internal/yaml/patcher.go rename internal/{patch/patch_test.go => yaml/patcher_test.go} (87%) create mode 100644 tapes/plan/plan-k8s.tape diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bd88208..28567e2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@master - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: go-version: 1.19 - name: golang build diff --git a/.github/workflows/golang-tests.yml b/.github/workflows/golang-tests.yml index 09e676f..44b7508 100644 --- a/.github/workflows/golang-tests.yml +++ b/.github/workflows/golang-tests.yml @@ -16,7 +16,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@master - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: go-version: 1.19 - name: run golang tests diff --git a/.gitignore b/.gitignore index e63b9a2..2fcf8f9 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,10 @@ homebrew-gitops/ .gitops-state.yaml sandbox/ +hack/soft-serve/data +hack/soft-serve/ssh-key +hack/soft-serve/ssh-key.pub + .vscode/launch.json # Ignore "main" binary diff --git a/cmd/gitops/main.go b/cmd/gitops/main.go index 4bbd96c..c093b9c 100644 --- a/cmd/gitops/main.go +++ b/cmd/gitops/main.go @@ -211,6 +211,18 @@ func main() { Name: "patch", Usage: "Patch a single file in a GitOps cluster repository", Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "repo-server", + Value: "", + Usage: "GitOps repo server to be used for the patch", + EnvVars: []string{"GITOPS_REPO_SERVER"}, + }, + &cli.StringFlag{ + Name: "repo-server-api-key", + Value: "", + Usage: "GitOps repo server to be used for the patch", + EnvVars: []string{"GITOPS_REPO_SERVER_API_KEY"}, + }, &cli.StringFlag{ Name: "repo", Value: "", @@ -227,12 +239,12 @@ func main() { Name: "basicauth", Value: "", Usage: "BasicAuth for authenticating against the GitOps repository", - EnvVars: []string{"GITOPS_BASICAUTH"}, + EnvVars: []string{"GITOPS_REPO_BASICAUTH"}, }, }, Action: func(c *cli.Context) error { initApplication(c) - return patch.Patch(c) + return patch.PatchCommand(c) }, }, }, diff --git a/hack/soft-serve/docker-compose.yml b/hack/soft-serve/docker-compose.yml new file mode 100644 index 0000000..527849b --- /dev/null +++ b/hack/soft-serve/docker-compose.yml @@ -0,0 +1,14 @@ +services: + soft-serve: + image: charmcli/soft-serve:latest + container_name: soft-serve + volumes: + - ./data:/soft-serve + ports: + - 23231:23231 + - 23232:23232 + - 23233:23233 + - 9418:9418 + environment: + SOFT_SERVE_INITIAL_ADMIN_KEYS: "$SOFT_SERVE_INITIAL_ADMIN_KEYS" + restart: unless-stopped \ No newline at end of file diff --git a/hack/soft-serve/fixtures/values.yaml b/hack/soft-serve/fixtures/values.yaml new file mode 100644 index 0000000..060e37a --- /dev/null +++ b/hack/soft-serve/fixtures/values.yaml @@ -0,0 +1,7 @@ +service: + global: + namespace: foo + image: + repository: bar + tag: asdf1234 + \ No newline at end of file diff --git a/hack/soft-serve/start.sh b/hack/soft-serve/start.sh new file mode 100755 index 0000000..9d15d07 --- /dev/null +++ b/hack/soft-serve/start.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +BASE="$(git rev-parse --show-toplevel)" +[[ $? -eq 0 ]] || { + echo 'Run this script from inside the repository (cannot determine toplevel directory)' + exit 1 +} + +log() { + if [[ $VERBOSE == 'true' ]]; then + echo $1 + fi +} + +# cleanup +rm -rf $BASE/hack/soft-serve/ssh-key +rm -rf $BASE/hack/soft-serve/ssh-key.pub +rm -rf $BASE/hack/soft-serve/data +rm -rf $BASE/hack/soft-serve/gitops-test + +remove_ssh_key() { + ssh-add -d $BASE/hack/soft-serve/ssh-key.pub +} + +trap remove_ssh_key INT + +# generate ssh key +ssh-keygen -t ed25519 -N '' -f $BASE/hack/soft-serve/ssh-key + +# set config vars +export SOFT_SERVE_INITIAL_ADMIN_KEYS=$(cat $BASE/hack/soft-serve/ssh-key.pub) + +docker compose -f $BASE/hack/soft-serve/docker-compose.yml up -d + +sleep 5 + +ssh-add $BASE/hack/soft-serve/ssh-key +ssh -p 23231 -o StrictHostKeychecking=no -i $BASE/hack/soft-serve/ssh-key localhost repo create gitops-test + +git clone ssh://git@localhost:23231/gitops-test $BASE/hack/soft-serve/gitops-test +mkdir -p $BASE/hack/soft-serve/gitops-test/applications/dev/service-test +cp $BASE/hack/soft-serve/fixtures/values.yaml $BASE/hack/soft-serve/gitops-test/applications/dev/service-test/values.yaml +cd $BASE/hack/soft-serve/gitops-test +# git add . +# git commit -m "feat: add service-test application" +# git push origin main + +cd $BASE/hack/soft-serve \ No newline at end of file diff --git a/hack/soft-serve/stop.sh b/hack/soft-serve/stop.sh new file mode 100755 index 0000000..3656a96 --- /dev/null +++ b/hack/soft-serve/stop.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +BASE="$(git rev-parse --show-toplevel)" +[[ $? -eq 0 ]] || { + echo 'Run this script from inside the repository (cannot determine toplevel directory)' + exit 1 +} + +log() { + if [[ $VERBOSE == 'true' ]]; then + echo $1 + fi +} + +docker compose -f $BASE/hack/soft-serve/docker-compose.yml down + +# cleanup +rm -rf $BASE/hack/soft-serve/ssh-key +rm -rf $BASE/hack/soft-serve/ssh-key.pub +rm -rf $BASE/hack/soft-serve/data +rm -rf $BASE/hack/soft-serve/gitops-test diff --git a/internal/git/clone.go b/internal/git/clone.go index ce5233a..0b0c4a4 100644 --- a/internal/git/clone.go +++ b/internal/git/clone.go @@ -7,34 +7,82 @@ import ( "github.com/go-git/go-billy/v5/memfs" git "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" - "github.com/go-git/go-git/v5/plumbing/transport" "github.com/go-git/go-git/v5/storage/memory" log "github.com/sirupsen/logrus" ) -type GitOpsCloneOptions struct { - Repository string - Branch string - FilePath string - Auth transport.AuthMethod -} - -func Clone(options *GitOpsCloneOptions) (*git.Repository, error) { +func (c *GitConnection) Clone() error { startTime := time.Now() repo, err := git.Clone(memory.NewStorage(), memfs.New(), &git.CloneOptions{ - URL: options.Repository, - Auth: options.Auth, + URL: c.Options.Repository, + Auth: c.Options.Auth, Depth: 1, - ReferenceName: plumbing.ReferenceName(fmt.Sprintf("refs/heads/%s", options.Branch)), + ReferenceName: plumbing.ReferenceName(fmt.Sprintf("refs/heads/%s", c.Options.Branch)), SingleBranch: true, Tags: git.NoTags, // Progress: os.Stdout, }) if err != nil { - log.Error(err) + log.WithError(err).Error("Error cloning repository ", c.Options.Repository, " on branch ", c.Options.Branch) + return err + } + log.Debug("Cloned repository ", c.Options.Repository, " on branch ", c.Options.Branch, " in ", time.Since(startTime)) + + c.Repository = repo + + return nil +} + +func (c *GitConnection) Commit(files []string, message string) (*plumbing.Hash, error) { + worktree, err := c.Repository.Worktree() + if err != nil { + log.WithError(err).Error("Error getting worktree") return nil, err } - log.Debug("Cloned repository ", options.Repository, " on branch ", options.Branch, " in ", time.Since(startTime)) - return repo, nil + for _, file := range files { + _, err := worktree.Add(file) + if err != nil { + log.WithError(err).Error("Error 'git add'ing file") + return nil, err + } + } + + hash, err := worktree.Commit(message, &git.CommitOptions{}) + if err != nil { + log.WithError(err).Error("Error 'git commit'ing files") + } + + return &hash, err +} + +func (c *GitConnection) Push(branch string) error { + err := c.Repository.Push(&git.PushOptions{ + RemoteName: "origin", + Auth: c.Options.Auth, + }) + if err != nil { + log.WithError(err).Error("Error pushing to branch ", branch) + return err + } + + log.Info("Pushed to origin/", branch) + + return nil +} + +func (c *GitConnection) HasChanges() (bool, error) { + worktree, err := c.Repository.Worktree() + if err != nil { + log.WithError(err).Error("Error getting worktree") + return false, err + } + + status, err := worktree.Status() + if err != nil { + log.WithError(err).Error("Error getting status") + return false, err + } + + return !status.IsClean(), nil } diff --git a/internal/git/git.go b/internal/git/git.go new file mode 100644 index 0000000..6a1a0ad --- /dev/null +++ b/internal/git/git.go @@ -0,0 +1,57 @@ +package git + +import ( + "errors" + "strings" + + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing/transport" + "github.com/go-git/go-git/v5/plumbing/transport/http" + gitssh "github.com/go-git/go-git/v5/plumbing/transport/ssh" + "golang.org/x/crypto/ssh" +) + +type GitConnectionOptions struct { + Repository string + Branch string + FilePath string + Auth transport.AuthMethod +} + +type GitConnection struct { + Repository *git.Repository + Options *GitConnectionOptions +} + +func NewGitConnection(options *GitConnectionOptions) (*GitConnection, error) { + return &GitConnection{ + Options: options, + }, nil +} + +func GetAuthFromUsernamePassword(username string, password string) (transport.AuthMethod, error) { + return &http.BasicAuth{ + Username: username, + Password: password, + }, nil +} + +func GetAuthFromBasicAuthString(basicAuth string) (transport.AuthMethod, error) { + split := strings.Split(basicAuth, ":") + if len(split) != 2 { + return nil, errors.New("invalid basic auth string") + } + return &http.BasicAuth{ + Username: split[0], + Password: split[1], + }, nil +} + +func GetAuthFromSshKey(sshKey []byte, sshKeyPassphrase string) (transport.AuthMethod, error) { + signer, err := ssh.ParsePrivateKey(sshKey) + if err != nil { + return nil, err + } + auth := &gitssh.PublicKeys{User: "git", Signer: signer} + return auth, nil +} diff --git a/internal/patch/method_git.go b/internal/patch/method_git.go new file mode 100644 index 0000000..178b31f --- /dev/null +++ b/internal/patch/method_git.go @@ -0,0 +1,186 @@ +package patch + +import ( + "errors" + "io" + "os" + + "github.com/go-git/go-git/v5/plumbing/transport" + "github.com/mxcd/gitops-cli/internal/git" + "github.com/mxcd/gitops-cli/internal/yaml" + "github.com/urfave/cli/v2" + + log "github.com/sirupsen/logrus" +) + +type GitPatcherOptions struct { + Branch string + RepositoryUrl string + + BasicAuth string + SshPrivateKey []byte + SshKeyPassphrase string +} + +type GitPatcher struct { + Options *GitPatcherOptions + GitConnection *git.GitConnection +} + +func GetGitPatcherOptionsFromCli(c *cli.Context) (*GitPatcherOptions, error) { + options := &GitPatcherOptions{ + Branch: c.String("branch"), + RepositoryUrl: c.String("repo"), + } + + if c.String("basicauth") != "" { + options.BasicAuth = c.String("basicauth") + } + + if c.String("ssh-key") != "" { + options.SshPrivateKey = []byte(c.String("sshkey")) + } else if c.String("ssh-key-file") != "" { + file, err := os.ReadFile(c.String("ssh-key-file")) + if err != nil { + return nil, err + } + options.SshPrivateKey = file + } + if c.String("ssh-key-passphrase") != "" { + options.SshKeyPassphrase = c.String("ssh-key-passphrase") + } + + return options, nil +} + +func NewGitPatcher(options *GitPatcherOptions) (*GitPatcher, error) { + if options.BasicAuth == "" && len(options.SshPrivateKey) == 0 { + return nil, errors.New("no authentication method specified") + } + + return &GitPatcher{ + Options: options, + }, nil +} + +func (p *GitPatcher) Prepare() error { + var authMethod transport.AuthMethod = nil + + if p.Options.BasicAuth != "" { + auth, err := git.GetAuthFromBasicAuthString(p.Options.BasicAuth) + if err != nil { + return err + } + authMethod = auth + } else if len(p.Options.SshPrivateKey) > 0 { + auth, err := git.GetAuthFromSshKey([]byte(p.Options.SshPrivateKey), p.Options.SshKeyPassphrase) + if err != nil { + return err + } + authMethod = auth + } + + gitConnection, err := git.NewGitConnection(&git.GitConnectionOptions{ + Repository: p.Options.RepositoryUrl, + Branch: p.Options.Branch, + Auth: authMethod, + }) + + if err != nil { + return err + } + + err = gitConnection.Clone() + if err != nil { + return err + } + + p.GitConnection = gitConnection + + return nil +} + +func (p *GitPatcher) Patch(patchTasks []PatchTask) error { + + worktree, err := p.GitConnection.Repository.Worktree() + if err != nil { + log.WithError(err).Error("Failed to get worktree") + return err + } + + for _, patchTask := range patchTasks { + filePath := patchTask.FilePath + + fileStat, err := worktree.Filesystem.Stat(filePath) + if err != nil { + log.Error("Failed to stat file: ", err) + } + + file, err := worktree.Filesystem.OpenFile(filePath, os.O_RDWR, fileStat.Mode()) + if err != nil { + log.Error("Failed to open file: ", err) + return err + } + defer file.Close() + + // Read the contents of the file + fileContents, err := io.ReadAll(file) + if err != nil { + log.Error("Failed to read file: ", err) + return err + } + + log.Debug("original yaml file: ", string(fileContents)) + + for _, patch := range patchTask.Patches { + selector := patch.Selector + value := patch.Value + + log.Debug("patching file with selector '", selector, "' and value '", value, "'") + patchedData, err := yaml.PatchYaml(fileContents, selector, value) + if err != nil { + return err + } + log.Debug("patched yaml file:\n", string(patchedData)) + + err = file.Truncate(0) + if err != nil { + log.WithError(err).Error("Failed to truncate file") + return err + } + + _, err = file.Seek(0, 0) + if err != nil { + log.WithError(err).Error("Failed to seek file") + return err + } + + _, err = file.Write(patchedData) + if err != nil { + log.Error("Failed to write file: ", err) + return err + } + + hasChanges, err := p.GitConnection.HasChanges() + if err != nil { + return err + } + + if !hasChanges { + log.Info("No changes detected, exiting") + return nil + } + + commitHash, err := p.GitConnection.Commit([]string{filePath}, "feat(gitops): patching "+filePath) + if err != nil { + return err + } + log.Info("Created patch commit: ", commitHash.String()) + } + + } + + err = p.GitConnection.Push(p.Options.Branch) + + return err +} diff --git a/internal/patch/method_git_test.go b/internal/patch/method_git_test.go new file mode 100644 index 0000000..d63eb24 --- /dev/null +++ b/internal/patch/method_git_test.go @@ -0,0 +1,31 @@ +package patch + +import ( + "os" + "path" + "testing" + + "github.com/mxcd/gitops-cli/internal/util" + "github.com/stretchr/testify/assert" +) + +func getSshKeyData(t *testing.T) []byte { + baseDir, err := util.GetGitRepoRoot() + assert.NoError(t, err) + assert.NotEmpty(t, baseDir) + + sshKeyPath := path.Join(baseDir, "hack", "soft-serve", "ssh-key") + assert.FileExists(t, sshKeyPath) + + sshKey, err := os.ReadFile(sshKeyPath) + assert.NoError(t, err) + assert.NotEmpty(t, sshKey) + + return sshKey +} + +func TestGitPath(t *testing.T) { + sshKey := getSshKeyData(t) + + +} diff --git a/internal/patch/patch.go b/internal/patch/patch.go index ae8c78f..a406e6e 100644 --- a/internal/patch/patch.go +++ b/internal/patch/patch.go @@ -1,198 +1,88 @@ package patch import ( - "bytes" "errors" - "io" - "strings" - "github.com/go-git/go-git/v5/plumbing/transport" - "github.com/go-git/go-git/v5/plumbing/transport/http" - "github.com/mxcd/gitops-cli/internal/git" - log "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" - "gopkg.in/yaml.v3" ) -func Patch(c *cli.Context) error { - branch := c.String("branch") - basicAuth := c.String("basicauth") - - var auth transport.AuthMethod = nil +type PatchTask struct { + FilePath string + Patches []Patch +} - if basicAuth != "" { - split := strings.Split(basicAuth, ":") - if len(split) != 2 { - return errors.New("invalid basic auth string") - } - auth = &http.BasicAuth{ - Username: split[0], - Password: split[1], - } - } +type Patch struct { + Selector string + Value string +} - repository := c.String("repo") - if repository == "" { - return errors.New("no repository specified") - } +type PatchMethod interface { + Prepare() error + Patch(patchTasks []PatchTask) error +} - filePath := c.Args().First() - if filePath == "" { - return errors.New("no file specified for patching") - } +func PatchCommand(c *cli.Context) error { - selector := c.Args().Get(1) - value := c.Args().Get(2) + var patchMethod PatchMethod - repo, err := git.Clone(&git.GitOpsCloneOptions{ - Repository: repository, - Branch: branch, - Auth: auth, - }) + if c.String("repo") != "" { + patcherOptions, err := GetGitPatcherOptionsFromCli(c) + if err != nil { + return err + } - if err != nil { - return err - } + patcher, err := NewGitPatcher(patcherOptions) + if err != nil { + return err + } - worktree, err := repo.Worktree() - if err != nil { - log.Error("Failed to get worktree: ", err) - return err + patchMethod = patcher + } else if c.String("repo-server") != "" { + // return PatchMethodRepoServer(c) + } else { + return errors.New("no repository specified") } - file, err := worktree.Filesystem.Open(filePath) + err := patchMethod.Prepare() if err != nil { - log.Error("Failed to open file: ", err) return err } - defer file.Close() - // Read the contents of the file - fileContents, err := io.ReadAll(file) + patchTask, err := GetPatchTaskFromCli(c) if err != nil { - log.Error("Failed to read file: ", err) return err } - log.Debug("Read file ", filePath, ":\n", string(fileContents)) - - // TODO patch single file - var fileData yaml.Node - err = yaml.Unmarshal(fileContents, &fileData) - if err != nil { - panic(err) - } - log.Debug("File data: ", fileData) - - patchedData, err := patchYamlData(&fileData, selector, value) + err = patchMethod.Patch([]PatchTask{patchTask}) if err != nil { return err } - log.Debug("Patched file data: ", patchedData) - patchedFileContents, err := yaml.Marshal(patchedData) - if err != nil { - return err - } - log.Debug("Patched file contents: ", string(patchedFileContents)) - - // TODO commit and push - - return err + return nil } -func patchYamlString(yamlString string, selector string, value string) (string, error) { - var fileData yaml.Node - err := yaml.Unmarshal([]byte(yamlString), &fileData) - if err != nil { - return "", err - } - - var patchedData *yaml.Node - if strings.HasPrefix(selector, ".") { - selector = selector[1:] - patchedData, err = patchYamlData(&fileData, selector, value) - if err != nil { - return "", err - } - } else { - patchedData, err = patchYamlDataWithSearch(&fileData, selector, value) - if err != nil { - return "", err - } - } - - var b bytes.Buffer - yamlEncoder := yaml.NewEncoder(&b) - yamlEncoder.SetIndent(2) - err = yamlEncoder.Encode(patchedData) - if err != nil { - return "", err - } - - return b.String(), nil -} - -func patchYamlData(data *yaml.Node, selector string, value string) (*yaml.Node, error) { - selectorParts := strings.Split(selector, ".") - - if err := findAndPatchNode(data, selectorParts, value); err != nil { - return nil, err +func GetPatchTaskFromCli(c *cli.Context) (PatchTask, error) { + filePath := c.Args().First() + if filePath == "" { + return PatchTask{}, errors.New("no file specified") } - return data, nil -} -func findAndPatchNode(node *yaml.Node, selectorParts []string, value string) error { - if len(selectorParts) == 0 { - node.Value = value - return nil - } + patches := []Patch{} + args := c.Args().Tail() - for i, child := range node.Content { - if child.Kind == yaml.MappingNode { - for j := 0; j < len(child.Content); j += 2 { - keyNode := child.Content[j] - valueNode := child.Content[j+1] - if keyNode.Value == selectorParts[0] { - return findAndPatchNode(valueNode, selectorParts[1:], value) - } - } - } else if child.Kind == yaml.ScalarNode { - if child.Value == selectorParts[0] { - return findAndPatchNode(node.Content[i+1], selectorParts[1:], value) - } - } + if len(args)%2 != 0 { + return PatchTask{}, errors.New("invalid number of arguments. patches must be in the form of 'selector value'") } - return errors.New("selector not found") -} - -func patchYamlDataWithSearch(data *yaml.Node, selector string, value string) (*yaml.Node, error) { - if err := findAndPatchNodeWithSearch(data, selector, value); err != nil { - return nil, err + for i := 0; i < len(args); i += 2 { + patches = append(patches, Patch{ + Selector: args[i], + Value: args[i+1], + }) } - return data, nil -} -func findAndPatchNodeWithSearch(node *yaml.Node, selector string, value string) error { - if node.Kind == yaml.MappingNode { - for i := 0; i < len(node.Content); i += 2 { - keyNode := node.Content[i] - valueNode := node.Content[i+1] - if keyNode.Kind == yaml.ScalarNode && keyNode.Value == selector { - valueNode.Value = value - return nil - } - if err := findAndPatchNodeWithSearch(valueNode, selector, value); err == nil { - return nil - } - } - } else if node.Kind == yaml.SequenceNode || node.Kind == yaml.DocumentNode { - for _, child := range node.Content { - if err := findAndPatchNodeWithSearch(child, selector, value); err == nil { - return nil - } - } - } - return errors.New("key not found") + return PatchTask{ + FilePath: filePath, + Patches: patches, + }, nil } diff --git a/internal/yaml/patcher.go b/internal/yaml/patcher.go new file mode 100644 index 0000000..d558b53 --- /dev/null +++ b/internal/yaml/patcher.go @@ -0,0 +1,105 @@ +package yaml + +import ( + "bytes" + "errors" + "strings" + + "gopkg.in/yaml.v3" +) + +func PatchYaml(yamlData []byte, selector string, value string) ([]byte, error) { + var node yaml.Node + err := yaml.Unmarshal(yamlData, &node) + if err != nil { + return []byte{}, err + } + + var patchedNode *yaml.Node + if strings.HasPrefix(selector, ".") { + selector = selector[1:] + patchedNode, err = patchYamlData(&node, selector, value) + if err != nil { + return []byte{}, err + } + } else { + patchedNode, err = patchYamlDataWithSearch(&node, selector, value) + if err != nil { + return []byte{}, err + } + } + + var b bytes.Buffer + yamlEncoder := yaml.NewEncoder(&b) + yamlEncoder.SetIndent(2) + err = yamlEncoder.Encode(patchedNode) + if err != nil { + return []byte{}, err + } + + return b.Bytes(), nil +} + +func patchYamlData(data *yaml.Node, selector string, value string) (*yaml.Node, error) { + selectorParts := strings.Split(selector, ".") + + if err := findAndPatchNode(data, selectorParts, value); err != nil { + return nil, err + } + return data, nil +} + +func findAndPatchNode(node *yaml.Node, selectorParts []string, value string) error { + if len(selectorParts) == 0 { + node.Value = value + return nil + } + + for i, child := range node.Content { + if child.Kind == yaml.MappingNode { + for j := 0; j < len(child.Content); j += 2 { + keyNode := child.Content[j] + valueNode := child.Content[j+1] + if keyNode.Value == selectorParts[0] { + return findAndPatchNode(valueNode, selectorParts[1:], value) + } + } + } else if child.Kind == yaml.ScalarNode { + if child.Value == selectorParts[0] { + return findAndPatchNode(node.Content[i+1], selectorParts[1:], value) + } + } + } + + return errors.New("selector not found") +} + +func patchYamlDataWithSearch(data *yaml.Node, selector string, value string) (*yaml.Node, error) { + if err := findAndPatchNodeWithSearch(data, selector, value); err != nil { + return nil, err + } + return data, nil +} + +func findAndPatchNodeWithSearch(node *yaml.Node, selector string, value string) error { + if node.Kind == yaml.MappingNode { + for i := 0; i < len(node.Content); i += 2 { + keyNode := node.Content[i] + valueNode := node.Content[i+1] + if keyNode.Kind == yaml.ScalarNode && keyNode.Value == selector { + valueNode.Value = value + return nil + } + if err := findAndPatchNodeWithSearch(valueNode, selector, value); err == nil { + return nil + } + } + } else if node.Kind == yaml.SequenceNode || node.Kind == yaml.DocumentNode { + for _, child := range node.Content { + if err := findAndPatchNodeWithSearch(child, selector, value); err == nil { + return nil + } + } + } + return errors.New("key not found") +} diff --git a/internal/patch/patch_test.go b/internal/yaml/patcher_test.go similarity index 87% rename from internal/patch/patch_test.go rename to internal/yaml/patcher_test.go index ef68d3a..316b74b 100644 --- a/internal/patch/patch_test.go +++ b/internal/yaml/patcher_test.go @@ -1,4 +1,4 @@ -package patch +package yaml import ( "testing" @@ -111,10 +111,10 @@ var testCases = []TestCase{ func TestYamlPatching(t *testing.T) { test := func(testCase TestCase) { - pathedYamlString, err := patchYamlString(testCase.originalYaml, testCase.selector, testCase.value) + pathedYamlString, err := PatchYaml([]byte(testCase.originalYaml), testCase.selector, testCase.value) assert.NoError(t, err) - assert.Equal(t, testCase.expectedYaml, pathedYamlString, "Patched data should be equal to expected data") + assert.Equal(t, testCase.expectedYaml, string(pathedYamlString), "Patched data should be equal to expected data") } for _, testCase := range testCases { diff --git a/tapes/plan/plan-k8s.tape b/tapes/plan/plan-k8s.tape new file mode 100644 index 0000000..3005279 --- /dev/null +++ b/tapes/plan/plan-k8s.tape @@ -0,0 +1,69 @@ +# VHS documentation +# +# Output: +# Output .gif Create a GIF output at the given +# Output .mp4 Create an MP4 output at the given +# Output .webm Create a WebM output at the given +# +# Require: +# Require Ensure a program is on the $PATH to proceed +# +# Settings: +# Set FontSize Set the font size of the terminal +# Set FontFamily Set the font family of the terminal +# Set Height Set the height of the terminal +# Set Width Set the width of the terminal +# Set LetterSpacing Set the font letter spacing (tracking) +# Set LineHeight Set the font line height +# Set LoopOffset % Set the starting frame offset for the GIF loop +# Set Theme Set the theme of the terminal +# Set Padding Set the padding of the terminal +# Set Framerate Set the framerate of the recording +# Set PlaybackSpeed Set the playback speed of the recording +# Set MarginFill Set the file or color the margin will be filled with. +# Set Margin Set the size of the margin. Has no effect if MarginFill isn't set. +# Set BorderRadius Set terminal border radius, in pixels. +# Set WindowBar Set window bar type. (one of: Rings, RingsRight, Colorful, ColorfulRight) +# Set WindowBarSize Set window bar size, in pixels. Default is 40. +# Set TypingSpeed