Skip to content

Commit b54fa8a

Browse files
authored
Merge pull request #1274 from sj14/sj/updatekeys-inputs
Allow to pass multiple paths to 'updatekeys'
2 parents 0f19e7d + b693f29 commit b54fa8a

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

cmd/sops/main.go

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ func main() {
515515
},
516516
{
517517
Name: "updatekeys",
518-
Usage: "update the keys of a SOPS file using the config file",
518+
Usage: "update the keys of SOPS files using the config file",
519519
ArgsUsage: `file`,
520520
Flags: append([]cli.Flag{
521521
cli.BoolFlag{
@@ -541,18 +541,35 @@ func main() {
541541
if c.NArg() < 1 {
542542
return common.NewExitError("Error: no file specified", codes.NoFileSpecified)
543543
}
544-
err = updatekeys.UpdateKeys(updatekeys.Opts{
545-
InputPath: c.Args()[0],
546-
GroupQuorum: c.Int("shamir-secret-sharing-quorum"),
547-
KeyServices: keyservices(c),
548-
Interactive: !c.Bool("yes"),
549-
ConfigPath: configPath,
550-
InputType: c.String("input-type"),
551-
})
552-
if cliErr, ok := err.(*cli.ExitError); ok && cliErr != nil {
553-
return cliErr
554-
} else if err != nil {
555-
return common.NewExitError(err, codes.ErrorGeneric)
544+
failedCounter := 0
545+
for _, path := range c.Args() {
546+
err := updatekeys.UpdateKeys(updatekeys.Opts{
547+
InputPath: path,
548+
GroupQuorum: c.Int("shamir-secret-sharing-quorum"),
549+
KeyServices: keyservices(c),
550+
Interactive: !c.Bool("yes"),
551+
ConfigPath: configPath,
552+
InputType: c.String("input-type"),
553+
})
554+
555+
if c.NArg() == 1 {
556+
// a single argument was given, keep compatibility of the error
557+
if cliErr, ok := err.(*cli.ExitError); ok && cliErr != nil {
558+
return cliErr
559+
} else if err != nil {
560+
return common.NewExitError(err, codes.ErrorGeneric)
561+
}
562+
}
563+
564+
// multiple arguments given (patched functionality),
565+
// finish updating of remaining files and fail afterwards
566+
if err != nil {
567+
failedCounter++
568+
log.Error(err)
569+
}
570+
}
571+
if failedCounter > 0 {
572+
return common.NewExitError(fmt.Errorf("failed updating %d key(s)", failedCounter), codes.ErrorGeneric)
556573
}
557574
return nil
558575
},

0 commit comments

Comments
 (0)