From 13ba870fc6f7a164feb8a59fdf5e8c5fa48098f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Wed, 6 Aug 2025 13:46:59 +0200 Subject: [PATCH] internal/awscloud: use AWS.Upload() from osbuild/images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomáš Hozza --- internal/cloud/awscloud/awscloud.go | 24 ------------------------ internal/cloud/awscloud/awscloud_test.go | 12 ------------ 2 files changed, 36 deletions(-) diff --git a/internal/cloud/awscloud/awscloud.go b/internal/cloud/awscloud/awscloud.go index 9376b3be0..d80acc20f 100644 --- a/internal/cloud/awscloud/awscloud.go +++ b/internal/cloud/awscloud/awscloud.go @@ -218,30 +218,6 @@ func NewForEndpointFromFile(filename, endpoint, region, caBundle string, skipSSL return newAwsFromCredsWithEndpoint(config.WithSharedCredentialsFiles([]string{filename, "default"}), region, endpoint, caBundle, skipSSLVerification, imagesAWS) } -func (a *AWS) Upload(filename, bucket, key string) (*manager.UploadOutput, error) { - file, err := os.Open(filename) - if err != nil { - return nil, err - } - - defer func() { - err := file.Close() - if err != nil { - logrus.Warnf("[AWS] ‼ Failed to close the file uploaded to S3️: %v", err) - } - }() - - logrus.Infof("[AWS] 🚀 Uploading image to S3: %s/%s", bucket, key) - return a.s3uploader.Upload( - context.Background(), - &s3.PutObjectInput{ - Bucket: aws.String(bucket), - Key: aws.String(key), - Body: file, - }, - ) -} - // Register is a function that imports a snapshot, waits for the snapshot to // fully import, tags the snapshot, cleans up the image in S3, and registers // an AMI in AWS. diff --git a/internal/cloud/awscloud/awscloud_test.go b/internal/cloud/awscloud/awscloud_test.go index 1e3bb3695..7d8bbce7d 100644 --- a/internal/cloud/awscloud/awscloud_test.go +++ b/internal/cloud/awscloud/awscloud_test.go @@ -1,8 +1,6 @@ package awscloud_test import ( - "os" - "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -17,16 +15,6 @@ func TestS3MarkObjectAsPublic(t *testing.T) { require.NoError(t, aws.MarkS3ObjectAsPublic("bucket", "object-key")) } -func TestS3Upload(t *testing.T) { - tmpDir := t.TempDir() - require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "file"), []byte("imanimage"), 0600)) - - aws := awscloud.NewForTest(nil, nil, nil, &s3upldrmock{t, "imanimage", "bucket", "object-key"}, nil) - require.NotNil(t, aws) - _, err := aws.Upload(filepath.Join(tmpDir, "file"), "bucket", "object-key") - require.NoError(t, err) -} - func TestS3ObjectPresignedURL(t *testing.T) { aws := awscloud.NewForTest(nil, nil, nil, nil, &s3signmock{t, "bucket", "object-key"}) require.NotNil(t, aws)