pulley

package module
v0.0.0-...-7aeeefe Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2016 License: Apache-2.0 Imports: 5 Imported by: 0

README

Pulley Build Status GoDoc

A suckless way to use SSH as a client in golang.

Installation

Simply import it in your project and run go get

import "github.com/chasinglogic/pulley"

Alternatively you can go get it directly:

go get github.com/chasinglogic/pulley

Usage

For full usage you can check out the godoc

TODO: Add examples.

Contributing

  1. Fork 🍴 it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push :shipit: to the branch: git push origin my-new-feature
  5. 🔥 Submit a pull request :D 🔥

All pull(ey) requests should go to the develop branch not master. Thanks!

History

This library was inspired by a combination of paramiko and parallel ssh I was working on a tool for remote management of Unix systems and was writing so much wrapper code for the golang ssh package that I realized it should be a library of it's own and thus Pulley was born.

License

This code is distributed under the Apache 2.0 License.

Copyright 2016 Mathew Robinson

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Overview

Package pulley is a wrapper around the golang.org/x/crypto/ssh package providing a suckless experience.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HostName string
	Port     string
	User     string
	// contains filtered or unexported fields
}

Client is the client for the ssh connection and the primary way to interact with pulley.

func New

func New(user string) *Client

New creates a default Client. Modify this client via it's public members, HostName, Port, and User. These default to localhost, 22, and the current user running the process.

func (*Client) Connect

func (s *Client) Connect() error

Connect will connect the client to it's hostname and port, if LoadKey or LoadDefaultKey have not been called yet this will call LoadDefaultKey

func (*Client) Exec

func (s *Client) Exec(cmd string) Result

Exec runs the command on the server that's connected to by this client, if It will handle sessions automatically and return a pulley.Result

func (*Client) ExecAsync

func (s *Client) ExecAsync(cmd string, rc chan Result)

ExecAsync is the same as exec however will execute in a go routine and takes a channel which it will send the result over.

func (*Client) ExecAsyncErr

func (s *Client) ExecAsyncErr(cmd string, rc chan Result)

ExecAsyncErr is the same as ExecAsync however the result's output will have both stderr and stdout.

func (*Client) ExecErr

func (s *Client) ExecErr(cmd string) Result

ExecErr is the same as exec however the result's output will have both stdout and stderr.

func (*Client) LoadDefaultKey

func (s *Client) LoadDefaultKey() error

LoadDefaultKey will load the ssh key at $HOME/.ssh/id_rsa

func (*Client) LoadKey

func (s *Client) LoadKey(key []byte) error

LoadKey will load the given key

func (*Client) Session

func (s *Client) Session() (*ssh.Session, error)

Session will return a new session for the current connection or an error if there was one. You only need to use this if you're doing something advanced.

func (*Client) Ugly

func (s *Client) Ugly() (*ssh.Client, *ssh.ClientConfig)

Ugly will return the underlying ssh.Client and ssh.ClientConfig in case you need those structs directly.

type Result

type Result struct {
	Output []byte
	// contains filtered or unexported fields
}

Result represents the result of a command executed via SSH

func (*Result) Err

func (r *Result) Err() error

Err will return the error that occurred and nil if there was no errors.

func (*Result) Failure

func (r *Result) Failure() bool

Failure returns a boolean indicating sucess or failure. true == failed

func (*Result) String

func (r *Result) String() string

String is a convenience method for printing and for getting the stringified output

func (*Result) Success

func (r *Result) Success() bool

Success returns a boolean indicating sucess or failure. true == success

Jump to

Keyboard shortcuts

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