open-vault/builtin/logical/ssh/path_fetch.go

42 lines
1.0 KiB
Go
Raw Normal View History

2016-12-26 14:03:27 +00:00
package ssh
import (
"context"
2016-12-26 14:03:27 +00:00
"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)
2016-12-26 14:03:27 +00:00
if err != nil {
return nil, err
}
if publicKeyEntry == nil || publicKeyEntry.Key == "" {
return nil, nil
}
2016-12-26 14:03:27 +00:00
response := &logical.Response{
Data: map[string]interface{}{
logical.HTTPContentType: "text/plain",
logical.HTTPRawBody: []byte(publicKeyEntry.Key),
2016-12-26 14:03:27 +00:00
logical.HTTPStatusCode: 200,
},
}
2016-12-26 14:03:27 +00:00
return response, nil
}