forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 1
/
secret_otp.go
45 lines (38 loc) · 961 Bytes
/
secret_otp.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
package ssh
import (
"fmt"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
)
const SecretOTPType = "secret_otp_type"
func secretOTP(b *backend) *framework.Secret {
return &framework.Secret{
Type: SecretOTPType,
Fields: map[string]*framework.FieldSchema{
"otp": &framework.FieldSchema{
Type: framework.TypeString,
Description: "One time password",
},
},
Revoke: b.secretOTPRevoke,
}
}
func (b *backend) secretOTPRevoke(req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
otpRaw, ok := req.Secret.InternalData["otp"]
if !ok {
return nil, fmt.Errorf("secret is missing internal data")
}
otp, ok := otpRaw.(string)
if !ok {
return nil, fmt.Errorf("secret is missing internal data")
}
salt, err := b.Salt()
if err != nil {
return nil, err
}
err = req.Storage.Delete("otp/" + salt.SaltID(otp))
if err != nil {
return nil, err
}
return nil, nil
}