cli

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 18, 2017 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Registrar = map[CmdName](func() Command){}

Registrar is used to register command generators within the module.

Functions

func CheckEnvWarp added in v0.0.3

func CheckEnvWarp(
	ctx context.Context,
) error

CheckWarpEnv checks that the warp.EnvWarp env variable is set. If not it returns an error after displaying an helpful message.

func ConfigPath added in v0.0.3

func ConfigPath(
	ctx context.Context,
) (*string, error)

ConfigPath returns the crendentials path for the current environment.

func RunLocalCommand

func RunLocalCommand(
	ctx context.Context,
	cmd warp.Command,
) (*warp.CommandResult, error)

RunLocalCommand runs a local in-warp command and returns the result. If an error is returned as part of the result, it formats a human readable error that can be safely returned top the user.

Types

type Cli

type Cli struct {
	Ctx   context.Context
	Flags map[string]string
	Args  []string
}

Cli represents a cli instance.

func New

func New(
	argv []string,
) (*Cli, error)

New initializes a new Cli by parsing the passed arguments.

func (*Cli) Run

func (c *Cli) Run() error

Run the cli.

type CmdName

type CmdName string

CmdName represents a command name.

type Command

type Command interface {
	// Name returns the command name.
	Name() CmdName

	// Help prints out the help message for the command.
	Help(context.Context)

	// Parse the arguments and flags passed to the command.
	Parse(context.Context, []string, map[string]string) error

	// Execute the command or return a human-friendly error.
	Execute(context.Context) error
}

Command is the interface for a cli command.

type Config added in v0.0.3

type Config struct {
	Credentials Credentials `json:"credentials"`
}

Config represents the local configuration for warp.

func GenerateConfig added in v0.0.3

func GenerateConfig(
	ctx context.Context,
) (*Config, error)

GenerateConfig generates a new config and store it. As part of it, it generates a new set of credentials.

func RetrieveConfig added in v0.0.3

func RetrieveConfig(
	ctx context.Context,
) (*Config, error)

RetrieveConfig retrieves the current user config by reading ConfigPath.

func RetrieveOrGenerateConfig added in v0.0.3

func RetrieveOrGenerateConfig(
	ctx context.Context,
) (*Config, error)

RetrieveOrGenerateConfig retrieves the current config or generates it.

type Credentials added in v0.0.3

type Credentials struct {
	User   string `json:"user"`
	Secret string `json:"secret"`
}

Credentials repesents the credentials of the currently logged in user.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session represents a session to warpd as part of a client or a host. All methods are thread-safe except the Decode* methods.

func NewSession

func NewSession(
	ctx context.Context,
	session warp.Session,
	w string,
	sessionType warp.SessionType,
	username string,
	cancel func(),
	conn net.Conn,
) (*Session, error)

NewSession sets up a session, opens the associated channels and return a Session object.

func (*Session) DataC

func (ss *Session) DataC() net.Conn

DataC returns the data channel. Using the dataC is not thread-safe and should happen from only one go routine for reading only. Writing should go through thread-safe WriteDataC.

func (*Session) DecodeError

func (ss *Session) DecodeError(
	ctx context.Context,
) (*warp.Error, error)

DecodeError attempts to decode an error from the errorC. This method is not thread-safe.

func (*Session) DecodeState

func (ss *Session) DecodeState(
	ctx context.Context,
) (*warp.State, error)

DecodeState attempts to decode state from the sateC. This method is not thread-safe.

func (*Session) GetMode added in v0.0.3

func (ss *Session) GetMode(
	user string,
) (*warp.Mode, error)

GetMode returns the mode of a user.

func (*Session) HostCanReceiveWrite added in v0.0.3

func (ss *Session) HostCanReceiveWrite() bool

HostCanReceiverWrite retruns whether the host can receive write from any shell client.

func (*Session) Modes added in v0.0.3

func (ss *Session) Modes() map[string]warp.Mode

Modes returns user modes.

func (*Session) ProtocolState added in v0.0.3

func (ss *Session) ProtocolState() warp.State

State returns the session warp state.

func (*Session) SendHostUpdate

func (ss *Session) SendHostUpdate(
	ctx context.Context,
	update warp.HostUpdate,
) error

