worker/osbuild: use dedicated struct for GCP config internally

Previously, the internal `OSBuildJobImpl` structure defined only
`GCPCreds` member. This is not practical, once there will be more
than one GCP-related variable.

Define a new `GCPConfiguration` structure, move the credentials variable
into it and use it in `OSBuildJobImpl` instead.
This commit is contained in:
Tomáš Hozza 2022-09-23 12:54:17 +02:00 committed by Ondřej Budai
parent 13f0894094
commit cc53f5423e
2 changed files with 10 additions and 6 deletions

View file

@ -31,6 +31,10 @@ import (
"github.com/osbuild/osbuild-composer/internal/worker/clienterrors"
)
type GCPConfiguration struct {
Creds string
}
type S3Configuration struct {
Creds string
Endpoint string
@ -52,7 +56,7 @@ type OSBuildJobImpl struct {
Store string
Output string
KojiServers map[string]kojiServer
GCPCreds string
GCPConfig GCPConfiguration
AzureCreds *azure.Credentials
AWSCreds string
AWSBucket string
@ -160,9 +164,9 @@ func (impl *OSBuildJobImpl) getGCP(credentials []byte) (*gcp.GCP, error) {
if credentials != nil {
logrus.Info("[GCP] 🔑 using credentials provided with the job request")
return gcp.New(credentials)
} else if impl.GCPCreds != "" {
} else if impl.GCPConfig.Creds != "" {
logrus.Info("[GCP] 🔑 using credentials from the worker configuration")
return gcp.NewFromFile(impl.GCPCreds)
return gcp.NewFromFile(impl.GCPConfig.Creds)
} else {
logrus.Info("[GCP] 🔑 using Application Default Credentials via Google library")
return gcp.New(nil)

View file

@ -351,9 +351,9 @@ func main() {
// If the credentials are not provided in the configuration, then the
// worker will rely on the GCP library to authenticate using default means.
var gcpCredentials string
var gcpConfig GCPConfiguration
if config.GCP != nil {
gcpCredentials = config.GCP.Credentials
gcpConfig.Creds = config.GCP.Credentials
}
// If the credentials are not provided in the configuration, then the
@ -435,7 +435,7 @@ func main() {
Store: store,
Output: output,
KojiServers: kojiServers,
GCPCreds: gcpCredentials,
GCPConfig: gcpConfig,
AzureCreds: azureCredentials,
AWSCreds: awsCredentials,
AWSBucket: awsBucket,