package api

import "github.com/cloudflare/cfssl/api"

Package api implements an HTTP-based API and server for CFSSL.

Index

Functions

func HandleError

func HandleError(w http.ResponseWriter, err error) (code int)

HandleError is the centralised error handling and reporting.

func ProcessRequestFirstMatchOf

func ProcessRequestFirstMatchOf(r *http.Request, keywordSets [][]string) (map[string]string, []string, error)

ProcessRequestFirstMatchOf reads a JSON blob for the request and returns the first match of a set of keywords. For example, a request might have one of the following combinations: (foo=1, bar=2), (foo=1), and (bar=2) By giving a specific ordering of those combinations, we could decide how to accept the request.

func ProcessRequestOneOf

func ProcessRequestOneOf(r *http.Request, keywordSets [][]string) (map[string]string, []string, error)

ProcessRequestOneOf reads a JSON blob for the request and makes sure it contains one of a set of keywords. For example, a request might have the ('foo' && 'bar') keys, OR it might have the 'baz' key. In either case, we want to accept the request; however, if none of these sets shows up, the request is a bad request, and it should be returned.

func SendResponse

func SendResponse(w http.ResponseWriter, result interface{}) error

SendResponse builds a response from the result, sets the JSON header, and writes to the http.ResponseWriter.

func SendResponseWithMessage

func SendResponseWithMessage(w http.ResponseWriter, result interface{}, message string, code int) error

SendResponseWithMessage builds a response from the result and the provided message, sets the JSON header, and writes to the http.ResponseWriter.

Types

type HTTPHandler

type HTTPHandler struct {
	Handler          // CFSSL handler
	Methods []string // The associated HTTP methods
}

HTTPHandler is a wrapper that encapsulates Handler interface as http.Handler. HTTPHandler also enforces that the Handler only responds to requests with registered HTTP methods.

func (HTTPHandler) ServeHTTP

func (h HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP encapsulates the call to underlying Handler to handle the request and return the response with proper HTTP status code

type Handler

type Handler interface {
	Handle(w http.ResponseWriter, r *http.Request) error
}

Handler is an interface providing a generic mechanism for handling HTTP requests.

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *http.Request) error

HandlerFunc is similar to the http.HandlerFunc type; it serves as an adapter allowing the use of ordinary functions as Handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler object that calls f.

func (HandlerFunc) Handle

func (f HandlerFunc) Handle(w http.ResponseWriter, r *http.Request) error

Handle calls f(w, r)

type Response

type Response struct {
	Success  bool              `json:"success"`
	Result   interface{}       `json:"result"`
	Errors   []ResponseMessage `json:"errors"`
	Messages []ResponseMessage `json:"messages"`
}

Response implements the CloudFlare standard for API responses.

func NewErrorResponse

func NewErrorResponse(message string, code int) Response

NewErrorResponse is a shortcut for creating an error response for a single error.

func NewSuccessResponse

func NewSuccessResponse(result interface{}) Response

NewSuccessResponse is a shortcut for creating new successful API responses.

func NewSuccessResponseWithMessage

func NewSuccessResponseWithMessage(result interface{}, message string, code int) Response

NewSuccessResponseWithMessage is a shortcut for creating new successul API responses that includes a message.

type ResponseMessage

type ResponseMessage struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

ResponseMessage implements the standard for response errors and messages. A message has a code and a string message.

Source Files

api.go

Directories

PathSynopsis
api/bundlePackage bundle implements the HTTP handler for the bundle command.
api/certadd
api/certinfoPackage certinfo implements the HTTP handler for the certinfo command.
api/clientPackage client implements a Go client for CFSSL API commands.
api/crlPackage crl implements the HTTP handler for the crl command.
api/gencrlPackage gencrl implements the HTTP handler for the gencrl commands.
api/generatorPackage generator implements the HTTP handlers for certificate generation.
api/health
api/infoPackage info implements the HTTP handler for the info command.
api/initcaPackage initca implements the HTTP handler for the CA initialization command
api/ocspPackage ocsp implements the HTTP handler for the ocsp commands.
api/revokePackage revoke implements the HTTP handler for the revoke command
api/scan
api/signPackage sign implements the HTTP handler for the certificate signing command.
api/signhandlerPackage signhandler provides the handlers for signers.
Version
v1.6.5 (latest)
Published
Mar 5, 2024
Platform
linux/amd64
Imports
5 packages
Last checked
6 days ago

Tools for package owners.