Skip to content

Commit

Permalink
Allow to override fileName with different value.
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Fontein <felix@fontein.de>
  • Loading branch information
felixfontein committed Dec 15, 2023
1 parent 0edeb3b commit 93fe402
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions cmd/sops/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,10 @@ func main() {
Name: "output",
Usage: "Save the output after encryption or decryption to the file specified",
},
cli.StringFlag{
Name: "filename-override",
Usage: "Use this filename instead of the provided argument for loading configuration, and for determining input type and output type",
},
}, keyserviceFlags...)

app.Action = func(c *cli.Context) error {
Expand All @@ -741,13 +745,17 @@ func main() {
return common.NewExitError("Error: cannot operate on non-existent file", codes.NoFileSpecified)
}
}
fileNameOverride := c.String("filename-override")
if fileNameOverride == "" {
fileNameOverride = fileName
}

unencryptedSuffix := c.String("unencrypted-suffix")
encryptedSuffix := c.String("encrypted-suffix")
encryptedRegex := c.String("encrypted-regex")
unencryptedRegex := c.String("unencrypted-regex")
macOnlyEncrypted := c.Bool("mac-only-encrypted")
conf, err := loadConfig(c, fileName, nil)
conf, err := loadConfig(c, fileNameOverride, nil)
if err != nil {
return toExitError(err)
}
Expand Down Expand Up @@ -793,19 +801,19 @@ func main() {
unencryptedSuffix = sops.DefaultUnencryptedSuffix
}

inputStore := inputStore(c, fileName)
outputStore := outputStore(c, fileName)
inputStore := inputStore(c, fileNameOverride)
outputStore := outputStore(c, fileNameOverride)
svcs := keyservices(c)

var output []byte
if c.Bool("encrypt") {
var groups []sops.KeyGroup
groups, err = keyGroups(c, fileName)
groups, err = keyGroups(c, fileNameOverride)
if err != nil {
return toExitError(err)
}
var threshold int
threshold, err = shamirThreshold(c, fileName)
threshold, err = shamirThreshold(c, fileNameOverride)
if err != nil {
return toExitError(err)
}
Expand Down Expand Up @@ -961,12 +969,12 @@ func main() {
} else {
// File doesn't exist, edit the example file instead
var groups []sops.KeyGroup
groups, err = keyGroups(c, fileName)
groups, err = keyGroups(c, fileNameOverride)
if err != nil {
return toExitError(err)
}
var threshold int
threshold, err = shamirThreshold(c, fileName)
threshold, err = shamirThreshold(c, fileNameOverride)
if err != nil {
return toExitError(err)
}
Expand Down

0 comments on commit 93fe402

Please sign in to comment.