From 6e7a6449d8c420c4f1386b712e83a498d7ff5da1 Mon Sep 17 00:00:00 2001 From: Maren Sofie Ringsby Date: Fri, 31 May 2024 13:02:17 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20hent=20ut=20shamir=20threshold=20fra=20e?= =?UTF-8?q?ncrypt-config=20istedenfor=20=C3=A5=20lete=20p=C3=A5=20rot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dersom den settes til 0, vil man senere ved updatekeys sette shamir til å være lengden av keygroups - som ofte blir litt i meste laget --- cmd/sops/main.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/sops/main.go b/cmd/sops/main.go index f00303b84..d0268bf29 100644 --- a/cmd/sops/main.go +++ b/cmd/sops/main.go @@ -1857,7 +1857,7 @@ func getEncryptConfigFromString(c *cli.Context, fileName string, configString st } var threshold int - threshold, err = shamirThreshold(c, fileName) + threshold, err = shamirThresholdFromString(configString, fileName) if err != nil { return encryptConfig{}, err } @@ -2237,6 +2237,17 @@ func shamirThreshold(c *cli.Context, file string) (int, error) { return conf.ShamirThreshold, nil } +func shamirThresholdFromString(c string, file string) (int, error) { + conf, err := loadConfigFromString(c, file, nil) + if conf == nil { + // This takes care of the following two case: + // 1. No config was provided. Err will be nil and ShamirThreshold will be the default value of 0. + // 2. We did find a config file, but failed to load it. In that case the calling function will print the error and exit. + return 0, err + } + return conf.ShamirThreshold, nil +} + func jsonValueToTreeInsertableValue(jsonValue string) (interface{}, error) { var valueToInsert interface{} err := encodingjson.Unmarshal([]byte(jsonValue), &valueToInsert)