Skip to content

Commit 39123de

Browse files
committed
add: checking multiple registries in config file
Signed-off-by: Lazar Slavković-Raco <[email protected]>
1 parent beefbd7 commit 39123de

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

cmd/podman/login.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/containers/common/pkg/auth"
1010
"github.com/containers/common/pkg/completion"
11+
"github.com/containers/image/v5/pkg/sysregistriesv2"
1112
"github.com/containers/image/v5/types"
1213
"github.com/containers/podman/v5/cmd/podman/common"
1314
"github.com/containers/podman/v5/cmd/podman/registry"
@@ -99,6 +100,10 @@ func login(cmd *cobra.Command, args []string) error {
99100
DockerInsecureSkipTLSVerify: skipTLS,
100101
}
101102
setRegistriesConfPath(sysCtx)
103+
registriesFromFile, _ := sysregistriesv2.UnqualifiedSearchRegistries(sysCtx)
104+
if len(registriesFromFile) > 1 {
105+
return errors.New("multiple registries in registry.conf, a registry must be provided")
106+
}
102107
loginOptions.GetLoginSet = cmd.Flag("get-login").Changed
103108
return auth.Login(context.Background(), sysCtx, &loginOptions.LoginOptions, args)
104109
}

cmd/podman/logout.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package main
22

33
import (
4+
"errors"
45
"os"
56

67
"github.com/containers/common/pkg/auth"
78
"github.com/containers/common/pkg/completion"
9+
"github.com/containers/image/v5/pkg/sysregistriesv2"
810
"github.com/containers/image/v5/types"
911
"github.com/containers/podman/v5/cmd/podman/common"
1012
"github.com/containers/podman/v5/cmd/podman/registry"
@@ -50,5 +52,9 @@ func init() {
5052
func logout(cmd *cobra.Command, args []string) error {
5153
sysCtx := &types.SystemContext{}
5254
setRegistriesConfPath(sysCtx)
55+
registriesFromFile, _ := sysregistriesv2.UnqualifiedSearchRegistries(sysCtx)
56+
if len(registriesFromFile) > 1 {
57+
return errors.New("multiple registries in registry.conf, a registry must be provided")
58+
}
5359
return auth.Logout(sysCtx, &logoutOptions, args)
5460
}

0 commit comments

Comments
 (0)