SendHostUpdate is used to safely concurrently sending host updates.

func (*Session) Session

func (ss *Session) Session() warp.Session

Session returns the protocol session representation.

func (*Session) SetMode added in v0.0.3

func (ss *Session) SetMode(
	user string,
	mode warp.Mode,
) error

SetMode sets the mode for a user.

func (*Session) TearDown

func (ss *Session) TearDown()

TearDown tears down a session, closing and reclaiming channels.

func (*Session) TornDown

func (ss *Session) TornDown() bool

TornDown returns the session tornDown value.

func (*Session) UpdateState added in v0.0.3

func (ss *Session) UpdateState(
	state warp.State,
	hosting bool,
) error

UpdateState updates the session state with a received warp.State.

func (*Session) Warp

func (ss *Session) Warp() string

Warp returns the session warp token.

func (*Session) WindowSize added in v0.0.3

func (ss *Session) WindowSize() warp.Size

WindowSizse returns the current window size.

func (*Session) WriteDataC added in v0.0.3

func (ss *Session) WriteDataC(
	data []byte,
)

WriteData writes to dataC in a thread-safe way, checking that the session is not torn down.

type Shell added in v0.0.3

type Shell struct {
	Command string
}

func DetectShell added in v0.0.3

func DetectShell(
	ctx context.Context,
) (*Shell, error)

type Srv

type Srv struct {
	// contains filtered or unexported fields
}

func NewSrv

func NewSrv(
	ctx context.Context,
	warp string,
) *Srv

NewSrv constructs a Srv ready to start serving local requests.

func (*Srv) Path

func (s *Srv) Path() string

Path returns the unix socket path.

func (*Srv) Run

func (s *Srv) Run(
	ctx context.Context,
) error

Run starts the local server.

func (*Srv) SetSession added in v0.0.3

func (s *Srv) SetSession(
	ctx context.Context,
	session *Session,
)

SetSession sets the session the srv should use. It is set to nil if the warp is currently disconnected. The write to the session variable is protected by a mutex that is locked when comands are executed (to avoid accessing a niled out session).

type UserState

type UserState struct {
	// contains filtered or unexported fields
}

UserState represents the state of a user as seen client-side.

func (*UserState) ProtocolUser added in v0.0.3

func (u *UserState) ProtocolUser() warp.User

User returns a warp.User from the current UserState.

type WarpState added in v0.0.3

type WarpState struct {
	// contains filtered or unexported fields
}

WarpState repreents the state of a warp client side. The warp state method are not thread-safe and access to it should be protected by the associated session lock.

func NewWarpState added in v0.0.3

func NewWarpState(
	hello warp.SessionHello,
) *WarpState

Returns a new warp state initialized by a hello message.

func (*WarpState) GetMode added in v0.0.3

func (w *WarpState) GetMode(
	user string,
) (*warp.Mode, error)

GetMode returns the mode of a given user.

func (*WarpState) HostCanReceiveWrite added in v0.0.3

func (w *WarpState) HostCanReceiveWrite() bool

HostCanReceiveWrite computes whether the host can receive write from the shell clients. This is used as defense in depth to prevent any write if that's not the case.

func (*WarpState) Modes added in v0.0.3

func (w *WarpState) Modes() map[string]warp.Mode

Modes returns user modes.

func (*WarpState) ProtocolState added in v0.0.3

func (w *WarpState) ProtocolState() warp.State

ProtocolState computes a warp.State from the current warp. It acquires the warp lock.

func (*WarpState) SetMode added in v0.0.3

func (w *WarpState) SetMode(
	user string,
	mode warp.Mode,
) error

SetMode updates the mode of a given user.

func (*WarpState) Update added in v0.0.3

func (w *WarpState) Update(
	state warp.State,
	hosting bool,
) error

Update the warp state given a warp.State received over the wire.

If preserveModes is true the modes are preserved (used from the host session as the server is not trusted with modes). If the state includes an unknown user, the default secure modes are used (~read-only).

func (*WarpState) WindowSize added in v0.0.3

func (w *WarpState) WindowSize() warp.Size

WindowSizse returns the current window size.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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