internal/awscloud: remove S3 manager from AWS struct
This functionality is not needed any more, since it is provided by the osbuild/images version of AWS. Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
parent
0b5bfa044f
commit
4f0ae84add
7 changed files with 27 additions and 56 deletions
2
go.mod
2
go.mod
|
|
@ -12,7 +12,6 @@ require (
|
||||||
github.com/aws/aws-sdk-go-v2/config v1.30.3
|
github.com/aws/aws-sdk-go-v2/config v1.30.3
|
||||||
github.com/aws/aws-sdk-go-v2/credentials v1.18.3
|
github.com/aws/aws-sdk-go-v2/credentials v1.18.3
|
||||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.2
|
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.2
|
||||||
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.18.3
|
|
||||||
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.56.0
|
github.com/aws/aws-sdk-go-v2/service/autoscaling v1.56.0
|
||||||
github.com/aws/aws-sdk-go-v2/service/ec2 v1.241.0
|
github.com/aws/aws-sdk-go-v2/service/ec2 v1.241.0
|
||||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.86.0
|
github.com/aws/aws-sdk-go-v2/service/s3 v1.86.0
|
||||||
|
|
@ -79,6 +78,7 @@ require (
|
||||||
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
|
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
|
||||||
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
|
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.0 // indirect
|
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.0 // indirect
|
||||||
|
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.18.3 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.2 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.2 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.2 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.2 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"github.com/aws/aws-sdk-go-v2/config"
|
"github.com/aws/aws-sdk-go-v2/config"
|
||||||
"github.com/aws/aws-sdk-go-v2/credentials"
|
"github.com/aws/aws-sdk-go-v2/credentials"
|
||||||
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
|
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
|
||||||
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
|
|
||||||
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
|
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/ec2"
|
"github.com/aws/aws-sdk-go-v2/service/ec2"
|
||||||
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
|
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
|
||||||
|
|
@ -25,20 +24,18 @@ type AWS struct {
|
||||||
// related to image upload and sharing.
|
// related to image upload and sharing.
|
||||||
*images_awscloud.AWS
|
*images_awscloud.AWS
|
||||||
|
|
||||||
ec2 EC2
|
ec2 EC2
|
||||||
ec2imds EC2Imds
|
ec2imds EC2Imds
|
||||||
s3 S3
|
s3 S3
|
||||||
s3uploader S3Manager
|
asg ASG
|
||||||
asg ASG
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newForTest(ec2cli EC2, ec2imds EC2Imds, s3cli S3, upldr S3Manager) *AWS {
|
func newForTest(ec2cli EC2, ec2imds EC2Imds, s3cli S3) *AWS {
|
||||||
return &AWS{
|
return &AWS{
|
||||||
ec2: ec2cli,
|
ec2: ec2cli,
|
||||||
ec2imds: ec2imds,
|
ec2imds: ec2imds,
|
||||||
s3: s3cli,
|
s3: s3cli,
|
||||||
s3uploader: upldr,
|
asg: nil,
|
||||||
asg: nil,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,12 +44,11 @@ func newForTest(ec2cli EC2, ec2imds EC2Imds, s3cli S3, upldr S3Manager) *AWS {
|
||||||
func newAwsFromConfig(cfg aws.Config, imagesAWS *images_awscloud.AWS) *AWS {
|
func newAwsFromConfig(cfg aws.Config, imagesAWS *images_awscloud.AWS) *AWS {
|
||||||
s3cli := s3.NewFromConfig(cfg)
|
s3cli := s3.NewFromConfig(cfg)
|
||||||
return &AWS{
|
return &AWS{
|
||||||
AWS: imagesAWS,
|
AWS: imagesAWS,
|
||||||
ec2: ec2.NewFromConfig(cfg),
|
ec2: ec2.NewFromConfig(cfg),
|
||||||
ec2imds: imds.NewFromConfig(cfg),
|
ec2imds: imds.NewFromConfig(cfg),
|
||||||
s3: s3cli,
|
s3: s3cli,
|
||||||
s3uploader: manager.NewUploader(s3cli),
|
asg: autoscaling.NewFromConfig(cfg),
|
||||||
asg: autoscaling.NewFromConfig(cfg),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -177,12 +173,11 @@ func newAwsFromCredsWithEndpoint(creds config.LoadOptionsFunc, region, endpoint,
|
||||||
})
|
})
|
||||||
|
|
||||||
return &AWS{
|
return &AWS{
|
||||||
AWS: imagesAWS,
|
AWS: imagesAWS,
|
||||||
ec2: ec2.NewFromConfig(cfg),
|
ec2: ec2.NewFromConfig(cfg),
|
||||||
ec2imds: imds.NewFromConfig(cfg),
|
ec2imds: imds.NewFromConfig(cfg),
|
||||||
s3: s3cli,
|
s3: s3cli,
|
||||||
s3uploader: manager.NewUploader(s3cli),
|
asg: autoscaling.NewFromConfig(cfg),
|
||||||
asg: autoscaling.NewFromConfig(cfg),
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
func TestEC2CopyImage(t *testing.T) {
|
func TestEC2CopyImage(t *testing.T) {
|
||||||
m := newEc2Mock(t)
|
m := newEc2Mock(t)
|
||||||
aws := awscloud.NewForTest(m, nil, &s3mock{t, "bucket", "object-key"}, nil)
|
aws := awscloud.NewForTest(m, nil, &s3mock{t, "bucket", "object-key"})
|
||||||
imageId, err := aws.CopyImage("image-name", "image-id", "region")
|
imageId, err := aws.CopyImage("image-name", "image-id", "region")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, "image-id", imageId)
|
require.Equal(t, "image-id", imageId)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
|
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
|
||||||
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
|
|
||||||
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
|
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/ec2"
|
"github.com/aws/aws-sdk-go-v2/service/ec2"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
|
|
@ -65,7 +64,3 @@ type S3 interface {
|
||||||
DeleteObject(context.Context, *s3.DeleteObjectInput, ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)
|
DeleteObject(context.Context, *s3.DeleteObjectInput, ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)
|
||||||
PutObjectAcl(context.Context, *s3.PutObjectAclInput, ...func(*s3.Options)) (*s3.PutObjectAclOutput, error)
|
PutObjectAcl(context.Context, *s3.PutObjectAclInput, ...func(*s3.Options)) (*s3.PutObjectAclOutput, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type S3Manager interface {
|
|
||||||
Upload(context.Context, *s3.PutObjectInput, ...func(*manager.Uploader)) (*manager.UploadOutput, error)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
func TestEC2RemoveSnapshotAndDeregisterImage(t *testing.T) {
|
func TestEC2RemoveSnapshotAndDeregisterImage(t *testing.T) {
|
||||||
m := newEc2Mock(t)
|
m := newEc2Mock(t)
|
||||||
aws := awscloud.NewForTest(m, nil, &s3mock{t, "bucket", "object-key"}, nil)
|
aws := awscloud.NewForTest(m, nil, &s3mock{t, "bucket", "object-key"})
|
||||||
require.NotNil(t, aws)
|
require.NotNil(t, aws)
|
||||||
|
|
||||||
err := aws.RemoveSnapshotAndDeregisterImage(&ec2types.Image{
|
err := aws.RemoveSnapshotAndDeregisterImage(&ec2types.Image{
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,10 @@ package awscloud_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go-v2/aws"
|
"github.com/aws/aws-sdk-go-v2/aws"
|
||||||
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
|
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
|
||||||
"github.com/aws/aws-sdk-go-v2/feature/s3/manager"
|
|
||||||
"github.com/aws/aws-sdk-go-v2/service/ec2"
|
"github.com/aws/aws-sdk-go-v2/service/ec2"
|
||||||
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
|
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
|
|
@ -35,23 +33,6 @@ func (m *s3mock) PutObjectAcl(ctx context.Context, input *s3.PutObjectAclInput,
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type s3upldrmock struct {
|
|
||||||
t *testing.T
|
|
||||||
|
|
||||||
contents string
|
|
||||||
bucket string
|
|
||||||
key string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *s3upldrmock) Upload(ctx context.Context, input *s3.PutObjectInput, optfns ...func(*manager.Uploader)) (*manager.UploadOutput, error) {
|
|
||||||
body, err := io.ReadAll(input.Body)
|
|
||||||
require.NoError(m.t, err)
|
|
||||||
require.Equal(m.t, m.contents, string(body))
|
|
||||||
require.Equal(m.t, m.bucket, *input.Bucket)
|
|
||||||
require.Equal(m.t, m.key, *input.Key)
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type ec2imdsmock struct {
|
type ec2imdsmock struct {
|
||||||
t *testing.T
|
t *testing.T
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ write_files:
|
||||||
|
|
||||||
func TestSIRunSecureInstance(t *testing.T) {
|
func TestSIRunSecureInstance(t *testing.T) {
|
||||||
m := newEc2Mock(t)
|
m := newEc2Mock(t)
|
||||||
aws := awscloud.NewForTest(m, &ec2imdsmock{t, "instance-id", "region1"}, nil, nil)
|
aws := awscloud.NewForTest(m, &ec2imdsmock{t, "instance-id", "region1"}, nil)
|
||||||
require.NotNil(t, aws)
|
require.NotNil(t, aws)
|
||||||
|
|
||||||
si, err := aws.RunSecureInstance("iam-profile", "key-name", "cw-group", "hostname")
|
si, err := aws.RunSecureInstance("iam-profile", "key-name", "cw-group", "hostname")
|
||||||
|
|
@ -88,7 +88,7 @@ func TestSIRunSecureInstance(t *testing.T) {
|
||||||
|
|
||||||
func TestSITerminateSecureInstance(t *testing.T) {
|
func TestSITerminateSecureInstance(t *testing.T) {
|
||||||
m := newEc2Mock(t)
|
m := newEc2Mock(t)
|
||||||
aws := awscloud.NewForTest(m, &ec2imdsmock{t, "instance-id", "region1"}, nil, nil)
|
aws := awscloud.NewForTest(m, &ec2imdsmock{t, "instance-id", "region1"}, nil)
|
||||||
require.NotNil(t, aws)
|
require.NotNil(t, aws)
|
||||||
|
|
||||||
// Small hack, describeinstances returns terminate/running
|
// Small hack, describeinstances returns terminate/running
|
||||||
|
|
@ -110,7 +110,7 @@ func TestSITerminateSecureInstance(t *testing.T) {
|
||||||
|
|
||||||
func TestSICreateSGFailures(t *testing.T) {
|
func TestSICreateSGFailures(t *testing.T) {
|
||||||
m := newEc2Mock(t)
|
m := newEc2Mock(t)
|
||||||
aws := awscloud.NewForTest(m, &ec2imdsmock{t, "instance-id", "region1"}, nil, nil)
|
aws := awscloud.NewForTest(m, &ec2imdsmock{t, "instance-id", "region1"}, nil)
|
||||||
require.NotNil(t, aws)
|
require.NotNil(t, aws)
|
||||||
|
|
||||||
m.failFn["CreateSecurityGroup"] = fmt.Errorf("some-error")
|
m.failFn["CreateSecurityGroup"] = fmt.Errorf("some-error")
|
||||||
|
|
@ -126,7 +126,7 @@ func TestSICreateSGFailures(t *testing.T) {
|
||||||
|
|
||||||
func TestSICreateLTFailures(t *testing.T) {
|
func TestSICreateLTFailures(t *testing.T) {
|
||||||
m := newEc2Mock(t)
|
m := newEc2Mock(t)
|
||||||
aws := awscloud.NewForTest(m, &ec2imdsmock{t, "instance-id", "region1"}, nil, nil)
|
aws := awscloud.NewForTest(m, &ec2imdsmock{t, "instance-id", "region1"}, nil)
|
||||||
require.NotNil(t, aws)
|
require.NotNil(t, aws)
|
||||||
|
|
||||||
m.failFn["CreateLaunchTemplate"] = fmt.Errorf("some-error")
|
m.failFn["CreateLaunchTemplate"] = fmt.Errorf("some-error")
|
||||||
|
|
@ -142,7 +142,7 @@ func TestSICreateLTFailures(t *testing.T) {
|
||||||
|
|
||||||
func TestSICreateFleetFailures(t *testing.T) {
|
func TestSICreateFleetFailures(t *testing.T) {
|
||||||
m := newEc2Mock(t)
|
m := newEc2Mock(t)
|
||||||
aws := awscloud.NewForTest(m, &ec2imdsmock{t, "instance-id", "region1"}, nil, nil)
|
aws := awscloud.NewForTest(m, &ec2imdsmock{t, "instance-id", "region1"}, nil)
|
||||||
require.NotNil(t, aws)
|
require.NotNil(t, aws)
|
||||||
|
|
||||||
// create fleet error should call create fleet thrice
|
// create fleet error should call create fleet thrice
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue