Documentation ¶
Overview ¶
Package registry provides a basic implementation of the binder template registry.
Index ¶
- Variables
- func NewDefaultRouter(registry Registry) *mux.Router
- type APIErrorResponse
- type AuthStore
- type ContainerLimits
- type ErrorHint
- type InMemoryStore
- type Registry
- func (registry Registry) Index(w http.ResponseWriter, r *http.Request)
- func (registry Registry) TemplateCreate(w http.ResponseWriter, r *http.Request)
- func (registry Registry) TemplateIndex(w http.ResponseWriter, r *http.Request)
- func (registry Registry) TemplateShow(w http.ResponseWriter, r *http.Request)
- func (registry Registry) TemplateUpdate(w http.ResponseWriter, r *http.Request)
- type Store
- type Template
- type TokenAuthStore
Constants ¶
This section is empty.
Variables ¶
var DontPanicError = APIErrorResponse{Message: "Internal Server Error. Don't Panic. We will."}
DontPanicError is an APIErrorResponse when there's a mostly catastrophic error
var ExistingTemplateError = APIErrorResponse{Message: "Template already exists"}
ExistingTemplateError is an APIErrorResponse with a boilerplate message for when a template already exists
var InvalidTokenError = APIErrorResponse{Message: "Invalid token"}
InvalidTokenError is an APIErrorResponse for when a token is invalid
var MissingAuthHeaderError = APIErrorResponse{
Message: "Authorization header not set. Should be of format 'Authorization: token key'",
}
MissingAuthHeaderError is an APIErrorResponse for when the Authorization header is not set
var MissingTokenFieldError = APIErrorResponse{
Message: "Token field not present in Authorization header. Should be of format 'Authorization: token key'",
}
MissingTokenFieldError is an APIErrorResponse for when the token field is missing
var TemplateNotFoundError = APIErrorResponse{Message: "Template Not Found"}
TemplateNotFoundError is an APIErrorResponse reported when the template requested doesn't exist
var UnableToListError = APIErrorResponse{Message: "Unable to list templates"}
UnableToListError is an APIErrorResponse reported when templates are unable to be listed
UnavailableTemplateError is an APIErrorResponse with a boilerplate unavailable template message
Functions ¶
func NewDefaultRouter ¶
NewDefaultRouter sets up a mux.Router with the registry routes
Types ¶
type APIErrorResponse ¶
type APIErrorResponse struct { Message string `json:"message"` Errors []ErrorHint `json:"errors,omitempty"` }
APIErrorResponse mirrors the GitHub error model, providing a message as well as possible error hints
func (APIErrorResponse) Error ¶
func (apiError APIErrorResponse) Error() string
Error implements the error interface and tries to return the serialized JSON form of the APIErrorResponse
type AuthStore ¶
AuthStore is an interface for connecting to some authentication endpoint, assumed to be used as middleware in front of authenticated endpoints much like the default setup for TemplateUpdate or TemplateCreate
type ContainerLimits ¶
type ContainerLimits struct { Memory int64 `json:"memory,omitempty"` }
ContainerLimits is the specific set of limits we have for containers QUESTION: Should this come from Docker itself?
type ErrorHint ¶
type ErrorHint struct { Resource string `json:"resource"` Field string `json:"field"` Code string `json:"code"` }
ErrorHint allows you to specify specific fields the user is potentially missing
type InMemoryStore ¶
type InMemoryStore struct {
// contains filtered or unexported fields
}
InMemoryStore implements a non-thread-safe registry of binder templates
func NewInMemoryStore ¶
func NewInMemoryStore() InMemoryStore
NewInMemoryStore create a new InMemoryStore
func (InMemoryStore) GetTemplate ¶
func (store InMemoryStore) GetTemplate(name string) (Template, error)
GetTemplate retrieves the template with name, erroring otherwise
func (InMemoryStore) ListTemplates ¶
func (store InMemoryStore) ListTemplates() ([]Template, error)
ListTemplates provides a listing of all registered templates
func (InMemoryStore) RegisterTemplate ¶
func (store InMemoryStore) RegisterTemplate(tmpl Template) (Template, error)
RegisterTemplate registers the template in the Store
func (InMemoryStore) UpdateTemplate ¶
func (store InMemoryStore) UpdateTemplate(tmpl Template) (Template, error)
UpdateTemplate will allow for updating ImageName and Command
type Registry ¶
Registry keeps context for Store with the API Handlers
func (Registry) Index ¶
func (registry Registry) Index(w http.ResponseWriter, r *http.Request)
Index lists available resources at this endpoint
func (Registry) TemplateCreate ¶
func (registry Registry) TemplateCreate(w http.ResponseWriter, r *http.Request)
TemplateCreate registers a template
func (Registry) TemplateIndex ¶
func (registry Registry) TemplateIndex(w http.ResponseWriter, r *http.Request)
TemplateIndex lists the available templates as well as their configuration
func (Registry) TemplateShow ¶
func (registry Registry) TemplateShow(w http.ResponseWriter, r *http.Request)
TemplateShow displays the requested template
func (Registry) TemplateUpdate ¶
func (registry Registry) TemplateUpdate(w http.ResponseWriter, r *http.Request)
TemplateUpdate updates an individual template by name
type Store ¶
type Store interface { // GetTemplate retrieves the template with name, erroring otherwise GetTemplate(name string) (Template, error) // RegisterTemplate registers the template in the DB RegisterTemplate(tmpl Template) (Template, error) // ListTemplates provides a listing of all registered templates ListTemplates() ([]Template, error) // UpdateTemplate will allow for updating ImageName and Command UpdateTemplate(tmpl Template) (Template, error) }
Store is an interface for registering templates into some backend storage, which could be in-memory, mongo, Postgres, Bolt, etc.
This current interface makes no guarantees about thread safety, that's up to the implementer of the interface!
type Template ¶
type Template struct { Name string `json:"name"` ImageName string `json:"image-name"` Command string `json:"command"` Limits ContainerLimits `json:"limits,omitempty"` TimeCreated time.Time `json:"time-created"` TimeModified time.Time `json:"time-modified"` // TODO: Add these to the binder API spec? RedirectURI string `json:"redirect-uri,omitempty"` BindIP string `json:"container-ip,omitempty"` BindPort int64 `json:"bind-port,omitempty"` }
Template defines an image to be run along with its configuration
type TokenAuthStore ¶
type TokenAuthStore struct {
Token string
}
TokenAuthStore uses a single token for authentication