worker: add an option to upload public objects to aws.s3 target
If the object is marked as public, its direct download URL will be returned instead of the presigned one. Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
parent
0e6c132ee6
commit
54e2c2304c
2 changed files with 13 additions and 3 deletions
|
|
@ -185,7 +185,7 @@ func validateResult(result *worker.OSBuildJobResult, jobID string) {
|
|||
result.Success = true
|
||||
}
|
||||
|
||||
func uploadToS3(a *awscloud.AWS, outputDirectory, exportPath, bucket, key, filename string) (string, *clienterrors.Error) {
|
||||
func uploadToS3(a *awscloud.AWS, outputDirectory, exportPath, bucket, key, filename string, public bool) (string, *clienterrors.Error) {
|
||||
imagePath := path.Join(outputDirectory, exportPath, filename)
|
||||
|
||||
if key == "" {
|
||||
|
|
@ -193,12 +193,21 @@ func uploadToS3(a *awscloud.AWS, outputDirectory, exportPath, bucket, key, filen
|
|||
}
|
||||
key += "-" + filename
|
||||
|
||||
_, err := a.Upload(imagePath, bucket, key)
|
||||
result, err := a.Upload(imagePath, bucket, key)
|
||||
if err != nil {
|
||||
return "", clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
|
||||
}
|
||||
|
||||
if public {
|
||||
err := a.MarkS3ObjectAsPublic(bucket, key)
|
||||
if err != nil {
|
||||
return "", clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
}
|
||||
|
||||
return result.Location, nil
|
||||
}
|
||||
|
||||
url, err := a.S3ObjectPresignedURL(bucket, key)
|
||||
if err != nil {
|
||||
return "", clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
|
|
@ -506,7 +515,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
break
|
||||
}
|
||||
|
||||
url, targetError := uploadToS3(a, outputDirectory, jobTarget.OsbuildArtifact.ExportName, bucket, targetOptions.Key, jobTarget.OsbuildArtifact.ExportFilename)
|
||||
url, targetError := uploadToS3(a, outputDirectory, jobTarget.OsbuildArtifact.ExportName, bucket, targetOptions.Key, jobTarget.OsbuildArtifact.ExportFilename, targetOptions.Public)
|
||||
if targetError != nil {
|
||||
targetResult.TargetError = targetError
|
||||
break
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ type AWSS3TargetOptions struct {
|
|||
Endpoint string `json:"endpoint"`
|
||||
CABundle string `json:"ca_bundle"`
|
||||
SkipSSLVerification bool `json:"skip_ssl_verification"`
|
||||
Public bool `json:"public,omitempty"`
|
||||
}
|
||||
|
||||
func (AWSS3TargetOptions) isTargetOptions() {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue