-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
42 lines (35 loc) · 898 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package windurs
import (
"io"
"github.com/masterzen/winrm/winrm"
)
type Client struct {
addr string
user string
pass string
inner *winrm.Client
}
func New(addr, user, pass string) (*Client, error) {
endpoint, err := parseEndpoint(addr)
if err != nil {
return nil, err
}
inner, err := winrm.NewClient(endpoint, user, pass)
if err != nil {
return nil, err
}
return &Client{addr, user, pass, inner}, nil
}
func (c *Client) Info() (*Info, error) {
return fetchInfo(c.inner, c.user, c.pass)
}
func (c *Client) List(remotePath string) ([]FileItem, error) {
return fetchList(c.inner, winPath(remotePath))
}
func (c *Client) Cmd(stdout, stderr io.Writer, impersonate bool, arguments ...string) (int, error) {
if !impersonate {
return runCmd(c.inner, stdout, stderr, arguments...)
} else {
return runElevatedCmd(c.inner, c.user, c.pass, stdout, stderr, arguments...)
}
}