From 004f0ca3e019667c484629c7a41f89b53af26763 Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Fri, 15 Jul 2022 11:09:44 -0400 Subject: [PATCH] cmd/gitops-pusher: format HuJSON, enabling exact ACL matches (#5061) Signed-off-by: Xe --- cmd/gitops-pusher/gitops-pusher.go | 13 +++++++++---- go.mod | 2 +- go.sum | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cmd/gitops-pusher/gitops-pusher.go b/cmd/gitops-pusher/gitops-pusher.go index 14efbc363..007954ad4 100644 --- a/cmd/gitops-pusher/gitops-pusher.go +++ b/cmd/gitops-pusher/gitops-pusher.go @@ -13,13 +13,14 @@ import ( "encoding/json" "flag" "fmt" - "io" "log" "net/http" "os" "regexp" "strings" "time" + + "github.com/tailscale/hujson" ) var ( @@ -94,14 +95,18 @@ func main() { } func sumFile(fname string) (string, error) { - fin, err := os.Open(fname) + data, err := os.ReadFile(fname) + if err != nil { + return "", err + } + + formatted, err := hujson.Format(data) if err != nil { return "", err } - defer fin.Close() h := sha256.New() - _, err = io.Copy(h, fin) + _, err = h.Write(formatted) if err != nil { return "", err } diff --git a/go.mod b/go.mod index a5018e79f..65e40311d 100644 --- a/go.mod +++ b/go.mod @@ -42,7 +42,7 @@ require ( github.com/tailscale/goexpect v0.0.0-20210902213824-6e8c725cea41 github.com/tailscale/golang-x-crypto v0.0.0-20220428210705-0b941c09a5e1 github.com/tailscale/goupnp v1.0.1-0.20210804011211-c64d0f06ea05 - github.com/tailscale/hujson v0.0.0-20220506202205-92b4b88a9e17 + github.com/tailscale/hujson v0.0.0-20220630195928-54599719472f github.com/tailscale/mkctr v0.0.0-20220601142259-c0b937af2e89 github.com/tailscale/netlink v1.1.1-0.20211101221916-cabfb018fe85 github.com/tcnksm/go-httpstat v0.2.0 diff --git a/go.sum b/go.sum index b372855c9..06d9ac39c 100644 --- a/go.sum +++ b/go.sum @@ -1102,6 +1102,8 @@ github.com/tailscale/goupnp v1.0.1-0.20210804011211-c64d0f06ea05 h1:4chzWmimtJPx github.com/tailscale/goupnp v1.0.1-0.20210804011211-c64d0f06ea05/go.mod h1:PdCqy9JzfWMJf1H5UJW2ip33/d4YkoKN0r67yKH1mG8= github.com/tailscale/hujson v0.0.0-20220506202205-92b4b88a9e17 h1:QaQrUggZ7U2lE3HhoPx6bDK7fO385FR7pHRYSPEv70Q= github.com/tailscale/hujson v0.0.0-20220506202205-92b4b88a9e17/go.mod h1:DFSS3NAGHthKo1gTlmEcSBiZrRJXi28rLNd/1udP1c8= +github.com/tailscale/hujson v0.0.0-20220630195928-54599719472f h1:n4r/sJ92cBSBHK8n9lR1XLFr0OiTVeGfN5TR+9LaN7E= +github.com/tailscale/hujson v0.0.0-20220630195928-54599719472f/go.mod h1:DFSS3NAGHthKo1gTlmEcSBiZrRJXi28rLNd/1udP1c8= github.com/tailscale/mkctr v0.0.0-20220601142259-c0b937af2e89 h1:7xU7AFQE83h0wz/dIMvD0t77g0FxFfZIQjghDQxyG2U= github.com/tailscale/mkctr v0.0.0-20220601142259-c0b937af2e89/go.mod h1:OGMqrTzDqmJkGumUTtOv44Rp3/4xS+QFbE8Rn0AGlaU= github.com/tailscale/netlink v1.1.1-0.20211101221916-cabfb018fe85 h1:zrsUcqrG2uQSPhaUPjUQwozcRdDdSxxqhNgNZ3drZFk=