forked from laincloud/lvault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset.go
31 lines (28 loc) · 763 Bytes
/
reset.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
package main
import (
"net/http"
"github.com/hashicorp/vault/api"
"github.com/mijia/sweb/form"
"github.com/mijia/sweb/log"
"golang.org/x/net/context"
)
func (l *Lvault) settokenkeys(ctx context.Context, w http.ResponseWriter, req *http.Request) context.Context {
initResponse := api.InitResponse{}
if err := form.ParamBodyJson(req, &initResponse); err != nil {
log.Error(err)
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(err.Error()))
} else {
if l.GetMissToken() {
if l.Vault.CheckRootToken(initResponse.RootToken) {
l.SetMissToken(false)
l.RootToken = initResponse.RootToken
} else {
log.Debug("invalid root token")
l.RootToken = initResponse.RootToken
}
}
l.UnsealKey = initResponse.Keys
}
return ctx
}