Skip to content
Open
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
23 changes: 22 additions & 1 deletion cmd/sops/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ func main() {
Name: "user",
Usage: "the user to run the command as",
},
cli.StringFlag{
Name: "extract",
Usage: "extract a specific key or branch from the input document. Example: --extract '[\"somekey\"][0]'",
},
}, keyserviceFlags...),
Action: func(c *cli.Context) error {
if c.NArg() != 2 {
Expand All @@ -178,6 +182,12 @@ func main() {
if err != nil {
return toExitError(err)
}

extract, err := parseTreePath(c.String("extract"))
if err != nil {
return common.NewExitError(fmt.Errorf("error parsing --extract path: %s", err), codes.InvalidTreePathFormat)
}

opts := decryptOpts{
OutputStore: &dotenv.Store{},
InputStore: inputStore,
Expand All @@ -186,6 +196,7 @@ func main() {
KeyServices: svcs,
DecryptionOrder: order,
IgnoreMAC: c.Bool("ignore-mac"),
Extract: extract,
}

if c.Bool("background") {
Expand Down Expand Up @@ -239,6 +250,10 @@ func main() {
Name: "filename",
Usage: "filename for the temporarily file (default: tmp-file)",
},
cli.StringFlag{
Name: "extract",
Usage: "extract a specific key or branch from the input document. Example: --extract '[\"somekey\"][0]'",
},
}, keyserviceFlags...),
Action: func(c *cli.Context) error {
if c.NArg() != 2 {
Expand All @@ -251,6 +266,11 @@ func main() {
inputStore := inputStore(c, fileName)
outputStore := outputStore(c, fileName)

extract, err := parseTreePath(c.String("extract"))
if err != nil {
return common.NewExitError(fmt.Errorf("error parsing --extract path: %s", err), codes.InvalidTreePathFormat)
}

svcs := keyservices(c)

order, err := decryptionOrder(c.String("decryption-order"))
Expand All @@ -265,6 +285,7 @@ func main() {
KeyServices: svcs,
DecryptionOrder: order,
IgnoreMAC: c.Bool("ignore-mac"),
Extract: extract,
}

output, err := decrypt(opts)
Expand Down Expand Up @@ -680,7 +701,7 @@ func main() {
},
cli.StringFlag{
Name: "extract",
Usage: "extract a specific key or branch from the input document. Decrypt mode only. Example: --extract '[\"somekey\"][0]'",
Usage: "extract a specific key or branch from the input document. Example: --extract '[\"somekey\"][0]'",
},
cli.StringFlag{
Name: "input-type",
Expand Down