2015-03-15 20:52:43 +00:00
|
|
|
package logical
|
|
|
|
|
|
|
|
// Response is a struct that stores the response of a request.
|
|
|
|
// It is used to abstract the details of the higher level request protocol.
|
|
|
|
type Response struct {
|
2015-03-19 22:11:42 +00:00
|
|
|
// Secret, if not nil, denotes that this response represents a secret.
|
|
|
|
Secret *Secret
|
2015-03-15 20:52:43 +00:00
|
|
|
|
2015-03-30 21:23:32 +00:00
|
|
|
// Auth, if not nil, contains the authentication information for
|
|
|
|
// this response. This is only checked and means something for
|
|
|
|
// credential backends.
|
|
|
|
Auth *Auth
|
|
|
|
|
2015-03-19 22:11:42 +00:00
|
|
|
// Response data is an opaque map that must have string keys. For
|
|
|
|
// secrets, this data is sent down to the user as-is. To store internal
|
|
|
|
// data that you don't want the user to see, store it in
|
|
|
|
// Secret.InternalData.
|
2015-03-15 20:52:43 +00:00
|
|
|
Data map[string]interface{}
|
2015-03-31 00:56:24 +00:00
|
|
|
|
|
|
|
// Redirect is an HTTP URL to redirect to for further authentication.
|
|
|
|
// This is only valid for credential backends. This will be blanked
|
|
|
|
// for any logical backend and ignored.
|
|
|
|
Redirect string
|
2015-03-15 20:52:43 +00:00
|
|
|
}
|
|
|
|
|
2015-03-20 16:59:48 +00:00
|
|
|
// IsError returns true if this response seems to indicate an error.
|
|
|
|
func (r *Response) IsError() bool {
|
|
|
|
return r != nil && len(r.Data) == 1 && r.Data["error"] != nil
|
2015-03-15 20:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// HelpResponse is used to format a help response
|
|
|
|
func HelpResponse(text string, seeAlso []string) *Response {
|
|
|
|
return &Response{
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"help": text,
|
|
|
|
"see_also": seeAlso,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrorResponse is used to format an error response
|
|
|
|
func ErrorResponse(text string) *Response {
|
|
|
|
return &Response{
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"error": text,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2015-03-15 21:26:48 +00:00
|
|
|
|
|
|
|
// ListResponse is used to format a response to a list operation.
|
|
|
|
func ListResponse(keys []string) *Response {
|
|
|
|
return &Response{
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"keys": keys,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|