Skip to content

Commit

Permalink
add support for Redis
Browse files Browse the repository at this point in the history
  • Loading branch information
afeld committed Jan 7, 2017
1 parent 9e06d2e commit d5cd809
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 6 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ This plugin makes it easy to connect to your databases or other Cloud Foundry se

Currently supports (most) service brokers for the following:

* MySQL
* PostgreSQL
* MySQL (requires `mysql` CLI)
* PostgreSQL (requires `psql` CLI)
* Redis (requires `redis-cli`)

Doesn't run on Windows [yet](https://github.com/18F/cf-service-connect/issues/13).

Expand All @@ -22,7 +23,7 @@ Doesn't run on Windows [yet](https://github.com/18F/cf-service-connect/issues/13
# https://github.com/18F/cf-service-connect/releases/download/<version>/cf-service-connect_<os>_<arch>
```

1. Install `psql` or `mysql` (depending on which you need to connect to).
1. Install CLI corresponding to the service type (see above).

## Usage

Expand Down
2 changes: 1 addition & 1 deletion launcher/ssh_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (t *SSHTunnel) Open() (err error) {

select {
default:
// success (we hope)!
fmt.Println("SSH tunnel created.") // we hope
case e := <-t.errChan:
// SSH tunnel failed
if e == nil {
Expand Down
2 changes: 1 addition & 1 deletion service/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ func (p mySQL) Launch(localPort int, creds models.Credentials) error {
})
}

// singleton
// MySQL is the service singleton.
var MySQL = mySQL{}
2 changes: 1 addition & 1 deletion service/psql.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ func (p pSQL) Launch(localPort int, creds models.Credentials) error {
})
}

// singleton
// PSQL is the service singleton.
var PSQL = pSQL{}
24 changes: 24 additions & 0 deletions service/redis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package service

import (
"strconv"

"github.com/18F/cf-service-connect/launcher"
"github.com/18F/cf-service-connect/models"
)

type redis struct{}

func (p redis) Match(si models.ServiceInstance) bool {
return si.ContainsTerms("redis")
}

func (p redis) Launch(localPort int, creds models.Credentials) error {
return launcher.StartShell("redis-cli", []string{
"-p", strconv.Itoa(localPort),
"-a", creds.GetPassword(),
})
}

// Redis is the service singleton.
var Redis = redis{}
48 changes: 48 additions & 0 deletions service/redis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package service

import (
"testing"

"github.com/18F/cf-service-connect/models"
"github.com/stretchr/testify/assert"
)

type redisMatchTest struct {
serviceName string
planName string
expected bool
}

func TestRedisMatch(t *testing.T) {
tests := []redisMatchTest{
{
"redis",
"shared",
true,
},
{
"somedb",
"shared-redis",
true,
},
{
"aws",
"rds",
false,
},
{
"psql",
"shared",
false,
},
}

for _, test := range tests {
serviceInstance := models.ServiceInstance{
Service: test.serviceName,
Plan: test.planName,
}
result := Redis.Match(serviceInstance)
assert.Equal(t, result, test.expected)
}
}
1 change: 1 addition & 0 deletions service/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Service interface {
var services = []Service{
MySQL,
PSQL,
Redis,
}

func GetService(si models.ServiceInstance) (Service, bool) {
Expand Down

0 comments on commit d5cd809

Please sign in to comment.