cmd/osbuild-worker: Configure s3 bucket on the worker itself

Parameterize aws section of worker config. If credentials is empty,
the iam role will be used.
This commit is contained in:
Sanne Raymaekers 2022-03-08 11:27:29 +01:00
parent 3a2002f557
commit 63a0bbc1f2
3 changed files with 16 additions and 5 deletions

View file

@ -36,6 +36,7 @@ type OSBuildJobImpl struct {
GCPCreds []byte
AzureCreds *azure.Credentials
AWSCreds string
AWSBucket string
}
// Returns an *awscloud.AWS object with the credentials of the request. If they
@ -268,13 +269,17 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
key = uuid.New().String()
}
_, err = a.Upload(path.Join(outputDirectory, exportPath, options.Filename), options.Bucket, key)
bucket := options.Bucket
if impl.AWSBucket != "" {
bucket = impl.AWSBucket
}
_, err = a.Upload(path.Join(outputDirectory, exportPath, options.Filename), bucket, key)
if err != nil {
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error())
return nil
}
ami, err := a.Register(args.Targets[0].ImageName, options.Bucket, key, options.ShareWithAccounts, common.CurrentArch())
ami, err := a.Register(args.Targets[0].ImageName, bucket, key, options.ShareWithAccounts, common.CurrentArch())
if err != nil {
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorImportingImage, err.Error())
return nil
@ -305,12 +310,16 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
}
key += "-" + options.Filename
_, err = a.Upload(path.Join(outputDirectory, exportPath, options.Filename), options.Bucket, key)
bucket := options.Bucket
if impl.AWSBucket != "" {
bucket = impl.AWSBucket
}
_, err = a.Upload(path.Join(outputDirectory, exportPath, options.Filename), bucket, key)
if err != nil {
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error())
return nil
}
url, err := a.S3ObjectPresignedURL(options.Bucket, key)
url, err := a.S3ObjectPresignedURL(bucket, key)
if err != nil {
osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error())
return nil

View file

@ -137,6 +137,7 @@ func main() {
} `toml:"azure"`
AWS *struct {
Credentials string `toml:"credentials"`
Bucket string `toml:"bucket"`
} `toml:"aws"`
Authentication *struct {
OAuthURL string `toml:"oauth_url"`