forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
path_fetch.go
41 lines (33 loc) · 1.02 KB
/
path_fetch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package ssh
import (
"context"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
)
func pathFetchPublicKey(b *backend) *framework.Path {
return &framework.Path{
Pattern: `public_key`,
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.ReadOperation: b.pathFetchPublicKey,
},
HelpSynopsis: `Retrieve the public key.`,
HelpDescription: `This allows the public key, that this backend has been configured with, to be fetched.`,
}
}
func (b *backend) pathFetchPublicKey(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
publicKeyEntry, err := caKey(ctx, req.Storage, caPublicKey)
if err != nil {
return nil, err
}
if publicKeyEntry == nil || publicKeyEntry.Key == "" {
return nil, nil
}
response := &logical.Response{
Data: map[string]interface{}{
logical.HTTPContentType: "text/plain",
logical.HTTPRawBody: []byte(publicKeyEntry.Key),
logical.HTTPStatusCode: 200,
},
}
return response, nil
}