Documentation ¶
Overview ¶
Package heroku provides a Heroku Platform API compatible http.Handler implementation for Empire.
Index ¶
- Constants
- Variables
- func Decode(r *http.Request, v interface{}) error
- func DecodeRequest(r *http.Request, v interface{}, ignoreEOF bool) error
- func Encode(w http.ResponseWriter, v interface{}) error
- func Error(w http.ResponseWriter, err error, status int) error
- func NoContent(w http.ResponseWriter) error
- func RangeHeader(r *http.Request) (headerutil.Range, error)
- func SAMLUnauthorized(loginURL string) func(error) *ErrorResource
- func Stream(w http.ResponseWriter, v interface{}) error
- type AccessToken
- type App
- type Authorization
- type Domain
- type Dyno
- type ErrorResource
- type Formation
- type PatchFormationForm
- type PostAppsForm
- type PostDeployForm
- type PostDomainsForm
- type PostLogsForm
- type PostProcessForm
- type PostReleasesForm
- type Release
- type Server
- func (s *Server) AccessTokensCreate(token *AccessToken) (*AccessToken, error)
- func (s *Server) AccessTokensFind(token string) (*AccessToken, error)
- func (s *Server) Authenticate(r *http.Request, strategies ...string) (context.Context, error)
- func (h *Server) DeleteApp(w http.ResponseWriter, r *http.Request) error
- func (h *Server) DeleteDomain(w http.ResponseWriter, r *http.Request) error
- func (h *Server) DeleteProcesses(w http.ResponseWriter, r *http.Request) error
- func (h *Server) DeployApp(w http.ResponseWriter, r *http.Request) error
- func (h *Server) GetAppInfo(w http.ResponseWriter, r *http.Request) error
- func (h *Server) GetApps(w http.ResponseWriter, r *http.Request) error
- func (h *Server) GetConfigs(w http.ResponseWriter, r *http.Request) error
- func (h *Server) GetDomains(w http.ResponseWriter, r *http.Request) error
- func (h *Server) GetFormation(w http.ResponseWriter, r *http.Request) error
- func (h *Server) GetProcesses(w http.ResponseWriter, r *http.Request) error
- func (h *Server) GetRelease(w http.ResponseWriter, r *http.Request) error
- func (h *Server) GetReleases(w http.ResponseWriter, r *http.Request) error
- func (h *Server) PatchApp(w http.ResponseWriter, r *http.Request) error
- func (h *Server) PatchConfigs(w http.ResponseWriter, r *http.Request) error
- func (h *Server) PatchFormation(w http.ResponseWriter, r *http.Request) error
- func (h *Server) PostApps(w http.ResponseWriter, r *http.Request) error
- func (h *Server) PostAuthorizations(w http.ResponseWriter, r *http.Request) error
- func (h *Server) PostCerts(w http.ResponseWriter, r *http.Request) error
- func (h *Server) PostDeploys(w http.ResponseWriter, req *http.Request) error
- func (h *Server) PostDomains(w http.ResponseWriter, r *http.Request) error
- func (h *Server) PostLogs(w http.ResponseWriter, r *http.Request) error
- func (h *Server) PostProcess(w http.ResponseWriter, r *http.Request) error
- func (h *Server) PostReleases(w http.ResponseWriter, r *http.Request) error
- func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
Constants ¶
const AcceptHeader = "application/vnd.heroku+json; version=3"
The Accept header that controls the api version. See https://devcenter.heroku.com/articles/platform-api-reference#clients
const (
HeaderTwoFactor = "Heroku-Two-Factor-Code"
)
Variables ¶
var ( ErrBadRequest = &ErrorResource{ Status: http.StatusBadRequest, ID: "bad_request", Message: "Request invalid, validate usage and try again", } Status: http.StatusUnauthorized, ID: "unauthorized", Message: "Request not authenticated, API token is missing, invalid or expired", } ErrForbidden = &ErrorResource{ Status: http.StatusForbidden, ID: "forbidden", Message: "Request not authorized, provided credentials do not provide access to specified resource", } ErrNotFound = &ErrorResource{ Status: http.StatusNotFound, ID: "not_found", Message: "Request failed, the specified resource does not exist", } ErrTwoFactor = &ErrorResource{ Status: http.StatusUnauthorized, ID: "two_factor", Message: "Two factor code is required.", } ErrSSLRemoved = &ErrorResource{ Status: http.StatusNotFound, ID: "not_found", Message: "Support for uploading SSL certificates through Empire has been removed and replaced with certificate attachments.", URL: "http://empire.readthedocs.org/en/latest/ssl_certs/", } ErrMessageRequired = &ErrorResource{ Status: http.StatusBadRequest, ID: "message_required", Message: fmt.Sprintf("Header '%s' is required", heroku.CommitMessageHeader), } )
Named matching heroku's error codes. See https://devcenter.heroku.com/articles/platform-api-reference#error-responses
var Vars = mux.Vars
Function used to obtain URL parameters.
Functions ¶
func DecodeRequest ¶ added in v0.10.1
DecodeRequest json decodes the request body into v, optionally ignoring EOF errors to handle cases where the request body might be empty.
func Error ¶
func Error(w http.ResponseWriter, err error, status int) error
Error is used to respond with errors in the heroku error format, which is specified at https://devcenter.heroku.com/articles/platform-api-reference#errors
If an ErrorResource is provided as the error, and it provides a non-zero status, that will be used as the response status code.
func NoContent ¶
func NoContent(w http.ResponseWriter) error
NoContent responds with a 404 and an empty body.
func RangeHeader ¶
func RangeHeader(r *http.Request) (headerutil.Range, error)
RangeHeader parses the Range header and returns an headerutil.Range.
func SAMLUnauthorized ¶ added in v0.12.0
func SAMLUnauthorized(loginURL string) func(error) *ErrorResource
SAMLUnauthorized can be used in place of Unauthorized to return a link to login via SAML.
func Stream ¶
func Stream(w http.ResponseWriter, v interface{}) error
Stream encodes and flushes data to the client.
Types ¶
type AccessToken ¶ added in v0.12.0
type AccessToken struct { // The encoded token. Token string // The time that the token expires. ExpiresAt *time.Time // The user that this AccessToken belongs to. User *empire.User }
AccessToken represents a token that allow access to the api.
func (*AccessToken) ExpiresIn ¶ added in v0.12.0
func (t *AccessToken) ExpiresIn() time.Duration
Returns the amount of time before the token expires.
func (*AccessToken) IsValid ¶ added in v0.12.0
func (t *AccessToken) IsValid() error
IsValid returns nil if the AccessToken is valid.
type Authorization ¶
type Authorization heroku.OAuthAuthorization
type ErrorResource ¶
type ErrorResource struct { Status int `json:"-"` ID string `json:"id"` Message string `json:"message"` URL string `json:"url"` }
ErrorResource represents the error response format that we return.
func Unauthorized ¶ added in v0.12.0
func Unauthorized(reason error) *ErrorResource
Returns an appropriate ErrorResource when a request is unauthorized.
func (*ErrorResource) Error ¶
func (e *ErrorResource) Error() string
Error implements error interface.
type PatchFormationForm ¶
type PatchFormationForm struct { Updates []struct { Process string `json:"process"` // Refers to process type Quantity int `json:"quantity"` Size *empire.Constraints `json:"size"` } `json:"updates"` }
type PostAppsForm ¶
type PostAppsForm struct {
Name string `json:"name"`
}
type PostDeployForm ¶
PostDeployForm is the form object that represents the POST body.
type PostDomainsForm ¶
type PostDomainsForm struct {
Hostname string `json:"hostname"`
}
type PostLogsForm ¶ added in v0.10.1
type PostLogsForm struct {
Duration int64
}
type PostProcessForm ¶
type PostReleasesForm ¶
type PostReleasesForm struct {
Version string `json:"release"`
}
func (*PostReleasesForm) ReleaseVersion ¶
func (p *PostReleasesForm) ReleaseVersion() (int, error)
type Server ¶ added in v0.11.0
type Server struct { *empire.Empire // Secret used to sign JWT access tokens. Secret []byte // Auth is the auth.Auth that will be used to authenticate and authorize // requests. Auth *auth.Auth // provided, heroku.UnauthorizedError will be used. This can be // overriden to provide better instructions for how to authenticate // (e.g. when SAML is enabled). Unauthorized func(reason error) *ErrorResource // contains filtered or unexported fields }
Server provides an http.Handler for serving the Heroku compatible API.
func (*Server) AccessTokensCreate ¶ added in v0.12.0
func (s *Server) AccessTokensCreate(token *AccessToken) (*AccessToken, error)
AccessTokensCreate "creates" the token by jwt signing it and setting the Token value.
func (*Server) AccessTokensFind ¶ added in v0.12.0
func (s *Server) AccessTokensFind(token string) (*AccessToken, error)
func (*Server) Authenticate ¶ added in v0.12.0
func (*Server) DeleteDomain ¶ added in v0.11.0
func (*Server) DeleteProcesses ¶ added in v0.11.0
func (*Server) GetAppInfo ¶ added in v0.11.0
func (*Server) GetConfigs ¶ added in v0.11.0
func (*Server) GetDomains ¶ added in v0.11.0
func (*Server) GetFormation ¶ added in v0.11.0
ServeHTTPContext handles the http response
func (*Server) GetProcesses ¶ added in v0.11.0
func (*Server) GetRelease ¶ added in v0.11.0
func (*Server) GetReleases ¶ added in v0.11.0
func (*Server) PatchConfigs ¶ added in v0.11.0
func (*Server) PatchFormation ¶ added in v0.11.0
func (*Server) PostAuthorizations ¶ added in v0.11.0
func (*Server) PostDeploys ¶ added in v0.11.0
ServeHTTPContext implements the Handler interface.