Skip to content
This repository has been archived by the owner on Mar 29, 2018. It is now read-only.

Commit

Permalink
Merge pull request #2 from bryanl/ssh-support
Browse files Browse the repository at this point in the history
Allow a user to ssh to drop given name or id
  • Loading branch information
bryanl committed Jun 17, 2015
2 parents 6ec10a8 + da433d7 commit cd6c8b9
Show file tree
Hide file tree
Showing 29 changed files with 493 additions and 142 deletions.
2 changes: 1 addition & 1 deletion account.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func AccountGet(c *cli.Context) {
client := NewClient(c, DefaultClientSource)
client := NewClient(c, DefaultConfig)
err := accountGet(client, c.App.Writer)
if err != nil {
log.WithField("err", err).Fatal("could not display account")
Expand Down
2 changes: 1 addition & 1 deletion account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestAccountAction(t *testing.T) {
},
}

cs := &TestClientSource{client}
cs := NewTestConfig(client)

WithinTest(cs, nil, func(c *cli.Context) {
AccountGet(c)
Expand Down
4 changes: 2 additions & 2 deletions actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func ActionList(c *cli.Context) {
client := NewClient(c, DefaultClientSource)
client := NewClient(c, DefaultConfig)
opts := LoadOpts(c)
err := actionsList(client, opts, c.App.Writer)
if err != nil {
Expand All @@ -19,7 +19,7 @@ func ActionList(c *cli.Context) {
}

func ActionGet(c *cli.Context) {
client := NewClient(c, DefaultClientSource)
client := NewClient(c, DefaultConfig)
id := c.Int("action-id")

if id < 1 {
Expand Down
4 changes: 2 additions & 2 deletions actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestActionList(t *testing.T) {
},
}

cs := &TestClientSource{client}
cs := NewTestConfig(client)

WithinTest(cs, nil, func(c *cli.Context) {
ActionList(c)
Expand All @@ -54,7 +54,7 @@ func TestActionGet(t *testing.T) {
},
}

cs := &TestClientSource{client}
cs := NewTestConfig(client)
fs := flag.NewFlagSet("flag set", 0)
fs.Int("action-id", testAction.ID, "action-id")

Expand Down
5 changes: 3 additions & 2 deletions cmd/docli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (t *tokenSource) Token() (*oauth2.Token, error) {

func init() {
logrus.SetOutput(os.Stderr)
logrus.SetLevel(logrus.WarnLevel)
logrus.SetLevel(logrus.InfoLevel)

docli.Bail = func(err error, msg string) {
logrus.WithField("err", err).Fatal(msg)
Expand All @@ -46,9 +46,10 @@ func main() {
dropletActionCommands(),
imageActionCommands(),
imageCommands(),
sshKeyCommands(),
regionCommands(),
sizeCommands(),
sshKeyCommands(),
sshCommands(),
}

app.RunAndExitOnError()
Expand Down
24 changes: 24 additions & 0 deletions cmd/docli/ssh_commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"github.com/bryanl/docli"
"github.com/codegangsta/cli"
)

func sshCommands() cli.Command {
return cli.Command{
Name: "ssh",
Usage: "SSH to droplet. Provide name or id",
Flags: []cli.Flag{
cli.StringFlag{
Name: docli.ArgDropletName,
Usage: "droplet name",
},
cli.IntFlag{
Name: docli.ArgDropletID,
Usage: "droplet id",
},
},
Action: docli.SSH,
}
}
20 changes: 19 additions & 1 deletion docli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,27 @@ package docli
import (
"os"
"testing"

"github.com/digitalocean/godo"
)

var lastBailOut bailOut
var (
testDroplet = godo.Droplet{
ID: 1,
Name: "a-droplet",
Networks: &godo.Networks{
V4: []godo.NetworkV4{
{IPAddress: "8.8.8.8", Type: "public"},
{IPAddress: "172.16.1.2", Type: "private"},
},
},
}
testDropletList = []godo.Droplet{testDroplet}
testKernel = godo.Kernel{ID: 1}
testKernelList = []godo.Kernel{testKernel}

lastBailOut bailOut
)

type bailOut struct {
err error
Expand Down
10 changes: 5 additions & 5 deletions domainrecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func RecordCreate(c *cli.Context) {
client := NewClient(c, DefaultClientSource)
client := NewClient(c, DefaultConfig)
domainName := c.String("domain-name")

drcr := &godo.DomainRecordEditRequest{
Expand All @@ -28,7 +28,7 @@ func RecordCreate(c *cli.Context) {
}

func RecordDelete(c *cli.Context) {
client := NewClient(c, DefaultClientSource)
client := NewClient(c, DefaultConfig)
domainName := c.String("domain-name")
recordID := c.Int("record-id")

Expand All @@ -40,7 +40,7 @@ func RecordDelete(c *cli.Context) {

// List records for a domain.
func RecordList(c *cli.Context) {
client := NewClient(c, DefaultClientSource)
client := NewClient(c, DefaultConfig)
opts := LoadOpts(c)
name := c.String("domain-name")

Expand Down Expand Up @@ -73,7 +73,7 @@ func RecordList(c *cli.Context) {

// Retrieve a domain record.
func RecordGet(c *cli.Context) {
client := NewClient(c, DefaultClientSource)
client := NewClient(c, DefaultConfig)
domainName := c.String("domain-name")
recordID := c.Int("record-id")

Expand All @@ -86,7 +86,7 @@ func RecordGet(c *cli.Context) {
}

func RecordUpdate(c *cli.Context) {
client := NewClient(c, DefaultClientSource)
client := NewClient(c, DefaultConfig)
domainName := c.String("domain-name")
recordID := c.Int("record-id")

Expand Down
10 changes: 5 additions & 5 deletions domainrecs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestRecordsList(t *testing.T) {
},
}

cs := &TestClientSource{client}
cs := NewTestConfig(client)
fs := flag.NewFlagSet("flag set", 0)
fs.String("domain-name", "example.com", "domain-name")

Expand All @@ -53,7 +53,7 @@ func TestRecordsGet(t *testing.T) {
},
}

cs := &TestClientSource{client}
cs := NewTestConfig(client)
fs := flag.NewFlagSet("flag set", 0)
fs.String("domain-name", "example.com", "domain-name")
fs.Int("record-id", testRecord.ID, "record-id")
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestRecordsCreate(t *testing.T) {
},
}

cs := &TestClientSource{client}
cs := NewTestConfig(client)
fs := flag.NewFlagSet("flag set", 0)
fs.String("domain-name", "example.com", "domain-name")
fs.String("record-type", "A", "record-type")
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestRecordsUpdate(t *testing.T) {
},
}

cs := &TestClientSource{client}
cs := NewTestConfig(client)
fs := flag.NewFlagSet("flag set", 0)
fs.String("domain-name", "example.com", "domain-name")
fs.Int("record-id", 1, "record-id")
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestRecordsDelete(t *testing.T) {
},
}

cs := &TestClientSource{client}
cs := NewTestConfig(client)
fs := flag.NewFlagSet("flag set", 0)
fs.String("domain-name", "example.com", "domain-name")
fs.Int("record-id", 1, "record-id")
Expand Down
8 changes: 4 additions & 4 deletions domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func DomainCreate(c *cli.Context) {
client := NewClient(c, DefaultClientSource)
client := NewClient(c, DefaultConfig)
req := &godo.DomainCreateRequest{
Name: c.String("domain-name"),
IPAddress: c.String("ip-address"),
Expand All @@ -21,7 +21,7 @@ func DomainCreate(c *cli.Context) {
}

func DomainDelete(c *cli.Context) {
client := NewClient(c, DefaultClientSource)
client := NewClient(c, DefaultConfig)
name := c.String("domain-name")
_, err := client.Domains.Delete(name)
if err != nil {
Expand All @@ -31,7 +31,7 @@ func DomainDelete(c *cli.Context) {

// List lists all domains.
func DomainList(c *cli.Context) {
client := NewClient(c, DefaultClientSource)
client := NewClient(c, DefaultConfig)
opts := LoadOpts(c)

f := func(opt *godo.ListOptions) ([]interface{}, *godo.Response, error) {
Expand Down Expand Up @@ -62,7 +62,7 @@ func DomainList(c *cli.Context) {
}

func DomainGet(c *cli.Context) {
client := NewClient(c, DefaultClientSource)
client := NewClient(c, DefaultConfig)
id := c.String("domain-name")
a, _, err := client.Domains.Get(id)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestDomainsList(t *testing.T) {
},
}

cs := &TestClientSource{client}
cs := NewTestConfig(client)

WithinTest(cs, nil, func(c *cli.Context) {
DomainList(c)
Expand All @@ -53,7 +53,7 @@ func TestDomainsGet(t *testing.T) {
},
}

cs := &TestClientSource{client}
cs := NewTestConfig(client)
fs := flag.NewFlagSet("flag set", 0)
fs.String("domain-name", testDomain.Name, "domain-id")

Expand All @@ -78,7 +78,7 @@ func TestDomainsCreate(t *testing.T) {
},
}

cs := &TestClientSource{client}
cs := NewTestConfig(client)
fs := flag.NewFlagSet("flag set", 0)
fs.String("domain-name", testDomain.Name, "domain-name")
fs.String("ip-address", "127.0.0.1", "ip- address")
Expand All @@ -100,7 +100,7 @@ func TestDomainsDelete(t *testing.T) {
},
}

cs := &TestClientSource{client}
cs := NewTestConfig(client)
fs := flag.NewFlagSet("flag set", 0)
fs.String("domain-name", testDomain.Name, "domain-name")

Expand Down
Loading

0 comments on commit cd6c8b9

Please sign in to comment.