open-vault/builtin/logical/ssh/path_fetch.go
Vishal Nayak 766c2e6ee0 SSH CA enhancements (#2442)
* Use constants for storage paths

* Upgrade path for public key storage

* Fix calculateValidPrincipals, upgrade ca_private_key, and other changes

* Remove a print statement

* Added tests for upgrade case

* Make exporting consistent in creation bundle

* unexporting and constants

* Move keys into a struct instead of plain string

* minor changes
2017-03-08 17:36:21 -05:00

40 lines
1,007 B
Go

package ssh
import (
"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(req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
publicKeyEntry, err := caKey(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
}