FEAT: Media Convert + s3 Integration
This commit is contained in:
@@ -2,8 +2,11 @@ package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
)
|
||||
|
||||
@@ -46,3 +49,38 @@ func (svc S3Concrete) DoesFileExist(ctx context.Context, key string) (bool, erro
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// AssertSuccessfulConnection verifies that the bucket is reachable and that
|
||||
// the configured credentials can get, put, and presign objects in it. It
|
||||
// panics with a descriptive message on the first check that fails, since the
|
||||
// service cannot function without these permissions.
|
||||
func (svc S3Concrete) AssertSuccessfulConnection(ctx context.Context) {
|
||||
if _, err := svc.S3Client.HeadBucket(ctx, &s3.HeadBucketInput{
|
||||
Bucket: &svc.Bucket,
|
||||
}); err != nil {
|
||||
panic(fmt.Errorf("s3: cannot connect to bucket %q: %w", svc.Bucket, err))
|
||||
}
|
||||
|
||||
const probeKey = ".s3-connectivity-check"
|
||||
|
||||
if _, err := svc.S3Client.PutObject(ctx, &s3.PutObjectInput{
|
||||
Bucket: &svc.Bucket,
|
||||
Key: aws.String(probeKey),
|
||||
Body: strings.NewReader("ok"),
|
||||
}); err != nil {
|
||||
panic(fmt.Errorf("s3: missing permission to put objects in bucket %q: %w", svc.Bucket, err))
|
||||
}
|
||||
|
||||
object, err := svc.S3Client.GetObject(ctx, &s3.GetObjectInput{
|
||||
Bucket: &svc.Bucket,
|
||||
Key: aws.String(probeKey),
|
||||
})
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("s3: missing permission to get objects from bucket %q: %w", svc.Bucket, err))
|
||||
}
|
||||
object.Body.Close()
|
||||
|
||||
if _, err := svc.GetPresignedURL(ctx, probeKey, "text/plain", time.Minute); err != nil {
|
||||
panic(fmt.Errorf("s3: cannot create presigned urls for bucket %q: %w", svc.Bucket, err))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user