Documentation ¶
Index ¶
- func BadRequest(err error) error
- func Forbidden(err error) error
- func InternalServerError(err error) error
- func JSON(w http.ResponseWriter, v interface{})
- func LogError(rw http.ResponseWriter, err error)
- func NewError(status int, err error) error
- func NotFound(err error) error
- func ReadJSON(r io.Reader, v interface{}) error
- func Unauthorized(err error) error
- func WriteError(w http.ResponseWriter, err error)
- type Authority
- type Certificate
- type CertificateRequest
- type Error
- type ErrorResponse
- type HealthResponse
- type ProvisionerKeyResponse
- type ProvisionersResponse
- type RootResponse
- type Router
- type RouterHandler
- type SignRequest
- type SignResponse
- type StackTracer
- type StatusCoder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BadRequest ¶
BadRequest returns an 400 error with the given error.
func InternalServerError ¶
InternalServerError returns a 500 error with the given error.
func JSON ¶
func JSON(w http.ResponseWriter, v interface{})
JSON writes the passed value into the http.ResponseWriter.
func LogError ¶
func LogError(rw http.ResponseWriter, err error)
LogError adds to the response writer the given error if it implements logging.ResponseLogger. If it does not implement it, then writes the error using the log package.
func NewError ¶
NewError returns a new Error. If the given error implements the StatusCoder interface we will ignore the given status.
func Unauthorized ¶
Unauthorized returns an 401 error with the given error.
func WriteError ¶
func WriteError(w http.ResponseWriter, err error)
WriteError writes to w a JSON representation of the given error.
Types ¶
type Authority ¶
type Authority interface { Authorize(ott string) ([]interface{}, error) GetTLSOptions() *tlsutil.TLSOptions Root(shasum string) (*x509.Certificate, error) Sign(cr *x509.CertificateRequest, signOpts authority.SignOptions, extraOpts ...interface{}) (*x509.Certificate, *x509.Certificate, error) Renew(cert *x509.Certificate) (*x509.Certificate, *x509.Certificate, error) GetProvisioners(cursor string, limit int) ([]*authority.Provisioner, string, error) GetEncryptedKey(kid string) (string, error) }
Authority is the interface implemented by a CA authority.
type Certificate ¶
type Certificate struct {
*x509.Certificate
}
Certificate wraps a *x509.Certificate and adds the json.Marshaler interface.
func NewCertificate ¶
func NewCertificate(cr *x509.Certificate) Certificate
NewCertificate is a helper method that returns a Certificate from a *x509.Certificate.
func (Certificate) MarshalJSON ¶
func (c Certificate) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface. The certificate is quoted string using the PEM encoding.
func (*Certificate) UnmarshalJSON ¶
func (c *Certificate) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface. The certificate is expected to be a quoted string using the PEM encoding.
type CertificateRequest ¶
type CertificateRequest struct {
*x509.CertificateRequest
}
CertificateRequest wraps a *x509.CertificateRequest and adds the json.Unmarshaler interface.
func NewCertificateRequest ¶
func NewCertificateRequest(cr *x509.CertificateRequest) CertificateRequest
NewCertificateRequest is a helper method that returns a CertificateRequest from a *x509.CertificateRequest.
func (CertificateRequest) MarshalJSON ¶
func (c CertificateRequest) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface. The certificate request is a quoted string using the PEM encoding.
func (*CertificateRequest) UnmarshalJSON ¶
func (c *CertificateRequest) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface. The certificate request is expected to be a quoted string using the PEM encoding.
type Error ¶
Error represents the CA API errors.
func (*Error) MarshalJSON ¶
MarshalJSON implements json.Marshaller interface for the Error struct.
func (*Error) StatusCode ¶
StatusCode implements the StatusCoder interface and returns the HTTP response code.
func (*Error) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler interface for the Error struct.
type ErrorResponse ¶
ErrorResponse represents an error in JSON format.
type HealthResponse ¶
type HealthResponse struct {
Status string `json:"status"`
}
HealthResponse is the response object that returns the health of the server.
type ProvisionerKeyResponse ¶
type ProvisionerKeyResponse struct {
Key string `json:"key"`
}
ProvisionerKeyResponse is the response object that returns the encryptoed key of a provisioner.
type ProvisionersResponse ¶
type ProvisionersResponse struct { Provisioners []*authority.Provisioner `json:"provisioners"` NextCursor string `json:"nextCursor"` }
ProvisionersResponse is the response object that returns the list of provisioners.
type RootResponse ¶
type RootResponse struct {
RootPEM Certificate `json:"ca"`
}
RootResponse is the response object that returns the PEM of a root certificate.
type Router ¶
type Router interface { // MethodFunc adds routes for `pattern` that matches // the `method` HTTP method. MethodFunc(method, pattern string, h http.HandlerFunc) }
Router defines a common router interface.
type RouterHandler ¶
type RouterHandler interface {
Route(r Router)
}
RouterHandler is the interface that a HTTP handler that manages multiple endpoints will implement.
func New ¶
func New(authority Authority) RouterHandler
New creates a new RouterHandler with the CA endpoints.
type SignRequest ¶
type SignRequest struct { CsrPEM CertificateRequest `json:"csr"` OTT string `json:"ott"` NotAfter time.Time `json:"notAfter"` NotBefore time.Time `json:"notBefore"` }
SignRequest is the request body for a certificate signature request.
func (*SignRequest) Validate ¶
func (s *SignRequest) Validate() error
Validate checks the fields of the SignRequest and returns nil if they are ok or an error if something is wrong.
type SignResponse ¶
type SignResponse struct { ServerPEM Certificate `json:"crt"` CaPEM Certificate `json:"ca"` TLSOptions *tlsutil.TLSOptions `json:"tlsOptions,omitempty"` TLS *tls.ConnectionState `json:"-"` }
SignResponse is the response object of the certificate signature request.
type StackTracer ¶
type StackTracer interface {
StackTrace() errors.StackTrace
}
StackTracer must be by those errors that return an stack trace.
type StatusCoder ¶
type StatusCoder interface {
StatusCode() int
}
StatusCoder interface is used by errors that returns the HTTP response code.