github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/cmd/podman/main_remote.go (about)

     1  // +build remoteclient
     2  
     3  package main
     4  
     5  import (
     6  	"os"
     7  	"os/user"
     8  	"strconv"
     9  
    10  	"github.com/pkg/errors"
    11  	"github.com/spf13/cobra"
    12  )
    13  
    14  const remote = true
    15  
    16  func init() {
    17  	var username string
    18  	if username = os.Getenv("PODMAN_USER"); username == "" {
    19  		if curruser, err := user.Current(); err == nil {
    20  			username = curruser.Username
    21  		}
    22  	}
    23  	host := os.Getenv("PODMAN_HOST")
    24  	port := 22
    25  	if portstr := os.Getenv("PODMAN_PORT"); portstr != "" {
    26  		if p, err := strconv.Atoi(portstr); err == nil {
    27  			port = p
    28  		}
    29  	}
    30  	key := os.Getenv("PODMAN_IDENTITY_FILE")
    31  	ignore := false
    32  	if ignorestr := os.Getenv("PODMAN_IGNORE_HOSTS"); ignorestr != "" {
    33  		if b, err := strconv.ParseBool(ignorestr); err == nil {
    34  			ignore = b
    35  		}
    36  	}
    37  	rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.ConnectionName, "connection", "", "remote connection name")
    38  	rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.RemoteConfigFilePath, "remote-config-path", "", "alternate path for configuration file")
    39  	rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.RemoteUserName, "username", username, "username on the remote host")
    40  	rootCmd.PersistentFlags().IntVar(&MainGlobalOpts.Port, "port", port, "port on remote host")
    41  	rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.RemoteHost, "remote-host", host, "remote host")
    42  	rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.IdentityFile, "identity-file", key, "identity-file")
    43  	rootCmd.PersistentFlags().BoolVar(&MainGlobalOpts.IgnoreHosts, "ignore-hosts", ignore, "ignore hosts")
    44  	// TODO maybe we allow the altering of this for bridge connections?
    45  	// rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.VarlinkAddress, "varlink-address", adapter.DefaultAddress, "address of the varlink socket")
    46  	rootCmd.PersistentFlags().StringVar(&MainGlobalOpts.LogLevel, "log-level", "error", "Log messages above specified level: debug, info, warn, error, fatal or panic. Logged to ~/.config/containers/podman.log")
    47  	rootCmd.PersistentFlags().BoolVar(&MainGlobalOpts.Syslog, "syslog", false, "Output logging information to syslog as well as the console")
    48  }
    49  
    50  func profileOn(cmd *cobra.Command) error {
    51  	return nil
    52  }
    53  
    54  func profileOff(cmd *cobra.Command) error {
    55  	return nil
    56  }
    57  
    58  func setupRootless(cmd *cobra.Command, args []string) error {
    59  	return nil
    60  }
    61  
    62  func setRLimits() error {
    63  	return nil
    64  }
    65  
    66  func setUMask() {}
    67  
    68  // checkInput can be used to verify any of the globalopt values
    69  func checkInput() error {
    70  	if MainGlobalOpts.Port < 0 || MainGlobalOpts.Port > 65536 {
    71  		return errors.Errorf("remote port must be between 0 and 65536")
    72  	}
    73  	return nil
    74  }