Merge pull request #666 from jcgruenhage/ansible-genkeys-progress-bar

add a progress bar to the ansible key generator
This commit is contained in:
Neil Alexander 2020-03-25 20:55:15 +00:00 committed by GitHub
commit e7228c7ae4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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