Skip to content

Commit

Permalink
Do not ignore errors when trying to parse a config file.
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Fontein <felix@fontein.de>
  • Loading branch information
felixfontein committed Oct 3, 2024
1 parent e36155a commit 8c567aa
Showing 1 changed file with 109 additions and 29 deletions.
138 changes: 109 additions & 29 deletions cmd/sops/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ func main() {
fileName := c.Args()[0]
command := c.Args()[1]

inputStore := inputStore(c, fileName)
inputStore, err := inputStore(c, fileName)
if err != nil {
return toExitError(err)
}

svcs := keyservices(c)

Expand Down Expand Up @@ -272,8 +275,14 @@ func main() {
fileName := c.Args()[0]
command := c.Args()[1]

inputStore := inputStore(c, fileName)
outputStore := outputStore(c, fileName)
inputStore, err := inputStore(c, fileName)
if err != nil {
return toExitError(err)
}
outputStore, err := outputStore(c, fileName)
if err != nil {
return toExitError(err)
}

svcs := keyservices(c)

Expand Down Expand Up @@ -365,13 +374,17 @@ func main() {
return toExitError(err)
}
if !info.IsDir() {
inputStore, err := inputStore(c, subPath)
if err != nil {
return toExitError(err)
}
err = publishcmd.Run(publishcmd.Opts{
ConfigPath: configPath,
InputPath: subPath,
Cipher: aes.NewCipher(),
KeyServices: keyservices(c),
DecryptionOrder: order,
InputStore: inputStore(c, subPath),
InputStore: inputStore,
Interactive: !c.Bool("yes"),
OmitExtensions: c.Bool("omit-extensions"),
Recursive: c.Bool("recursive"),
Expand Down Expand Up @@ -440,7 +453,10 @@ func main() {
}

fileName := c.Args()[0]
inputStore := inputStore(c, fileName)
inputStore, err := inputStore(c, fileName)
if err != nil {
return toExitError(err)
}
opts := filestatuscmd.Opts{
InputStore: inputStore,
InputPath: fileName,
Expand Down Expand Up @@ -560,11 +576,19 @@ func main() {
group = append(group, key)
}
}
inputStore, err := inputStore(c, c.String("file"))
if err != nil {
return toExitError(err)
}
outputStore, err := outputStore(c, c.String("file"))
if err != nil {
return toExitError(err)
}
return groups.Add(groups.AddOpts{
InputPath: c.String("file"),
InPlace: c.Bool("in-place"),
InputStore: inputStore(c, c.String("file")),
OutputStore: outputStore(c, c.String("file")),
InputStore: inputStore,
OutputStore: outputStore,
Group: group,
GroupThreshold: c.Int("shamir-secret-sharing-threshold"),
KeyServices: keyservices(c),
Expand Down Expand Up @@ -599,11 +623,19 @@ func main() {
return fmt.Errorf("failed to parse [index] argument: %s", err)
}

inputStore, err := inputStore(c, c.String("file"))
if err != nil {
return toExitError(err)
}
outputStore, err := outputStore(c, c.String("file"))
if err != nil {
return toExitError(err)
}
return groups.Delete(groups.DeleteOpts{
InputPath: c.String("file"),
InPlace: c.Bool("in-place"),
InputStore: inputStore(c, c.String("file")),
OutputStore: outputStore(c, c.String("file")),
InputStore: inputStore,
OutputStore: outputStore,
Group: uint(group),
GroupThreshold: c.Int("shamir-secret-sharing-threshold"),
KeyServices: keyservices(c),
Expand Down Expand Up @@ -735,8 +767,14 @@ func main() {
fileNameOverride = fileName
}

inputStore := inputStore(c, fileNameOverride)
outputStore := outputStore(c, fileNameOverride)
inputStore, err := inputStore(c, fileNameOverride)
if err != nil {
return toExitError(err)
}
outputStore, err := outputStore(c, fileNameOverride)
if err != nil {
return toExitError(err)
}
svcs := keyservices(c)

order, err := decryptionOrder(c.String("decryption-order"))
Expand Down Expand Up @@ -899,8 +937,14 @@ func main() {
fileNameOverride = fileName
}

inputStore := inputStore(c, fileNameOverride)
outputStore := outputStore(c, fileNameOverride)
inputStore, err := inputStore(c, fileNameOverride)
if err != nil {
return toExitError(err)
}
outputStore, err := outputStore(c, fileNameOverride)
if err != nil {
return toExitError(err)
}
svcs := keyservices(c)

encConfig, err := getEncryptConfig(c, fileNameOverride)
Expand Down Expand Up @@ -1058,8 +1102,14 @@ func main() {
fileNameOverride = fileName
}

inputStore := inputStore(c, fileNameOverride)
outputStore := outputStore(c, fileNameOverride)
inputStore, err := inputStore(c, fileNameOverride)
if err != nil {
return toExitError(err)
}
outputStore, err := outputStore(c, fileNameOverride)
if err != nil {
return toExitError(err)
}
svcs := keyservices(c)

order, err := decryptionOrder(c.String("decryption-order"))
Expand Down Expand Up @@ -1203,8 +1253,14 @@ func main() {
return toExitError(err)
}

inputStore := inputStore(c, fileName)
outputStore := outputStore(c, fileName)
inputStore, err := inputStore(c, fileName)
if err != nil {
return toExitError(err)
}
outputStore, err := outputStore(c, fileName)
if err != nil {
return toExitError(err)
}
svcs := keyservices(c)

order, err := decryptionOrder(c.String("decryption-order"))
Expand Down Expand Up @@ -1298,8 +1354,14 @@ func main() {
return toExitError(err)
}

inputStore := inputStore(c, fileName)
outputStore := outputStore(c, fileName)
inputStore, err := inputStore(c, fileName)
if err != nil {
return toExitError(err)
}
outputStore, err := outputStore(c, fileName)
if err != nil {
return toExitError(err)
}
svcs := keyservices(c)

path, err := parseTreePath(c.Args()[1])
Expand Down Expand Up @@ -1389,8 +1451,14 @@ func main() {
return toExitError(err)
}

inputStore := inputStore(c, fileName)
outputStore := outputStore(c, fileName)
inputStore, err := inputStore(c, fileName)
if err != nil {
return toExitError(err)
}
outputStore, err := outputStore(c, fileName)
if err != nil {
return toExitError(err)
}
svcs := keyservices(c)

path, err := parseTreePath(c.Args()[1])
Expand Down Expand Up @@ -1687,8 +1755,14 @@ func main() {
}
}

inputStore := inputStore(c, fileNameOverride)
outputStore := outputStore(c, fileNameOverride)
inputStore, err := inputStore(c, fileNameOverride)
if err != nil {
return toExitError(err)
}
outputStore, err := outputStore(c, fileNameOverride)
if err != nil {
return toExitError(err)
}
svcs := keyservices(c)

order, err := decryptionOrder(c.String("decryption-order"))
Expand Down Expand Up @@ -2049,21 +2123,27 @@ func loadStoresConfig(context *cli.Context, path string) (*config.StoresConfig,
return config.LoadStoresConfig(configPath)
}

func inputStore(context *cli.Context, path string) common.Store {
storesConf, _ := loadStoresConfig(context, path)
return common.DefaultStoreForPathOrFormat(storesConf, path, context.String("input-type"))
func inputStore(context *cli.Context, path string) (common.Store, error) {
storesConf, err := loadStoresConfig(context, path)
if err != nil {
return nil, err
}
return common.DefaultStoreForPathOrFormat(storesConf, path, context.String("input-type")), nil
}

func outputStore(context *cli.Context, path string) common.Store {
storesConf, _ := loadStoresConfig(context, path)
func outputStore(context *cli.Context, path string) (common.Store, error) {
storesConf, err := loadStoresConfig(context, path)
if err != nil {
return nil, err
}
if context.IsSet("indent") {
indent := context.Int("indent")
storesConf.YAML.Indent = indent
storesConf.JSON.Indent = indent
storesConf.JSONBinary.Indent = indent
}

return common.DefaultStoreForPathOrFormat(storesConf, path, context.String("output-type"))
return common.DefaultStoreForPathOrFormat(storesConf, path, context.String("output-type")), nil
}

func parseTreePath(arg string) ([]interface{}, error) {
Expand Down

0 comments on commit 8c567aa

Please sign in to comment.