func New(opts *Options) (*Client, error) {
	if opts.Port == 0 {
		opts.Port = DefaultSSHPort
	}

	if opts.BinDir == "" {
		opts.BinDir = DefaultBinPath
	}

	if opts.TempDir == "" {
		opts.TempDir = DefaultTempDir
	}

	config := &ssh.ClientConfig{
		User: opts.Username,
		Auth: []ssh.AuthMethod{
			ssh.Password(opts.Password),
		},
	}

	if opts.HostKey != "" {
		pk, err := ssh.ParsePublicKey([]byte(opts.HostKey))
		if err != nil {
			return nil, err
		}
		config.HostKeyCallback = ssh.FixedHostKey(pk)
	} else if opts.IgnoreHostKey {
		config.HostKeyCallback = ssh.InsecureIgnoreHostKey()
	}

	address := fmt.Sprintf("%s:%d", opts.Host, opts.Port)
	sshClient, err := ssh.Dial("tcp", address, config)
	if err != nil {
		return nil, err
	}

	ossec := &Client{
		debug:      opts.Debug,
		sshClient:  sshClient,
		address:    address,
		noSudo:     opts.NoSudo,
		manageExec: filepath.Join(opts.BinDir, "manage_agents"),
		tempDir:    opts.TempDir,
		password:   opts.Password,
	}

	return ossec, nil
}
// New returns a new ossec client
New returns a new ossec client
// New returns a new ossec client
func New(opts *Options) (*Client, error) {
	if opts.Port == 0 {
		opts.Port = DefaultSSHPort
	}
	if opts.BinDir == "" {
		opts.BinDir = DefaultBinPath
	}
	if opts.TempDir == "" {
		opts.TempDir = DefaultTempDir
	}
	config := &ssh.ClientConfig{
		User: opts.Username,
		Auth: []ssh.AuthMethod{
			ssh.Password(opts.Password),
		},
	}
	if opts.HostKey != "" {
		pk, err := ssh.ParsePublicKey([]byte(opts.HostKey))
		if err != nil {
			return nil, err
		}
		config.HostKeyCallback = ssh.FixedHostKey(pk)
	} else if opts.IgnoreHostKey {
		config.HostKeyCallback = ssh.InsecureIgnoreHostKey()
	}
	address := fmt.Sprintf("%s:%d", opts.Host, opts.Port)
	sshClient, err := ssh.Dial("tcp", address, config)
	if err != nil {
		return nil, err
	}
	ossec := &Client{
		debug:      opts.Debug,
		sshClient:  sshClient,
		address:    address,
		noSudo:     opts.NoSudo,
		manageExec: filepath.Join(opts.BinDir, "manage_agents"),
		tempDir:    opts.TempDir,
		password:   opts.Password,
	}
	return ossec, nil
}
func New ( opts * Options ) ( * Client , error ) { if opts . Port == 0 { opts . Port = DefaultSSHPort } if opts . BinDir == " " { opts . BinDir = DefaultBinPath } if opts . TempDir == " " { opts . TempDir = DefaultTempDir } config := & ssh . ClientConfig { User : opts . Username , Auth : [ ] ssh . AuthMethod { ssh . Password ( opts . Password ) , } , } if opts . HostKey != " " { pk , err := ssh . ParsePublicKey ( [ ] byte ( opts . HostKey ) ) if err != nil { return nil , err } config . HostKeyCallback = ssh . FixedHostKey ( pk ) } else if opts . IgnoreHostKey { config . HostKeyCallback = ssh . InsecureIgnoreHostKey ( ) } address := fmt . Sprintf ( " " , opts . Host , opts . Port ) sshClient , err := ssh . Dial ( " " , address , config ) if err != nil { return nil , err } ossec := & Client { debug : opts . Debug , sshClient : sshClient , address : address , noSudo : opts . NoSudo , manageExec : filepath . Join ( opts . BinDir , " " ) , tempDir : opts . TempDir , password : opts . Password , } return ossec , nil }
New returns a new ossec client
New returns a new ossec client