heroku

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2017 License: BSD-2-Clause Imports: 26 Imported by: 0

Documentation

Overview

Package heroku provides a Heroku Platform API compatible http.Handler implementation for Empire.

Index

Constants

View Source
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

View Source
const (
	HeaderTwoFactor = "Heroku-Two-Factor-Code"
)

Variables

View Source
var (
	ErrBadRequest = &ErrorResource{
		Status:  http.StatusBadRequest,
		ID:      "bad_request",
		Message: "Request invalid, validate usage and try again",
	}
	ErrUnauthorized = &ErrorResource{
		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

View Source
var Vars = mux.Vars

Function used to obtain URL parameters.

Functions

func Decode

func Decode(r *http.Request, v interface{}) error

Decode json decodes the request body into v.

func DecodeRequest added in v0.10.1

func DecodeRequest(r *http.Request, v interface{}, ignoreEOF bool) error

DecodeRequest json decodes the request body into v, optionally ignoring EOF errors to handle cases where the request body might be empty.

func Encode

func Encode(w http.ResponseWriter, v interface{}) error

Encode json encodes v into w.

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 App

type App heroku.App

type Authorization

type Authorization heroku.OAuthAuthorization

type Domain

type Domain heroku.Domain

type Dyno

type Dyno heroku.Dyno

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 Formation

type Formation heroku.Formation

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

type PostDeployForm struct {
	Image  image.Image
	Stream bool
}

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 PostProcessForm struct {
	Command string              `json:"command"`
	Attach  bool                `json:"attach"`
	Env     map[string]string   `json:"env"`
	Size    *empire.Constraints `json:"size"`
}

type PostReleasesForm

type PostReleasesForm struct {
	Version string `json:"release"`
}

func (*PostReleasesForm) ReleaseVersion

func (p *PostReleasesForm) ReleaseVersion() (int, error)

type Release

type Release heroku.Release

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

	// Unauthorized is called when a request is not authorized If not
	// 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 New

func New(e *empire.Empire) *Server

New returns a new Server instance to serve 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 (s *Server) Authenticate(r *http.Request, strategies ...string) (context.Context, error)

func (*Server) DeleteApp added in v0.11.0

func (h *Server) DeleteApp(w http.ResponseWriter, r *http.Request) error

func (*Server) DeleteDomain added in v0.11.0

func (h *Server) DeleteDomain(w http.ResponseWriter, r *http.Request) error

func (*Server) DeleteProcesses added in v0.11.0

func (h *Server) DeleteProcesses(w http.ResponseWriter, r *http.Request) error

func (*Server) DeployApp added in v0.11.0

func (h *Server) DeployApp(w http.ResponseWriter, r *http.Request) error

func (*Server) GetAppInfo added in v0.11.0

func (h *Server) GetAppInfo(w http.ResponseWriter, r *http.Request) error

func (*Server) GetApps added in v0.11.0

func (h *Server) GetApps(w http.ResponseWriter, r *http.Request) error

func (*Server) GetConfigs added in v0.11.0

func (h *Server) GetConfigs(w http.ResponseWriter, r *http.Request) error

func (*Server) GetDomains added in v0.11.0

func (h *Server) GetDomains(w http.ResponseWriter, r *http.Request) error

func (*Server) GetFormation added in v0.11.0

func (h *Server) GetFormation(w http.ResponseWriter, r *http.Request) error

ServeHTTPContext handles the http response

func (*Server) GetProcesses added in v0.11.0

func (h *Server) GetProcesses(w http.ResponseWriter, r *http.Request) error

func (*Server) GetRelease added in v0.11.0

func (h *Server) GetRelease(w http.ResponseWriter, r *http.Request) error

func (*Server) GetReleases added in v0.11.0

func (h *Server) GetReleases(w http.ResponseWriter, r *http.Request) error

func (*Server) PatchApp added in v0.11.0

func (h *Server) PatchApp(w http.ResponseWriter, r *http.Request) error

func (*Server) PatchConfigs added in v0.11.0

func (h *Server) PatchConfigs(w http.ResponseWriter, r *http.Request) error

func (*Server) PatchFormation added in v0.11.0

func (h *Server) PatchFormation(w http.ResponseWriter, r *http.Request) error

func (*Server) PostApps added in v0.11.0

func (h *Server) PostApps(w http.ResponseWriter, r *http.Request) error

func (*Server) PostAuthorizations added in v0.11.0

func (h *Server) PostAuthorizations(w http.ResponseWriter, r *http.Request) error

func (*Server) PostCerts added in v0.12.0

func (h *Server) PostCerts(w http.ResponseWriter, r *http.Request) error

func (*Server) PostDeploys added in v0.11.0

func (h *Server) PostDeploys(w http.ResponseWriter, req *http.Request) error

ServeHTTPContext implements the Handler interface.

func (*Server) PostDomains added in v0.11.0

func (h *Server) PostDomains(w http.ResponseWriter, r *http.Request) error

func (*Server) PostLogs added in v0.11.0

func (h *Server) PostLogs(w http.ResponseWriter, r *http.Request) error

func (*Server) PostProcess added in v0.11.0

func (h *Server) PostProcess(w http.ResponseWriter, r *http.Request) error

func (*Server) PostReleases added in v0.11.0

func (h *Server) PostReleases(w http.ResponseWriter, r *http.Request) error

func (*Server) ServeHTTP added in v0.13.0

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL