From f95b0995e521e252af52edaf57a31241d364e3d8 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Thu, 24 Jun 2021 14:35:10 +0200 Subject: remove `pkg/registries` Pull the trigger on the `pkg/registries` package which acted as a proxy for `c/image/pkg/sysregistriesv2`. Callers should be using the packages from c/image directly, if needed at all. Also make use of libimage's SystemContext() method which returns a copy of a system context, further reducing the risk of unintentionally altering global data. [NO TESTS NEEDED] Signed-off-by: Valentin Rothberg --- cmd/podman/login.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'cmd/podman/login.go') diff --git a/cmd/podman/login.go b/cmd/podman/login.go index 2101e32e2..a8dadf5cd 100644 --- a/cmd/podman/login.go +++ b/cmd/podman/login.go @@ -9,7 +9,6 @@ import ( "github.com/containers/image/v5/types" "github.com/containers/podman/v3/cmd/podman/common" "github.com/containers/podman/v3/cmd/podman/registry" - "github.com/containers/podman/v3/pkg/registries" "github.com/spf13/cobra" ) @@ -63,12 +62,29 @@ func login(cmd *cobra.Command, args []string) error { skipTLS = types.NewOptionalBool(!loginOptions.tlsVerify) } - sysCtx := types.SystemContext{ + sysCtx := &types.SystemContext{ AuthFilePath: loginOptions.AuthFile, DockerCertPath: loginOptions.CertDir, DockerInsecureSkipTLSVerify: skipTLS, - SystemRegistriesConfPath: registries.SystemRegistriesConfPath(), } + setRegistriesConfPath(sysCtx) loginOptions.GetLoginSet = cmd.Flag("get-login").Changed - return auth.Login(context.Background(), &sysCtx, &loginOptions.LoginOptions, args) + return auth.Login(context.Background(), sysCtx, &loginOptions.LoginOptions, args) +} + +// setRegistriesConfPath sets the registries.conf path for the specified context. +// NOTE: this is a verbatim copy from c/common/libimage which we're not using +// to prevent leaking c/storage into this file. Maybe this should go into c/image? +func setRegistriesConfPath(systemContext *types.SystemContext) { + if systemContext.SystemRegistriesConfPath != "" { + return + } + if envOverride, ok := os.LookupEnv("CONTAINERS_REGISTRIES_CONF"); ok { + systemContext.SystemRegistriesConfPath = envOverride + return + } + if envOverride, ok := os.LookupEnv("REGISTRIES_CONFIG_PATH"); ok { + systemContext.SystemRegistriesConfPath = envOverride + return + } } -- cgit v1.2.3-54-g00ecf