Track generated files with Git
The OpenAPI-generated files can be used by 3rd parties as well. This makes them available at `gitlab.com/blender/flamenco-goja-test/pkg/api`.
This commit is contained in:
parent
3d2263c177
commit
d6638ce114
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
|||||||
*.exe
|
*.exe
|
||||||
/flamenco*-poc
|
/flamenco*-poc
|
||||||
*.gen.go
|
|
||||||
|
1
Makefile
1
Makefile
@ -62,6 +62,7 @@ lint:
|
|||||||
clean:
|
clean:
|
||||||
@go clean -i -x
|
@go clean -i -x
|
||||||
rm -f flamenco*-poc-v* flamenco*-poc *.exe resource.syso pkg/api/*.gen.go
|
rm -f flamenco*-poc-v* flamenco*-poc *.exe resource.syso pkg/api/*.gen.go
|
||||||
|
go generate ./...
|
||||||
|
|
||||||
static: vet lint resource.syso
|
static: vet lint resource.syso
|
||||||
go build -v -o ${STATIC_OUT} -tags netgo -ldflags="-extldflags \"-static\" -w -s ${LDFLAGS}" ${PKG}
|
go build -v -o ${STATIC_OUT} -tags netgo -ldflags="-extldflags \"-static\" -w -s ${LDFLAGS}" ${PKG}
|
||||||
|
391
pkg/api/openapi_client.gen.go
Normal file
391
pkg/api/openapi_client.gen.go
Normal file
@ -0,0 +1,391 @@
|
|||||||
|
// 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 (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RequestEditorFn is the function signature for the RequestEditor callback function
|
||||||
|
type RequestEditorFn func(ctx context.Context, req *http.Request) error
|
||||||
|
|
||||||
|
// Doer performs HTTP requests.
|
||||||
|
//
|
||||||
|
// The standard http.Client implements this interface.
|
||||||
|
type HttpRequestDoer interface {
|
||||||
|
Do(req *http.Request) (*http.Response, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client which conforms to the OpenAPI3 specification for this service.
|
||||||
|
type Client struct {
|
||||||
|
// The endpoint of the server conforming to this interface, with scheme,
|
||||||
|
// https://api.deepmap.com for example. This can contain a path relative
|
||||||
|
// to the server, such as https://api.deepmap.com/dev-test, and all the
|
||||||
|
// paths in the swagger spec will be appended to the server.
|
||||||
|
Server string
|
||||||
|
|
||||||
|
// Doer for performing requests, typically a *http.Client with any
|
||||||
|
// customized settings, such as certificate chains.
|
||||||
|
Client HttpRequestDoer
|
||||||
|
|
||||||
|
// A list of callbacks for modifying requests which are generated before sending over
|
||||||
|
// the network.
|
||||||
|
RequestEditors []RequestEditorFn
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClientOption allows setting custom parameters during construction
|
||||||
|
type ClientOption func(*Client) error
|
||||||
|
|
||||||
|
// Creates a new Client, with reasonable defaults
|
||||||
|
func NewClient(server string, opts ...ClientOption) (*Client, error) {
|
||||||
|
// create a client with sane default values
|
||||||
|
client := Client{
|
||||||
|
Server: server,
|
||||||
|
}
|
||||||
|
// mutate client and add all optional params
|
||||||
|
for _, o := range opts {
|
||||||
|
if err := o(&client); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ensure the server URL always has a trailing slash
|
||||||
|
if !strings.HasSuffix(client.Server, "/") {
|
||||||
|
client.Server += "/"
|
||||||
|
}
|
||||||
|
// create httpClient, if not already present
|
||||||
|
if client.Client == nil {
|
||||||
|
client.Client = &http.Client{}
|
||||||
|
}
|
||||||
|
return &client, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithHTTPClient allows overriding the default Doer, which is
|
||||||
|
// automatically created using http.Client. This is useful for tests.
|
||||||
|
func WithHTTPClient(doer HttpRequestDoer) ClientOption {
|
||||||
|
return func(c *Client) error {
|
||||||
|
c.Client = doer
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithRequestEditorFn allows setting up a callback function, which will be
|
||||||
|
// called right before sending the request. This can be used to mutate the request.
|
||||||
|
func WithRequestEditorFn(fn RequestEditorFn) ClientOption {
|
||||||
|
return func(c *Client) error {
|
||||||
|
c.RequestEditors = append(c.RequestEditors, fn)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The interface specification for the client above.
|
||||||
|
type ClientInterface interface {
|
||||||
|
// RegisterWorker request with any body
|
||||||
|
RegisterWorkerWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
|
||||||
|
|
||||||
|
RegisterWorker(ctx context.Context, body RegisterWorkerJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
|
||||||
|
|
||||||
|
// ScheduleTask request
|
||||||
|
ScheduleTask(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) RegisterWorkerWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
||||||
|
req, err := NewRegisterWorkerRequestWithBody(c.Server, contentType, body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req = req.WithContext(ctx)
|
||||||
|
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return c.Client.Do(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) RegisterWorker(ctx context.Context, body RegisterWorkerJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
||||||
|
req, err := NewRegisterWorkerRequest(c.Server, body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req = req.WithContext(ctx)
|
||||||
|
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return c.Client.Do(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) ScheduleTask(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
||||||
|
req, err := NewScheduleTaskRequest(c.Server)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req = req.WithContext(ctx)
|
||||||
|
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return c.Client.Do(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewRegisterWorkerRequest calls the generic RegisterWorker builder with application/json body
|
||||||
|
func NewRegisterWorkerRequest(server string, body RegisterWorkerJSONRequestBody) (*http.Request, error) {
|
||||||
|
var bodyReader io.Reader
|
||||||
|
buf, err := json.Marshal(body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
bodyReader = bytes.NewReader(buf)
|
||||||
|
return NewRegisterWorkerRequestWithBody(server, "application/json", bodyReader)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewRegisterWorkerRequestWithBody generates requests for RegisterWorker with any type of body
|
||||||
|
func NewRegisterWorkerRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
serverURL, err := url.Parse(server)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
operationPath := fmt.Sprintf("/api/worker/register-worker")
|
||||||
|
if operationPath[0] == '/' {
|
||||||
|
operationPath = "." + operationPath
|
||||||
|
}
|
||||||
|
|
||||||
|
queryURL, err := serverURL.Parse(operationPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", queryURL.String(), body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Add("Content-Type", contentType)
|
||||||
|
|
||||||
|
return req, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewScheduleTaskRequest generates requests for ScheduleTask
|
||||||
|
func NewScheduleTaskRequest(server string) (*http.Request, error) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
serverURL, err := url.Parse(server)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
operationPath := fmt.Sprintf("/api/worker/task")
|
||||||
|
if operationPath[0] == '/' {
|
||||||
|
operationPath = "." + operationPath
|
||||||
|
}
|
||||||
|
|
||||||
|
queryURL, err := serverURL.Parse(operationPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", queryURL.String(), nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return req, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error {
|
||||||
|
for _, r := range c.RequestEditors {
|
||||||
|
if err := r(ctx, req); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, r := range additionalEditors {
|
||||||
|
if err := r(ctx, req); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClientWithResponses builds on ClientInterface to offer response payloads
|
||||||
|
type ClientWithResponses struct {
|
||||||
|
ClientInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClientWithResponses creates a new ClientWithResponses, which wraps
|
||||||
|
// Client with return type handling
|
||||||
|
func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) {
|
||||||
|
client, err := NewClient(server, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &ClientWithResponses{client}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithBaseURL overrides the baseURL.
|
||||||
|
func WithBaseURL(baseURL string) ClientOption {
|
||||||
|
return func(c *Client) error {
|
||||||
|
newBaseURL, err := url.Parse(baseURL)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.Server = newBaseURL.String()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClientWithResponsesInterface is the interface specification for the client with responses above.
|
||||||
|
type ClientWithResponsesInterface interface {
|
||||||
|
// RegisterWorker request with any body
|
||||||
|
RegisterWorkerWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RegisterWorkerResponse, error)
|
||||||
|
|
||||||
|
RegisterWorkerWithResponse(ctx context.Context, body RegisterWorkerJSONRequestBody, reqEditors ...RequestEditorFn) (*RegisterWorkerResponse, error)
|
||||||
|
|
||||||
|
// ScheduleTask request
|
||||||
|
ScheduleTaskWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*ScheduleTaskResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type RegisterWorkerResponse struct {
|
||||||
|
Body []byte
|
||||||
|
HTTPResponse *http.Response
|
||||||
|
JSON200 *RegisteredWorker
|
||||||
|
JSONDefault *Error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Status returns HTTPResponse.Status
|
||||||
|
func (r RegisterWorkerResponse) Status() string {
|
||||||
|
if r.HTTPResponse != nil {
|
||||||
|
return r.HTTPResponse.Status
|
||||||
|
}
|
||||||
|
return http.StatusText(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusCode returns HTTPResponse.StatusCode
|
||||||
|
func (r RegisterWorkerResponse) StatusCode() int {
|
||||||
|
if r.HTTPResponse != nil {
|
||||||
|
return r.HTTPResponse.StatusCode
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type ScheduleTaskResponse struct {
|
||||||
|
Body []byte
|
||||||
|
HTTPResponse *http.Response
|
||||||
|
JSON200 *AssignedTask
|
||||||
|
JSON403 *SecurityError
|
||||||
|
}
|
||||||
|
|
||||||
|
// Status returns HTTPResponse.Status
|
||||||
|
func (r ScheduleTaskResponse) Status() string {
|
||||||
|
if r.HTTPResponse != nil {
|
||||||
|
return r.HTTPResponse.Status
|
||||||
|
}
|
||||||
|
return http.StatusText(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatusCode returns HTTPResponse.StatusCode
|
||||||
|
func (r ScheduleTaskResponse) StatusCode() int {
|
||||||
|
if r.HTTPResponse != nil {
|
||||||
|
return r.HTTPResponse.StatusCode
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterWorkerWithBodyWithResponse request with arbitrary body returning *RegisterWorkerResponse
|
||||||
|
func (c *ClientWithResponses) RegisterWorkerWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*RegisterWorkerResponse, error) {
|
||||||
|
rsp, err := c.RegisterWorkerWithBody(ctx, contentType, body, reqEditors...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ParseRegisterWorkerResponse(rsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ClientWithResponses) RegisterWorkerWithResponse(ctx context.Context, body RegisterWorkerJSONRequestBody, reqEditors ...RequestEditorFn) (*RegisterWorkerResponse, error) {
|
||||||
|
rsp, err := c.RegisterWorker(ctx, body, reqEditors...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ParseRegisterWorkerResponse(rsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScheduleTaskWithResponse request returning *ScheduleTaskResponse
|
||||||
|
func (c *ClientWithResponses) ScheduleTaskWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*ScheduleTaskResponse, error) {
|
||||||
|
rsp, err := c.ScheduleTask(ctx, reqEditors...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ParseScheduleTaskResponse(rsp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseRegisterWorkerResponse parses an HTTP response from a RegisterWorkerWithResponse call
|
||||||
|
func ParseRegisterWorkerResponse(rsp *http.Response) (*RegisterWorkerResponse, error) {
|
||||||
|
bodyBytes, err := ioutil.ReadAll(rsp.Body)
|
||||||
|
defer func() { _ = rsp.Body.Close() }()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
response := &RegisterWorkerResponse{
|
||||||
|
Body: bodyBytes,
|
||||||
|
HTTPResponse: rsp,
|
||||||
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
|
||||||
|
var dest RegisteredWorker
|
||||||
|
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
response.JSON200 = &dest
|
||||||
|
|
||||||
|
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true:
|
||||||
|
var dest Error
|
||||||
|
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
response.JSONDefault = &dest
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseScheduleTaskResponse parses an HTTP response from a ScheduleTaskWithResponse call
|
||||||
|
func ParseScheduleTaskResponse(rsp *http.Response) (*ScheduleTaskResponse, error) {
|
||||||
|
bodyBytes, err := ioutil.ReadAll(rsp.Body)
|
||||||
|
defer func() { _ = rsp.Body.Close() }()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
response := &ScheduleTaskResponse{
|
||||||
|
Body: bodyBytes,
|
||||||
|
HTTPResponse: rsp,
|
||||||
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
|
||||||
|
var dest AssignedTask
|
||||||
|
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
response.JSON200 = &dest
|
||||||
|
|
||||||
|
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403:
|
||||||
|
var dest SecurityError
|
||||||
|
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
response.JSON403 = &dest
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return response, nil
|
||||||
|
}
|
76
pkg/api/openapi_server.gen.go
Normal file
76
pkg/api/openapi_server.gen.go
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
// 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 (
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ServerInterface represents all server handlers.
|
||||||
|
type ServerInterface interface {
|
||||||
|
// Register a new worker
|
||||||
|
// (POST /api/worker/register-worker)
|
||||||
|
RegisterWorker(ctx echo.Context) error
|
||||||
|
// Obtain a new task to execute
|
||||||
|
// (POST /api/worker/task)
|
||||||
|
ScheduleTask(ctx echo.Context) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServerInterfaceWrapper converts echo contexts to parameters.
|
||||||
|
type ServerInterfaceWrapper struct {
|
||||||
|
Handler ServerInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.POST(baseURL+"/api/worker/register-worker", wrapper.RegisterWorker)
|
||||||
|
router.POST(baseURL+"/api/worker/task", wrapper.ScheduleTask)
|
||||||
|
|
||||||
|
}
|
112
pkg/api/openapi_spec.gen.go
Normal file
112
pkg/api/openapi_spec.gen.go
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
// 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 (
|
||||||
|
"bytes"
|
||||||
|
"compress/gzip"
|
||||||
|
"encoding/base64"
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/getkin/kin-openapi/openapi3"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Base64 encoded, gzipped, json marshaled Swagger object
|
||||||
|
var swaggerSpec = []string{
|
||||||
|
|
||||||
|
"H4sIAAAAAAAC/7xX32/jNgz+VwRtj6mdXe8pb7fdbiiwH8W1wx6KolBsxlFrSzqSTi4o8r8PlOzEbpzr",
|
||||||
|
"gHV7imOR4sePHyn5WRe+Cd6BY9KLZ03FGhoTHz8Q2cpBeWvoSf6XQAXawNY7vRitKkvKKJYnQ8qy/Eco",
|
||||||
|
"wG6gVMud4jWovzw+AWZ6pgP6AMgWYpQHW8oP7wLohSZG6yq9nwmsxrgy2liGJj58j7DSC/1dfgSdd4jz",
|
||||||
|
"n5KD+HabGUSzk/+PfjkZ49EvHwJaj5Z3AwPrGCrA3iK9nXB3pple+PaexIbbV9MRXm+SpWRk6Ok8kJYA",
|
||||||
|
"Jxb2M43wpbUIpV7cRaYTF51Hl8EB0QD4C24GRAyxDKp0f2DdLx+hYIHVV+REO92CQggIJGkro8i6qgbV",
|
||||||
|
"7ajYK/gKRcvwmoLOloGA2bqKBos9uBfU9Dz0DlPZ/IzoI8vj6IUvY/SVx8ZwqvTlOz2bKHwDRKaC1ysV",
|
||||||
|
"9zzaT6H5DJUlBoQy0XIK7FxjmbJEIJpcqw3xgynYbsbqHWjeFk/ndV8bFh6mq+FXvDV4plSHnjhdakPw",
|
||||||
|
"yFA+HIQ3HgonHuP2n+yCQxpHPoZt0Ocx00WLCI5jbP2SoEFSZ3BOle4Gila66oyg/rFKviWPwfRYPGtw",
|
||||||
|
"bSMeEXhsW+MKqKFMHRxq4Pi8Mja9/NJCGx8kv4vD6+R2ISCAji6jF8G0lB7QF0DS1QOExyIl2SYZo0mD",
|
||||||
|
"4SUV/0JsUCDw/6GnLtJINJMhBqI7rViCHGVxIwdAgrSNHD2YltenQ/RPApTd5LCV8ZiM1dXHmQqGaOux",
|
||||||
|
"7JcSRlXZDThluDfFAfkyVuPRI6iWhmxxHGFr5qD3gtG6lU9Dz7Ep+Dh99afaNOAKr27BCAUt1p0nLfJ8",
|
||||||
|
"1a1m1ufC6DiTz+BKQPXJYKMa40wFqD5cX0m72QIcwSDOL9e/bi5P9t9ut1nl2sxjlXc+lFehvrjM5hm4",
|
||||||
|
"bM1NHStpuR6h7cLpmd4AUoLzQzbP5mLtAzgTrF7oy/hKxM3rWJncBJsnGnPsRvHF9jiJPUVyRMyR3qsy",
|
||||||
|
"5pkMu4mddATEP/py17MKLjqaEGpbRNf8kVJvpJvBa/eGib6KpRtTnqzkkO3R66GsGVuIOqfghUsJ+m4+",
|
||||||
|
"fzOQJ6fXBEQnB2qtegxJNivT1vxmMNIEnojdOvgaoGAoFXQ20tVNY3A3KKQyysG2a6d4M5LLxl3Xt/p+",
|
||||||
|
"wimVRPnVwDPe8IaK4u7GPS0jGRBlW8NtOpL+syKN7v8TJMWb//GalkkW7+bvTyfV7z5+G5AyG2Nrs6xB",
|
||||||
|
"rTwqXls6XOr2M/1+fvlm2Mdn7AT4a8DGknS8+gjOQjmawXpx92L63t3v74fV/GPJxrpOADxm4jUlROKo",
|
||||||
|
"qyIqcGXw1nHWQUAZRRFBGnK5ltDdjiefYddXkczDREuEksCRq3TrhEBQW8vro9Fvaexl/SfAoge6v9//",
|
||||||
|
"HQAA//+F23YLEg4AAA==",
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSwagger returns the content of the embedded swagger specification file
|
||||||
|
// or error if failed to decode
|
||||||
|
func decodeSpec() ([]byte, error) {
|
||||||
|
zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, ""))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error base64 decoding spec: %s", err)
|
||||||
|
}
|
||||||
|
zr, err := gzip.NewReader(bytes.NewReader(zipped))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error decompressing spec: %s", err)
|
||||||
|
}
|
||||||
|
var buf bytes.Buffer
|
||||||
|
_, err = buf.ReadFrom(zr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error decompressing spec: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf.Bytes(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var rawSpec = decodeSpecCached()
|
||||||
|
|
||||||
|
// a naive cached of a decoded swagger spec
|
||||||
|
func decodeSpecCached() func() ([]byte, error) {
|
||||||
|
data, err := decodeSpec()
|
||||||
|
return func() ([]byte, error) {
|
||||||
|
return data, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
|
||||||
|
func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) {
|
||||||
|
var res = make(map[string]func() ([]byte, error))
|
||||||
|
if len(pathToFile) > 0 {
|
||||||
|
res[pathToFile] = rawSpec
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSwagger returns the Swagger specification corresponding to the generated code
|
||||||
|
// in this file. The external references of Swagger specification are resolved.
|
||||||
|
// The logic of resolving external references is tightly connected to "import-mapping" feature.
|
||||||
|
// Externally referenced files must be embedded in the corresponding golang packages.
|
||||||
|
// Urls can be supported but this task was out of the scope.
|
||||||
|
func GetSwagger() (swagger *openapi3.T, err error) {
|
||||||
|
var resolvePath = PathToRawSpec("")
|
||||||
|
|
||||||
|
loader := openapi3.NewLoader()
|
||||||
|
loader.IsExternalRefsAllowed = true
|
||||||
|
loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
|
||||||
|
var pathToFile = url.String()
|
||||||
|
pathToFile = path.Clean(pathToFile)
|
||||||
|
getSpec, ok := resolvePath[pathToFile]
|
||||||
|
if !ok {
|
||||||
|
err1 := fmt.Errorf("path not found: %s", pathToFile)
|
||||||
|
return nil, err1
|
||||||
|
}
|
||||||
|
return getSpec()
|
||||||
|
}
|
||||||
|
var specData []byte
|
||||||
|
specData, err = rawSpec()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
swagger, err = loader.LoadFromData(specData)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
91
pkg/api/openapi_types.gen.go
Normal file
91
pkg/api/openapi_types.gen.go
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
// 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
|
||||||
|
|
||||||
|
const (
|
||||||
|
Worker_authScopes = "worker_auth.Scopes"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Defines values for TaskStatus.
|
||||||
|
const (
|
||||||
|
TaskStatusActive TaskStatus = "active"
|
||||||
|
|
||||||
|
TaskStatusCancelRequested TaskStatus = "cancel-requested"
|
||||||
|
|
||||||
|
TaskStatusCanceled TaskStatus = "canceled"
|
||||||
|
|
||||||
|
TaskStatusCompleted TaskStatus = "completed"
|
||||||
|
|
||||||
|
TaskStatusFailRequested TaskStatus = "fail-requested"
|
||||||
|
|
||||||
|
TaskStatusFailed TaskStatus = "failed"
|
||||||
|
|
||||||
|
TaskStatusPaused TaskStatus = "paused"
|
||||||
|
|
||||||
|
TaskStatusProcessing TaskStatus = "processing"
|
||||||
|
|
||||||
|
TaskStatusQueued TaskStatus = "queued"
|
||||||
|
|
||||||
|
TaskStatusSoftFailed TaskStatus = "soft-failed"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AssignedTask is a task as it is received by the Worker.
|
||||||
|
type AssignedTask struct {
|
||||||
|
Id string `json:"_id"`
|
||||||
|
Commands []Command `json:"commands"`
|
||||||
|
Job string `json:"job"`
|
||||||
|
JobPriority int `json:"job_priority"`
|
||||||
|
JobType string `json:"job_type"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Priority int `json:"priority"`
|
||||||
|
Status TaskStatus `json:"status"`
|
||||||
|
TaskType string `json:"task_type"`
|
||||||
|
User string `json:"user"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command represents a single command to execute by the Worker.
|
||||||
|
type Command struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Settings map[string]interface{} `json:"settings"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error defines model for Error.
|
||||||
|
type Error struct {
|
||||||
|
Code int32 `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisteredWorker defines model for RegisteredWorker.
|
||||||
|
type RegisteredWorker struct {
|
||||||
|
Id string `json:"_id"`
|
||||||
|
Address string `json:"address"`
|
||||||
|
LastActivity string `json:"last_activity"`
|
||||||
|
Nickname string `json:"nickname"`
|
||||||
|
Platform string `json:"platform"`
|
||||||
|
Software string `json:"software"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
SupportedTaskTypes []string `json:"supported_task_types"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SecurityError defines model for SecurityError.
|
||||||
|
type SecurityError struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TaskStatus defines model for TaskStatus.
|
||||||
|
type TaskStatus string
|
||||||
|
|
||||||
|
// WorkerRegistration defines model for WorkerRegistration.
|
||||||
|
type WorkerRegistration struct {
|
||||||
|
Nickname string `json:"nickname"`
|
||||||
|
Platform string `json:"platform"`
|
||||||
|
Secret string `json:"secret"`
|
||||||
|
SupportedTaskTypes []string `json:"supported_task_types"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterWorkerJSONBody defines parameters for RegisterWorker.
|
||||||
|
type RegisterWorkerJSONBody WorkerRegistration
|
||||||
|
|
||||||
|
// RegisterWorkerJSONRequestBody defines body for RegisterWorker for application/json ContentType.
|
||||||
|
type RegisterWorkerJSONRequestBody RegisterWorkerJSONBody
|
Loading…
x
Reference in New Issue
Block a user