worker/aws: don't generate object key in worker
There is a desire to make the worker as "dumb" as possible. Therefore it is not desired to generate the AWS object key names in the worker if it was not provided in the job. Modify the worker code to not generate the AWS object key in any case and instead set an error in case the object key was not provided. Modify Weldr API implementation to generate the object key, if it was not provided by the user. This is consistent with Cloud API implementation.
This commit is contained in:
parent
565b8d41c8
commit
13f0894094
2 changed files with 21 additions and 7 deletions
|
|
@ -468,9 +468,9 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
break
|
||||
}
|
||||
|
||||
key := targetOptions.Key
|
||||
if key == "" {
|
||||
key = uuid.New().String()
|
||||
if targetOptions.Key == "" {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, "No AWS object key provided", nil)
|
||||
break
|
||||
}
|
||||
|
||||
bucket := targetOptions.Bucket
|
||||
|
|
@ -496,13 +496,13 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
}
|
||||
}
|
||||
|
||||
_, err = a.Upload(imagePath, bucket, key)
|
||||
_, err = a.Upload(imagePath, bucket, targetOptions.Key)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
ami, err := a.Register(jobTarget.ImageName, bucket, key, targetOptions.ShareWithAccounts, common.CurrentArch())
|
||||
ami, err := a.Register(jobTarget.ImageName, bucket, targetOptions.Key, targetOptions.ShareWithAccounts, common.CurrentArch())
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorImportingImage, err.Error(), nil)
|
||||
break
|
||||
|
|
@ -525,6 +525,11 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
break
|
||||
}
|
||||
|
||||
if targetOptions.Key == "" {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, "No AWS object key provided", nil)
|
||||
break
|
||||
}
|
||||
|
||||
url, targetError := uploadToS3(a, outputDirectory, jobTarget.OsbuildArtifact.ExportName, bucket, targetOptions.Key, jobTarget.OsbuildArtifact.ExportFilename, targetOptions.Public)
|
||||
if targetError != nil {
|
||||
targetResult.TargetError = targetError
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue