New upload target: AWS S3

Uploads an artifact to an S£ bucket and returns a presigned URL to allow
the user to download the file.

Although it uses a lot of common code with the AWS AMI upload target,
it's treated as a completely separate target.
This commit is contained in:
Achilleas Koutsou 2021-05-27 14:52:32 +02:00 committed by Tom Gundersen
parent 14aea30bcd
commit e5b28c0bb3
8 changed files with 185 additions and 51 deletions

View file

@ -284,3 +284,17 @@ func (a *AWS) Register(name, bucket, key string, shareWith []string, rpmArch str
return registerOutput.ImageId, nil
}
func (a *AWS) S3ObjectPresignedURL(bucket, objectKey string) (string, error) {
log.Printf("[AWS] 📋 Generating Presigned URL for S3 object %s/%s", bucket, objectKey)
req, _ := a.s3.GetObjectRequest(&s3.GetObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(objectKey),
})
url, err := req.Presign(7 * 24 * time.Hour) // maximum allowed
if err != nil {
return "", err
}
log.Print("[AWS] 🎉 S3 Presigned URL ready")
return url, nil
}