winrm

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package winrm provides PowerShell command reconstruction and WinRM transport.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PowerShellQuote

func PowerShellQuote(token string) string

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

func ReconstructPowerShellCommand(pipeline *parser.Pipeline) string

ReconstructPowerShellCommand rebuilds a validated pipeline into a PowerShell command string with proper quoting.

func WrapForWinRM

func WrapForWinRM(psCommand string) string

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

type WinRMDialer struct {
	ConnectTimeout time.Duration
}

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.

func (*WinRMFileClient) Stat

func (f *WinRMFileClient) Stat(path string) (os.FileInfo, error)

Stat returns file information via PowerShell Get-Item.

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

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)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL