github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/cmd/podman/logout.go (about) 1 package main 2 3 import ( 4 "os" 5 6 "github.com/containers/common/pkg/auth" 7 "github.com/containers/common/pkg/completion" 8 "github.com/containers/image/v5/types" 9 "github.com/hanks177/podman/v4/cmd/podman/common" 10 "github.com/hanks177/podman/v4/cmd/podman/registry" 11 "github.com/spf13/cobra" 12 ) 13 14 var ( 15 logoutOptions = auth.LogoutOptions{} 16 logoutCommand = &cobra.Command{ 17 Use: "logout [options] [REGISTRY]", 18 Short: "Logout of a container registry", 19 Long: "Remove the cached username and password for the registry.", 20 RunE: logout, 21 Args: cobra.MaximumNArgs(1), 22 ValidArgsFunction: common.AutocompleteRegistries, 23 Example: `podman logout quay.io 24 podman logout --authfile dir/auth.json quay.io 25 podman logout --all`, 26 } 27 ) 28 29 func init() { 30 // Note that the local and the remote client behave the same: both 31 // store credentials locally while the remote client will pass them 32 // over the wire to the endpoint. 33 registry.Commands = append(registry.Commands, registry.CliCommand{ 34 Command: logoutCommand, 35 }) 36 flags := logoutCommand.Flags() 37 38 // Flags from the auth package. 39 flags.AddFlagSet(auth.GetLogoutFlags(&logoutOptions)) 40 41 // Add flag completion 42 completion.CompleteCommandFlags(logoutCommand, auth.GetLogoutFlagsCompletions()) 43 44 logoutOptions.Stdout = os.Stdout 45 logoutOptions.AcceptUnspecifiedRegistry = true 46 logoutOptions.AcceptRepositories = true 47 } 48 49 // Implementation of podman-logout. 50 func logout(cmd *cobra.Command, args []string) error { 51 sysCtx := &types.SystemContext{ 52 AuthFilePath: logoutOptions.AuthFile, 53 } 54 setRegistriesConfPath(sysCtx) 55 return auth.Logout(sysCtx, &logoutOptions, args) 56 }