소스 검색

Merge pull request #306 from docker/fix-credential-check

Fix credential checking on ACR image (for linux)
Guillaume Tardif 5 년 전
부모
커밋
664c48ba1e
2개의 변경된 파일23개의 추가작업 그리고 4개의 파일을 삭제
  1. 6 2
      azure/convert/registrycredentials.go
  2. 17 2
      azure/convert/registrycredentials_test.go

+ 6 - 2
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)
 			}

+ 17 - 2
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"),