diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-04-16 14:04:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-16 14:04:58 -0700 |
commit | 0d2b5532c417c58bd24e71a56c5c55b43e423a59 (patch) | |
tree | 4001e8e47a022bb1b9bfbf2332c42e1aeb802f9e /pkg/adapter/client.go | |
parent | 88c6fd06cd54fb9a8826306dfdf1a77e400de5de (diff) | |
parent | 241326a9a8c20ad7f2bcf651416b836e7778e090 (diff) | |
download | podman-0d2b5532c417c58bd24e71a56c5c55b43e423a59.tar.gz podman-0d2b5532c417c58bd24e71a56c5c55b43e423a59.tar.bz2 podman-0d2b5532c417c58bd24e71a56c5c55b43e423a59.zip |
Merge pull request #5852 from baude/v1prune
Podman V2 birth
Diffstat (limited to 'pkg/adapter/client.go')
-rw-r--r-- | pkg/adapter/client.go | 115 |
1 files changed, 0 insertions, 115 deletions
diff --git a/pkg/adapter/client.go b/pkg/adapter/client.go deleted file mode 100644 index a1b2bd507..000000000 --- a/pkg/adapter/client.go +++ /dev/null @@ -1,115 +0,0 @@ -// +build remoteclient - -package adapter - -import ( - "fmt" - "os" - - "github.com/containers/libpod/cmd/podman/remoteclientconfig" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "github.com/varlink/go/varlink" -) - -var remoteEndpoint *Endpoint // nolint: deadcode,unused - -func (r RemoteRuntime) RemoteEndpoint() (remoteEndpoint *Endpoint, err error) { - remoteConfigConnections, err := remoteclientconfig.ReadRemoteConfig(r.config) - if err != nil && errors.Cause(err) != remoteclientconfig.ErrNoConfigationFile { - return nil, err - } - // If the user defines an env variable for podman_varlink_bridge - // we use that as passed. - if bridge := os.Getenv("PODMAN_VARLINK_BRIDGE"); bridge != "" { - logrus.Debug("creating a varlink bridge based on env variable") - remoteEndpoint, err = newBridgeConnection(bridge, nil, r.cmd.LogLevel) - // if an environment variable for podman_varlink_address is defined, - // we used that as passed - } else if address := os.Getenv("PODMAN_VARLINK_ADDRESS"); address != "" { // nolint:gocritic - logrus.Debugf("creating a varlink address based on env variable: %s", address) - remoteEndpoint, err = newSocketConnection(address) - // if the user provides a remote host, we use it to configure a bridge connection - } else if len(r.cmd.RemoteHost) > 0 { - logrus.Debug("creating a varlink bridge based on user input") - if len(r.cmd.RemoteUserName) < 1 { - return nil, errors.New("you must provide a username when providing a remote host name") - } - rc := remoteclientconfig.RemoteConnection{r.cmd.RemoteHost, r.cmd.RemoteUserName, false, r.cmd.Port, r.cmd.IdentityFile, r.cmd.IgnoreHosts} // nolint: govet - remoteEndpoint, err = newBridgeConnection("", &rc, r.cmd.LogLevel) - // if the user has a config file with connections in it - } else if len(remoteConfigConnections.Connections) > 0 { - logrus.Debug("creating a varlink bridge based configuration file") - var rc *remoteclientconfig.RemoteConnection - if len(r.cmd.ConnectionName) > 0 { - rc, err = remoteConfigConnections.GetRemoteConnection(r.cmd.ConnectionName) - } else { - rc, err = remoteConfigConnections.GetDefault() - } - if err != nil { - return nil, err - } - if len(rc.Username) < 1 { - logrus.Debugf("Connection has no username, using current user %q", r.cmd.RemoteUserName) - rc.Username = r.cmd.RemoteUserName - } - remoteEndpoint, err = newBridgeConnection("", rc, r.cmd.LogLevel) - // last resort is to make a socket connection with the default varlink address for root user - } else { - logrus.Debug("creating a varlink address based default root address") - remoteEndpoint, err = newSocketConnection(DefaultVarlinkAddress) - } - return // nolint: nakedret -} - -// Connect provides a varlink connection -func (r RemoteRuntime) Connect() (*varlink.Connection, error) { - ep, err := r.RemoteEndpoint() - if err != nil { - return nil, err - } - switch ep.Type { - case DirectConnection: - return varlink.NewConnection(ep.Connection) - case BridgeConnection: - return varlink.NewBridge(ep.Connection) - } - return nil, errors.New(fmt.Sprintf("Unable to determine type of varlink connection: %s", ep.Connection)) -} - -// RefreshConnection is used to replace the current r.Conn after things like -// using an upgraded varlink connection -func (r RemoteRuntime) RefreshConnection() error { - newConn, err := r.Connect() - if err != nil { - return err - } - r.Conn = newConn - return nil -} - -// newSocketConnection returns an endpoint for a uds based connection -func newSocketConnection(address string) (*Endpoint, error) { - endpoint := Endpoint{ - Type: DirectConnection, - Connection: address, - } - return &endpoint, nil -} - -// newBridgeConnection creates a bridge type endpoint with username, destination, and log-level -func newBridgeConnection(formattedBridge string, remoteConn *remoteclientconfig.RemoteConnection, logLevel string) (*Endpoint, error) { - endpoint := Endpoint{ - Type: BridgeConnection, - } - - if len(formattedBridge) < 1 && remoteConn == nil { - return nil, errors.New("bridge connections must either be created by string or remoteconnection") - } - if len(formattedBridge) > 0 { - endpoint.Connection = formattedBridge - return &endpoint, nil - } - endpoint.Connection = formatDefaultBridge(remoteConn, logLevel) - return &endpoint, nil -} |