Skip to content

Commit

Permalink
Merge pull request #1506 from felixfontein/nil-check
Browse files Browse the repository at this point in the history
LoadCreationRuleForFile: correctly handle nil without error in callers
  • Loading branch information
felixfontein committed May 13, 2024
2 parents c0b1efd + 5e8ae12 commit a465b8a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/sops/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,7 @@ func keyGroups(c *cli.Context, file string) ([]sops.KeyGroup, error) {
conf, err := loadConfig(c, file, kmsEncryptionContext)
// config file might just not be supplied, without any error
if conf == nil {
errMsg := "config file not found and no keys provided through command line options"
errMsg := "config file not found, or has no creation rules, and no keys provided through command line options"
if err != nil {
errMsg = fmt.Sprintf("%s: %s", errMsg, err)
}
Expand Down Expand Up @@ -2031,7 +2031,7 @@ func shamirThreshold(c *cli.Context, file string) (int, error) {
conf, err := loadConfig(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.
// 1. No config was provided, or contains no creation rules. 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
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/sops/subcommand/updatekeys/updatekeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func updateFile(opts Opts) error {
if err != nil {
return err
}
if conf == nil {
return fmt.Errorf("The config file %s does not contain any creation rule", opts.ConfigPath)
}

diffs := common.DiffKeyGroups(tree.Metadata.KeyGroups, conf.KeyGroups)
keysWillChange := false
Expand Down

0 comments on commit a465b8a

Please sign in to comment.