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

Function set

cmd/sops/set.go:24–70  ·  view source on GitHub ↗
(opts setOpts)

Source from the content-addressed store, hash-verified

22}
23
24func set(opts setOpts) ([]byte, bool, error) {
25 // Load the file
26 // TODO: Issue #173: if the file does not exist, create it with the contents passed in as opts.Value
27 tree, err := common.LoadEncryptedFileWithBugFixes(common.GenericDecryptOpts{
28 Cipher: opts.Cipher,
29 InputStore: opts.InputStore,
30 InputPath: opts.InputPath,
31 IgnoreMAC: opts.IgnoreMAC,
32 KeyServices: opts.KeyServices,
33 })
34 if err != nil {
35 return nil, false, err
36 }
37
38 // Decrypt the file
39 dataKey, err := common.DecryptTree(common.DecryptTreeOpts{
40 Cipher: opts.Cipher,
41 IgnoreMac: opts.IgnoreMAC,
42 Tree: tree,
43 KeyServices: opts.KeyServices,
44 DecryptionOrder: opts.DecryptionOrder,
45 })
46 if err != nil {
47 return nil, false, err
48 }
49
50 // Set the value
51 var changed bool
52 tree.Branches[0], changed = tree.Branches[0].Set(opts.TreePath, opts.Value)
53
54 if err, code := validateFileForEncryption(opts.OutputStore, tree.Branches); err != nil {
55 return nil, false, common.NewExitError(err, code)
56 }
57
58 err = common.EncryptTree(common.EncryptTreeOpts{
59 DataKey: dataKey, Tree: tree, Cipher: opts.Cipher,
60 })
61 if err != nil {
62 return nil, false, err
63 }
64
65 encryptedFile, err := opts.OutputStore.EmitEncryptedFile(*tree)
66 if err != nil {
67 return nil, false, common.NewExitError(fmt.Sprintf("Could not marshal tree: %s", err), codes.ErrorDumpingTree)
68 }
69 return encryptedFile, changed, err
70}

Callers 1

mainFunction · 0.70

Calls 7

DecryptTreeFunction · 0.92
NewExitErrorFunction · 0.92
EncryptTreeFunction · 0.92
SetMethod · 0.80
EmitEncryptedFileMethod · 0.65

Tested by

no test coverage detected