From 30bfa04c477c6ffc18cb297c20a298f7957cf5ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Christian=20Gr=C3=BCnhage?= Date: Mon, 23 Mar 2020 23:26:41 +0100 Subject: [PATCH] add a progress bar to the ansible key generator --- contrib/ansible/genkeys.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contrib/ansible/genkeys.go b/contrib/ansible/genkeys.go index 5213e8b8..1d7c222d 100644 --- a/contrib/ansible/genkeys.go +++ b/contrib/ansible/genkeys.go @@ -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 {