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

LoadCreationRuleForFile: correctly handle nil without error in callers #1506

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
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
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
Loading