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

@ -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