Documentation
¶
Overview ¶
Package winrm provides PowerShell command reconstruction and WinRM transport.
Index ¶
- func DecodeCLIXMLStderr(stderr string) string
- func PowerShellQuote(token string) string
- func ReconstructPowerShellCommand(pipeline *parser.Pipeline) string
- func WrapForWinRM(psCommand string) string
- type ManagedWinRMConnection
- type WinRMDialer
- type WinRMFileClient
- func (f *WinRMFileClient) Chmod(_ string, _ os.FileMode) error
- func (f *WinRMFileClient) Close() error
- func (f *WinRMFileClient) Create(path string) (io.WriteCloser, error)
- func (f *WinRMFileClient) MkdirAll(path string) error
- func (f *WinRMFileClient) Open(path string) (io.ReadCloser, error)
- func (f *WinRMFileClient) Stat(path string) (os.FileInfo, error)
- type WinRMManager
- func (m *WinRMManager) Connect(ctx context.Context, params ssh.ConnectionParams) error
- func (m *WinRMManager) Disconnect(_ context.Context, host string) error
- func (m *WinRMManager) Execute(ctx context.Context, host, command string, timeout time.Duration) (ssh.ExecResult, error)
- func (m *WinRMManager) ExecuteRaw(ctx context.Context, host, command string, timeout time.Duration) (ssh.ExecResult, error)
- func (m *WinRMManager) SFTPSession(host string) (ssh.SFTPClient, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeCLIXMLStderr ¶ added in v0.9.9
DecodeCLIXMLStderr rewrites stderr from a remote PowerShell invocation into plain text. CLIXML blobs are parsed: progress and debug records are dropped entirely, and error/warning/verbose/info string records are decoded to their message text. Text outside CLIXML blobs passes through untouched, and a blob that fails to parse is preserved as-is rather than swallowed.
func PowerShellQuote ¶
PowerShellQuote single-quotes a token for safe use in PowerShell. Embedded single quotes are escaped by doubling (”). Flags (starting with -) and pipeline operators pass through unquoted.
func ReconstructPowerShellCommand ¶
ReconstructPowerShellCommand rebuilds a validated pipeline into a PowerShell command string with proper quoting.
func WrapForWinRM ¶
WrapForWinRM wraps a PowerShell command string for execution over WinRM. WinRM's default shell is cmd.exe, so we encode the PowerShell command as UTF-16LE base64 and pass it via -EncodedCommand to avoid quoting issues.
Types ¶
type ManagedWinRMConnection ¶
type ManagedWinRMConnection struct {
Client *winrmClient
Params ssh.ConnectionParams
}
ManagedWinRMConnection tracks a WinRM connection.
type WinRMDialer ¶
WinRMDialer creates WinRM connections.
func (*WinRMDialer) Dial ¶
func (d *WinRMDialer) Dial(_ context.Context, params ssh.ConnectionParams) (*winrmClient, error)
Dial creates a new WinRM connection.
type WinRMFileClient ¶
type WinRMFileClient struct {
// contains filtered or unexported fields
}
WinRMFileClient implements ssh.SFTPClient using PowerShell commands over WinRM.
func NewWinRMFileClient ¶
func NewWinRMFileClient(client *winrmClient) *WinRMFileClient
NewWinRMFileClient creates a new file client using an existing WinRM connection.
func (*WinRMFileClient) Chmod ¶
func (f *WinRMFileClient) Chmod(_ string, _ os.FileMode) error
Chmod is a no-op on Windows (ACLs are not managed this way).
func (*WinRMFileClient) Close ¶
func (f *WinRMFileClient) Close() error
Close is a no-op since WinRM file operations are stateless.
func (*WinRMFileClient) Create ¶
func (f *WinRMFileClient) Create(path string) (io.WriteCloser, error)
Create writes a file on the remote system via chunked base64 writes.
func (*WinRMFileClient) MkdirAll ¶
func (f *WinRMFileClient) MkdirAll(path string) error
MkdirAll creates a directory and all parents on the remote system.
func (*WinRMFileClient) Open ¶
func (f *WinRMFileClient) Open(path string) (io.ReadCloser, error)
Open reads a remote file and returns its content as a ReadCloser. Uses chunked reads for files larger than smallFileThreshold.
type WinRMManager ¶
type WinRMManager struct {
// contains filtered or unexported fields
}
WinRMManager manages WinRM connections, implementing server.Executor.
func NewWinRMManager ¶
func NewWinRMManager(dialer *WinRMDialer) *WinRMManager
NewWinRMManager creates a new WinRM connection manager.
func (*WinRMManager) Connect ¶
func (m *WinRMManager) Connect(ctx context.Context, params ssh.ConnectionParams) error
Connect establishes a connection, or joins one already being established.
Callers converge on a host at the same moment — several agents reacting to the same failure, say — and each used to open its own NTLM handshake and overwrite the map entry the others had just written. That cost seconds per caller and left orphaned clients behind. Now the first caller dials and the rest wait for its result.
func (*WinRMManager) Disconnect ¶
func (m *WinRMManager) Disconnect(_ context.Context, host string) error
func (*WinRMManager) Execute ¶
func (m *WinRMManager) Execute(ctx context.Context, host, command string, timeout time.Duration) (ssh.ExecResult, error)
func (*WinRMManager) ExecuteRaw ¶
func (m *WinRMManager) ExecuteRaw(ctx context.Context, host, command string, timeout time.Duration) (ssh.ExecResult, error)
func (*WinRMManager) SFTPSession ¶
func (m *WinRMManager) SFTPSession(host string) (ssh.SFTPClient, error)