mirror of
https://github.com/hashicorp/vault.git
synced 2026-02-18 18:38:08 -05:00
* VAULT-41675: Transit observations, key management (#12100) * start transit implementation * all observations and tests * add comments * cleanup * Fix broken build (#12384) --------- Co-authored-by: miagilepner <mia.epner@hashicorp.com> Co-authored-by: Nick Cabatoff <ncabatoff@hashicorp.com>
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
// Copyright IBM Corp. 2016, 2025
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package transit
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hashicorp/vault/sdk/framework"
|
|
"github.com/hashicorp/vault/sdk/logical"
|
|
)
|
|
|
|
func (b *backend) pathBackup() *framework.Path {
|
|
return &framework.Path{
|
|
Pattern: "backup/" + framework.GenericNameRegex("name"),
|
|
|
|
DisplayAttrs: &framework.DisplayAttributes{
|
|
OperationPrefix: operationPrefixTransit,
|
|
OperationVerb: "back-up",
|
|
OperationSuffix: "key",
|
|
},
|
|
|
|
Fields: map[string]*framework.FieldSchema{
|
|
"name": {
|
|
Type: framework.TypeString,
|
|
Description: "Name of the key",
|
|
},
|
|
},
|
|
|
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
|
logical.ReadOperation: b.pathBackupRead,
|
|
},
|
|
|
|
HelpSynopsis: pathBackupHelpSyn,
|
|
HelpDescription: pathBackupHelpDesc,
|
|
}
|
|
}
|
|
|
|
func (b *backend) pathBackupRead(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
|
name := d.Get("name").(string)
|
|
backup, err := b.lm.BackupPolicy(ctx, req.Storage, name)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
b.TryRecordObservationWithRequest(ctx, req, ObservationTypeTransitKeyBackup, map[string]interface{}{
|
|
"key_name": name,
|
|
})
|
|
return &logical.Response{
|
|
Data: map[string]interface{}{
|
|
"backup": backup,
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
const (
|
|
pathBackupHelpSyn = `Backup the named key`
|
|
pathBackupHelpDesc = `This path is used to backup the named key.`
|
|
)
|