Fix deprecated registry auth conversion.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu 2021-02-01 20:05:24 -08:00
parent a39478ab9a
commit b5bf1fd5d8
2 changed files with 10 additions and 1 deletions

View File

@ -18,6 +18,7 @@ package config
import ( import (
"context" "context"
"net/url"
"time" "time"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
@ -353,6 +354,14 @@ func ValidatePluginConfig(ctx context.Context, c *PluginConfig) error {
} }
for endpoint, auth := range c.Registry.Auths { for endpoint, auth := range c.Registry.Auths {
auth := auth auth := auth
u, err := url.Parse(endpoint)
if err != nil {
return errors.Wrapf(err, "failed to parse registry url %q from `registry.auths`", endpoint)
}
if u.Scheme != "" {
// Do not include the scheme in the new registry config.
endpoint = u.Host
}
config := c.Registry.Configs[endpoint] config := c.Registry.Configs[endpoint]
config.Auth = &auth config.Auth = &auth
c.Registry.Configs[endpoint] = config c.Registry.Configs[endpoint] = config

View File

@ -294,7 +294,7 @@ func TestValidateConfig(t *testing.T) {
}, },
Registry: Registry{ Registry: Registry{
Configs: map[string]RegistryConfig{ Configs: map[string]RegistryConfig{
"https://gcr.io": { "gcr.io": {
Auth: &AuthConfig{ Auth: &AuthConfig{
Username: "test", Username: "test",
}, },