registry

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2015 License: Apache-2.0 Imports: 11 Imported by: 0

README

Binder Registry

Build Status

CRUD for Binder Templates.

⚠ Prototype ⚠

This is an initial implementation of the registry API from the Binder API spec proposal.

Go get it.

$ go get github.com/binder-project/binder-registry

Build it.

$ cd $GOPATH/src/github.com/binder-project/binder-registry/simpleregistry
$ go build
$ BINDER_API_KEY=THISISMYTOKEN ./simpleregistry
2015/10/07 09:52:48 Serving on :8080

Use it.

$ curl 127.0.0.1:8080
{"status": "Binder Registry Live!"}
$ curl 127.0.0.1:8080/templates
[]
$ curl -X POST 127.0.0.1:8080/templates -d '{"name": "myenv", "image-name":"jupyter/demo"}'
{"message":"Authorization header not set. Should be of format 'Authorization: token key'"}
$ # Need the token for POST and PUT
$ curl -X POST 127.0.0.1:8080/templates -d '{"name": "myenv", "image-name":"jupyter/demo"}' -H "Authorization: token THISISMYTOKEN"
{"name":"myenv","image-name":"jupyter/demo","command":"","limits":{},"time-created":"2015-10-07T14:54:55.782549453Z","time-modified":"2015-10-07T14:54:55.782549453Z"}

Documentation

Overview

Package registry provides a basic implementation of the binder template registry.

Index

Constants

This section is empty.

Variables

View Source
var DontPanicError = APIErrorResponse{Message: "Internal Server Error. Don't Panic. We will."}

DontPanicError is an APIErrorResponse when there's a mostly catastrophic error

View Source
var ExistingTemplateError = APIErrorResponse{Message: "Template already exists"}

ExistingTemplateError is an APIErrorResponse with a boilerplate message for when a template already exists

View Source
var InvalidTokenError = APIErrorResponse{Message: "Invalid token"}

InvalidTokenError is an APIErrorResponse for when a token is invalid

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

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

View Source
var TemplateNotFoundError = APIErrorResponse{Message: "Template Not Found"}

TemplateNotFoundError is an APIErrorResponse reported when the template requested doesn't exist

View Source
var UnableToListError = APIErrorResponse{Message: "Unable to list templates"}

UnableToListError is an APIErrorResponse reported when templates are unable to be listed

View Source
var UnavailableTemplateError = APIErrorResponse{Message: "Template unavailable"}

UnavailableTemplateError is an APIErrorResponse with a boilerplate unavailable template message

Functions

func NewDefaultRouter

func NewDefaultRouter(registry Registry) *mux.Router

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

type AuthStore interface {
	Authorize(inner http.Handler) http.Handler
}

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"`
	CPUShares int64 `json:"cpu_shares,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

type Registry struct {
	Store
	AuthStore
}

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

func (TokenAuthStore) Authorize

func (authStore TokenAuthStore) Authorize(inner http.Handler) http.Handler

Authorize uses token based authentication, presuming that the endpoint is done over HTTPS

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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