2016-05-02 02:39:45 +00:00
|
|
|
package logical
|
|
|
|
|
2016-08-08 15:55:24 +00:00
|
|
|
import (
|
2016-09-29 19:03:47 +00:00
|
|
|
"time"
|
2016-08-08 15:55:24 +00:00
|
|
|
)
|
2016-06-07 20:01:09 +00:00
|
|
|
|
2016-05-16 20:12:45 +00:00
|
|
|
// This logic was pulled from the http package so that it can be used for
|
2017-10-23 20:42:56 +00:00
|
|
|
// encoding wrapped responses as well. It simply translates the logical
|
|
|
|
// response to an http response, with the values we want and omitting the
|
|
|
|
// values we don't.
|
2016-09-29 19:03:47 +00:00
|
|
|
func LogicalResponseToHTTPResponse(input *Response) *HTTPResponse {
|
|
|
|
httpResp := &HTTPResponse{
|
2016-05-02 02:39:45 +00:00
|
|
|
Data: input.Data,
|
2017-06-05 14:52:43 +00:00
|
|
|
Warnings: input.Warnings,
|
2016-05-02 02:39:45 +00:00
|
|
|
}
|
2016-05-02 04:08:07 +00:00
|
|
|
|
2016-05-02 02:39:45 +00:00
|
|
|
if input.Secret != nil {
|
2016-09-29 19:03:47 +00:00
|
|
|
httpResp.LeaseID = input.Secret.LeaseID
|
|
|
|
httpResp.Renewable = input.Secret.Renewable
|
|
|
|
httpResp.LeaseDuration = int(input.Secret.TTL.Seconds())
|
2016-05-02 02:39:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we have authentication information, then
|
|
|
|
// set up the result structure.
|
|
|
|
if input.Auth != nil {
|
2016-09-29 19:03:47 +00:00
|
|
|
httpResp.Auth = &HTTPAuth{
|
2018-06-14 13:49:33 +00:00
|
|
|
ClientToken: input.Auth.ClientToken,
|
|
|
|
Accessor: input.Auth.Accessor,
|
|
|
|
Policies: input.Auth.Policies,
|
|
|
|
TokenPolicies: input.Auth.TokenPolicies,
|
|
|
|
IdentityPolicies: input.Auth.IdentityPolicies,
|
|
|
|
Metadata: input.Auth.Metadata,
|
|
|
|
LeaseDuration: int(input.Auth.TTL.Seconds()),
|
|
|
|
Renewable: input.Auth.Renewable,
|
|
|
|
EntityID: input.Auth.EntityID,
|
2016-05-02 02:39:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-29 19:03:47 +00:00
|
|
|
return httpResp
|
|
|
|
}
|
|
|
|
|
|
|
|
func HTTPResponseToLogicalResponse(input *HTTPResponse) *Response {
|
|
|
|
logicalResp := &Response{
|
|
|
|
Data: input.Data,
|
2017-06-05 14:52:43 +00:00
|
|
|
Warnings: input.Warnings,
|
2016-09-29 19:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if input.LeaseID != "" {
|
|
|
|
logicalResp.Secret = &Secret{
|
|
|
|
LeaseID: input.LeaseID,
|
|
|
|
}
|
|
|
|
logicalResp.Secret.Renewable = input.Renewable
|
|
|
|
logicalResp.Secret.TTL = time.Second * time.Duration(input.LeaseDuration)
|
|
|
|
}
|
|
|
|
|
|
|
|
if input.Auth != nil {
|
|
|
|
logicalResp.Auth = &Auth{
|
2018-06-14 13:49:33 +00:00
|
|
|
ClientToken: input.Auth.ClientToken,
|
|
|
|
Accessor: input.Auth.Accessor,
|
|
|
|
Policies: input.Auth.Policies,
|
|
|
|
TokenPolicies: input.Auth.TokenPolicies,
|
|
|
|
IdentityPolicies: input.Auth.IdentityPolicies,
|
|
|
|
Metadata: input.Auth.Metadata,
|
|
|
|
EntityID: input.Auth.EntityID,
|
2016-09-29 19:03:47 +00:00
|
|
|
}
|
|
|
|
logicalResp.Auth.Renewable = input.Auth.Renewable
|
|
|
|
logicalResp.Auth.TTL = time.Second * time.Duration(input.Auth.LeaseDuration)
|
|
|
|
}
|
|
|
|
|
2016-05-02 02:39:45 +00:00
|
|
|
return logicalResp
|
|
|
|
}
|
|
|
|
|
|
|
|
type HTTPResponse struct {
|
2016-07-25 20:54:43 +00:00
|
|
|
RequestID string `json:"request_id"`
|
2016-05-02 02:39:45 +00:00
|
|
|
LeaseID string `json:"lease_id"`
|
|
|
|
Renewable bool `json:"renewable"`
|
|
|
|
LeaseDuration int `json:"lease_duration"`
|
|
|
|
Data map[string]interface{} `json:"data"`
|
2016-05-02 04:08:07 +00:00
|
|
|
WrapInfo *HTTPWrapInfo `json:"wrap_info"`
|
2016-05-02 02:39:45 +00:00
|
|
|
Warnings []string `json:"warnings"`
|
|
|
|
Auth *HTTPAuth `json:"auth"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type HTTPAuth struct {
|
2018-06-14 13:49:33 +00:00
|
|
|
ClientToken string `json:"client_token"`
|
|
|
|
Accessor string `json:"accessor"`
|
|
|
|
Policies []string `json:"policies"`
|
|
|
|
TokenPolicies []string `json:"token_policies,omitempty"`
|
|
|
|
IdentityPolicies []string `json:"identity_policies,omitempty"`
|
|
|
|
Metadata map[string]string `json:"metadata"`
|
|
|
|
LeaseDuration int `json:"lease_duration"`
|
|
|
|
Renewable bool `json:"renewable"`
|
|
|
|
EntityID string `json:"entity_id"`
|
2016-05-02 02:39:45 +00:00
|
|
|
}
|
2016-05-02 04:08:07 +00:00
|
|
|
|
|
|
|
type HTTPWrapInfo struct {
|
2016-09-23 16:32:07 +00:00
|
|
|
Token string `json:"token"`
|
2017-11-13 20:31:32 +00:00
|
|
|
Accessor string `json:"accessor"`
|
2016-09-23 16:32:07 +00:00
|
|
|
TTL int `json:"ttl"`
|
|
|
|
CreationTime string `json:"creation_time"`
|
2017-08-02 22:28:58 +00:00
|
|
|
CreationPath string `json:"creation_path"`
|
2016-09-23 16:32:07 +00:00
|
|
|
WrappedAccessor string `json:"wrapped_accessor,omitempty"`
|
2016-05-02 04:08:07 +00:00
|
|
|
}
|