diff --git a/parameters.go b/parameters.go index 08adcc9..1660de5 100644 --- a/parameters.go +++ b/parameters.go @@ -7,6 +7,8 @@ import "net" type Parameters struct { Timeout string Locale string + Cwd string + Env map[string]string EnvelopeSize int TransportDecorator func() Transporter Dial func(network, addr string) (net.Conn, error) diff --git a/request.go b/request.go index e66bfd7..571246e 100644 --- a/request.go +++ b/request.go @@ -42,6 +42,18 @@ func NewOpenShellRequest(uri string, params *Parameters) *soap.SoapMessage { input.SetContent("stdin") output := message.CreateElement(body, "OutputStreams", soap.DOM_NS_WIN_SHELL) output.SetContent("stdout stderr") + if len(params.Cwd) > 0 { + cwd := message.CreateElement(body, "WorkingDirectory", soap.DOM_NS_WIN_SHELL) + cwd.SetContent(params.Cwd) + } + if params.Env != nil { + env := message.CreateElement(body, "Environment", soap.DOM_NS_WIN_SHELL) + for name, value := range params.Env { + variable := message.CreateElement(env, "Variable", soap.DOM_NS_WIN_SHELL) + variable.SetAttr("Name", name) + variable.SetContent(value) + } + } return message } diff --git a/request_test.go b/request_test.go index a2cd42a..4f32d61 100644 --- a/request_test.go +++ b/request_test.go @@ -20,13 +20,20 @@ type WinRMSuite struct{} var _ = Suite(&WinRMSuite{}) func (s *WinRMSuite) TestOpenShellRequest(c *C) { - openShell := NewOpenShellRequest("http://localhost", nil) + parameters := NewParameters("PT60S", "en-US", 153600) + parameters.Cwd = "c:\\" + parameters.Env = map[string]string{ + "foo": "bar", + } + openShell := NewOpenShellRequest("http://localhost", parameters) defer openShell.Free() assertXPath(c, openShell.Doc(), "//a:Action", "http://schemas.xmlsoap.org/ws/2004/09/transfer/Create") assertXPath(c, openShell.Doc(), "//a:To", "http://localhost") assertXPath(c, openShell.Doc(), "//env:Body/rsp:Shell/rsp:InputStreams", "stdin") assertXPath(c, openShell.Doc(), "//env:Body/rsp:Shell/rsp:OutputStreams", "stdout stderr") + assertXPath(c, openShell.Doc(), "//env:Body/rsp:Shell/rsp:WorkingDirectory", "c:\\") + assertXPath(c, openShell.Doc(), "//env:Body/rsp:Shell/rsp:Environment/rsp:Variable[@Name=\"foo\"]", "bar") } func (s *WinRMSuite) TestDeleteShellRequest(c *C) {