2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2016-09-21 14:29:42 +00:00
|
|
|
package transit
|
|
|
|
|
|
|
|
import (
|
2018-01-08 18:31:38 +00:00
|
|
|
"context"
|
2022-05-03 14:07:23 +00:00
|
|
|
|
2022-05-02 19:42:07 +00:00
|
|
|
"github.com/hashicorp/vault/helper/random"
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/framework"
|
2019-04-13 07:44:06 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2016-09-21 14:29:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (b *backend) pathRandom() *framework.Path {
|
|
|
|
return &framework.Path{
|
2022-05-02 19:42:07 +00:00
|
|
|
Pattern: "random(/" + framework.GenericNameRegex("source") + ")?" + framework.OptionalParamRegex("urlbytes"),
|
2023-04-10 18:20:53 +00:00
|
|
|
|
|
|
|
DisplayAttrs: &framework.DisplayAttributes{
|
|
|
|
OperationPrefix: operationPrefixTransit,
|
|
|
|
OperationVerb: "generate",
|
|
|
|
OperationSuffix: "random|random-with-source|random-with-bytes|random-with-source-and-bytes",
|
|
|
|
},
|
|
|
|
|
2016-09-21 14:29:42 +00:00
|
|
|
Fields: map[string]*framework.FieldSchema{
|
2021-04-08 16:43:39 +00:00
|
|
|
"urlbytes": {
|
2016-09-21 14:29:42 +00:00
|
|
|
Type: framework.TypeString,
|
|
|
|
Description: "The number of bytes to generate (POST URL parameter)",
|
|
|
|
},
|
|
|
|
|
2021-04-08 16:43:39 +00:00
|
|
|
"bytes": {
|
2016-09-21 14:29:42 +00:00
|
|
|
Type: framework.TypeInt,
|
|
|
|
Default: 32,
|
|
|
|
Description: "The number of bytes to generate (POST body parameter). Defaults to 32 (256 bits).",
|
|
|
|
},
|
|
|
|
|
2021-04-08 16:43:39 +00:00
|
|
|
"format": {
|
2016-09-21 14:29:42 +00:00
|
|
|
Type: framework.TypeString,
|
|
|
|
Default: "base64",
|
|
|
|
Description: `Encoding format to use. Can be "hex" or "base64". Defaults to "base64".`,
|
|
|
|
},
|
2022-05-02 19:42:07 +00:00
|
|
|
|
|
|
|
"source": {
|
|
|
|
Type: framework.TypeString,
|
|
|
|
Default: "platform",
|
|
|
|
Description: `Which system to source random data from, ether "platform", "seal", or "all".`,
|
|
|
|
},
|
2016-09-21 14:29:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
|
|
|
logical.UpdateOperation: b.pathRandomWrite,
|
|
|
|
},
|
|
|
|
|
|
|
|
HelpSynopsis: pathRandomHelpSyn,
|
|
|
|
HelpDescription: pathRandomHelpDesc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-02 19:42:07 +00:00
|
|
|
func (b *backend) pathRandomWrite(_ context.Context, _ *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
|
|
|
return random.HandleRandomAPI(d, b.GetRandomReader())
|
2016-09-21 14:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const pathRandomHelpSyn = `Generate random bytes`
|
|
|
|
|
|
|
|
const pathRandomHelpDesc = `
|
|
|
|
This function can be used to generate high-entropy random bytes.
|
|
|
|
`
|