open-vault/builtin/credential/userpass/path_user_password.go

50 lines
1.2 KiB
Go
Raw Normal View History

package userpass
import (
"fmt"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
)
func pathUserPassword(b *backend) *framework.Path {
return &framework.Path{
Pattern: "users/" + framework.GenericNameRegex("name") + "/password$",
Fields: map[string]*framework.FieldSchema{
"name": &framework.FieldSchema{
Type: framework.TypeString,
Description: "Username for this user.",
},
"password": &framework.FieldSchema{
Type: framework.TypeString,
Description: "Password for this user.",
},
},
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.UpdateOperation: b.pathUserPasswordUpdate,
},
HelpSynopsis: pathUserPasswordHelpSyn,
HelpDescription: pathUserPasswordHelpDesc,
}
}
func (b *backend) pathUserPasswordUpdate(
req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
password := d.Get("password").(string)
if password == "" {
return nil, fmt.Errorf("missing password")
}
return b.userCreateUpdate(req, d)
}
const pathUserPasswordHelpSyn = `
Reset user's password.
`
const pathUserPasswordHelpDesc = `
This endpoint allows resetting the user's password.
`