osbuild-composer: merge cloud API into main binary
This removes the osbuild-composer-cloud package, binary, systemd units, the (unused) test binary, and the (only-run-on-RHEL) test in aws.sh. Instead, move the cloud API into the main package, using the same socket as the koji API, osbuild-composer-api.socket. Expose it next to the koji API on route `/api/composer/v1`. This is a backwards incompatible change, but only of the -cloud parts, which have been marked as subject to change.
This commit is contained in:
parent
835b556db7
commit
b25a350502
14 changed files with 50 additions and 428 deletions
|
|
@ -5,9 +5,9 @@ package cloudapi
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
|
|
@ -34,16 +34,16 @@ func NewServer(workers *worker.Server, rpmMetadata rpmmd.RPMMD, distros *distro.
|
|||
return server
|
||||
}
|
||||
|
||||
// Serve serves the cloud API over the provided listener socket
|
||||
func (server *Server) Serve(listener net.Listener) error {
|
||||
s := http.Server{Handler: Handler(server)}
|
||||
// Create an http.Handler() for this server, that provides the composer API at
|
||||
// the given path.
|
||||
func (server *Server) Handler(path string) http.Handler {
|
||||
r := chi.NewRouter()
|
||||
|
||||
err := s.Serve(listener)
|
||||
if err != nil && err != http.ErrServerClosed {
|
||||
return err
|
||||
}
|
||||
r.Route(path, func(r chi.Router) {
|
||||
HandlerFromMux(server, r)
|
||||
})
|
||||
|
||||
return nil
|
||||
return r
|
||||
}
|
||||
|
||||
// Compose handles a new /compose POST request
|
||||
|
|
@ -150,7 +150,7 @@ func (server *Server) Compose(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
key := fmt.Sprintf("composer-cloudapi-%s", uuid.New().String())
|
||||
key := fmt.Sprintf("composer-api-%s", uuid.New().String())
|
||||
t := target.NewAWSTarget(&target.AWSTargetOptions{
|
||||
Filename: imageType.Filename(),
|
||||
Region: awsUploadOptions.Region,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen -package=api -generate types,server -o api.gen.go openapi.yml
|
||||
|
||||
package api
|
||||
|
||||
const BasePath = "/api/composer-koji/v1"
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
|
|
@ -24,7 +23,7 @@ import (
|
|||
|
||||
// Server represents the state of the koji Server
|
||||
type Server struct {
|
||||
server *http.Server
|
||||
logger *log.Logger
|
||||
workers *worker.Server
|
||||
rpmMetadata rpmmd.RPMMD
|
||||
distros *distro.Registry
|
||||
|
|
@ -34,38 +33,26 @@ type Server struct {
|
|||
// NewServer creates a new koji server
|
||||
func NewServer(logger *log.Logger, workers *worker.Server, rpmMetadata rpmmd.RPMMD, distros *distro.Registry, kojiServers map[string]koji.GSSAPICredentials) *Server {
|
||||
s := &Server{
|
||||
logger: logger,
|
||||
workers: workers,
|
||||
rpmMetadata: rpmMetadata,
|
||||
distros: distros,
|
||||
kojiServers: kojiServers,
|
||||
}
|
||||
|
||||
e := echo.New()
|
||||
e.Binder = binder{}
|
||||
e.StdLogger = logger
|
||||
|
||||
api.RegisterHandlers(e.Group(api.BasePath), &apiHandlers{s})
|
||||
|
||||
s.server = &http.Server{
|
||||
ErrorLog: logger,
|
||||
Handler: e,
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// Serve serves the koji API over the provided listener socket
|
||||
func (s *Server) Serve(listener net.Listener) error {
|
||||
err := s.server.Serve(listener)
|
||||
if err != nil && err != http.ErrServerClosed {
|
||||
return err
|
||||
}
|
||||
// Create an http.Handler() for this server, that provides the koji API at the
|
||||
// given path.
|
||||
func (s *Server) Handler(path string) http.Handler {
|
||||
e := echo.New()
|
||||
e.Binder = binder{}
|
||||
e.StdLogger = s.logger
|
||||
|
||||
return nil
|
||||
}
|
||||
api.RegisterHandlers(e.Group(path), &apiHandlers{s})
|
||||
|
||||
func (s *Server) Handler() http.Handler {
|
||||
return s.server.Handler
|
||||
return e
|
||||
}
|
||||
|
||||
// apiHandlers implements api.ServerInterface - the http api route handlers
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ func newTestKojiServer(t *testing.T) *kojiapi.Server {
|
|||
|
||||
func TestStatus(t *testing.T) {
|
||||
server := newTestKojiServer(t)
|
||||
handler := server.Handler()
|
||||
handler := server.Handler("/api/composer-koji/v1")
|
||||
|
||||
req := httptest.NewRequest("GET", "/api/composer-koji/v1/status", nil)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue