unseal-vault/cmd/main.go

32 lines
713 B
Go
Raw Permalink Normal View History

2022-10-08 19:23:53 +00:00
package main
import(
"fmt"
"unseal-vault/internal/vault"
"unseal-vault/internal/consul"
2022-10-08 19:23:53 +00:00
)
func main() {
var key string
consulClient := consul.CreateConsul("consul.service.consul:8500")
services:=consulClient.SearchService("vault")
2022-10-08 19:23:53 +00:00
for _, element :=range services {
url:=fmt.Sprint("http://",element.ServiceAddress, ":", element.ServicePort)
vaultClient:=vault.CreateVault(url)
if vaultClient.Vaultisseal(){
2022-10-08 19:23:53 +00:00
fmt.Println(url + "is sealed")
if key == "" {
fmt.Print("enter your key: ")
fmt.Scan(&key)
}
if vaultClient.Vaultunseal(key){
2022-10-08 19:23:53 +00:00
fmt.Println("unseal success")
}
}else{
fmt.Println(url + " not sealed")
}
}
}