restapi

package
v0.0.0-...-6ed339e Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2015 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidAccountID is returned when an invalid Account ID is found.
	ErrInvalidAccountID = errors.New("invalid account ID")
)
View Source
var (
	// ErrInvalidAttemptID is returned when an invalid Attempt ID is found.
	ErrInvalidAttemptID = errors.New("invalid attempt ID")
)

Functions

func Authenticate

func Authenticate(w rest.ResponseWriter, r *rest.Request)

func DeleteAccount

func DeleteAccount(w rest.ResponseWriter, r *rest.Request)

DeleteAccount handles DELETE request on /accounts/:account

func DeleteApplication

func DeleteApplication(w rest.ResponseWriter, r *rest.Request)

DeleteApplication ...

func DeleteApplications

func DeleteApplications(w rest.ResponseWriter, r *rest.Request)

DeleteApplications ...

func DeleteQueue

func DeleteQueue(w rest.ResponseWriter, r *rest.Request)

DeleteQueue ...

func DeleteQueues

func DeleteQueues(w rest.ResponseWriter, r *rest.Request)

DeleteQueues ...

func DeleteTask

func DeleteTask(w rest.ResponseWriter, r *rest.Request)

DeleteTask ...

func DeleteTasks

func DeleteTasks(w rest.ResponseWriter, r *rest.Request)

DeleteTasks ...

func GetAccount

func GetAccount(w rest.ResponseWriter, r *rest.Request)

GetAccount handles GET request on /accounts/:account

func GetAccounts

func GetAccounts(w rest.ResponseWriter, r *rest.Request)

GetAccounts ...

func GetApplication

func GetApplication(w rest.ResponseWriter, r *rest.Request)

GetApplication ...

func GetApplications

func GetApplications(w rest.ResponseWriter, r *rest.Request)

GetApplications ...

func GetAttempt

func GetAttempt(w rest.ResponseWriter, r *rest.Request)

GetAttempt ...

func GetAttempts

func GetAttempts(w rest.ResponseWriter, r *rest.Request)

GetAttempts ...

func GetBase

func GetBase(r *rest.Request) *models.Base

func GetCurentAccount

func GetCurentAccount(r *rest.Request) *bson.ObjectId

func GetQueue

func GetQueue(w rest.ResponseWriter, r *rest.Request)

GetQueue ...

func GetQueues

func GetQueues(w rest.ResponseWriter, r *rest.Request)

GetQueues ...

func GetStatus

func GetStatus(w rest.ResponseWriter, r *rest.Request)

func GetTask

func GetTask(w rest.ResponseWriter, r *rest.Request)

GetTask ...

func GetTasks

func GetTasks(w rest.ResponseWriter, r *rest.Request)

GetTasks ...

func New

func New(s *store.Store, adminPassword string, logStyle string) (*rest.Api, error)

New creates a new instance of the Rest API.

func PatchAccount

func PatchAccount(w rest.ResponseWriter, r *rest.Request)

PatchAccount handles PATCH requests on /accounts

func PathAccountID

func PathAccountID(r *rest.Request) (bson.ObjectId, error)

func PostAccount

func PostAccount(w rest.ResponseWriter, r *rest.Request)

PostAccount handles POST requests on /accounts

func PostAttempt

func PostAttempt(w rest.ResponseWriter, r *rest.Request)

PostAttempt ...

func PutApplication

func PutApplication(w rest.ResponseWriter, r *rest.Request)

PutApplication ...

func PutQueue

func PutQueue(w rest.ResponseWriter, r *rest.Request)

PutQueue ...

func PutTask

func PutTask(w rest.ResponseWriter, r *rest.Request)

PutTask ...

func UnixToRFC3339

func UnixToRFC3339(ts int64) string

UnixToRFC3339 converts a Unix timestamp to a human readable format.

Types

type Account

type Account struct {
	// ID is the ID of the Account.
	ID string `json:"id"`

	// Name is display name for the Account.
	Name *string `json:"name"`

	// Created is the date when the Account was created.
	Created string `json:"created"`

	// Key is the secret key to authenticate the Account ID.
	Key string `json:"key"`
}

Account is an account to access the service.

func NewAccountFromModel

func NewAccountFromModel(account *models.Account) *Account

NewAccountFromModel returns an API Account given a model Account.

type Application

type Application struct {
	// ID is the ID of the Application.
	ID string `json:"id"`

	// Created is the date when the Application was created.
	Created string `json:"created"`

	// Account is the ID of the Account owning the Application.
	Account string `json:"account"`

	// Name is the application's name.
	Name string `json:"name"`
}

Application is a list of Tasks with a common application Name.

func NewApplicationFromModel

func NewApplicationFromModel(application *models.Application) *Application

NewApplicationFromModel returns a Application object for use with the Rest API from a Application model.

type Attempt

type Attempt struct {
	// ID is the Attempt ID.
	ID string `json:"id"`

	// Created is the date when the Attempt was created.
	Created string `json:"created"`

	// Account is the ID of the Account owning the Task.
	Account string `json:"account"`

	// Application is the name of the parent Application.
	Application string `json:"application"`

	// Task is the task's name.
	Task string `json:"name"`

	// TaskID is the ID of the parent Task of this attempt.
	TaskID string `json:"taskID"`

	// Queue is the name of the parent Queue.
	Queue string `json:"queue"`

	// URL is the URL that the worker with requests.
	URL string `json:"url"`

	// HTTPAuth is the HTTP authentication to use if any.
	HTTPAuth models.HTTPAuth `json:"auth"`

	// Method is the HTTP method that will be used to execute the request.
	Method string `json:"method"`

	// Headers are the HTTP headers that will be used schedule executing the request.
	Headers map[string]string `json:"headers,omitempty"`

	// Payload is arbitrary data that will be POSTed on the URL.
	Payload string `json:"payload,omitempty"`

	// At is a date representing the time this attempt will be executed.
	At string `json:"at,omitempty"`

	// Finished is a Unix timestamp representing the time the attempt finished.
	Finished string `json:"finished,omitempty"`

	// Status is either `pending`, `retrying`, `canceled`, `success` or `error`
	Status string `json:"status"`

	// StatusCode is the HTTP status code.
	StatusCode int32 `json:"statusCode,omitempty"`

	// StatusMessage is a human readable message related to the StatusCode.
	StatusMessage string `json:"statusMessage,omitempty"`
}

Attempt is used for the Rest API.

func NewAttemptFromModel

func NewAttemptFromModel(attempt *models.Attempt) *Attempt

NewAttemptFromModel returns a Task object for use with the Rest API from a Task model.

type AuthBasicMiddleware

type AuthBasicMiddleware struct {

	// Realm name to display to the user. Required.
	Realm string

	// Callback function that should perform the authentication of the user based on userId and
	// password. Must return true on success, false on failure. Required.
	Authenticator func(userId string, password string, request *rest.Request) bool

	// Callback function that should perform the authorization of the authenticated user. Called
	// only after an authentication success. Must return true on success, false on failure.
	// Optional, default to success.
	Authorizator func(userId string, request *rest.Request) bool
}

AuthBasicMiddleware provides a simple AuthBasic implementation. On failure, a 401 HTTP response is returned. On success, the wrapped middleware is called, and the userId is made available as request.Env["REMOTE_USER"].(string)

func (*AuthBasicMiddleware) MiddlewareFunc

func (mw *AuthBasicMiddleware) MiddlewareFunc(handler rest.HandlerFunc) rest.HandlerFunc

MiddlewareFunc makes AuthBasicMiddleware implement the Middleware interface.

type BaseMiddleware

type BaseMiddleware struct {
	Store *store.Store
}

func (*BaseMiddleware) MiddlewareFunc

func (mw *BaseMiddleware) MiddlewareFunc(next rest.HandlerFunc) rest.HandlerFunc

type Queue

type Queue struct {
	// ID is the ID of the Queue.
	ID string `json:"id"`

	// Created is the date when the Queue was created.
	Created string `json:"created"`

	// Account is the ID of the Account owning the Queue.
	Account string `json:"account"`

	// Application is the name of the parent Application.
	Application string `json:"application"`

	// Name is the queue's name.
	Name string `json:"name"`

	// Retry is the retry strategy parameters in case of errors.
	Retry *models.Retry `json:"retry"`

	// MaxInFlight is the maximum number of attempts executed in parallel.
	MaxInFlight int `json:"maxInFlight"`

	// InFlight is the current number of attempts executed in parallel.
	InFlight int `json:"inFlight"`
}

Queue ...

func NewQueueFromModel

func NewQueueFromModel(queue *models.Queue) *Queue

NewQueueFromModel returns a Queue object for use with the Rest API from a Queue model.

type Task

type Task struct {
	// ID is the Task ID.
	ID string `json:"id"`

	// Created is the date when the Task was created.
	Created string `json:"created"`

	// Account is the ID of the Account owning the Task.
	Account string `json:"account"`

	// Application is the name of the parent Application.
	Application string `json:"application"`

	// Name is the task's name.
	Name string `json:"name"`

	// Queue is the name of the parent Queue.
	Queue string `json:"queue"`

	// URL is the URL that the worker with requests.
	URL string `json:"url"`

	// HTTPAuth is the HTTP authentication to use if any.
	HTTPAuth models.HTTPAuth `json:"auth"`

	// Method is the HTTP method that will be used to execute the request.
	Method string `json:"method"`

	// Headers are the HTTP headers that will be used schedule executing the request.
	Headers map[string]string `json:"headers,omitempty"`

	// Payload is arbitrary data that will be POSTed on the URL.
	Payload string `json:"payload,omitempty"`

	// Schedule is a cron specification describing the recurrency if any.
	Schedule string `json:"schedule,omitempty"`

	// At is a date representing the next time a attempt will be executed.
	At string `json:"at,omitempty"`

	// Status is either `pending`, `retrying`, `canceled`, `success` or `error`
	Status string `json:"status"`

	// Executed is the date of the last time a attempt was executed.
	Executed string `json:"executed,omitempty"`

	// Active is the task active.
	Active *bool `json:"active"`

	// Errors counts the number of attempts that failed.
	Errors int `json:"errors"`

	// LastError is the date of the last attempt in error status.
	LastError string `json:"lastError,omitempty"`

	// LastSuccess is the date of the last attempt in success status.
	LastSuccess string `json:"lastSuccess,omitempty"`

	// Executions counts the number of attempts that were executed.
	Executions int `json:"executions"`

	// ErrorRate is the rate of errors in percent.
	ErrorRate int `json:"errorRate"`

	// Retry is the retry strategy parameters in case of errors.
	Retry *models.Retry `json:"retry"`
}

Task is used for the Rest API.

func NewTaskFromModel

func NewTaskFromModel(task *models.Task) *Task

NewTaskFromModel returns a Task object for use with the Rest API from a Task model.

Jump to

Keyboard shortcuts

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