winrm

package
v0.0.0-...-e7e6eed Latest Latest
Warning

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

Go to latest
Published: May 21, 2016 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// P224 curve which implements P-224 (see FIPS 186-3, section D.2.2)
	P224 = iota
	// P256 curve which implements P-256 (see FIPS 186-3, section D.2.3)
	P256
	// P384 curve which implements P-384 (see FIPS 186-3, section D.2.4)
	P384
	// P521 curve which implements P-521 (see FIPS 186-3, section D.2.5)
	P521

	// definition flags for specific methods that the cert will be generated
	// RSA method
	RSA KeyType = iota
	// ECDSA method
	ECDSA
)

definition flags for specific elliptic curves formats

Variables

View Source
var DefaultParameters = NewParameters("PT60S", "en-US", 153600)

DefaultParameters return constant config of type Parameters

Functions

func Http_post

func Http_post(client *Client, request *soap.SoapMessage) (string, error)

Http_post make post to the winrm soap service

func NewCert

func NewCert(config CertConfig) (string, string, error)

NewCert generates a new x509 certificates based on the CertConfig passed

func NewDeleteShellRequest

func NewDeleteShellRequest(uri string, shellId string, params *Parameters) (message *soap.SoapMessage)

NewDeleteShellRequest ...

func NewExecuteCommandRequest

func NewExecuteCommandRequest(uri, shellId, command string, arguments []string, params *Parameters) (message *soap.SoapMessage)

NewExecuteCommandRequest exec command on specific shellID

func NewGetOutputRequest

func NewGetOutputRequest(uri string, shellId string, commandId string, streams string, params *Parameters) (message *soap.SoapMessage)

func NewOpenShellRequest

func NewOpenShellRequest(uri string, params *Parameters) (message *soap.SoapMessage)

NewOpenShellRequest makes a new soap request

func NewSendInputRequest

func NewSendInputRequest(uri string, shellId string, commandId string, input []byte, params *Parameters) (message *soap.SoapMessage)

func NewSignalRequest

func NewSignalRequest(uri string, shellId string, commandId string, params *Parameters) (message *soap.SoapMessage)

func ParseExecuteCommandResponse

func ParseExecuteCommandResponse(response string) (commandId string, err error)

func ParseOpenShellResponse

func ParseOpenShellResponse(response string) (shellId string, err error)

func ParseSlurpOutputErrResponse

func ParseSlurpOutputErrResponse(response string, stdout io.Writer, stderr io.Writer) (finished bool, exitCode int, err error)

func ParseSlurpOutputResponse

func ParseSlurpOutputResponse(response string, stream io.Writer, streamType string) (finished bool, exitCode int, err error)

func Powershell

func Powershell(psCmd string) string

Powershell wraps a PowerShell script and prepares it for execution by the winrm client

Types

type CertConfig

type CertConfig struct {
	// Subject identifies the entity associated with the public
	// key stored in the subject public key fields.
	Subject pkix.Name
	// ValidFrom creation date formated as Feb 16 10:04:20 2016
	ValidFrom time.Time
	// ValidFor the duration that certificate will be valid for
	// The validity period for a certificate is the period of time
	// form notBefore through notAfter, inclusive.
	//	Note this fileds will be parsed into the notAfter,notBefore
	//	x509 cert fields
	ValidFor time.Duration
	// SizeT can represent the size of bytes RSA cert if you specify in the
	SizeT int
	// Method to be RSA or it can be ECDSA flag if you specify the ECDSA flag
	Method KeyType
}

CertConfig struct for generating base certificates x509 for ssl/tls auth

type Client

type Client struct {
	Parameters
	// contains filtered or unexported fields
}

Client struct

func NewClient

func NewClient(endpoint *Endpoint, user, password string) (client *Client, err error)

NewClient will create a new remote client on url, connecting with user and password This function doesn't connect (connection happens only when CreateShell is called)

func NewClientWithParameters

func NewClientWithParameters(endpoint *Endpoint, user, password string, params *Parameters) (client *Client, err error)

NewClientWithParameters will create a new remote client on url, connecting with user and password This function doesn't connect (connection happens only when CreateShell is called)

