Skip to content

Commit

Permalink
Move ec2 module to shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
timj-hh committed Oct 25, 2023
1 parent 6166b6e commit b518605
Show file tree
Hide file tree
Showing 80 changed files with 198,627 additions and 29 deletions.
2 changes: 1 addition & 1 deletion agent/api/ecsclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (

"github.com/aws/amazon-ecs-agent/agent/api"
"github.com/aws/amazon-ecs-agent/agent/config"
"github.com/aws/amazon-ecs-agent/agent/ec2"
"github.com/aws/amazon-ecs-agent/agent/utils"
agentversion "github.com/aws/amazon-ecs-agent/agent/version"
apicontainerstatus "github.com/aws/amazon-ecs-agent/ecs-agent/api/container/status"
apierrors "github.com/aws/amazon-ecs-agent/ecs-agent/api/errors"
"github.com/aws/amazon-ecs-agent/ecs-agent/async"
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials/instancecreds"
"github.com/aws/amazon-ecs-agent/ecs-agent/ec2"
"github.com/aws/amazon-ecs-agent/ecs-agent/ecs_client/model/ecs"
"github.com/aws/amazon-ecs-agent/ecs-agent/httpclient"
"github.com/aws/amazon-ecs-agent/ecs-agent/logger"
Expand Down
4 changes: 2 additions & 2 deletions agent/api/ecsclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ import (
apicontainer "github.com/aws/amazon-ecs-agent/agent/api/container"
mock_api "github.com/aws/amazon-ecs-agent/agent/api/mocks"
"github.com/aws/amazon-ecs-agent/agent/config"
"github.com/aws/amazon-ecs-agent/agent/ec2"
mock_ec2 "github.com/aws/amazon-ecs-agent/agent/ec2/mocks"
"github.com/aws/amazon-ecs-agent/ecs-agent/api/attachment"
apicontainerstatus "github.com/aws/amazon-ecs-agent/ecs-agent/api/container/status"
apitaskstatus "github.com/aws/amazon-ecs-agent/ecs-agent/api/task/status"
"github.com/aws/amazon-ecs-agent/ecs-agent/async"
mock_async "github.com/aws/amazon-ecs-agent/ecs-agent/async/mocks"
"github.com/aws/amazon-ecs-agent/ecs-agent/ec2"
mock_ec2 "github.com/aws/amazon-ecs-agent/ecs-agent/ec2/mocks"
"github.com/aws/amazon-ecs-agent/ecs-agent/ecs_client/model/ecs"
ni "github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
"github.com/aws/aws-sdk-go/aws"
Expand Down
2 changes: 1 addition & 1 deletion agent/app/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/aws/amazon-ecs-agent/agent/dockerclient/sdkclientfactory"
dockerdoctor "github.com/aws/amazon-ecs-agent/agent/doctor" // for Docker specific container instance health checks
ebs "github.com/aws/amazon-ecs-agent/agent/ebs"
"github.com/aws/amazon-ecs-agent/agent/ec2"
"github.com/aws/amazon-ecs-agent/agent/ecscni"
"github.com/aws/amazon-ecs-agent/agent/engine"
dm "github.com/aws/amazon-ecs-agent/agent/engine/daemonmanager"
Expand Down Expand Up @@ -61,6 +60,7 @@ import (
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials/instancecreds"
"github.com/aws/amazon-ecs-agent/ecs-agent/doctor"
"github.com/aws/amazon-ecs-agent/ecs-agent/ec2"
"github.com/aws/amazon-ecs-agent/ecs-agent/ecs_client/model/ecs"
"github.com/aws/amazon-ecs-agent/ecs-agent/eventstream"
"github.com/aws/amazon-ecs-agent/ecs-agent/logger"
Expand Down
2 changes: 1 addition & 1 deletion agent/app/agent_compatibility_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
apitask "github.com/aws/amazon-ecs-agent/agent/api/task"
"github.com/aws/amazon-ecs-agent/agent/config"
"github.com/aws/amazon-ecs-agent/agent/data"
"github.com/aws/amazon-ecs-agent/agent/ec2"
"github.com/aws/amazon-ecs-agent/agent/engine/dockerstate"
mock_statemanager "github.com/aws/amazon-ecs-agent/agent/statemanager/mocks"
"github.com/aws/amazon-ecs-agent/ecs-agent/ec2"
"github.com/aws/amazon-ecs-agent/ecs-agent/eventstream"

"github.com/golang/mock/gomock"
Expand Down
2 changes: 1 addition & 1 deletion agent/app/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/aws/amazon-ecs-agent/agent/dockerclient"
"github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi"
mock_dockerapi "github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi/mocks"
mock_ec2 "github.com/aws/amazon-ecs-agent/agent/ec2/mocks"
"github.com/aws/amazon-ecs-agent/agent/engine"
"github.com/aws/amazon-ecs-agent/agent/engine/daemonmanager"
dm "github.com/aws/amazon-ecs-agent/agent/engine/daemonmanager"
Expand All @@ -53,6 +52,7 @@ import (
"github.com/aws/amazon-ecs-agent/agent/version"
apierrors "github.com/aws/amazon-ecs-agent/ecs-agent/api/errors"
mock_credentials "github.com/aws/amazon-ecs-agent/ecs-agent/credentials/mocks"
mock_ec2 "github.com/aws/amazon-ecs-agent/ecs-agent/ec2/mocks"
"github.com/aws/amazon-ecs-agent/ecs-agent/ecs_client/model/ecs"
"github.com/aws/amazon-ecs-agent/ecs-agent/eventstream"
md "github.com/aws/amazon-ecs-agent/ecs-agent/manageddaemon"
Expand Down
2 changes: 1 addition & 1 deletion agent/app/agent_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/aws/amazon-ecs-agent/agent/config"
"github.com/aws/amazon-ecs-agent/agent/data"
"github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi"
mock_ec2 "github.com/aws/amazon-ecs-agent/agent/ec2/mocks"
"github.com/aws/amazon-ecs-agent/agent/ecscni"
mock_ecscni "github.com/aws/amazon-ecs-agent/agent/ecscni/mocks"
"github.com/aws/amazon-ecs-agent/agent/engine"
Expand All @@ -43,6 +42,7 @@ import (
"github.com/aws/amazon-ecs-agent/agent/taskresource/cgroup/control/mock_control"
mock_loader "github.com/aws/amazon-ecs-agent/agent/utils/loader/mocks"
mock_mobypkgwrapper "github.com/aws/amazon-ecs-agent/agent/utils/mobypkgwrapper/mocks"
mock_ec2 "github.com/aws/amazon-ecs-agent/ecs-agent/ec2/mocks"
"github.com/aws/amazon-ecs-agent/ecs-agent/ecs_client/model/ecs"
"github.com/aws/amazon-ecs-agent/ecs-agent/eventstream"
md "github.com/aws/amazon-ecs-agent/ecs-agent/manageddaemon"
Expand Down
2 changes: 1 addition & 1 deletion agent/app/agent_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import (

"github.com/aws/amazon-ecs-agent/agent/config"
"github.com/aws/amazon-ecs-agent/agent/data"
"github.com/aws/amazon-ecs-agent/agent/ec2"
mock_dockerstate "github.com/aws/amazon-ecs-agent/agent/engine/dockerstate/mocks"
mock_engine "github.com/aws/amazon-ecs-agent/agent/engine/mocks"
"github.com/aws/amazon-ecs-agent/agent/sighandlers"
"github.com/aws/amazon-ecs-agent/agent/sighandlers/exitcodes"
statemanager_mocks "github.com/aws/amazon-ecs-agent/agent/statemanager/mocks"
"github.com/aws/amazon-ecs-agent/ecs-agent/ec2"
"github.com/aws/amazon-ecs-agent/ecs-agent/eventstream"

"github.com/golang/mock/gomock"
Expand Down
2 changes: 1 addition & 1 deletion agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"time"

"github.com/aws/amazon-ecs-agent/agent/dockerclient"
"github.com/aws/amazon-ecs-agent/agent/ec2"
"github.com/aws/amazon-ecs-agent/agent/utils"
apierrors "github.com/aws/amazon-ecs-agent/ecs-agent/api/errors"
"github.com/aws/amazon-ecs-agent/ecs-agent/ec2"
commonutils "github.com/aws/amazon-ecs-agent/ecs-agent/utils"
"github.com/cihub/seelog"
)
Expand Down
4 changes: 2 additions & 2 deletions agent/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
"time"

"github.com/aws/amazon-ecs-agent/agent/dockerclient"
"github.com/aws/amazon-ecs-agent/agent/ec2"
mock_ec2 "github.com/aws/amazon-ecs-agent/agent/ec2/mocks"
"github.com/aws/amazon-ecs-agent/agent/utils"
"github.com/aws/amazon-ecs-agent/ecs-agent/ec2"
mock_ec2 "github.com/aws/amazon-ecs-agent/ecs-agent/ec2/mocks"

"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/golang/mock/gomock"
Expand Down
2 changes: 1 addition & 1 deletion agent/config/config_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/aws/amazon-ecs-agent/agent/dockerclient"
"github.com/aws/amazon-ecs-agent/agent/ec2"
"github.com/aws/amazon-ecs-agent/ecs-agent/ec2"
)

func TestConfigDefault(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion agent/config/config_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"golang.org/x/sys/windows"

"github.com/aws/amazon-ecs-agent/agent/dockerclient"
"github.com/aws/amazon-ecs-agent/agent/ec2"
"github.com/aws/amazon-ecs-agent/ecs-agent/ec2"
"github.com/aws/amazon-ecs-agent/ecs-agent/tmds"

"github.com/hectane/go-acl/api"
Expand Down
2 changes: 1 addition & 1 deletion agent/dockerclient/dockerapi/docker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ import (
"github.com/aws/amazon-ecs-agent/agent/dockerclient"
mock_sdkclient "github.com/aws/amazon-ecs-agent/agent/dockerclient/sdkclient/mocks"
mock_sdkclientfactory "github.com/aws/amazon-ecs-agent/agent/dockerclient/sdkclientfactory/mocks"
"github.com/aws/amazon-ecs-agent/agent/ec2"
mock_ecr "github.com/aws/amazon-ecs-agent/agent/ecr/mocks"
ecrapi "github.com/aws/amazon-ecs-agent/agent/ecr/model/ecr"
apicontainerstatus "github.com/aws/amazon-ecs-agent/ecs-agent/api/container/status"
apierrors "github.com/aws/amazon-ecs-agent/ecs-agent/api/errors"
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"
"github.com/aws/amazon-ecs-agent/ecs-agent/ec2"
"github.com/aws/amazon-ecs-agent/ecs-agent/utils/retry"
mock_ttime "github.com/aws/amazon-ecs-agent/ecs-agent/utils/ttime/mocks"

Expand Down
2 changes: 1 addition & 1 deletion agent/engine/common_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/aws/amazon-ecs-agent/agent/data"
"github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi"
"github.com/aws/amazon-ecs-agent/agent/dockerclient/sdkclientfactory"
"github.com/aws/amazon-ecs-agent/agent/ec2"
"github.com/aws/amazon-ecs-agent/agent/engine/dockerstate"
"github.com/aws/amazon-ecs-agent/agent/engine/execcmd"
engineserviceconnect "github.com/aws/amazon-ecs-agent/agent/engine/serviceconnect"
Expand All @@ -42,6 +41,7 @@ import (
apicontainerstatus "github.com/aws/amazon-ecs-agent/ecs-agent/api/container/status"
apitaskstatus "github.com/aws/amazon-ecs-agent/ecs-agent/api/task/status"
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"
"github.com/aws/amazon-ecs-agent/ecs-agent/ec2"
"github.com/aws/amazon-ecs-agent/ecs-agent/eventstream"
log "github.com/cihub/seelog"
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion agent/engine/docker_image_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import (
"github.com/aws/amazon-ecs-agent/agent/dockerclient"
"github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi"
mock_dockerapi "github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi/mocks"
"github.com/aws/amazon-ecs-agent/agent/ec2"
"github.com/aws/amazon-ecs-agent/agent/engine/dockerstate"
"github.com/aws/amazon-ecs-agent/agent/engine/image"
"github.com/aws/amazon-ecs-agent/ecs-agent/ec2"

"github.com/docker/docker/api/types"
"github.com/golang/mock/gomock"
Expand Down
2 changes: 1 addition & 1 deletion agent/engine/engine_sudo_linux_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import (
"github.com/aws/amazon-ecs-agent/agent/data"
"github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi"
"github.com/aws/amazon-ecs-agent/agent/dockerclient/sdkclientfactory"
"github.com/aws/amazon-ecs-agent/agent/ec2"
"github.com/aws/amazon-ecs-agent/agent/engine/dockerstate"
"github.com/aws/amazon-ecs-agent/agent/engine/execcmd"
engineserviceconnect "github.com/aws/amazon-ecs-agent/agent/engine/serviceconnect"
Expand All @@ -68,6 +67,7 @@ import (
apicontainerstatus "github.com/aws/amazon-ecs-agent/ecs-agent/api/container/status"
apitaskstatus "github.com/aws/amazon-ecs-agent/ecs-agent/api/task/status"
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"
"github.com/aws/amazon-ecs-agent/ecs-agent/ec2"
"github.com/aws/amazon-ecs-agent/ecs-agent/ecs_client/model/ecs"
"github.com/aws/amazon-ecs-agent/ecs-agent/eventstream"
)
Expand Down
2 changes: 1 addition & 1 deletion agent/engine/engine_windows_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/aws/amazon-ecs-agent/agent/data"
"github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi"
"github.com/aws/amazon-ecs-agent/agent/dockerclient/sdkclientfactory"
"github.com/aws/amazon-ecs-agent/agent/ec2"
"github.com/aws/amazon-ecs-agent/agent/engine/dockerstate"
"github.com/aws/amazon-ecs-agent/agent/engine/execcmd"
engineserviceconnect "github.com/aws/amazon-ecs-agent/agent/engine/serviceconnect"
Expand All @@ -49,6 +48,7 @@ import (
apicontainerstatus "github.com/aws/amazon-ecs-agent/ecs-agent/api/container/status"
apitaskstatus "github.com/aws/amazon-ecs-agent/ecs-agent/api/task/status"
"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"
"github.com/aws/amazon-ecs-agent/ecs-agent/ec2"
"github.com/aws/amazon-ecs-agent/ecs-agent/ecs_client/model/ecs"
"github.com/aws/amazon-ecs-agent/ecs-agent/eventstream"

Expand Down
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions agent/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ github.com/aws/amazon-ecs-agent/ecs-agent/csiclient
github.com/aws/amazon-ecs-agent/ecs-agent/csiclient/mocks
github.com/aws/amazon-ecs-agent/ecs-agent/data
github.com/aws/amazon-ecs-agent/ecs-agent/doctor
github.com/aws/amazon-ecs-agent/ecs-agent/ec2
github.com/aws/amazon-ecs-agent/ecs-agent/ec2/mocks
github.com/aws/amazon-ecs-agent/ecs-agent/ecs_client/model/ecs
github.com/aws/amazon-ecs-agent/ecs-agent/eventstream
github.com/aws/amazon-ecs-agent/ecs-agent/httpclient
Expand Down
90 changes: 90 additions & 0 deletions ecs-agent/ec2/blackhole_ec2_metadata_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package ec2

import (
"errors"

"github.com/aws/aws-sdk-go/aws/ec2metadata"
)

type blackholeMetadataClient struct{}

func NewBlackholeEC2MetadataClient() EC2MetadataClient {
return blackholeMetadataClient{}
}

func (blackholeMetadataClient) DefaultCredentials() (*RoleCredentials, error) {
return nil, errors.New("blackholed")
}

func (blackholeMetadataClient) InstanceIdentityDocument() (ec2metadata.EC2InstanceIdentityDocument, error) {
return ec2metadata.EC2InstanceIdentityDocument{}, errors.New("blackholed")
}

func (blackholeMetadataClient) PrimaryENIMAC() (string, error) {
return "", errors.New("blackholed")
}

func (blackholeMetadataClient) AllENIMacs() (string, error) {
return "", errors.New("blackholed")
}

func (blackholeMetadataClient) VPCID(mac string) (string, error) {
return "", errors.New("blackholed")
}

func (blackholeMetadataClient) SubnetID(mac string) (string, error) {
return "", errors.New("blackholed")
}

func (blackholeMetadataClient) InstanceID() (string, error) {
return "", errors.New("blackholed")
}

func (blackholeMetadataClient) GetMetadata(path string) (string, error) {
return "", errors.New("blackholed")
}

func (blackholeMetadataClient) GetDynamicData(path string) (string, error) {
return "", errors.New("blackholed")
}

func (blackholeMetadataClient) GetUserData() (string, error) {
return "", errors.New("blackholed")
}

func (blackholeMetadataClient) Region() (string, error) {
return "", errors.New("blackholed")
}

func (blackholeMetadataClient) PrivateIPv4Address() (string, error) {
return "", errors.New("blackholed")
}

func (blackholeMetadataClient) PublicIPv4Address() (string, error) {
return "", errors.New("blackholed")
}

func (blackholeMetadataClient) SpotInstanceAction() (string, error) {
return "", errors.New("blackholed")
}

func (blackholeMetadataClient) OutpostARN() (string, error) {
return "", errors.New("blackholed")
}

func (blackholeMetadataClient) TargetLifecycleState() (string, error) {
return "", errors.New("blackholed")
}
Loading

0 comments on commit b518605

Please sign in to comment.