Fix credential checking on ACR image (for linux)

Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
Ulysses Souza 2020-06-30 16:11:54 +02:00
parent e5e87d3357
commit a72ffee4ff
2 changed files with 23 additions and 4 deletions

View File

@ -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)
}

View File

@ -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"),