diff --git a/azure/convert/registrycredentials.go b/azure/convert/registrycredentials.go index 47374c154..e4f548ca7 100644 --- a/azure/convert/registrycredentials.go +++ b/azure/convert/registrycredentials.go @@ -83,7 +83,7 @@ func getRegistryCredentials(project compose.Project, registryLoader registryConf hostname = parsedURL.Path } if _, ok := usedRegistries[hostname]; ok { - if oneCred.Username != "" { + if oneCred.Password != "" { aciCredential := containerinstance.ImageRegistryCredential{ Server: to.StringPtr(hostname), Password: to.StringPtr(oneCred.Password), @@ -91,10 +91,14 @@ func getRegistryCredentials(project compose.Project, registryLoader registryConf } registryCreds = append(registryCreds, aciCredential) } else if oneCred.IdentityToken != "" { + userName := tokenUsername + if oneCred.Username != "" { + userName = oneCred.Username + } aciCredential := containerinstance.ImageRegistryCredential{ Server: to.StringPtr(hostname), Password: to.StringPtr(oneCred.IdentityToken), - Username: to.StringPtr(tokenUsername), + Username: to.StringPtr(userName), } registryCreds = append(registryCreds, aciCredential) } diff --git a/azure/convert/registrycredentials_test.go b/azure/convert/registrycredentials_test.go index b365dcacb..b56d41e0f 100644 --- a/azure/convert/registrycredentials_test.go +++ b/azure/convert/registrycredentials_test.go @@ -18,6 +18,7 @@ package convert import ( "strconv" + "testing" "github.com/Azure/go-autorest/autorest/to" "github.com/compose-spec/compose-go/types" @@ -27,8 +28,6 @@ import ( "github.com/Azure/azure-sdk-for-go/profiles/latest/containerinstance/mgmt/containerinstance" - "testing" - . "github.com/onsi/gomega" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" @@ -101,6 +100,22 @@ func (suite *RegistryConvertTestSuite) TestAcrPrivateImage() { })) } +func (suite *RegistryConvertTestSuite) TestAcrPrivateImageLinux() { + token := tokenCreds("123456") + token.Username = tokenUsername + suite.loader.On(getAllCredentials).Return(registry("https://mycontainerregistrygta.azurecr.io", token), nil) + + creds, err := getRegistryCredentials(composeServices("mycontainerregistrygta.azurecr.io/privateimg"), suite.loader) + Expect(err).To(BeNil()) + Expect(creds).To(Equal([]containerinstance.ImageRegistryCredential{ + { + Server: to.StringPtr("mycontainerregistrygta.azurecr.io"), + Username: to.StringPtr(tokenUsername), + Password: to.StringPtr("123456"), + }, + })) +} + func (suite *RegistryConvertTestSuite) TestNoMoreRegistriesThanImages() { configs := map[string]cliconfigtypes.AuthConfig{ "https://mycontainerregistrygta.azurecr.io": tokenCreds("123456"),