-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsopsget.go
57 lines (43 loc) · 1.47 KB
/
sopsget.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
package main
import (
"flag"
"fmt"
)
const DefaultPath string = ".sops.yaml"
var debugEnabled bool
func main() {
flag.BoolVar(&debugEnabled, "v", false, "enable verbose logging")
flag.Parse()
debug("logging on debug level enabled")
filePath := DefaultPath
if len(flag.Args()) < 1 {
fmt.Println("Using default filepath: ", filePath)
} else {
filePath = flag.Arg(0)
fmt.Println("Using specified filepath: ", filePath)
}
// read fingerprints from file
if _, err := checkIfValidFile(filePath); err != nil {
exitGracefully(err)
}
fileFingerprints := filterFingerprintsFromFile(filePath)
log(fmt.Sprintf("fingerprints from file: %d", len(fileFingerprints)))
// query gpg
gpgFingerprints := getLocalFingerprints()
log(fmt.Sprintf("fingerprints from gpg: %d", len(gpgFingerprints)))
missingFingerprints := detectUnknownFingerprints(fileFingerprints, gpgFingerprints)
log(fmt.Sprintf("missing fingerprints: %d", len(missingFingerprints)))
log("Starting to import missing keys...")
for i := 0; i < len(missingFingerprints); i++ {
currentFp := missingFingerprints[i]
content := fetchFingerprint(currentFp)
createPublicKeyFile(currentFp, content)
importKey(currentFp)
removeFile(currentFp)
debug(fmt.Sprintf("Imported key %s.", currentFp))
}
// check again
gpgFingerprints = getLocalFingerprints()
missingFingerprints = detectUnknownFingerprints(fileFingerprints, gpgFingerprints)
log(fmt.Sprintf("missing fingerprints: %d", len(missingFingerprints)))
}