cloudapi: split into handler and server
These "classes" are huge, let's split them into two files to make the file smaller. Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
parent
e773d4896b
commit
a6f3dd91b6
2 changed files with 51 additions and 42 deletions
|
|
@ -15,68 +15,26 @@ import (
|
|||
|
||||
"github.com/google/uuid"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/auth"
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/distroregistry"
|
||||
"github.com/osbuild/osbuild-composer/internal/jobqueue"
|
||||
osbuild "github.com/osbuild/osbuild-composer/internal/osbuild2"
|
||||
"github.com/osbuild/osbuild-composer/internal/ostree"
|
||||
"github.com/osbuild/osbuild-composer/internal/prometheus"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/target"
|
||||
"github.com/osbuild/osbuild-composer/internal/worker"
|
||||
"github.com/osbuild/osbuild-composer/internal/worker/clienterrors"
|
||||
)
|
||||
|
||||
// Server represents the state of the cloud Server
|
||||
type Server struct {
|
||||
workers *worker.Server
|
||||
distros *distroregistry.Registry
|
||||
config ServerConfig
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
AWSBucket string
|
||||
TenantProviderFields []string
|
||||
JWTEnabled bool
|
||||
}
|
||||
|
||||
type apiHandlers struct {
|
||||
server *Server
|
||||
}
|
||||
|
||||
type binder struct{}
|
||||
|
||||
func NewServer(workers *worker.Server, distros *distroregistry.Registry, config ServerConfig) *Server {
|
||||
server := &Server{
|
||||
workers: workers,
|
||||
distros: distros,
|
||||
config: config,
|
||||
}
|
||||
return server
|
||||
}
|
||||
|
||||
func (server *Server) Handler(path string) http.Handler {
|
||||
e := echo.New()
|
||||
e.Binder = binder{}
|
||||
e.HTTPErrorHandler = server.HTTPErrorHandler
|
||||
e.Pre(common.OperationIDMiddleware)
|
||||
e.Use(middleware.Recover())
|
||||
e.Logger = common.Logger()
|
||||
|
||||
handler := apiHandlers{
|
||||
server: server,
|
||||
}
|
||||
RegisterHandlers(e.Group(path, prometheus.MetricsMiddleware), &handler)
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
func (b binder) Bind(i interface{}, ctx echo.Context) error {
|
||||
contentType := ctx.Request().Header["Content-Type"]
|
||||
if len(contentType) != 1 || contentType[0] != "application/json" {
|
||||
51
internal/cloudapi/v2/server.go
Normal file
51
internal/cloudapi/v2/server.go
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package v2
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"github.com/osbuild/osbuild-composer/internal/distroregistry"
|
||||
"github.com/osbuild/osbuild-composer/internal/prometheus"
|
||||
"github.com/osbuild/osbuild-composer/internal/worker"
|
||||
)
|
||||
|
||||
// Server represents the state of the cloud Server
|
||||
type Server struct {
|
||||
workers *worker.Server
|
||||
distros *distroregistry.Registry
|
||||
config ServerConfig
|
||||
}
|
||||
|
||||
type ServerConfig struct {
|
||||
AWSBucket string
|
||||
TenantProviderFields []string
|
||||
JWTEnabled bool
|
||||
}
|
||||
|
||||
func NewServer(workers *worker.Server, distros *distroregistry.Registry, config ServerConfig) *Server {
|
||||
server := &Server{
|
||||
workers: workers,
|
||||
distros: distros,
|
||||
config: config,
|
||||
}
|
||||
return server
|
||||
}
|
||||
|
||||
func (s *Server) Handler(path string) http.Handler {
|
||||
e := echo.New()
|
||||
e.Binder = binder{}
|
||||
e.HTTPErrorHandler = s.HTTPErrorHandler
|
||||
e.Pre(common.OperationIDMiddleware)
|
||||
e.Use(middleware.Recover())
|
||||
e.Logger = common.Logger()
|
||||
|
||||
handler := apiHandlers{
|
||||
server: s,
|
||||
}
|
||||
RegisterHandlers(e.Group(path, prometheus.MetricsMiddleware), &handler)
|
||||
|
||||
return e
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue