As deepmap/oapi-codegen didn't work with this newer version, upgrade to oapi-codegen/oapi-codegen v2. Mitigating CVE-2025-30153
414 lines
15 KiB
Go
414 lines
15 KiB
Go
// Package api provides primitives to interact with the openapi HTTP API.
|
|
//
|
|
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.4.1 DO NOT EDIT.
|
|
package api
|
|
|
|
import (
|
|
"bytes"
|
|
"compress/gzip"
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"path"
|
|
"strings"
|
|
|
|
"github.com/getkin/kin-openapi/openapi3"
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/oapi-codegen/runtime"
|
|
openapi_types "github.com/oapi-codegen/runtime/types"
|
|
)
|
|
|
|
const (
|
|
BearerScopes = "Bearer.Scopes"
|
|
)
|
|
|
|
// Error defines model for Error.
|
|
type Error struct {
|
|
Code string `json:"code"`
|
|
Href string `json:"href"`
|
|
Id string `json:"id"`
|
|
Kind string `json:"kind"`
|
|
|
|
// Message Backward compatibility with workers <= v33, equals reason
|
|
Message string `json:"message"`
|
|
OperationId string `json:"operation_id"`
|
|
Reason string `json:"reason"`
|
|
}
|
|
|
|
// GetJobResponse defines model for GetJobResponse.
|
|
type GetJobResponse struct {
|
|
Canceled bool `json:"canceled"`
|
|
Href string `json:"href"`
|
|
Id string `json:"id"`
|
|
Kind string `json:"kind"`
|
|
}
|
|
|
|
// ObjectReference defines model for ObjectReference.
|
|
type ObjectReference struct {
|
|
Href string `json:"href"`
|
|
Id string `json:"id"`
|
|
Kind string `json:"kind"`
|
|
}
|
|
|
|
// PostWorkersRequest defines model for PostWorkersRequest.
|
|
type PostWorkersRequest struct {
|
|
Arch string `json:"arch"`
|
|
}
|
|
|
|
// PostWorkersResponse defines model for PostWorkersResponse.
|
|
type PostWorkersResponse struct {
|
|
Href string `json:"href"`
|
|
Id string `json:"id"`
|
|
Kind string `json:"kind"`
|
|
WorkerId openapi_types.UUID `json:"worker_id"`
|
|
}
|
|
|
|
// RequestJobRequest defines model for RequestJobRequest.
|
|
type RequestJobRequest struct {
|
|
Arch string `json:"arch"`
|
|
Types []string `json:"types"`
|
|
WorkerId *string `json:"worker_id,omitempty"`
|
|
}
|
|
|
|
// RequestJobResponse defines model for RequestJobResponse.
|
|
type RequestJobResponse struct {
|
|
Args *json.RawMessage `json:"args,omitempty"`
|
|
ArtifactLocation string `json:"artifact_location"`
|
|
DynamicArgs *[]json.RawMessage `json:"dynamic_args,omitempty"`
|
|
Href string `json:"href"`
|
|
Id string `json:"id"`
|
|
Kind string `json:"kind"`
|
|
Location string `json:"location"`
|
|
Type string `json:"type"`
|
|
}
|
|
|
|
// StatusResponse defines model for StatusResponse.
|
|
type StatusResponse struct {
|
|
Href string `json:"href"`
|
|
Id string `json:"id"`
|
|
Kind string `json:"kind"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
// UpdateJobRequest defines model for UpdateJobRequest.
|
|
type UpdateJobRequest struct {
|
|
Result json.RawMessage `json:"result"`
|
|
}
|
|
|
|
// UpdateJobResponse defines model for UpdateJobResponse.
|
|
type UpdateJobResponse = ObjectReference
|
|
|
|
// RequestJobJSONRequestBody defines body for RequestJob for application/json ContentType.
|
|
type RequestJobJSONRequestBody = RequestJobRequest
|
|
|
|
// UpdateJobJSONRequestBody defines body for UpdateJob for application/json ContentType.
|
|
type UpdateJobJSONRequestBody = UpdateJobRequest
|
|
|
|
// PostWorkersJSONRequestBody defines body for PostWorkers for application/json ContentType.
|
|
type PostWorkersJSONRequestBody = PostWorkersRequest
|
|
|
|
// ServerInterface represents all server handlers.
|
|
type ServerInterface interface {
|
|
// Get error description
|
|
// (GET /errors/{id})
|
|
GetError(ctx echo.Context, id string) error
|
|
// Request a job
|
|
// (POST /jobs)
|
|
RequestJob(ctx echo.Context) error
|
|
// Get running job
|
|
// (GET /jobs/{token})
|
|
GetJob(ctx echo.Context, token string) error
|
|
// Update a running job
|
|
// (PATCH /jobs/{token})
|
|
UpdateJob(ctx echo.Context, token string) error
|
|
// Upload an artifact
|
|
// (PUT /jobs/{token}/artifacts/{name})
|
|
UploadJobArtifact(ctx echo.Context, token string, name string) error
|
|
// Get the openapi spec in json format
|
|
// (GET /openapi)
|
|
GetOpenapi(ctx echo.Context) error
|
|
// status
|
|
// (GET /status)
|
|
GetStatus(ctx echo.Context) error
|
|
// Create a new worker
|
|
// (POST /workers)
|
|
PostWorkers(ctx echo.Context) error
|
|
// Refresh worker status
|
|
// (POST /workers/{worker_id}/status)
|
|
PostWorkerStatus(ctx echo.Context, workerId openapi_types.UUID) error
|
|
}
|
|
|
|
// ServerInterfaceWrapper converts echo contexts to parameters.
|
|
type ServerInterfaceWrapper struct {
|
|
Handler ServerInterface
|
|
}
|
|
|
|
// GetError converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetError(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "id" -------------
|
|
var id string
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "id", ctx.Param("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
|
}
|
|
|
|
ctx.Set(BearerScopes, []string{})
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.GetError(ctx, id)
|
|
return err
|
|
}
|
|
|
|
// RequestJob converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) RequestJob(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.RequestJob(ctx)
|
|
return err
|
|
}
|
|
|
|
// GetJob converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetJob(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "token" -------------
|
|
var token string
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "token", ctx.Param("token"), &token, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter token: %s", err))
|
|
}
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.GetJob(ctx, token)
|
|
return err
|
|
}
|
|
|
|
// UpdateJob converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) UpdateJob(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "token" -------------
|
|
var token string
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "token", ctx.Param("token"), &token, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter token: %s", err))
|
|
}
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.UpdateJob(ctx, token)
|
|
return err
|
|
}
|
|
|
|
// UploadJobArtifact converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) UploadJobArtifact(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "token" -------------
|
|
var token string
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "token", ctx.Param("token"), &token, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter token: %s", err))
|
|
}
|
|
|
|
// ------------- Path parameter "name" -------------
|
|
var name string
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "name", ctx.Param("name"), &name, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter name: %s", err))
|
|
}
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.UploadJobArtifact(ctx, token, name)
|
|
return err
|
|
}
|
|
|
|
// GetOpenapi converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetOpenapi(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.GetOpenapi(ctx)
|
|
return err
|
|
}
|
|
|
|
// GetStatus converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetStatus(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.GetStatus(ctx)
|
|
return err
|
|
}
|
|
|
|
// PostWorkers converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) PostWorkers(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.PostWorkers(ctx)
|
|
return err
|
|
}
|
|
|
|
// PostWorkerStatus converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) PostWorkerStatus(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "worker_id" -------------
|
|
var workerId openapi_types.UUID
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "worker_id", ctx.Param("worker_id"), &workerId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true})
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter worker_id: %s", err))
|
|
}
|
|
|
|
// Invoke the callback with all the unmarshaled arguments
|
|
err = w.Handler.PostWorkerStatus(ctx, workerId)
|
|
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+"/errors/:id", wrapper.GetError)
|
|
router.POST(baseURL+"/jobs", wrapper.RequestJob)
|
|
router.GET(baseURL+"/jobs/:token", wrapper.GetJob)
|
|
router.PATCH(baseURL+"/jobs/:token", wrapper.UpdateJob)
|
|
router.PUT(baseURL+"/jobs/:token/artifacts/:name", wrapper.UploadJobArtifact)
|
|
router.GET(baseURL+"/openapi", wrapper.GetOpenapi)
|
|
router.GET(baseURL+"/status", wrapper.GetStatus)
|
|
router.POST(baseURL+"/workers", wrapper.PostWorkers)
|
|
router.POST(baseURL+"/workers/:worker_id/status", wrapper.PostWorkerStatus)
|
|
|
|
}
|
|
|
|
// Base64 encoded, gzipped, json marshaled Swagger object
|
|
var swaggerSpec = []string{
|
|
|
|
"H4sIAAAAAAAC/9xYbW/bvhH/KgduwDZAsZyme2NgL5puKNKhS5GsWIEmKE7S2WJCkSp5imsY/u4DSflR",
|
|
"sp0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40tTzF4Nm247jjDtkOf8JAbbGhYMbuP43hIyFf5Gvxm+fTXj",
|
|
"nc7QtfwfE9IyxY28JMB2BjhBqcWvxvnd+AKL10y/WVZfH/Wa4emczSPpzTrZKXVLUp6oyuxsIT2hXP9b",
|
|
"/JIVaKvM2EZrqScR/k7f6OkLITEHW0NPL6iR40y9ncXVPHGi6tIZkXqLy/AU9n5j2sQoAbe5s3t10+WY",
|
|
"7dK5p064y3XDfSxQBouPJnvXnhDP4WH4eAkNk9ej8/O4anImPnNsCatt0HdV7iPlb0ccn2g/3y65EWmz",
|
|
"Gpr3F/vrVuQ5OLXqwrgMUoP3HdpXBB/oKUbR3Uv+RdPPmnKmoh3kTJ431vOrW4L9IH7QZ4/RemXs3Rtu",
|
|
"pZ/GIUq1e4yFaSnzEixxY7UDR/ZJ5kuhvu3hdvnLySrkzk79O5bHFt6QtXbP3D+wx0HTz+uapu1aGlbR",
|
|
"ZdIQmkYWbSZdaRpVQEbQOCo8T1ApcE3mfEHSDDkq5QZ3upPcjQe7E/XanlfHE4/yfY+Q+2f5LYh3bmEU",
|
|
"6Uos85fOV+94i42beLxJrZ//DnWYYy+cfoDas+6NLbmSXKghJaHljJCX2320ngQ+eQUuXH0vjJ4qekUk",
|
|
"NlD4OCqpCcwTWVTqTrdsLAkVl4P2yaM9XRjQhiHmtoCpVCp8kRE8Us3AFvNH7weO2TMaWFZkGh7A1fhO",
|
|
"F9bUNRWrZ5gpWVpNE2EVSID96hpWIa87I2+L0TIVh/l9sIZtw+eaPCc3bpSaQROGmqVLf3GwcY0315UA",
|
|
"+PKirmTCYm+f+p9bPqHU8NfamqLJ/Vd/gygrEtFYJUaiZK7dKE2xlgPfCFwpxzzITeW/SWWFEzrLGqkK",
|
|
"smfRcvp0Hp4Vd5oA48QjeEC9Y5zQC41ELS8R2/jhfvH/AAAA///y4vKhRRsAAA==",
|
|
}
|
|
|
|
// 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: %w", err)
|
|
}
|
|
zr, err := gzip.NewReader(bytes.NewReader(zipped))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error decompressing spec: %w", err)
|
|
}
|
|
var buf bytes.Buffer
|
|
_, err = buf.ReadFrom(zr)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error decompressing spec: %w", 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) {
|
|
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) {
|
|
resolvePath := PathToRawSpec("")
|
|
|
|
loader := openapi3.NewLoader()
|
|
loader.IsExternalRefsAllowed = true
|
|
loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
|
|
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
|
|
}
|