MCPcopy
hub / github.com/getsops/sops / extract

Function extract

cmd/sops/decrypt.go:75–98  ·  view source on GitHub ↗
(tree *sops.Tree, path []interface{}, outputStore sops.Store)

Source from the content-addressed store, hash-verified

73}
74
75func extract(tree *sops.Tree, path []interface{}, outputStore sops.Store) (output []byte, err error) {
76 v, err := tree.Branches[0].Truncate(path)
77 if err != nil {
78 return nil, fmt.Errorf("error truncating tree: %s", err)
79 }
80 if newBranch, ok := v.(sops.TreeBranch); ok {
81 tree.Branches[0] = newBranch
82 decrypted, err := outputStore.EmitPlainFile(tree.Branches)
83 if errors.Is(err, json.BinaryStoreEmitPlainError) {
84 err = fmt.Errorf("%s\n\n%s", err.Error(), notBinaryHint)
85 }
86 if err != nil {
87 return nil, common.NewExitError(fmt.Sprintf("Error dumping file: %s", err), codes.ErrorDumpingTree)
88 }
89 return decrypted, err
90 } else if str, ok := v.(string); ok {
91 return []byte(str), nil
92 }
93 bytes, err := outputStore.EmitValue(v)
94 if err != nil {
95 return nil, common.NewExitError(fmt.Sprintf("Error dumping tree: %s", err), codes.ErrorDumpingTree)
96 }
97 return bytes, nil
98}

Callers 1

decryptFunction · 0.85

Calls 5

NewExitErrorFunction · 0.92
TruncateMethod · 0.80
EmitPlainFileMethod · 0.65
EmitValueMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected