mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2026-01-09 08:12:54 -05:00
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:
commit
bdea96e832
2 changed files with 33 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
`
|
||||
|
|
|
|||
Loading…
Reference in a new issue