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

View file

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