Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not ignore errors when trying to parse a config file #1614

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading