2022-10-08 19:23:53 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import(
|
|
|
|
"fmt"
|
2023-04-09 10:54:58 +00:00
|
|
|
"unseal-vault/internal/vault"
|
|
|
|
"unseal-vault/internal/consul"
|
2022-10-08 19:23:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var key string
|
2023-04-09 10:54:58 +00:00
|
|
|
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)
|
2023-04-09 10:54:58 +00:00
|
|
|
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)
|
|
|
|
}
|
2023-04-09 10:54:58 +00:00
|
|
|
if vaultClient.Vaultunseal(key){
|
2022-10-08 19:23:53 +00:00
|
|
|
fmt.Println("unseal success")
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
fmt.Println(url + " not sealed")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|