-
Notifications
You must be signed in to change notification settings - Fork 12
/
autounseal.go
36 lines (31 loc) · 928 Bytes
/
autounseal.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
Copyright (C) 2021-2023, Kubefirst
This program is licensed under MIT.
See the LICENSE file for more details.
*/
package vault
import (
vaultapi "github.com/hashicorp/vault/api"
"github.com/rs/zerolog/log"
)
func (conf *VaultConfiguration) AutoUnseal() (*vaultapi.InitResponse, error) {
vaultClient, err := vaultapi.NewClient(&conf.Config)
if err != nil {
return &vaultapi.InitResponse{}, err
}
vaultClient.CloneConfig().ConfigureTLS(&vaultapi.TLSConfig{
Insecure: true,
})
log.Info().Msg("created vault client, initializing vault with auto unseal")
initResponse, err := vaultClient.Sys().Init(&vaultapi.InitRequest{
RecoveryShares: RecoveryShares,
RecoveryThreshold: RecoveryThreshold,
SecretShares: SecretShares,
SecretThreshold: SecretThreshold,
})
if err != nil {
return &vaultapi.InitResponse{}, err
}
log.Info().Msg("vault initialization complete")
return initResponse, nil
}