open-vault/builtin/logical/ssh/secret_otp.go

50 lines
1 KiB
Go
Raw Normal View History

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
2015-07-22 18:15:19 +00:00
package ssh
import (
"context"
2015-07-22 18:15:19 +00:00
"fmt"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/logical"
2015-07-22 18:15:19 +00:00
)
const SecretOTPType = "secret_otp_type"
func secretOTP(b *backend) *framework.Secret {
return &framework.Secret{
Type: SecretOTPType,
Fields: map[string]*framework.FieldSchema{
"otp": {
2015-07-22 18:15:19 +00:00
Type: framework.TypeString,
Description: "One time password",
},
},
Revoke: b.secretOTPRevoke,
2015-07-22 18:15:19 +00:00
}
}
func (b *backend) secretOTPRevoke(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
2015-07-22 18:15:19 +00:00
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))
2015-07-22 18:15:19 +00:00
if err != nil {
return nil, err
}
return nil, nil
}