-
Notifications
You must be signed in to change notification settings - Fork 7
/
sops.go
65 lines (51 loc) · 1.86 KB
/
sops.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package filecrypt
import (
"github.com/Ibotta/sopstool/fileutil"
"github.com/Ibotta/sopstool/oswrap"
)
type sopsCrypt struct {
execWrap oswrap.ExecWrap
osWrap oswrap.OsWrap
}
var sops = sopsCrypt{
execWrap: oswrap.ExecWrapInstance(),
osWrap: oswrap.Instance(),
}
// SopsCryptInstance gets an instance of the sops wrapper
func SopsCryptInstance() FileCrypt {
return sops
}
// EncryptFile encrypts a file rewriting the sops encrypted file
func (sops sopsCrypt) EncryptFile(fn string) error {
cryptfile := fileutil.NormalizeToSopsFile(fn)
return sops.execWrap.RunCommandStdoutToFile(cryptfile, []string{"sops", "-e", fn})
}
// DecryptFile decrypts a file rewriting the plaintext file
func (sops sopsCrypt) DecryptFile(fn string) error {
cryptfile := fileutil.NormalizeToSopsFile(fn)
return sops.execWrap.RunCommandStdoutToFile(fn, []string{"sops", "-d", cryptfile})
}
// DecryptFilePrint decrypts a file printing the result
func (sops sopsCrypt) DecryptFilePrint(fn string) error {
cryptfile := fileutil.NormalizeToSopsFile(fn)
return sops.execWrap.RunCommandDirect([]string{"sops", "-d", cryptfile})
}
// RemoveFile removes a plaintext file from the filesystem
func (sops sopsCrypt) RemoveFile(fn string) error {
return sops.osWrap.Remove(fn)
}
// RemoveCryptFile removes a sops file from the filesystem
func (sops sopsCrypt) RemoveCryptFile(fn string) error {
cryptfile := fileutil.NormalizeToSopsFile(fn)
return sops.osWrap.Remove(cryptfile)
}
// RotateFile rotates keys on a file
func (sops sopsCrypt) RotateFile(fn string) error {
cryptfile := fileutil.NormalizeToSopsFile(fn)
return sops.execWrap.RunCommandDirect([]string{"sops", "-i", "-r", cryptfile})
}
// EditFile should open the editor for a file
func (sops sopsCrypt) EditFile(fn string) error {
cryptfile := fileutil.NormalizeToSopsFile(fn)
return sops.execWrap.RunCommandDirect([]string{"sops", cryptfile})
}