mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-20 11:55:11 +00:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
73 lines
2.0 KiB
Go
73 lines
2.0 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package transit
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
|
|
"github.com/hashicorp/vault/sdk/framework"
|
|
"github.com/hashicorp/vault/sdk/logical"
|
|
)
|
|
|
|
func (b *backend) pathRestore() *framework.Path {
|
|
return &framework.Path{
|
|
Pattern: "restore" + framework.OptionalParamRegex("name"),
|
|
|
|
DisplayAttrs: &framework.DisplayAttributes{
|
|
OperationPrefix: operationPrefixTransit,
|
|
OperationVerb: "restore",
|
|
OperationSuffix: "key|and-rename-key",
|
|
},
|
|
|
|
Fields: map[string]*framework.FieldSchema{
|
|
"backup": {
|
|
Type: framework.TypeString,
|
|
Description: "Backed up key data to be restored. This should be the output from the 'backup/' endpoint.",
|
|
},
|
|
"name": {
|
|
Type: framework.TypeString,
|
|
Description: "If set, this will be the name of the restored key.",
|
|
},
|
|
"force": {
|
|
Type: framework.TypeBool,
|
|
Description: "If set and a key by the given name exists, force the restore operation and override the key.",
|
|
Default: false,
|
|
},
|
|
},
|
|
|
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
|
logical.UpdateOperation: b.pathRestoreUpdate,
|
|
},
|
|
|
|
HelpSynopsis: pathRestoreHelpSyn,
|
|
HelpDescription: pathRestoreHelpDesc,
|
|
}
|
|
}
|
|
|
|
func (b *backend) pathRestoreUpdate(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
|
backupB64 := d.Get("backup").(string)
|
|
force := d.Get("force").(bool)
|
|
if backupB64 == "" {
|
|
return logical.ErrorResponse("'backup' must be supplied"), nil
|
|
}
|
|
|
|
// If a name is given, make sure it does not contain any slashes. The Transit
|
|
// secret engine does not allow sub-paths in key names
|
|
keyName := d.Get("name").(string)
|
|
if strings.Contains(keyName, "/") {
|
|
return nil, ErrInvalidKeyName
|
|
}
|
|
|
|
return nil, b.lm.RestorePolicy(ctx, req.Storage, keyName, backupB64, force)
|
|
}
|
|
|
|
const (
|
|
pathRestoreHelpSyn = `Restore the named key`
|
|
pathRestoreHelpDesc = `This path is used to restore the named key.`
|
|
)
|
|
|
|
var ErrInvalidKeyName = errors.New("key names cannot be paths")
|