5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-21 21:50:29 +00:00

add a progress bar to the ansible key generator

This commit is contained in:
Jan Christian Grünhage 2020-03-23 23:26:41 +01:00
parent ea7e074cf0
commit 30bfa04c47

View File

@ -14,6 +14,7 @@ import (
"github.com/yggdrasil-network/yggdrasil-go/src/address"
"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
"github.com/cheggaaa/pb/v3"
)
var numHosts = flag.Int("hosts", 1, "number of host vars to generate")
@ -29,6 +30,8 @@ type keySet struct {
func main() {
flag.Parse()
bar := pb.StartNew(*keyTries * 2 + *numHosts)
if *numHosts > *keyTries {
println("Can't generate less keys than hosts.")
return
@ -37,21 +40,25 @@ func main() {
var encryptionKeys []keySet
for i := 0; i < *numHosts+1; i++ {
encryptionKeys = append(encryptionKeys, newBoxKey())
bar.Increment()
}
encryptionKeys = sortKeySetArray(encryptionKeys)
for i := 0; i < *keyTries-*numHosts-1; i++ {
encryptionKeys[0] = newBoxKey()
encryptionKeys = bubbleUpTo(encryptionKeys, 0)
bar.Increment()
}
var signatureKeys []keySet
for i := 0; i < *numHosts+1; i++ {
signatureKeys = append(signatureKeys, newSigKey())
bar.Increment()
}
signatureKeys = sortKeySetArray(signatureKeys)
for i := 0; i < *keyTries-*numHosts-1; i++ {
signatureKeys[0] = newSigKey()
signatureKeys = bubbleUpTo(signatureKeys, 0)
bar.Increment()
}
os.MkdirAll("host_vars", 0755)
@ -76,7 +83,9 @@ func main() {
defer file.Close()
file.WriteString(fmt.Sprintf("vault_yggdrasil_encryption_private_key: %v\n", hex.EncodeToString(encryptionKeys[i].priv)))
file.WriteString(fmt.Sprintf("vault_yggdrasil_signing_private_key: %v\n", hex.EncodeToString(signatureKeys[i].priv)))
bar.Increment()
}
bar.Finish()
}
func newBoxKey() keySet {