diff --git a/go.mod b/go.mod index 20479a5d..c65fec5b 100644 --- a/go.mod +++ b/go.mod @@ -8,9 +8,9 @@ require ( github.com/aws/aws-sdk-go-v2/credentials v1.6.4 github.com/aws/aws-sdk-go-v2/service/ec2 v1.24.0 github.com/aws/smithy-go v1.9.0 + github.com/golang/mock v1.6.0 github.com/openshift-online/ocm-sdk-go v0.1.224 github.com/spf13/cobra v1.8.0 - go.uber.org/mock v0.4.0 golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb google.golang.org/api v0.84.0 ) @@ -34,7 +34,7 @@ require ( github.com/spf13/pflag v1.0.5 // indirect go.opencensus.io v0.23.0 // indirect golang.org/x/net v0.0.0-20220607020251-c690dde0001d // indirect - golang.org/x/sys v0.1.0 // indirect + golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d // indirect golang.org/x/text v0.3.7 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90 // indirect diff --git a/go.sum b/go.sum index 94c06853..b49c4462 100644 --- a/go.sum +++ b/go.sum @@ -210,6 +210,7 @@ github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -576,8 +577,6 @@ go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= -go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= -go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= @@ -802,9 +801,8 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d h1:Zu/JngovGLVi6t2J3nmAf3AoTDwuzw85YZ3b9o4yU7s= golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= -golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= diff --git a/pkg/clients/aws/aws.go b/pkg/clients/aws/aws.go index 70836750..2ba7561a 100644 --- a/pkg/clients/aws/aws.go +++ b/pkg/clients/aws/aws.go @@ -83,17 +83,12 @@ type EC2Client interface { ImportKeyPair(ctx context.Context, params *ec2.ImportKeyPairInput, optFns ...func(*ec2.Options)) (*ec2.ImportKeyPairOutput, error) DeleteKeyPair(ctx context.Context, params *ec2.DeleteKeyPairInput, optFns ...func(*ec2.Options)) (*ec2.DeleteKeyPairOutput, error) DescribeKeyPairs(ctx context.Context, params *ec2.DescribeKeyPairsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeKeyPairsOutput, error) - ModifyInstanceAttribute(ctx context.Context, params *ec2.ModifyInstanceAttributeInput, optFns ...func(*ec2.Options)) (*ec2.ModifyInstanceAttributeOutput, error) } func (c *Client) DescribeKeyPairs(ctx context.Context, params *ec2.DescribeKeyPairsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeKeyPairsOutput, error) { return c.ec2Client.DescribeKeyPairs(ctx, params, optFns...) } -func (c *Client) ModifyInstanceAttribute(ctx context.Context, params *ec2.ModifyInstanceAttributeInput, optFns ...func(*ec2.Options)) (*ec2.ModifyInstanceAttributeOutput, error) { - return c.ec2Client.ModifyInstanceAttribute(ctx, params, optFns...) -} - func (c *Client) DescribeVpcAttribute(ctx context.Context, input *ec2.DescribeVpcAttributeInput, optFns ...func(*ec2.Options)) (*ec2.DescribeVpcAttributeOutput, error) { return c.ec2Client.DescribeVpcAttribute(ctx, input, optFns...) } diff --git a/pkg/mocks/mock_aws.go b/pkg/mocks/mock_aws.go index 0cf11e76..2ae61ed8 100644 --- a/pkg/mocks/mock_aws.go +++ b/pkg/mocks/mock_aws.go @@ -1,361 +1,335 @@ // Code generated by MockGen. DO NOT EDIT. // Source: pkg/clients/aws/aws.go -// -// Generated by this command: -// -// mockgen -source=pkg/clients/aws/aws.go -package mocks -destination=pkg/mocks/mock_aws.go -// // Package mocks is a generated GoMock package. package mocks import ( context "context" - reflect "reflect" - ec2 "github.com/aws/aws-sdk-go-v2/service/ec2" - gomock "go.uber.org/mock/gomock" + gomock "github.com/golang/mock/gomock" + reflect "reflect" ) -// MockEC2Client is a mock of EC2Client interface. +// MockEC2Client is a mock of EC2Client interface type MockEC2Client struct { ctrl *gomock.Controller recorder *MockEC2ClientMockRecorder } -// MockEC2ClientMockRecorder is the mock recorder for MockEC2Client. +// MockEC2ClientMockRecorder is the mock recorder for MockEC2Client type MockEC2ClientMockRecorder struct { mock *MockEC2Client } -// NewMockEC2Client creates a new mock instance. +// NewMockEC2Client creates a new mock instance func NewMockEC2Client(ctrl *gomock.Controller) *MockEC2Client { mock := &MockEC2Client{ctrl: ctrl} mock.recorder = &MockEC2ClientMockRecorder{mock} return mock } -// EXPECT returns an object that allows the caller to indicate expected use. +// EXPECT returns an object that allows the caller to indicate expected use func (m *MockEC2Client) EXPECT() *MockEC2ClientMockRecorder { return m.recorder } -// AuthorizeSecurityGroupEgress mocks base method. -func (m *MockEC2Client) AuthorizeSecurityGroupEgress(ctx context.Context, params *ec2.AuthorizeSecurityGroupEgressInput, optFns ...func(*ec2.Options)) (*ec2.AuthorizeSecurityGroupEgressOutput, error) { - m.ctrl.T.Helper() - varargs := []any{ctx, params} - for _, a := range optFns { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "AuthorizeSecurityGroupEgress", varargs...) - ret0, _ := ret[0].(*ec2.AuthorizeSecurityGroupEgressOutput) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// AuthorizeSecurityGroupEgress indicates an expected call of AuthorizeSecurityGroupEgress. -func (mr *MockEC2ClientMockRecorder) AuthorizeSecurityGroupEgress(ctx, params any, optFns ...any) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]any{ctx, params}, optFns...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AuthorizeSecurityGroupEgress", reflect.TypeOf((*MockEC2Client)(nil).AuthorizeSecurityGroupEgress), varargs...) -} - -// CreateSecurityGroup mocks base method. -func (m *MockEC2Client) CreateSecurityGroup(ctx context.Context, params *ec2.CreateSecurityGroupInput, optFns ...func(*ec2.Options)) (*ec2.CreateSecurityGroupOutput, error) { +// RunInstances mocks base method +func (m *MockEC2Client) RunInstances(ctx context.Context, params *ec2.RunInstancesInput, optFns ...func(*ec2.Options)) (*ec2.RunInstancesOutput, error) { m.ctrl.T.Helper() - varargs := []any{ctx, params} + varargs := []interface{}{ctx, params} for _, a := range optFns { varargs = append(varargs, a) } - ret := m.ctrl.Call(m, "CreateSecurityGroup", varargs...) - ret0, _ := ret[0].(*ec2.CreateSecurityGroupOutput) + ret := m.ctrl.Call(m, "RunInstances", varargs...) + ret0, _ := ret[0].(*ec2.RunInstancesOutput) ret1, _ := ret[1].(error) return ret0, ret1 } -// CreateSecurityGroup indicates an expected call of CreateSecurityGroup. -func (mr *MockEC2ClientMockRecorder) CreateSecurityGroup(ctx, params any, optFns ...any) *gomock.Call { +// RunInstances indicates an expected call of RunInstances +func (mr *MockEC2ClientMockRecorder) RunInstances(ctx, params interface{}, optFns ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]any{ctx, params}, optFns...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateSecurityGroup", reflect.TypeOf((*MockEC2Client)(nil).CreateSecurityGroup), varargs...) + varargs := append([]interface{}{ctx, params}, optFns...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RunInstances", reflect.TypeOf((*MockEC2Client)(nil).RunInstances), varargs...) } -// DeleteKeyPair mocks base method. -func (m *MockEC2Client) DeleteKeyPair(ctx context.Context, params *ec2.DeleteKeyPairInput, optFns ...func(*ec2.Options)) (*ec2.DeleteKeyPairOutput, error) { +// DescribeInstances mocks base method +func (m *MockEC2Client) DescribeInstances(ctx context.Context, params *ec2.DescribeInstancesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeInstancesOutput, error) { m.ctrl.T.Helper() - varargs := []any{ctx, params} + varargs := []interface{}{ctx, params} for _, a := range optFns { varargs = append(varargs, a) } - ret := m.ctrl.Call(m, "DeleteKeyPair", varargs...) - ret0, _ := ret[0].(*ec2.DeleteKeyPairOutput) + ret := m.ctrl.Call(m, "DescribeInstances", varargs...) + ret0, _ := ret[0].(*ec2.DescribeInstancesOutput) ret1, _ := ret[1].(error) return ret0, ret1 } -// DeleteKeyPair indicates an expected call of DeleteKeyPair. -func (mr *MockEC2ClientMockRecorder) DeleteKeyPair(ctx, params any, optFns ...any) *gomock.Call { +// DescribeInstances indicates an expected call of DescribeInstances +func (mr *MockEC2ClientMockRecorder) DescribeInstances(ctx, params interface{}, optFns ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]any{ctx, params}, optFns...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteKeyPair", reflect.TypeOf((*MockEC2Client)(nil).DeleteKeyPair), varargs...) + varargs := append([]interface{}{ctx, params}, optFns...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeInstances", reflect.TypeOf((*MockEC2Client)(nil).DescribeInstances), varargs...) } -// DeleteSecurityGroup mocks base method. -func (m *MockEC2Client) DeleteSecurityGroup(ctx context.Context, params *ec2.DeleteSecurityGroupInput, optFns ...func(*ec2.Options)) (*ec2.DeleteSecurityGroupOutput, error) { +// DescribeInstanceTypes mocks base method +func (m *MockEC2Client) DescribeInstanceTypes(ctx context.Context, input *ec2.DescribeInstanceTypesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeInstanceTypesOutput, error) { m.ctrl.T.Helper() - varargs := []any{ctx, params} + varargs := []interface{}{ctx, input} for _, a := range optFns { varargs = append(varargs, a) } - ret := m.ctrl.Call(m, "DeleteSecurityGroup", varargs...) - ret0, _ := ret[0].(*ec2.DeleteSecurityGroupOutput) + ret := m.ctrl.Call(m, "DescribeInstanceTypes", varargs...) + ret0, _ := ret[0].(*ec2.DescribeInstanceTypesOutput) ret1, _ := ret[1].(error) return ret0, ret1 } -// DeleteSecurityGroup indicates an expected call of DeleteSecurityGroup. -func (mr *MockEC2ClientMockRecorder) DeleteSecurityGroup(ctx, params any, optFns ...any) *gomock.Call { +// DescribeInstanceTypes indicates an expected call of DescribeInstanceTypes +func (mr *MockEC2ClientMockRecorder) DescribeInstanceTypes(ctx, input interface{}, optFns ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]any{ctx, params}, optFns...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteSecurityGroup", reflect.TypeOf((*MockEC2Client)(nil).DeleteSecurityGroup), varargs...) + varargs := append([]interface{}{ctx, input}, optFns...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeInstanceTypes", reflect.TypeOf((*MockEC2Client)(nil).DescribeInstanceTypes), varargs...) } -// DescribeInstanceTypes mocks base method. -func (m *MockEC2Client) DescribeInstanceTypes(ctx context.Context, input *ec2.DescribeInstanceTypesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeInstanceTypesOutput, error) { +// GetConsoleOutput mocks base method +func (m *MockEC2Client) GetConsoleOutput(ctx context.Context, input *ec2.GetConsoleOutputInput, optFns ...func(*ec2.Options)) (*ec2.GetConsoleOutputOutput, error) { m.ctrl.T.Helper() - varargs := []any{ctx, input} + varargs := []interface{}{ctx, input} for _, a := range optFns { varargs = append(varargs, a) } - ret := m.ctrl.Call(m, "DescribeInstanceTypes", varargs...) - ret0, _ := ret[0].(*ec2.DescribeInstanceTypesOutput) + ret := m.ctrl.Call(m, "GetConsoleOutput", varargs...) + ret0, _ := ret[0].(*ec2.GetConsoleOutputOutput) ret1, _ := ret[1].(error) return ret0, ret1 } -// DescribeInstanceTypes indicates an expected call of DescribeInstanceTypes. -func (mr *MockEC2ClientMockRecorder) DescribeInstanceTypes(ctx, input any, optFns ...any) *gomock.Call { +// GetConsoleOutput indicates an expected call of GetConsoleOutput +func (mr *MockEC2ClientMockRecorder) GetConsoleOutput(ctx, input interface{}, optFns ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]any{ctx, input}, optFns...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeInstanceTypes", reflect.TypeOf((*MockEC2Client)(nil).DescribeInstanceTypes), varargs...) + varargs := append([]interface{}{ctx, input}, optFns...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetConsoleOutput", reflect.TypeOf((*MockEC2Client)(nil).GetConsoleOutput), varargs...) } -// DescribeInstances mocks base method. -func (m *MockEC2Client) DescribeInstances(ctx context.Context, params *ec2.DescribeInstancesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeInstancesOutput, error) { +// TerminateInstances mocks base method +func (m *MockEC2Client) TerminateInstances(ctx context.Context, input *ec2.TerminateInstancesInput, optFns ...func(*ec2.Options)) (*ec2.TerminateInstancesOutput, error) { m.ctrl.T.Helper() - varargs := []any{ctx, params} + varargs := []interface{}{ctx, input} for _, a := range optFns { varargs = append(varargs, a) } - ret := m.ctrl.Call(m, "DescribeInstances", varargs...) - ret0, _ := ret[0].(*ec2.DescribeInstancesOutput) + ret := m.ctrl.Call(m, "TerminateInstances", varargs...) + ret0, _ := ret[0].(*ec2.TerminateInstancesOutput) ret1, _ := ret[1].(error) return ret0, ret1 } -// DescribeInstances indicates an expected call of DescribeInstances. -func (mr *MockEC2ClientMockRecorder) DescribeInstances(ctx, params any, optFns ...any) *gomock.Call { +// TerminateInstances indicates an expected call of TerminateInstances +func (mr *MockEC2ClientMockRecorder) TerminateInstances(ctx, input interface{}, optFns ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]any{ctx, params}, optFns...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeInstances", reflect.TypeOf((*MockEC2Client)(nil).DescribeInstances), varargs...) + varargs := append([]interface{}{ctx, input}, optFns...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TerminateInstances", reflect.TypeOf((*MockEC2Client)(nil).TerminateInstances), varargs...) } -// DescribeKeyPairs mocks base method. -func (m *MockEC2Client) DescribeKeyPairs(ctx context.Context, params *ec2.DescribeKeyPairsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeKeyPairsOutput, error) { +// DescribeVpcAttribute mocks base method +func (m *MockEC2Client) DescribeVpcAttribute(ctx context.Context, input *ec2.DescribeVpcAttributeInput, optFns ...func(*ec2.Options)) (*ec2.DescribeVpcAttributeOutput, error) { m.ctrl.T.Helper() - varargs := []any{ctx, params} + varargs := []interface{}{ctx, input} for _, a := range optFns { varargs = append(varargs, a) } - ret := m.ctrl.Call(m, "DescribeKeyPairs", varargs...) - ret0, _ := ret[0].(*ec2.DescribeKeyPairsOutput) + ret := m.ctrl.Call(m, "DescribeVpcAttribute", varargs...) + ret0, _ := ret[0].(*ec2.DescribeVpcAttributeOutput) ret1, _ := ret[1].(error) return ret0, ret1 } -// DescribeKeyPairs indicates an expected call of DescribeKeyPairs. -func (mr *MockEC2ClientMockRecorder) DescribeKeyPairs(ctx, params any, optFns ...any) *gomock.Call { +// DescribeVpcAttribute indicates an expected call of DescribeVpcAttribute +func (mr *MockEC2ClientMockRecorder) DescribeVpcAttribute(ctx, input interface{}, optFns ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]any{ctx, params}, optFns...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeKeyPairs", reflect.TypeOf((*MockEC2Client)(nil).DescribeKeyPairs), varargs...) + varargs := append([]interface{}{ctx, input}, optFns...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeVpcAttribute", reflect.TypeOf((*MockEC2Client)(nil).DescribeVpcAttribute), varargs...) } -// DescribeSecurityGroups mocks base method. -func (m *MockEC2Client) DescribeSecurityGroups(ctx context.Context, params *ec2.DescribeSecurityGroupsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeSecurityGroupsOutput, error) { +// CreateSecurityGroup mocks base method +func (m *MockEC2Client) CreateSecurityGroup(ctx context.Context, params *ec2.CreateSecurityGroupInput, optFns ...func(*ec2.Options)) (*ec2.CreateSecurityGroupOutput, error) { m.ctrl.T.Helper() - varargs := []any{ctx, params} + varargs := []interface{}{ctx, params} for _, a := range optFns { varargs = append(varargs, a) } - ret := m.ctrl.Call(m, "DescribeSecurityGroups", varargs...) - ret0, _ := ret[0].(*ec2.DescribeSecurityGroupsOutput) + ret := m.ctrl.Call(m, "CreateSecurityGroup", varargs...) + ret0, _ := ret[0].(*ec2.CreateSecurityGroupOutput) ret1, _ := ret[1].(error) return ret0, ret1 } -// DescribeSecurityGroups indicates an expected call of DescribeSecurityGroups. -func (mr *MockEC2ClientMockRecorder) DescribeSecurityGroups(ctx, params any, optFns ...any) *gomock.Call { +// CreateSecurityGroup indicates an expected call of CreateSecurityGroup +func (mr *MockEC2ClientMockRecorder) CreateSecurityGroup(ctx, params interface{}, optFns ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]any{ctx, params}, optFns...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeSecurityGroups", reflect.TypeOf((*MockEC2Client)(nil).DescribeSecurityGroups), varargs...) + varargs := append([]interface{}{ctx, params}, optFns...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateSecurityGroup", reflect.TypeOf((*MockEC2Client)(nil).CreateSecurityGroup), varargs...) } -// DescribeSubnets mocks base method. -func (m *MockEC2Client) DescribeSubnets(ctx context.Context, params *ec2.DescribeSubnetsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeSubnetsOutput, error) { +// DeleteSecurityGroup mocks base method +func (m *MockEC2Client) DeleteSecurityGroup(ctx context.Context, params *ec2.DeleteSecurityGroupInput, optFns ...func(*ec2.Options)) (*ec2.DeleteSecurityGroupOutput, error) { m.ctrl.T.Helper() - varargs := []any{ctx, params} + varargs := []interface{}{ctx, params} for _, a := range optFns { varargs = append(varargs, a) } - ret := m.ctrl.Call(m, "DescribeSubnets", varargs...) - ret0, _ := ret[0].(*ec2.DescribeSubnetsOutput) + ret := m.ctrl.Call(m, "DeleteSecurityGroup", varargs...) + ret0, _ := ret[0].(*ec2.DeleteSecurityGroupOutput) ret1, _ := ret[1].(error) return ret0, ret1 } -// DescribeSubnets indicates an expected call of DescribeSubnets. -func (mr *MockEC2ClientMockRecorder) DescribeSubnets(ctx, params any, optFns ...any) *gomock.Call { +// DeleteSecurityGroup indicates an expected call of DeleteSecurityGroup +func (mr *MockEC2ClientMockRecorder) DeleteSecurityGroup(ctx, params interface{}, optFns ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]any{ctx, params}, optFns...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeSubnets", reflect.TypeOf((*MockEC2Client)(nil).DescribeSubnets), varargs...) + varargs := append([]interface{}{ctx, params}, optFns...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteSecurityGroup", reflect.TypeOf((*MockEC2Client)(nil).DeleteSecurityGroup), varargs...) } -// DescribeVpcAttribute mocks base method. -func (m *MockEC2Client) DescribeVpcAttribute(ctx context.Context, input *ec2.DescribeVpcAttributeInput, optFns ...func(*ec2.Options)) (*ec2.DescribeVpcAttributeOutput, error) { +// DescribeSecurityGroups mocks base method +func (m *MockEC2Client) DescribeSecurityGroups(ctx context.Context, params *ec2.DescribeSecurityGroupsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeSecurityGroupsOutput, error) { m.ctrl.T.Helper() - varargs := []any{ctx, input} + varargs := []interface{}{ctx, params} for _, a := range optFns { varargs = append(varargs, a) } - ret := m.ctrl.Call(m, "DescribeVpcAttribute", varargs...) - ret0, _ := ret[0].(*ec2.DescribeVpcAttributeOutput) + ret := m.ctrl.Call(m, "DescribeSecurityGroups", varargs...) + ret0, _ := ret[0].(*ec2.DescribeSecurityGroupsOutput) ret1, _ := ret[1].(error) return ret0, ret1 } -// DescribeVpcAttribute indicates an expected call of DescribeVpcAttribute. -func (mr *MockEC2ClientMockRecorder) DescribeVpcAttribute(ctx, input any, optFns ...any) *gomock.Call { +// DescribeSecurityGroups indicates an expected call of DescribeSecurityGroups +func (mr *MockEC2ClientMockRecorder) DescribeSecurityGroups(ctx, params interface{}, optFns ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]any{ctx, input}, optFns...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeVpcAttribute", reflect.TypeOf((*MockEC2Client)(nil).DescribeVpcAttribute), varargs...) + varargs := append([]interface{}{ctx, params}, optFns...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeSecurityGroups", reflect.TypeOf((*MockEC2Client)(nil).DescribeSecurityGroups), varargs...) } -// GetConsoleOutput mocks base method. -func (m *MockEC2Client) GetConsoleOutput(ctx context.Context, input *ec2.GetConsoleOutputInput, optFns ...func(*ec2.Options)) (*ec2.GetConsoleOutputOutput, error) { +// AuthorizeSecurityGroupEgress mocks base method +func (m *MockEC2Client) AuthorizeSecurityGroupEgress(ctx context.Context, params *ec2.AuthorizeSecurityGroupEgressInput, optFns ...func(*ec2.Options)) (*ec2.AuthorizeSecurityGroupEgressOutput, error) { m.ctrl.T.Helper() - varargs := []any{ctx, input} + varargs := []interface{}{ctx, params} for _, a := range optFns { varargs = append(varargs, a) } - ret := m.ctrl.Call(m, "GetConsoleOutput", varargs...) - ret0, _ := ret[0].(*ec2.GetConsoleOutputOutput) + ret := m.ctrl.Call(m, "AuthorizeSecurityGroupEgress", varargs...) + ret0, _ := ret[0].(*ec2.AuthorizeSecurityGroupEgressOutput) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetConsoleOutput indicates an expected call of GetConsoleOutput. -func (mr *MockEC2ClientMockRecorder) GetConsoleOutput(ctx, input any, optFns ...any) *gomock.Call { +// AuthorizeSecurityGroupEgress indicates an expected call of AuthorizeSecurityGroupEgress +func (mr *MockEC2ClientMockRecorder) AuthorizeSecurityGroupEgress(ctx, params interface{}, optFns ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]any{ctx, input}, optFns...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetConsoleOutput", reflect.TypeOf((*MockEC2Client)(nil).GetConsoleOutput), varargs...) + varargs := append([]interface{}{ctx, params}, optFns...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AuthorizeSecurityGroupEgress", reflect.TypeOf((*MockEC2Client)(nil).AuthorizeSecurityGroupEgress), varargs...) } -// ImportKeyPair mocks base method. -func (m *MockEC2Client) ImportKeyPair(ctx context.Context, params *ec2.ImportKeyPairInput, optFns ...func(*ec2.Options)) (*ec2.ImportKeyPairOutput, error) { +// RevokeSecurityGroupEgress mocks base method +func (m *MockEC2Client) RevokeSecurityGroupEgress(ctx context.Context, params *ec2.RevokeSecurityGroupEgressInput, optFns ...func(*ec2.Options)) (*ec2.RevokeSecurityGroupEgressOutput, error) { m.ctrl.T.Helper() - varargs := []any{ctx, params} + varargs := []interface{}{ctx, params} for _, a := range optFns { varargs = append(varargs, a) } - ret := m.ctrl.Call(m, "ImportKeyPair", varargs...) - ret0, _ := ret[0].(*ec2.ImportKeyPairOutput) + ret := m.ctrl.Call(m, "RevokeSecurityGroupEgress", varargs...) + ret0, _ := ret[0].(*ec2.RevokeSecurityGroupEgressOutput) ret1, _ := ret[1].(error) return ret0, ret1 } -// ImportKeyPair indicates an expected call of ImportKeyPair. -func (mr *MockEC2ClientMockRecorder) ImportKeyPair(ctx, params any, optFns ...any) *gomock.Call { +// RevokeSecurityGroupEgress indicates an expected call of RevokeSecurityGroupEgress +func (mr *MockEC2ClientMockRecorder) RevokeSecurityGroupEgress(ctx, params interface{}, optFns ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]any{ctx, params}, optFns...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImportKeyPair", reflect.TypeOf((*MockEC2Client)(nil).ImportKeyPair), varargs...) + varargs := append([]interface{}{ctx, params}, optFns...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RevokeSecurityGroupEgress", reflect.TypeOf((*MockEC2Client)(nil).RevokeSecurityGroupEgress), varargs...) } -// ModifyInstanceAttribute mocks base method. -func (m *MockEC2Client) ModifyInstanceAttribute(ctx context.Context, params *ec2.ModifyInstanceAttributeInput, optFns ...func(*ec2.Options)) (*ec2.ModifyInstanceAttributeOutput, error) { +// DescribeSubnets mocks base method +func (m *MockEC2Client) DescribeSubnets(ctx context.Context, params *ec2.DescribeSubnetsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeSubnetsOutput, error) { m.ctrl.T.Helper() - varargs := []any{ctx, params} + varargs := []interface{}{ctx, params} for _, a := range optFns { varargs = append(varargs, a) } - ret := m.ctrl.Call(m, "ModifyInstanceAttribute", varargs...) - ret0, _ := ret[0].(*ec2.ModifyInstanceAttributeOutput) + ret := m.ctrl.Call(m, "DescribeSubnets", varargs...) + ret0, _ := ret[0].(*ec2.DescribeSubnetsOutput) ret1, _ := ret[1].(error) return ret0, ret1 } -// ModifyInstanceAttribute indicates an expected call of ModifyInstanceAttribute. -func (mr *MockEC2ClientMockRecorder) ModifyInstanceAttribute(ctx, params any, optFns ...any) *gomock.Call { +// DescribeSubnets indicates an expected call of DescribeSubnets +func (mr *MockEC2ClientMockRecorder) DescribeSubnets(ctx, params interface{}, optFns ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]any{ctx, params}, optFns...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ModifyInstanceAttribute", reflect.TypeOf((*MockEC2Client)(nil).ModifyInstanceAttribute), varargs...) + varargs := append([]interface{}{ctx, params}, optFns...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeSubnets", reflect.TypeOf((*MockEC2Client)(nil).DescribeSubnets), varargs...) } -// RevokeSecurityGroupEgress mocks base method. -func (m *MockEC2Client) RevokeSecurityGroupEgress(ctx context.Context, params *ec2.RevokeSecurityGroupEgressInput, optFns ...func(*ec2.Options)) (*ec2.RevokeSecurityGroupEgressOutput, error) { +// ImportKeyPair mocks base method +func (m *MockEC2Client) ImportKeyPair(ctx context.Context, params *ec2.ImportKeyPairInput, optFns ...func(*ec2.Options)) (*ec2.ImportKeyPairOutput, error) { m.ctrl.T.Helper() - varargs := []any{ctx, params} + varargs := []interface{}{ctx, params} for _, a := range optFns { varargs = append(varargs, a) } - ret := m.ctrl.Call(m, "RevokeSecurityGroupEgress", varargs...) - ret0, _ := ret[0].(*ec2.RevokeSecurityGroupEgressOutput) + ret := m.ctrl.Call(m, "ImportKeyPair", varargs...) + ret0, _ := ret[0].(*ec2.ImportKeyPairOutput) ret1, _ := ret[1].(error) return ret0, ret1 } -// RevokeSecurityGroupEgress indicates an expected call of RevokeSecurityGroupEgress. -func (mr *MockEC2ClientMockRecorder) RevokeSecurityGroupEgress(ctx, params any, optFns ...any) *gomock.Call { +// ImportKeyPair indicates an expected call of ImportKeyPair +func (mr *MockEC2ClientMockRecorder) ImportKeyPair(ctx, params interface{}, optFns ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]any{ctx, params}, optFns...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RevokeSecurityGroupEgress", reflect.TypeOf((*MockEC2Client)(nil).RevokeSecurityGroupEgress), varargs...) + varargs := append([]interface{}{ctx, params}, optFns...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImportKeyPair", reflect.TypeOf((*MockEC2Client)(nil).ImportKeyPair), varargs...) } -// RunInstances mocks base method. -func (m *MockEC2Client) RunInstances(ctx context.Context, params *ec2.RunInstancesInput, optFns ...func(*ec2.Options)) (*ec2.RunInstancesOutput, error) { +// DeleteKeyPair mocks base method +func (m *MockEC2Client) DeleteKeyPair(ctx context.Context, params *ec2.DeleteKeyPairInput, optFns ...func(*ec2.Options)) (*ec2.DeleteKeyPairOutput, error) { m.ctrl.T.Helper() - varargs := []any{ctx, params} + varargs := []interface{}{ctx, params} for _, a := range optFns { varargs = append(varargs, a) } - ret := m.ctrl.Call(m, "RunInstances", varargs...) - ret0, _ := ret[0].(*ec2.RunInstancesOutput) + ret := m.ctrl.Call(m, "DeleteKeyPair", varargs...) + ret0, _ := ret[0].(*ec2.DeleteKeyPairOutput) ret1, _ := ret[1].(error) return ret0, ret1 } -// RunInstances indicates an expected call of RunInstances. -func (mr *MockEC2ClientMockRecorder) RunInstances(ctx, params any, optFns ...any) *gomock.Call { +// DeleteKeyPair indicates an expected call of DeleteKeyPair +func (mr *MockEC2ClientMockRecorder) DeleteKeyPair(ctx, params interface{}, optFns ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]any{ctx, params}, optFns...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RunInstances", reflect.TypeOf((*MockEC2Client)(nil).RunInstances), varargs...) + varargs := append([]interface{}{ctx, params}, optFns...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteKeyPair", reflect.TypeOf((*MockEC2Client)(nil).DeleteKeyPair), varargs...) } -// TerminateInstances mocks base method. -func (m *MockEC2Client) TerminateInstances(ctx context.Context, input *ec2.TerminateInstancesInput, optFns ...func(*ec2.Options)) (*ec2.TerminateInstancesOutput, error) { +// DescribeKeyPairs mocks base method +func (m *MockEC2Client) DescribeKeyPairs(ctx context.Context, params *ec2.DescribeKeyPairsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeKeyPairsOutput, error) { m.ctrl.T.Helper() - varargs := []any{ctx, input} + varargs := []interface{}{ctx, params} for _, a := range optFns { varargs = append(varargs, a) } - ret := m.ctrl.Call(m, "TerminateInstances", varargs...) - ret0, _ := ret[0].(*ec2.TerminateInstancesOutput) + ret := m.ctrl.Call(m, "DescribeKeyPairs", varargs...) + ret0, _ := ret[0].(*ec2.DescribeKeyPairsOutput) ret1, _ := ret[1].(error) return ret0, ret1 } -// TerminateInstances indicates an expected call of TerminateInstances. -func (mr *MockEC2ClientMockRecorder) TerminateInstances(ctx, input any, optFns ...any) *gomock.Call { +// DescribeKeyPairs indicates an expected call of DescribeKeyPairs +func (mr *MockEC2ClientMockRecorder) DescribeKeyPairs(ctx, params interface{}, optFns ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]any{ctx, input}, optFns...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TerminateInstances", reflect.TypeOf((*MockEC2Client)(nil).TerminateInstances), varargs...) + varargs := append([]interface{}{ctx, params}, optFns...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeKeyPairs", reflect.TypeOf((*MockEC2Client)(nil).DescribeKeyPairs), varargs...) } diff --git a/pkg/verifier/aws/aws_verifier_test.go b/pkg/verifier/aws/aws_verifier_test.go index 7e215f59..22cfa4cc 100644 --- a/pkg/verifier/aws/aws_verifier_test.go +++ b/pkg/verifier/aws/aws_verifier_test.go @@ -9,10 +9,10 @@ import ( awss "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/ec2" ec2Types "github.com/aws/aws-sdk-go-v2/service/ec2/types" + "github.com/golang/mock/gomock" ocmlog "github.com/openshift-online/ocm-sdk-go/logging" "github.com/openshift/osd-network-verifier/pkg/clients/aws" "github.com/openshift/osd-network-verifier/pkg/mocks" - gomock "go.uber.org/mock/gomock" ) func TestFindUnreachableEndpointsSuccess(t *testing.T) { diff --git a/pkg/verifier/aws/entry_point.go b/pkg/verifier/aws/entry_point.go index 506af99e..efe07faa 100644 --- a/pkg/verifier/aws/entry_point.go +++ b/pkg/verifier/aws/entry_point.go @@ -144,18 +144,16 @@ func (a *AwsVerifier) ValidateEgress(vei verifier.ValidateEgressInput) *output.O } // If security group not given, create a temporary one - VpcId, err := a.GetVpcIdFromSubnetId(vei.Ctx, vei.SubnetID) - if err != nil { - return a.Output.AddError(err) - } - if vei.AWS.SecurityGroupId == "" && len(vei.AWS.SecurityGroupIDs) == 0 { - - createSecurityGroupOutput, err := a.CreateSecurityGroup(vei.Ctx, vei.Tags, "osd-network-verifier", VpcId) + vpcId, err := a.GetVpcIdFromSubnetId(vei.Ctx, vei.SubnetID) if err != nil { return a.Output.AddError(err) } + createSecurityGroupOutput, err := a.CreateSecurityGroup(vei.Ctx, vei.Tags, "osd-network-verifier", vpcId) + if err != nil { + return a.Output.AddError(err) + } vei.AWS.SecurityGroupId = *createSecurityGroupOutput.GroupId // Now that security group has been created, ensure we clean it up @@ -208,49 +206,6 @@ func (a *AwsVerifier) ValidateEgress(vei verifier.ValidateEgressInput) *output.O // Terminate the EC2 instance (unless user requests otherwise) if !vei.SkipInstanceTermination { - - //Replaced the SGs atached to the network-verifier-instance by the default SG in order to allow - //deletion of temporary SGs created - - //Getting a list of the SGs for the current VPC of our instance - var defaultSecurityGroupID = "" - - describeSGOutput, err := a.AwsClient.DescribeSecurityGroups(vei.Ctx, &ec2.DescribeSecurityGroupsInput{ - Filters: []ec2Types.Filter{ - { - Name: awsTools.String("vpc-id"), - Values: []string{VpcId}, - }, - { - Name: awsTools.String("group-name"), - Values: []string{"default"}, - }, - }, - }) - if err != nil { - a.Output.AddError(err) - } - - //Filtering SGs to get only the default SG ID finishing the iteration as soon as we find the default SG. - if describeSGOutput != nil { - - for _, SG := range describeSGOutput.SecurityGroups { - if *SG.GroupName == "default" { - defaultSecurityGroupID = *SG.GroupId - } - } - - //Replacing the SGs attach to instance by the default one. This is to clean the SGs created in case the instance - //termination times out - _, err = a.AwsClient.ModifyInstanceAttribute(vei.Ctx, &ec2.ModifyInstanceAttributeInput{ - InstanceId: &instanceID, - Groups: []string{defaultSecurityGroupID}, - }) - if err != nil { - a.Output.AddError(err) - } - } - a.Logger.Info(vei.Ctx, "Deleting instance with ID: %s", instanceID) if err := a.AwsClient.TerminateEC2Instance(vei.Ctx, instanceID); err != nil { a.Output.AddError(err)