353 lines
13 KiB
Go
353 lines
13 KiB
Go
// Package api provides primitives to interact with the openapi HTTP API.
|
|
//
|
|
// Code generated by github.com/deepmap/oapi-codegen version v1.9.0 DO NOT EDIT.
|
|
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/deepmap/oapi-codegen/pkg/runtime"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
// ServerInterface represents all server handlers.
|
|
type ServerInterface interface {
|
|
// Get the configuration of this Manager.
|
|
// (GET /api/configuration)
|
|
GetConfiguration(ctx echo.Context) error
|
|
// Submit a new job for Flamenco Manager to execute.
|
|
// (POST /api/jobs)
|
|
SubmitJob(ctx echo.Context) error
|
|
// Get list of job types and their parameters.
|
|
// (GET /api/jobs/types)
|
|
GetJobTypes(ctx echo.Context) error
|
|
// Fetch info about the job.
|
|
// (GET /api/jobs/{job_id})
|
|
FetchJob(ctx echo.Context, jobId string) error
|
|
// Get the Flamenco version of this Manager
|
|
// (GET /api/version)
|
|
GetVersion(ctx echo.Context) error
|
|
// Register a new worker
|
|
// (POST /api/worker/register-worker)
|
|
RegisterWorker(ctx echo.Context) error
|
|
// Mark the worker as offline
|
|
// (POST /api/worker/sign-off)
|
|
SignOff(ctx echo.Context) error
|
|
// Authenticate & sign in the worker.
|
|
// (POST /api/worker/sign-on)
|
|
SignOn(ctx echo.Context) error
|
|
|
|
// (GET /api/worker/state)
|
|
WorkerState(ctx echo.Context) error
|
|
// Worker changed state. This could be as acknowledgement of a Manager-requested state change, or in response to worker-local signals.
|
|
// (POST /api/worker/state-changed)
|
|
WorkerStateChanged(ctx echo.Context) error
|
|
// Obtain a new task to execute
|
|
// (POST /api/worker/task)
|
|
ScheduleTask(ctx echo.Context) error
|
|
// Update the task, typically to indicate progress, completion, or failure.
|
|
// (POST /api/worker/task/{task_id})
|
|
TaskUpdate(ctx echo.Context, taskId string) error
|
|
// Create a directory, and symlink the required files into it. The files must all have been uploaded to Shaman before calling this endpoint.
|
|
// (POST /shaman/checkout/create)
|
|
ShamanCheckout(ctx echo.Context) error
|
|
// Checks a Shaman Requirements file, and reports which files are unknown.
|
|
// (POST /shaman/checkout/requirements)
|
|
ShamanCheckoutRequirements(ctx echo.Context) error
|
|
// Check the status of a file on the Shaman server.
|
|
// (GET /shaman/files/{checksum}/{filesize})
|
|
ShamanFileStoreCheck(ctx echo.Context, checksum string, filesize int) error
|
|
// Store a new file on the Shaman server. Note that the Shaman server can forcibly close the HTTP connection when another client finishes uploading the exact same file, to prevent double uploads.
|
|
// The file's contents should be sent in the request body.
|
|
// (POST /shaman/files/{checksum}/{filesize})
|
|
ShamanFileStore(ctx echo.Context, checksum string, filesize int, params ShamanFileStoreParams) error
|
|
}
|
|
|
|
// ServerInterfaceWrapper converts echo contexts to parameters.
|
|
type ServerInterfaceWrapper struct {
|
|
Handler ServerInterface
|
|
}
|
|
|
|
// GetConfiguration converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetConfiguration(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.GetConfiguration(ctx)
|
|
return err
|
|
}
|
|
|
|
// SubmitJob converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) SubmitJob(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.SubmitJob(ctx)
|
|
return err
|
|
}
|
|
|
|
// GetJobTypes converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetJobTypes(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.GetJobTypes(ctx)
|
|
return err
|
|
}
|
|
|
|
// FetchJob converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) FetchJob(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "job_id" -------------
|
|
var jobId string
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "job_id", runtime.ParamLocationPath, ctx.Param("job_id"), &jobId)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter job_id: %s", err))
|
|
}
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.FetchJob(ctx, jobId)
|
|
return err
|
|
}
|
|
|
|
// GetVersion converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetVersion(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.GetVersion(ctx)
|
|
return err
|
|
}
|
|
|
|
// RegisterWorker converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) RegisterWorker(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.RegisterWorker(ctx)
|
|
return err
|
|
}
|
|
|
|
// SignOff converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) SignOff(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(Worker_authScopes, []string{""})
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.SignOff(ctx)
|
|
return err
|
|
}
|
|
|
|
// SignOn converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) SignOn(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(Worker_authScopes, []string{""})
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.SignOn(ctx)
|
|
return err
|
|
}
|
|
|
|
// WorkerState converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) WorkerState(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(Worker_authScopes, []string{""})
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.WorkerState(ctx)
|
|
return err
|
|
}
|
|
|
|
// WorkerStateChanged converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) WorkerStateChanged(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(Worker_authScopes, []string{""})
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.WorkerStateChanged(ctx)
|
|
return err
|
|
}
|
|
|
|
// ScheduleTask converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) ScheduleTask(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(Worker_authScopes, []string{""})
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.ScheduleTask(ctx)
|
|
return err
|
|
}
|
|
|
|
// TaskUpdate converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) TaskUpdate(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "task_id" -------------
|
|
var taskId string
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "task_id", runtime.ParamLocationPath, ctx.Param("task_id"), &taskId)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter task_id: %s", err))
|
|
}
|
|
|
|
ctx.Set(Worker_authScopes, []string{""})
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.TaskUpdate(ctx, taskId)
|
|
return err
|
|
}
|
|
|
|
// ShamanCheckout converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) ShamanCheckout(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.ShamanCheckout(ctx)
|
|
return err
|
|
}
|
|
|
|
// ShamanCheckoutRequirements converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) ShamanCheckoutRequirements(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.ShamanCheckoutRequirements(ctx)
|
|
return err
|
|
}
|
|
|
|
// ShamanFileStoreCheck converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) ShamanFileStoreCheck(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "checksum" -------------
|
|
var checksum string
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "checksum", runtime.ParamLocationPath, ctx.Param("checksum"), &checksum)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter checksum: %s", err))
|
|
}
|
|
|
|
// ------------- Path parameter "filesize" -------------
|
|
var filesize int
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "filesize", runtime.ParamLocationPath, ctx.Param("filesize"), &filesize)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter filesize: %s", err))
|
|
}
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.ShamanFileStoreCheck(ctx, checksum, filesize)
|
|
return err
|
|
}
|
|
|
|
// ShamanFileStore converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) ShamanFileStore(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "checksum" -------------
|
|
var checksum string
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "checksum", runtime.ParamLocationPath, ctx.Param("checksum"), &checksum)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter checksum: %s", err))
|
|
}
|
|
|
|
// ------------- Path parameter "filesize" -------------
|
|
var filesize int
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "filesize", runtime.ParamLocationPath, ctx.Param("filesize"), &filesize)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter filesize: %s", err))
|
|
}
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params ShamanFileStoreParams
|
|
|
|
headers := ctx.Request().Header
|
|
// ------------- Optional header parameter "X-Shaman-Can-Defer-Upload" -------------
|
|
if valueList, found := headers[http.CanonicalHeaderKey("X-Shaman-Can-Defer-Upload")]; found {
|
|
var XShamanCanDeferUpload bool
|
|
n := len(valueList)
|
|
if n != 1 {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for X-Shaman-Can-Defer-Upload, got %d", n))
|
|
}
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "X-Shaman-Can-Defer-Upload", runtime.ParamLocationHeader, valueList[0], &XShamanCanDeferUpload)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter X-Shaman-Can-Defer-Upload: %s", err))
|
|
}
|
|
|
|
params.XShamanCanDeferUpload = &XShamanCanDeferUpload
|
|
}
|
|
// ------------- Optional header parameter "X-Shaman-Original-Filename" -------------
|
|
if valueList, found := headers[http.CanonicalHeaderKey("X-Shaman-Original-Filename")]; found {
|
|
var XShamanOriginalFilename string
|
|
n := len(valueList)
|
|
if n != 1 {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Expected one value for X-Shaman-Original-Filename, got %d", n))
|
|
}
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "X-Shaman-Original-Filename", runtime.ParamLocationHeader, valueList[0], &XShamanOriginalFilename)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter X-Shaman-Original-Filename: %s", err))
|
|
}
|
|
|
|
params.XShamanOriginalFilename = &XShamanOriginalFilename
|
|
}
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.ShamanFileStore(ctx, checksum, filesize, params)
|
|
return err
|
|
}
|
|
|
|
// This is a simple interface which specifies echo.Route addition functions which
|
|
// are present on both echo.Echo and echo.Group, since we want to allow using
|
|
// either of them for path registration
|
|
type EchoRouter interface {
|
|
CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
}
|
|
|
|
// RegisterHandlers adds each server route to the EchoRouter.
|
|
func RegisterHandlers(router EchoRouter, si ServerInterface) {
|
|
RegisterHandlersWithBaseURL(router, si, "")
|
|
}
|
|
|
|
// Registers handlers, and prepends BaseURL to the paths, so that the paths
|
|
// can be served under a prefix.
|
|
func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL string) {
|
|
|
|
wrapper := ServerInterfaceWrapper{
|
|
Handler: si,
|
|
}
|
|
|
|
router.GET(baseURL+"/api/configuration", wrapper.GetConfiguration)
|
|
router.POST(baseURL+"/api/jobs", wrapper.SubmitJob)
|
|
router.GET(baseURL+"/api/jobs/types", wrapper.GetJobTypes)
|
|
router.GET(baseURL+"/api/jobs/:job_id", wrapper.FetchJob)
|
|
router.GET(baseURL+"/api/version", wrapper.GetVersion)
|
|
router.POST(baseURL+"/api/worker/register-worker", wrapper.RegisterWorker)
|
|
router.POST(baseURL+"/api/worker/sign-off", wrapper.SignOff)
|
|
router.POST(baseURL+"/api/worker/sign-on", wrapper.SignOn)
|
|
router.GET(baseURL+"/api/worker/state", wrapper.WorkerState)
|
|
router.POST(baseURL+"/api/worker/state-changed", wrapper.WorkerStateChanged)
|
|
router.POST(baseURL+"/api/worker/task", wrapper.ScheduleTask)
|
|
router.POST(baseURL+"/api/worker/task/:task_id", wrapper.TaskUpdate)
|
|
router.POST(baseURL+"/shaman/checkout/create", wrapper.ShamanCheckout)
|
|
router.POST(baseURL+"/shaman/checkout/requirements", wrapper.ShamanCheckoutRequirements)
|
|
router.GET(baseURL+"/shaman/files/:checksum/:filesize", wrapper.ShamanFileStoreCheck)
|
|
router.POST(baseURL+"/shaman/files/:checksum/:filesize", wrapper.ShamanFileStore)
|
|
|
|
}
|