mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-12-25 16:35:42 +00:00
Merge pull request #666 from jcgruenhage/ansible-genkeys-progress-bar
add a progress bar to the ansible key generator
This commit is contained in:
commit
e7228c7ae4
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user