forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
secret_otp.go
43 lines (37 loc) · 1019 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
package ssh
import (
"fmt"
"time"
"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",
},
},
DefaultDuration: 0, // this will use sysview's value
DefaultGracePeriod: 2 * time.Minute,
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")
}
err := req.Storage.Delete("otp/" + b.salt.SaltID(otp))
if err != nil {
return nil, err
}
return nil, nil
}