forked from splunk/vault-plugin-splunk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath_reset.go
52 lines (43 loc) · 1.41 KB
/
path_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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package splunk
import (
"context"
"fmt"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
)
// pathResetConnection configures a path to reset a plugin.
func (b *backend) pathResetConnection() *framework.Path {
return &framework.Path{
Pattern: fmt.Sprintf("reset/%s", framework.GenericNameRegex("name")),
Fields: map[string]*framework.FieldSchema{
"name": &framework.FieldSchema{
Type: framework.TypeString,
Description: "Name of this Splunk connection",
},
},
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.UpdateOperation: b.connectionResetHandler,
},
HelpSynopsis: pathResetConnectionHelpSyn,
HelpDescription: pathResetConnectionHelpDesc,
}
}
// connectionResetHandler resets a connection by clearing the existing instance
func (b *backend) connectionResetHandler(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
name := data.Get("name").(string)
config, err := connectionConfigLoad(ctx, req.Storage, name)
if err != nil {
return nil, err
}
if err := b.clearConnection(config.ID); err != nil {
return nil, err
}
return nil, nil
}
const pathResetConnectionHelpSyn = `
Resets a Splunk connection.
`
const pathResetConnectionHelpDesc = `
This path resets the Splunk connection by closing the existing
connection. Upon further access, new connections are established.
`