(tree *sops.Tree, path []interface{}, outputStore sops.Store)
| 73 | } |
| 74 | |
| 75 | func 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 | } |
no test coverage detected