forked from splunk/vault-plugin-splunk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollback.go
42 lines (35 loc) · 916 Bytes
/
rollback.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
37
38
39
40
41
42
package splunk
import (
"context"
"fmt"
"time"
"github.com/hashicorp/vault/logical"
"github.com/mitchellh/mapstructure"
)
const (
walTypeConn = "connection"
walRollbackMinAge = 5 * time.Minute
)
type walConnection struct {
ID string
}
func (b *backend) walRollback(ctx context.Context, req *logical.Request, kind string, data interface{}) error {
switch kind {
case walTypeConn:
return b.connectionRollback(ctx, req, data)
default:
return fmt.Errorf("unknown type to rollback")
}
}
func (b *backend) connectionRollback(ctx context.Context, req *logical.Request, data interface{}) error {
var entry walConnection
if err := mapstructure.Decode(data, &entry); err != nil {
return err
}
// remove old connection from cache
if err := b.clearConnection(entry.ID); err != nil {
// log and ignore errors
b.Logger().Warn("error while clearing connection", "err", err)
}
return nil
}