Skip to content

Commit

Permalink
Update go modules' dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
danehlim committed Dec 3, 2024
1 parent 3165584 commit 0e64539
Show file tree
Hide file tree
Showing 579 changed files with 49,680 additions and 22,851 deletions.
3 changes: 2 additions & 1 deletion agent/api/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/cihub/seelog"
"github.com/docker/docker/api/types"
dockercontainer "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/registry"
)

const (
Expand Down Expand Up @@ -977,7 +978,7 @@ func (c *Container) ShouldPullWithASMAuth() bool {
// SetASMDockerAuthConfig add the docker auth config data to the
// RegistryAuthentication struct held by the container, this is then passed down
// to the docker client to pull the image
func (c *Container) SetASMDockerAuthConfig(dac types.AuthConfig) {
func (c *Container) SetASMDockerAuthConfig(dac registry.AuthConfig) {
c.RegistryAuthentication.ASMAuthData.SetDockerAuthConfig(dac)
}

Expand Down
14 changes: 7 additions & 7 deletions agent/api/container/registryauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

"github.com/aws/amazon-ecs-agent/ecs-agent/credentials"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/registry"
)

// RegistryAuthenticationData is the authentication data sent by the ECS backend. Currently, the only supported
Expand All @@ -36,7 +36,7 @@ type ECRAuthData struct {
RegistryID string `json:"registryId"`
UseExecutionRole bool `json:"useExecutionRole"`
pullCredentials credentials.IAMRoleCredentials
dockerAuthConfig types.AuthConfig
dockerAuthConfig registry.AuthConfig
lock sync.RWMutex
}

Expand All @@ -50,7 +50,7 @@ type ASMAuthData struct {
Region string `json:"region"`
// dockerAuthConfig gets populated during the ASM resource creation
// by the task engine
dockerAuthConfig types.AuthConfig
dockerAuthConfig registry.AuthConfig
lock sync.RWMutex
}

Expand All @@ -71,7 +71,7 @@ func (auth *ECRAuthData) SetPullCredentials(creds credentials.IAMRoleCredentials
}

// GetDockerAuthConfig returns the pull credentials in the auth
func (auth *ECRAuthData) GetDockerAuthConfig() types.AuthConfig {
func (auth *ECRAuthData) GetDockerAuthConfig() registry.AuthConfig {
auth.lock.RLock()
defer auth.lock.RUnlock()

Expand All @@ -80,15 +80,15 @@ func (auth *ECRAuthData) GetDockerAuthConfig() types.AuthConfig {

// SetDockerAuthConfig sets the credentials to pull from ECR in the
// ecr auth data
func (auth *ECRAuthData) SetDockerAuthConfig(dac types.AuthConfig) {
func (auth *ECRAuthData) SetDockerAuthConfig(dac registry.AuthConfig) {
auth.lock.Lock()
defer auth.lock.Unlock()

auth.dockerAuthConfig = dac
}

// GetDockerAuthConfig returns the pull credentials in the auth
func (auth *ASMAuthData) GetDockerAuthConfig() types.AuthConfig {
func (auth *ASMAuthData) GetDockerAuthConfig() registry.AuthConfig {
auth.lock.RLock()
defer auth.lock.RUnlock()

Expand All @@ -97,7 +97,7 @@ func (auth *ASMAuthData) GetDockerAuthConfig() types.AuthConfig {

// SetDockerAuthConfig sets the credentials to pull from ECR in the
// auth
func (auth *ASMAuthData) SetDockerAuthConfig(dac types.AuthConfig) {
func (auth *ASMAuthData) SetDockerAuthConfig(dac registry.AuthConfig) {
auth.lock.Lock()
defer auth.lock.Unlock()

Expand Down
20 changes: 10 additions & 10 deletions agent/asm/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/aws/aws-sdk-go/service/secretsmanager"
"github.com/aws/aws-sdk-go/service/secretsmanager/secretsmanageriface"
"github.com/cihub/seelog"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/registry"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -61,54 +61,54 @@ func augmentErrMsg(secretID string, err error) string {

// GetDockerAuthFromASM makes the api call to the AWS Secrets Manager service to
// retrieve the docker auth data
func GetDockerAuthFromASM(secretID string, client secretsmanageriface.SecretsManagerAPI) (types.AuthConfig, error) {
func GetDockerAuthFromASM(secretID string, client secretsmanageriface.SecretsManagerAPI) (registry.AuthConfig, error) {
in := &secretsmanager.GetSecretValueInput{
SecretId: aws.String(secretID),
}

out, err := client.GetSecretValue(in)
if err != nil {
return types.AuthConfig{}, errors.Wrapf(err,
return registry.AuthConfig{}, errors.Wrapf(err,
"asm fetching secret from the service for %s", secretID)
}

return extractASMValue(out)
}

func extractASMValue(out *secretsmanager.GetSecretValueOutput) (types.AuthConfig, error) {
func extractASMValue(out *secretsmanager.GetSecretValueOutput) (registry.AuthConfig, error) {
if out == nil {
return types.AuthConfig{}, errors.New(
return registry.AuthConfig{}, errors.New(
"asm fetching authorization data: empty response")
}

secretValue := aws.StringValue(out.SecretString)
if secretValue == "" {
return types.AuthConfig{}, errors.New(
return registry.AuthConfig{}, errors.New(
"asm fetching authorization data: empty secrets value")
}

authDataValue := AuthDataValue{}
err := json.Unmarshal([]byte(secretValue), &authDataValue)
if err != nil {
// could not unmarshal, incorrect secret value schema
return types.AuthConfig{}, errors.New(
return registry.AuthConfig{}, errors.New(
"asm fetching authorization data: unable to unmarshal secret value, invalid schema")
}

username := aws.StringValue(authDataValue.Username)
password := aws.StringValue(authDataValue.Password)

if username == "" {
return types.AuthConfig{}, errors.New(
return registry.AuthConfig{}, errors.New(
"asm fetching username: AuthorizationData is malformed, empty field")
}

if password == "" {
return types.AuthConfig{}, errors.New(
return registry.AuthConfig{}, errors.New(
"asm fetching password: AuthorizationData is malformed, empty field")
}

dac := types.AuthConfig{
dac := registry.AuthConfig{
Username: username,
Password: password,
}
Expand Down
2 changes: 1 addition & 1 deletion agent/dockerclient/dockerapi/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ func (dg *dockerGoClient) InspectImage(image string) (*types.ImageInspect, error
return &imageData, err
}

func (dg *dockerGoClient) getAuthdata(image string, authData *apicontainer.RegistryAuthenticationData) (types.AuthConfig, error) {
func (dg *dockerGoClient) getAuthdata(image string, authData *apicontainer.RegistryAuthenticationData) (registry.AuthConfig, error) {

if authData == nil {
return dg.auth.GetAuthconfig(image, nil)
Expand Down
4 changes: 2 additions & 2 deletions agent/dockerclient/dockerapi/docker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func TestPullImageManifest(t *testing.T) {
Type: apicontainer.AuthTypeASM,
ASMAuthData: &apicontainer.ASMAuthData{},
}
authConfig := types.AuthConfig{Username: "username", Password: "password"}
authConfig := registry.AuthConfig{Username: "username", Password: "password"}
authData.ASMAuthData.SetDockerAuthConfig(authConfig)
encodedAuthConfig, err := registry.EncodeAuthConfig(authConfig)
require.NoError(t, err)
Expand Down Expand Up @@ -1091,7 +1091,7 @@ func TestContainerEvents(t *testing.T) {

// Verify only the container type event will translate to our event stream
// Events type: network, image, volume, daemon, plugins won't be handled
ignoreEventType := map[string]string{
ignoreEventType := map[events.Type]string{
"network": "connect",
"image": "pull",
"volume": "create",
Expand Down
4 changes: 2 additions & 2 deletions agent/dockerclient/dockerapi/docker_client_unix_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/aws/amazon-ecs-agent/agent/dockerclient"
"github.com/aws/amazon-ecs-agent/agent/dockerclient/sdkclientfactory"
"github.com/aws/amazon-ecs-agent/ecs-agent/utils/retry"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/registry"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestImageManifestPullInteg(t *testing.T) {
imageRef: "127.0.0.1:51671/busybox:latest",
authData: func() *container.RegistryAuthenticationData {
asmAuthData := &apicontainer.ASMAuthData{}
asmAuthData.SetDockerAuthConfig(types.AuthConfig{
asmAuthData.SetDockerAuthConfig(registry.AuthConfig{
Username: "username",
Password: "password",
})
Expand Down
5 changes: 3 additions & 2 deletions agent/dockerclient/dockerapi/mocks/dockerapi_mocks.go

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

16 changes: 8 additions & 8 deletions agent/dockerclient/dockerauth/dockerauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (

apicontainer "github.com/aws/amazon-ecs-agent/agent/api/container"
"github.com/aws/amazon-ecs-agent/agent/utils"
"github.com/docker/docker/api/types/registry"

"github.com/cihub/seelog"
"github.com/docker/docker/api/types"
)

func NewDockerAuthProvider(authType string, authData json.RawMessage) DockerAuthProvider {
Expand All @@ -38,7 +38,7 @@ type dockerAuthProvider struct {
}

// map from registry url (minus schema) to auth information
type dockerAuths map[string]types.AuthConfig
type dockerAuths map[string]registry.AuthConfig

type dockercfgConfigEntry struct {
Auth string `json:"auth"`
Expand All @@ -47,7 +47,7 @@ type dockercfgConfigEntry struct {
type dockercfgData map[string]dockercfgConfigEntry

// GetAuthconfig retrieves the correct auth configuration for the given repository
func (authProvider *dockerAuthProvider) GetAuthconfig(image string, registryAuthData *apicontainer.RegistryAuthenticationData) (types.AuthConfig, error) {
func (authProvider *dockerAuthProvider) GetAuthconfig(image string, registryAuthData *apicontainer.RegistryAuthenticationData) (registry.AuthConfig, error) {
// Ignore 'tag', not used in auth determination
repository, _ := utils.ParseRepositoryTag(image)
authDataMap := authProvider.authMap
Expand Down Expand Up @@ -87,7 +87,7 @@ func (authProvider *dockerAuthProvider) GetAuthconfig(image string, registryAuth
if longestKey != "" {
return authDataMap[longestKey], nil
}
return types.AuthConfig{}, nil
return registry.AuthConfig{}, nil
}

// Normalize all auth types into a uniform 'dockerAuths' type.
Expand All @@ -109,19 +109,19 @@ func parseAuthData(authType string, authData json.RawMessage) dockerAuths {
return dockerAuths{}
}

for registry, auth := range base64dAuthInfo {
for registryIdentifier, auth := range base64dAuthInfo {
data, err := base64.StdEncoding.DecodeString(auth.Auth)
if err != nil {
seelog.Warnf("Malformed auth data for registry %v", registry)
seelog.Warnf("Malformed auth data for registry %v", registryIdentifier)
continue
}

usernamePass := strings.SplitN(string(data), ":", 2)
if len(usernamePass) != 2 {
seelog.Warnf("Malformed auth data for registry %v; must contain ':'", registry)
seelog.Warnf("Malformed auth data for registry %v; must contain ':'", registryIdentifier)
continue
}
intermediateAuthData[registry] = types.AuthConfig{
intermediateAuthData[registryIdentifier] = registry.AuthConfig{
Username: usernamePass[0],
Password: usernamePass[1],
}
Expand Down
6 changes: 3 additions & 3 deletions agent/dockerclient/dockerauth/dockerauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"strings"
"testing"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/registry"
)

type authTestPair struct {
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestAuthErrors(t *testing.T) {
for _, pair := range badPairs {
provider := NewDockerAuthProvider(pair.t, []byte(pair.a))
result, _ := provider.GetAuthconfig("nginx", nil)
if !reflect.DeepEqual(result, types.AuthConfig{}) {
if !reflect.DeepEqual(result, registry.AuthConfig{}) {
t.Errorf("Expected empty auth config for %v; got %v", pair, result)
}
}
Expand All @@ -132,7 +132,7 @@ func TestAuthErrors(t *testing.T) {
func TestEmptyConfig(t *testing.T) {
provider := NewDockerAuthProvider("", []byte(""))
authConfig, _ := provider.GetAuthconfig("nginx", nil)
if !reflect.DeepEqual(authConfig, types.AuthConfig{}) {
if !reflect.DeepEqual(authConfig, registry.AuthConfig{}) {
t.Errorf("Expected empty authconfig to not return any auth data at all")
}
}
26 changes: 13 additions & 13 deletions agent/dockerclient/dockerauth/ecr.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/aws/amazon-ecs-agent/ecs-agent/utils/retry"
"github.com/aws/aws-sdk-go/aws"
log "github.com/cihub/seelog"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/registry"
)

type cacheKey struct {
Expand Down Expand Up @@ -70,16 +70,16 @@ func NewECRAuthProvider(ecrFactory ecr.ECRFactory, cache async.Cache) DockerAuth

// GetAuthconfig retrieves the correct auth configuration for the given repository
func (authProvider *ecrAuthProvider) GetAuthconfig(image string,
registryAuthData *apicontainer.RegistryAuthenticationData) (types.AuthConfig, error) {
registryAuthData *apicontainer.RegistryAuthenticationData) (registry.AuthConfig, error) {

if registryAuthData == nil {
return types.AuthConfig{}, fmt.Errorf("dockerauth: missing container's registry auth data")
return registry.AuthConfig{}, fmt.Errorf("dockerauth: missing container's registry auth data")
}

authData := registryAuthData.ECRAuthData

if authData == nil {
return types.AuthConfig{}, fmt.Errorf("dockerauth: missing container's ecr auth data")
return registry.AuthConfig{}, fmt.Errorf("dockerauth: missing container's ecr auth data")
}

// First try to get the token from cache, if the token does not exist,
Expand Down Expand Up @@ -109,7 +109,7 @@ func (authProvider *ecrAuthProvider) GetAuthconfig(image string,
}

// getAuthconfigFromCache retrieves the token from cache
func (authProvider *ecrAuthProvider) getAuthConfigFromCache(key cacheKey) *types.AuthConfig {
func (authProvider *ecrAuthProvider) getAuthConfigFromCache(key cacheKey) *registry.AuthConfig {
token, ok := authProvider.tokenCache.Get(key.String())
if !ok {
return nil
Expand Down Expand Up @@ -138,11 +138,11 @@ func (authProvider *ecrAuthProvider) getAuthConfigFromCache(key cacheKey) *types
}

// getAuthConfigFromECR calls the ECR API to get docker auth config
func (authProvider *ecrAuthProvider) getAuthConfigFromECR(image string, key cacheKey, authData *apicontainer.ECRAuthData) (types.AuthConfig, error) {
func (authProvider *ecrAuthProvider) getAuthConfigFromECR(image string, key cacheKey, authData *apicontainer.ECRAuthData) (registry.AuthConfig, error) {
// Create ECR client to get the token
client, err := authProvider.factory.GetClient(authData)
if err != nil {
return types.AuthConfig{}, err
return registry.AuthConfig{}, err
}

logger.Debug("Calling ECR.GetAuthorizationToken", logger.Fields{
Expand All @@ -155,10 +155,10 @@ func (authProvider *ecrAuthProvider) getAuthConfigFromECR(image string, key cach
})
ecrAuthData, err := client.GetAuthorizationToken(authData.RegistryID)
if err != nil {
return types.AuthConfig{}, err
return registry.AuthConfig{}, err
}
if ecrAuthData == nil {
return types.AuthConfig{}, fmt.Errorf("ecr auth: missing AuthorizationData in ECR response for %s", image)
return registry.AuthConfig{}, fmt.Errorf("ecr auth: missing AuthorizationData in ECR response for %s", image)
}

// Verify the auth data has the correct format for ECR
Expand All @@ -170,16 +170,16 @@ func (authProvider *ecrAuthProvider) getAuthConfigFromECR(image string, key cach
authProvider.tokenCache.Set(key.String(), ecrAuthData)
return extractToken(ecrAuthData)
}
return types.AuthConfig{}, fmt.Errorf("ecr auth: AuthorizationData is malformed for %s", image)
return registry.AuthConfig{}, fmt.Errorf("ecr auth: AuthorizationData is malformed for %s", image)
}

func extractToken(authData *ecrapi.AuthorizationData) (types.AuthConfig, error) {
func extractToken(authData *ecrapi.AuthorizationData) (registry.AuthConfig, error) {
decodedToken, err := base64.StdEncoding.DecodeString(aws.StringValue(authData.AuthorizationToken))
if err != nil {
return types.AuthConfig{}, err
return registry.AuthConfig{}, err
}
parts := strings.SplitN(string(decodedToken), ":", 2)
return types.AuthConfig{
return registry.AuthConfig{
Username: parts[0],
Password: parts[1],
ServerAddress: aws.StringValue(authData.ProxyEndpoint),
Expand Down
Loading

0 comments on commit 0e64539

Please sign in to comment.