clouadpi: NewServer: move awsBucket parameter to a new ServerConfig struct

We will have more parameters soon so let's make this prettier sooner rather
than later.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
Ondřej Budai 2022-03-03 14:22:52 +01:00 committed by Ondřej Budai
parent 2765d2d9a8
commit 9feb7b59d6
4 changed files with 24 additions and 13 deletions

View file

@ -19,6 +19,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/auth"
"github.com/osbuild/osbuild-composer/internal/cloudapi"
v2 "github.com/osbuild/osbuild-composer/internal/cloudapi/v2"
"github.com/osbuild/osbuild-composer/internal/distroregistry"
"github.com/osbuild/osbuild-composer/internal/jobqueue"
"github.com/osbuild/osbuild-composer/internal/jobqueue/dbjobqueue"
@ -119,7 +120,10 @@ func (c *Composer) InitWeldr(repoPaths []string, weldrListener net.Listener,
}
func (c *Composer) InitAPI(cert, key string, enableTLS bool, enableMTLS bool, enableJWT bool, l net.Listener) error {
c.api = cloudapi.NewServer(c.workers, c.distros, c.config.Koji.AWS.Bucket)
config := v2.ServerConfig{
AWSBucket: c.config.Koji.AWS.Bucket,
}
c.api = cloudapi.NewServer(c.workers, c.distros, config)
c.koji = kojiapi.NewServer(c.logger, c.workers, c.rpm, c.distros)
if !enableTLS {

View file

@ -13,9 +13,9 @@ type Server struct {
v2 *v2.Server
}
func NewServer(workers *worker.Server, distros *distroregistry.Registry, awsBucket string) *Server {
func NewServer(workers *worker.Server, distros *distroregistry.Registry, config v2.ServerConfig) *Server {
server := &Server{
v2: v2.NewServer(workers, distros, awsBucket),
v2: v2.NewServer(workers, distros, config),
}
return server
}

View file

@ -34,9 +34,13 @@ import (
// Server represents the state of the cloud Server
type Server struct {
workers *worker.Server
distros *distroregistry.Registry
awsBucket string
workers *worker.Server
distros *distroregistry.Registry
config ServerConfig
}
type ServerConfig struct {
AWSBucket string
}
type apiHandlers struct {
@ -45,11 +49,11 @@ type apiHandlers struct {
type binder struct{}
func NewServer(workers *worker.Server, distros *distroregistry.Registry, bucket string) *Server {
func NewServer(workers *worker.Server, distros *distroregistry.Registry, config ServerConfig) *Server {
server := &Server{
workers: workers,
distros: distros,
awsBucket: bucket,
workers: workers,
distros: distros,
config: config,
}
return server
}
@ -345,7 +349,7 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
t := target.NewAWSTarget(&target.AWSTargetOptions{
Filename: imageType.Filename(),
Region: awsUploadOptions.Region,
Bucket: h.server.awsBucket,
Bucket: h.server.config.AWSBucket,
Key: key,
ShareWithAccounts: awsUploadOptions.ShareWithAccounts,
})
@ -381,7 +385,7 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
t := target.NewAWSS3Target(&target.AWSS3TargetOptions{
Filename: imageType.Filename(),
Region: awsS3UploadOptions.Region,
Bucket: h.server.awsBucket,
Bucket: h.server.config.AWSBucket,
Key: key,
})
t.ImageName = key

View file

@ -32,7 +32,10 @@ func newV2Server(t *testing.T, dir string) (*v2.Server, *worker.Server, context.
require.NoError(t, err)
require.NotNil(t, distros)
v2Server := v2.NewServer(workerServer, distros, "image-builder.service")
config := v2.ServerConfig{
AWSBucket: "image-builder.service",
}
v2Server := v2.NewServer(workerServer, distros, config)
require.NotNil(t, v2Server)
// start a routine which just completes depsolve jobs