// SSHHost returns a function that can be given to the SSH communicator
769213
func SSHHost(e alicloudSSHHelper, private bool) func(multistep.StateBag) (string, error) {
	return func(state multistep.StateBag) (string, error) {
		ipAddress := state.Get("ipaddress").(string)
		return ipAddress, nil
	}
}
254857
func (client *SSHClient) GetSSHPassword() string {
	client.Creds.mu.Lock()
	defer client.Creds.mu.Unlock()
	return client.Creds.SSHPassword
}
1035667
func (e *PodEndpoint) SetHostPort(port int) *PodEndpoint {
	e.HostPort = port
	return e
}
558699
func (s *RedirectActionConfig) SetHost(v string) *RedirectActionConfig {
	s.Host = &v
	return s
}
413873
func parse(input string) ([]*SSHHost, error) {
	sshConfigs := []*SSHHost{}
	var next item
	var sshHost *SSHHost

	lexer := lex(input)
Loop:
	for {
		token := lexer.nextItem()

		if sshHost == nil && token.typ != itemHost {
			return nil, fmt.Errorf("config variable before Host variable")
		}

		switch token.typ {
		case itemHost:
			if sshHost != nil {
				sshConfigs = append(sshConfigs, sshHost)
			}

			sshHost = &SSHHost{Host: []string{}, Port: 22}
		case itemHostValue:
			sshHost.Host = strings.Split(token.val, " ")
		case itemHostName:
			next = lexer.nextItem()
			if next.typ != itemValue {
				return nil, fmt.Errorf(next.val)
			}
			sshHost.HostName = next.val
		case itemUser:
			next = lexer.nextItem()
			if next.typ != itemValue {
				return nil, fmt.Errorf(next.val)
			}
			sshHost.User = next.val
		case itemPort:
			next = lexer.nextItem()
			if next.typ != itemValue {
				return nil, fmt.Errorf(next.val)
			}
			port, err := strconv.Atoi(next.val)
			if err != nil {
				return nil, err
			}
			sshHost.Port = port
		case itemProxyCommand:
			next = lexer.nextItem()
			if next.typ != itemValue {
				return nil, fmt.Errorf(next.val)
			}
			sshHost.ProxyCommand = next.val
		case itemHostKeyAlgorithms:
			next = lexer.nextItem()
			if next.typ != itemValue {
				return nil, fmt.Errorf(next.val)
			}
			sshHost.HostKeyAlgorithms = next.val
		case itemIdentityFile:
			next = lexer.nextItem()
			if next.typ != itemValue {
				return nil, fmt.Errorf(next.val)
			}
			sshHost.IdentityFile = next.val
		case itemError:
			return nil, fmt.Errorf("%s at pos %d", token.val, token.pos)
		case itemEOF:
			if sshHost != nil {
				sshConfigs = append(sshConfigs, sshHost)
			}
			break Loop
		default:
			// continue onwards
		}
	}
	return sshConfigs, nil
}
962518
func (st *State) GetSSHHostKeys(tag names.MachineTag) (SSHHostKeys, error) {
	coll, closer := st.db().GetCollection(sshHostKeysC)
	defer closer()

	var doc sshHostKeysDoc
	err := coll.FindId(machineGlobalKey(tag.Id())).One(&doc)
	if err == mgo.ErrNotFound {
		return nil, errors.NotFoundf("keys")
	} else if err != nil {
		return nil, errors.Annotate(err, "key lookup failed")
	}
	return SSHHostKeys(doc.Keys), nil
}
596114
func (r *Request) SetHost(host string) {
	r.context.Request.SetHost(host)
}
122305
func (c *FakeSSHCredentials) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.SSHCredential, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewPatchSubresourceAction(sshcredentialsResource, c.ns, name, data, subresources...), &v1alpha1.SSHCredential{})

	if obj == nil {
		return nil, err
	}
	return obj.(*v1alpha1.SSHCredential), err
}
1279950
func (o *InfrastructureAccessProfile) SSHKeys(info *bambou.FetchingInfo) (SSHKeysList, *bambou.Error) {

	var list SSHKeysList
	err := bambou.CurrentSession().FetchChildren(o, SSHKeyIdentity, &list, info)
	return list, err
}
355104
func SSHTunnelListener(addr string, config *SSHConfig) (Listener, error) {
	ln, err := net.Listen("tcp", addr)
	if err != nil {
		return nil, err
	}

	if config == nil {
		config = &SSHConfig{}
	}

	sshConfig := &ssh.ServerConfig{}
	sshConfig.PasswordCallback = defaultSSHPasswordCallback(config.Authenticator)
	if config.Authenticator == nil {
		sshConfig.NoClientAuth = true
	}
	tlsConfig := config.TLSConfig
	if tlsConfig == nil {
		tlsConfig = DefaultTLSConfig
	}

	signer, err := ssh.NewSignerFromKey(tlsConfig.Certificates[0].PrivateKey)
	if err != nil {
		ln.Close()
		return nil, err

	}
	sshConfig.AddHostKey(signer)

	l := &sshTunnelListener{
		Listener: tcpKeepAliveListener{ln.(*net.TCPListener)},
		config:   sshConfig,
		connChan: make(chan net.Conn, 1024),
		errChan:  make(chan error, 1),
	}

	go l.listenLoop()

	return l, nil
}
820982
func (s *NetworkBinding) SetHostPort(v int64) *NetworkBinding {
	s.HostPort = &v
	return s
}
285124
func (s *PortMapping) SetHostPort(v int64) *PortMapping {
	s.HostPort = &v
	return s
}
1324965
func (c *Client) HSet(key, field, value string) (err error) {
	_, err = c.execWithKey(true, "HSET", key, field, value)
	return
}
995357
func (c *configV7) setHost(alias string, cfg hostConfigV7) {
	if _, ok := c.Hosts[alias]; !ok {
		c.Hosts[alias] = cfg
	}
}
899515
func sshParseShellCommand(command string, existing string) (ssh string, cmd string, needShell bool) {
	ssh = existing
	if cmdArgs := tools.QuotedFields(command); len(cmdArgs) > 0 {
		needShell = true
		ssh = cmdArgs[0]
		cmd = command
	}
	return
}
1362990
func CreateSSHClient(params *SSHClientParams) (*ssh.Client, error) {

	// collect file info
	fileExists := false
	if params.PrivateKeyPath != "" {
		_, err := os.Stat(params.PrivateKeyPath)
		fileExists = err == nil
	}

	// collect option
	strOpt := ""
	if fileExists {
		strOpt = fmt.Sprintf(" -i %s", params.PrivateKeyPath)
	}

	if !params.Quiet {
		// output connect info
		fmt.Fprintf(params.Out, "\nconnecting server...\n\tcommand: ssh %s@%s%s\n\n", params.UserName, params.TargetHost(), strOpt)
	}
	cnf := &ssh.ClientConfig{
		User:    params.UserName,
		Timeout: 10 * time.Second,
	}

	// build auth methods
	var authMethods []ssh.AuthMethod

	// add ssh-agent
	//sshSock := os.ExpandEnv("$SSH_AUTH_SOCK")
	//if sshSock != "" {
	//	addr, _ := net.ResolveUnixAddr("unix", sshSock)
	//	agentConn, _ := net.DialUnix("unix", nil, addr)
	//	ag := agent.NewClient(agentConn)
	//	authMethods = append(authMethods, ssh.PublicKeysCallback(ag.Signers))
	//}

	// private key

	if fileExists {
		signer, err := getSigners(params.PrivateKeyPath, params.Password)
		if err != nil {
			return nil, fmt.Errorf("parse private-key(%s) is failed: %s", params.PrivateKeyPath, err)
		}
		authMethods = append(authMethods, ssh.PublicKeys(signer...))
	}

	// password prompt
	authMethods = append(authMethods, ssh.PasswordCallback(func() (string, error) {
		if params.Password == "" {
			prefix := ""
			if params.DisplayName != "" {
				prefix = fmt.Sprintf("%s | ", params.DisplayName)
			}
			return pprompt(fmt.Sprintf("%spassword: ", prefix))
		}
		return params.Password, nil
	}))

	cnf.Auth = authMethods
	var conn *ssh.Client

	conn, err := ssh.Dial("tcp", params.TargetHost(), cnf)
	if err != nil {
		return nil, fmt.Errorf("connecting(%s) is failed: %s", params.TargetHost(), err)
	}

	return conn, nil
}
715511
func (c *asyncClient) Hset(arg0 string, arg1 string, arg2 []byte) (stat FutureBool, err Error) {
	arg0bytes := []byte(arg0)
	arg1bytes := []byte(arg1)
	arg2bytes := arg2

	resp, err := c.conn.QueueRequest(&HSET, [][]byte{arg0bytes, arg1bytes, arg2bytes})
	if err == nil {
		stat = resp.future.(FutureBool)
	}

	return
}