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

Function editExample

cmd/sops/edit.go:50–73  ·  view source on GitHub ↗
(opts editExampleOpts)

Source from the content-addressed store, hash-verified

48}
49
50func editExample(opts editExampleOpts) ([]byte, error) {
51 fileBytes := opts.InputStore.EmitExample()
52 branches, err := opts.InputStore.LoadPlainFile(fileBytes)
53 if err != nil {
54 return nil, common.NewExitError(fmt.Sprintf("Error unmarshalling file: %s", err), codes.CouldNotReadInputFile)
55 }
56 path, err := filepath.Abs(opts.InputPath)
57 if err != nil {
58 return nil, err
59 }
60 tree := sops.Tree{
61 Branches: branches,
62 Metadata: metadataFromEncryptionConfig(opts.encryptConfig),
63 FilePath: path,
64 }
65
66 // Generate a data key
67 dataKey, errs := tree.GenerateDataKeyWithKeyServices(opts.KeyServices)
68 if len(errs) > 0 {
69 return nil, common.NewExitError(fmt.Sprintf("Error encrypting the data key with one or more master keys: %s", errs), codes.CouldNotRetrieveKey)
70 }
71
72 return editTree(opts.editOpts, &tree, dataKey)
73}
74
75func edit(opts editOpts) ([]byte, error) {
76 // Load the file

Callers 1

mainFunction · 0.85

Calls 6

NewExitErrorFunction · 0.92
editTreeFunction · 0.85
EmitExampleMethod · 0.65
LoadPlainFileMethod · 0.65

Tested by

no test coverage detected