open-vault/builtin/logical/ssh/secret_otp.go
Brian Kassouf 303c2aee7c
Run a more strict formatter over the code (#11312)
* Update tooling

* Run gofumpt

* go mod vendor
2021-04-08 09:43:39 -07:00

47 lines
977 B
Go

package ssh
import (
"context"
"fmt"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/logical"
)
const SecretOTPType = "secret_otp_type"
func secretOTP(b *backend) *framework.Secret {
return &framework.Secret{
Type: SecretOTPType,
Fields: map[string]*framework.FieldSchema{
"otp": {
Type: framework.TypeString,
Description: "One time password",
},
},
Revoke: b.secretOTPRevoke,
}
}
func (b *backend) secretOTPRevoke(ctx context.Context, 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(ctx)
if err != nil {
return nil, err
}
err = req.Storage.Delete(ctx, "otp/"+salt.SaltID(otp))
if err != nil {
return nil, err
}
return nil, nil
}