2023-03-15 16:00:52 +00:00
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
2016-12-26 14:03:27 +00:00
package ssh
import (
2018-01-08 18:31:38 +00:00
"context"
2019-04-12 21:54:35 +00:00
"github.com/hashicorp/vault/sdk/framework"
2019-04-13 07:44:06 +00:00
"github.com/hashicorp/vault/sdk/logical"
2016-12-26 14:03:27 +00:00
)
func pathFetchPublicKey ( b * backend ) * framework . Path {
return & framework . Path {
Pattern : ` public_key ` ,
2023-04-10 18:18:00 +00:00
DisplayAttrs : & framework . DisplayAttributes {
OperationPrefix : operationPrefixSSH ,
OperationSuffix : "public-key" ,
} ,
2016-12-26 14:03:27 +00:00
Callbacks : map [ logical . Operation ] framework . OperationFunc {
logical . ReadOperation : b . pathFetchPublicKey ,
} ,
HelpSynopsis : ` Retrieve the public key. ` ,
2023-01-31 21:02:22 +00:00
HelpDescription : ` This allows the public key of the SSH CA certificate that this backend has been configured with to be fetched. This is a raw response endpoint without JSON encoding; use -format=raw or an external tool (e.g., curl) to fetch this value. ` ,
2016-12-26 14:03:27 +00:00
}
}
2018-01-08 18:31:38 +00:00
func ( b * backend ) pathFetchPublicKey ( ctx context . Context , req * logical . Request , data * framework . FieldData ) ( * logical . Response , error ) {
2018-01-19 06:44:44 +00:00
publicKeyEntry , err := caKey ( ctx , req . Storage , caPublicKey )
2016-12-26 14:03:27 +00:00
if err != nil {
return nil , err
}
2017-03-08 22:36:21 +00:00
if publicKeyEntry == nil || publicKeyEntry . Key == "" {
2017-03-01 20:50:23 +00:00
return nil , nil
}
2016-12-26 14:03:27 +00:00
response := & logical . Response {
Data : map [ string ] interface { } {
logical . HTTPContentType : "text/plain" ,
2017-03-08 22:36:21 +00:00
logical . HTTPRawBody : [ ] byte ( publicKeyEntry . Key ) ,
2016-12-26 14:03:27 +00:00
logical . HTTPStatusCode : 200 ,
2017-03-01 20:50:23 +00:00
} ,
}
2016-12-26 14:03:27 +00:00
return response , nil
}