Merge branch 'bugfix/support_missing_auth_in_provider' of git://github.com/edgarpoce/terraform-provider-docker into edgarpoce-bugfix/support_missing_auth_in_provider

This commit is contained in:
Manuel Vogel 2020-10-08 20:06:03 +02:00
commit bdea96e832
No known key found for this signature in database
GPG key ID: 24E54F214569A8A5
2 changed files with 33 additions and 6 deletions

View file

@ -215,20 +215,17 @@ func providerSetToRegistryAuth(authSet *schema.Set) (*AuthConfigs, error) {
}
filePath = strings.Replace(filePath, "~", usr.HomeDir, 1)
}
r, err := os.Open(filePath)
if err != nil {
return nil, fmt.Errorf("Error opening docker registry config file: %v", err)
continue
}
c, err := loadConfigFile(r)
if err != nil {
return nil, fmt.Errorf("Error parsing docker registry config json: %v", err)
continue
}
authFileConfig, err := c.GetAuthConfig(registryHostname)
if err != nil {
return nil, fmt.Errorf("Couldn't find registry config for '%s' in file: %s",
registryHostname, filePath)
continue
}
authConfig.Username = authFileConfig.Username
authConfig.Password = authFileConfig.Password

View file

@ -2,8 +2,10 @@ package docker
import (
"os/exec"
"regexp"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)
@ -24,6 +26,19 @@ func TestProvider(t *testing.T) {
}
}
func TestAccDockerProvider_WithIncompleteRegistryAuth(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDockerProviderWithIncompleteAuthConfig,
ExpectError: regexp.MustCompile(`401 Unauthorized`),
},
},
})
}
func TestProvider_impl(t *testing.T) {
var _ terraform.ResourceProvider = Provider()
}
@ -47,3 +62,18 @@ func testAccPreCheck(t *testing.T) {
t.Fatal(err)
}
}
const testAccDockerProviderWithIncompleteAuthConfig = `
provider "docker" {
alias = "private"
registry_auth {
address = ""
username = ""
password = ""
}
}
data "docker_registry_image" "foobar" {
provider = "docker.private"
name = "localhost:15000/helloworld:1.0"
}
`