func (*Client) CreateShell

func (client *Client) CreateShell() (*Shell, error)

CreateShell will create a WinRM Shell, which is the prealable for running commands.

func (*Client) NewShell

func (client *Client) NewShell(shellID string) *Shell

NewShell will create a new WinRM Shell for the given shellID

func (*Client) Run

func (client *Client) Run(command string, stdout io.Writer, stderr io.Writer) (exitCode int, err error)

Run will run command on the the remote host, writing the process stdout and stderr to the given writers. Note with this method it isn't possible to inject stdin.

func (*Client) RunWithInput

func (client *Client) RunWithInput(command string, stdout io.Writer, stderr io.Writer, stdin io.Reader) (exitCode int, err error)

RunWithInput will run command on the the remote host, writing the process stdout and stderr to the given writers, and injecting the process stdin with the stdin reader. Warning stdin (not stdout/stderr) are bufferized, which means reading only one byte in stdin will send a winrm http packet to the remote host. If stdin is a pipe, it might be better for performance reasons to buffer it.

func (*Client) RunWithString

func (client *Client) RunWithString(command string, stdin string) (stdout string, stderr string, exitCode int, err error)

RunWithString will run command on the the remote host, returning the process stdout and stderr as strings, and using the input stdin string as the process input

type Command

type Command struct {
	ID string

	Stdin  *commandWriter
	Stdout *commandReader
	Stderr *commandReader
	// contains filtered or unexported fields
}

Command represents a given command running on a Shell. This structure allows to get access to the various stdout, stderr and stdin pipes.

func (*Command) Close

func (command *Command) Close() (err error)

Close will terminate the running command

func (*Command) ExitCode

func (command *Command) ExitCode() int

ExitCode returns command exit code when it is finished. Before that the result is always 0.

func (*Command) Wait

func (command *Command) Wait()

Wait function will block the current goroutine until the remote command terminates.

type Endpoint

type Endpoint struct {
	Host     string
	Port     int
	HTTPS    bool
	Insecure bool
	CACert   *[]byte
	Timeout  time.Duration
}

Endpoint struct holds configurations for the server endpoint

func NewEndpoint

func NewEndpoint(host string, port int, https bool, insecure bool, cert *[]byte) *Endpoint

NewEndpoint returns new pointer to struct Endpoint, with a default 60s response header timeout

func NewEndpointWithTimeout

func NewEndpointWithTimeout(host string, port int, https bool, insecure bool, cert *[]byte, timeout time.Duration) *Endpoint

NewEndpointWithTimeout returns a new Endpoint with a defined timeout

type GeneralName

type GeneralName struct {
	OID       asn1.ObjectIdentifier
	OtherName `asn1:"tag:0"`
}

GeneralName type for asn1 encoding

type GeneralNames

type GeneralNames struct {
	GeneralName `asn1:"tag:0"`
}

GeneralNames type for asn1 encoding

type HttpPost

type HttpPost func(*Client, *soap.SoapMessage) (string, error)

HttpPost type func for handling http requests

type KeyType

type KeyType uint8

KeyType for RSA/ECDSA

type OtherName

type OtherName struct {
	A string `asn1:"utf8"`
}

OtherName type for asn1 encoding

type Parameters

type Parameters struct {
	Timeout            string
	Locale             string
	EnvelopeSize       int
	TransportDecorator func(*http.Transport) http.RoundTripper
}

Parameters struct defines metadata information and http transport config

func NewParameters

func NewParameters(timeout, locale string, envelopeSize int) *Parameters

NewParameters return new struct of type Parameters this struct makes the configuration for the request, size message, etc.

type Shell

type Shell struct {
	ID string
	// contains filtered or unexported fields
}

Shell is the local view of a WinRM Shell of a given Client

func (*Shell) Close

func (shell *Shell) Close() (err error)

Close will terminate this shell. No commands can be issued once the shell is closed.

func (*Shell) Execute

func (shell *Shell) Execute(command string, arguments ...string) (cmd *Command, err error)

Execute command on the given Shell, returning either an error or a Command

Jump to

Keyboard shortcuts

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