Skip to content

Commit

Permalink
goimports, docker travis
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeneas Rekkas (arekkas) committed May 26, 2016
1 parent a352d05 commit 15436d0
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 140 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ install:
# Workaround for travis
- go get -t -v ./...
- go install github.com/ory-am/hydra
- git clone https://github.com/docker-library/official-images.git ~/official-images

script:
- go test -race -bench=. $(go list ./... | grep -v /vendor | grep -v /cmd)
- gotestcover -coverprofile="cover.out" $(go list ./... | grep -v /vendor/)
- goveralls -coverprofile="cover.out"
- $GOPATH/bin/hydra
- $GOPATH/bin/hydra
- docker build -t hydra-travis-ci .
- ~/official-images/test/run.sh hydra-travis-ci
11 changes: 6 additions & 5 deletions client/manager_rethinkdb.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package client

import (
r "github.com/dancannon/gorethink"
"sync"
"github.com/ory-am/fosite"

r "github.com/dancannon/gorethink"
"github.com/go-errors/errors"
"golang.org/x/net/context"
"github.com/ory-am/hydra/pkg"
"github.com/ory-am/fosite"
"github.com/ory-am/fosite/hash"
"github.com/ory-am/hydra/pkg"
"github.com/pborman/uuid"
"golang.org/x/net/context"
)

type RethinkManager struct {
Expand Down Expand Up @@ -148,4 +149,4 @@ func (m *RethinkManager) Watch(ctx context.Context) error {
}()

return nil
}
}
18 changes: 10 additions & 8 deletions client/manager_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package client_test

import (
r "github.com/dancannon/gorethink"
"net/http/httptest"
"net/url"
"testing"

r "github.com/dancannon/gorethink"

"log"
"os"
"time"

"github.com/julienschmidt/httprouter"
"github.com/ory-am/fosite"
"github.com/ory-am/fosite/hash"
Expand All @@ -15,11 +20,8 @@ import (
"github.com/ory-am/hydra/pkg"
"github.com/ory-am/ladon"
"github.com/stretchr/testify/assert"
"time"
"os"
"gopkg.in/ory-am/dockertest.v2"
"log"
"golang.org/x/net/context"
"gopkg.in/ory-am/dockertest.v2"
)

var clientManagers = map[string]Storage{}
Expand Down Expand Up @@ -67,7 +69,7 @@ func TestMain(m *testing.M) {
var err error

c, err := dockertest.ConnectToRethinkDB(20, time.Second, func(url string) bool {
if session, err = r.Connect(r.ConnectOpts{Address: url, Database: "hydra"}); err != nil {
if session, err = r.Connect(r.ConnectOpts{Address: url, Database: "hydra"}); err != nil {
return false
} else if _, err = r.DBCreate("hydra").RunWrite(session); err != nil {
log.Printf("Database exists: %s", err)
Expand All @@ -79,8 +81,8 @@ func TestMain(m *testing.M) {

rethinkManager = &RethinkManager{
Session: session,
Table: r.Table("hydra_clients"),
Clients:make(map[string]*fosite.DefaultClient),
Table: r.Table("hydra_clients"),
Clients: make(map[string]*fosite.DefaultClient),
Hasher: &hash.BCrypt{
// Low workfactor reduces test time
WorkFactor: 4,
Expand Down
24 changes: 12 additions & 12 deletions cmd/server/handler_oauth2_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/url"

"github.com/Sirupsen/logrus"
r "github.com/dancannon/gorethink"
"github.com/go-errors/errors"
"github.com/julienschmidt/httprouter"
"github.com/ory-am/fosite"
Expand All @@ -28,7 +29,6 @@ import (
"github.com/ory-am/hydra/oauth2"
"github.com/ory-am/hydra/pkg"
"golang.org/x/net/context"
r "github.com/dancannon/gorethink"
)

func injectFositeStore(c *config.Config, clients client.Manager) {
Expand All @@ -53,18 +53,18 @@ func injectFositeStore(c *config.Config, clients client.Manager) {
con.CreateTableIfNotExists("hydra_implicit")
con.CreateTableIfNotExists("hydra_refresh_token")
m := &internal.FositeRehinkDBStore{
Session: con.GetSession(),
Manager: clients,
Session: con.GetSession(),
Manager: clients,
AuthorizeCodesTable: r.Table("hydra_authorize_code"),
IDSessionsTable: r.Table("hydra_id_sessions"),
AccessTokensTable: r.Table("hydra_access_token"),
ImplicitTable: r.Table("hydra_implicit"),
RefreshTokensTable: r.Table("hydra_refresh_token"),
AuthorizeCodes: make(map[string]*internal.RdbSchema),
IDSessions: make(map[string]*internal.RdbSchema),
AccessTokens: make(map[string]*internal.RdbSchema),
Implicit: make(map[string]*internal.RdbSchema),
RefreshTokens: make(map[string]*internal.RdbSchema),
IDSessionsTable: r.Table("hydra_id_sessions"),
AccessTokensTable: r.Table("hydra_access_token"),
ImplicitTable: r.Table("hydra_implicit"),
RefreshTokensTable: r.Table("hydra_refresh_token"),
AuthorizeCodes: make(map[string]*internal.RdbSchema),
IDSessions: make(map[string]*internal.RdbSchema),
AccessTokens: make(map[string]*internal.RdbSchema),
Implicit: make(map[string]*internal.RdbSchema),
RefreshTokens: make(map[string]*internal.RdbSchema),
}
m.ColdStart()
m.Watch(context.Background())
Expand Down
5 changes: 3 additions & 2 deletions config/backend_connections.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package config

import (
r "github.com/dancannon/gorethink"
"net/url"

"github.com/Sirupsen/logrus"
r "github.com/dancannon/gorethink"
)

type MemoryConnection struct{}
Expand All @@ -21,7 +22,7 @@ func (c *RethinkDBConnection) GetSession() *r.Session {
var err error
password, _ := c.URL.User.Password()
if c.Session, err = r.Connect(r.ConnectOpts{
Address: c.URL.Host,
Address: c.URL.Host,
Database: c.URL.Path,
Username: c.URL.User.Username(),
Password: password,
Expand Down
20 changes: 10 additions & 10 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,31 @@ import (
)

type Config struct {
BindPort int `mapstructure:"port" yaml:"port,omitempty"`
BindPort int `mapstructure:"port" yaml:"port,omitempty"`

BindHost string `mapstructure:"host" yaml:"host,omitempty"`
BindHost string `mapstructure:"host" yaml:"host,omitempty"`

Issuer string `mapstructure:"issuer" yaml:"issuer,omitempty"`
Issuer string `mapstructure:"issuer" yaml:"issuer,omitempty"`

SystemSecret []byte `mapstructure:"system_secret" yaml:"-"`

DatabaseURL string `mapstructure:"database_url" yaml:"database_url,omitempty"`
DatabaseURL string `mapstructure:"database_url" yaml:"database_url,omitempty"`

ConsentURL string `mapstructure:"consent_url" yaml:"consent_url,omitempty"`
ConsentURL string `mapstructure:"consent_url" yaml:"consent_url,omitempty"`

ClusterURL string `mapstructure:"cluster_url" yaml:"cluster_url,omitempty"`
ClusterURL string `mapstructure:"cluster_url" yaml:"cluster_url,omitempty"`

ClientID string `mapstructure:"client_id" yaml:"client_id,omitempty"`
ClientID string `mapstructure:"client_id" yaml:"client_id,omitempty"`

ClientSecret string `mapstructure:"client_secret" yaml:"client_secret,omitempty"`

ForceHTTP bool `mapstructure:"foolishly_force_http" yaml:"-"`
ForceHTTP bool `mapstructure:"foolishly_force_http" yaml:"-"`

cluster *url.URL
cluster *url.URL

oauth2Client *http.Client

context *Context
context *Context

sync.Mutex
}
Expand Down
9 changes: 5 additions & 4 deletions connection/manager_rethinkdb.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package connection

import (
r "github.com/dancannon/gorethink"
"sync"

r "github.com/dancannon/gorethink"

"github.com/go-errors/errors"
"github.com/ory-am/hydra/pkg"
"golang.org/x/net/context"
)

type RethinkManager struct {
Session *r.Session
Table r.Term
Session *r.Session
Table r.Term

Connections map[string]*Connection

Expand Down Expand Up @@ -137,4 +138,4 @@ func (m *RethinkManager) Watch(ctx context.Context) error {
}()

return nil
}
}
21 changes: 11 additions & 10 deletions connection/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
"net/http/httptest"
"net/url"

"log"
"os"
"time"

r "github.com/dancannon/gorethink"
"github.com/julienschmidt/httprouter"
"github.com/ory-am/fosite"
"github.com/ory-am/hydra/herodot"
Expand All @@ -15,12 +20,8 @@ import (
"github.com/pborman/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
r "github.com/dancannon/gorethink"
"time"
"os"
"gopkg.in/ory-am/dockertest.v2"
"log"
"golang.org/x/net/context"
"gopkg.in/ory-am/dockertest.v2"
)

var connections = []*Connection{
Expand Down Expand Up @@ -73,7 +74,7 @@ func TestMain(m *testing.M) {
var err error

c, err := dockertest.ConnectToRethinkDB(20, time.Second, func(url string) bool {
if session, err = r.Connect(r.ConnectOpts{Address: url, Database: "hydra"}); err != nil {
if session, err = r.Connect(r.ConnectOpts{Address: url, Database: "hydra"}); err != nil {
return false
} else if _, err = r.DBCreate("hydra").RunWrite(session); err != nil {
log.Printf("Database exists: %s", err)
Expand All @@ -84,9 +85,9 @@ func TestMain(m *testing.M) {
}

rethinkManager = &RethinkManager{
Session: session,
Table: r.Table("hydra_clients"),
Connections:make(map[string]*Connection),
Session: session,
Table: r.Table("hydra_clients"),
Connections: make(map[string]*Connection),
}
err := rethinkManager.Watch(context.Background())
if err != nil {
Expand Down Expand Up @@ -117,7 +118,7 @@ func BenchmarkRethinkGet(b *testing.B) {
LocalSubject: "peter",
RemoteSubject: "peterson",
Provider: "google",
}, )
})
if err != nil {
b.Fatalf("%s", err)
}
Expand Down
22 changes: 11 additions & 11 deletions internal/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ func NewFirewall(issuer string, subject string, scopes fosite.Arguments, p ...la
conf := &oauth2.Config{Scopes: scopes, Endpoint: oauth2.Endpoint{}}

return &warden.LocalWarden{
Warden: ladonWarden,
TokenValidator: &core.CoreValidator{
AccessTokenStrategy: pkg.HMACStrategy,
AccessTokenStorage: fositeStore,
Warden: ladonWarden,
TokenValidator: &core.CoreValidator{
AccessTokenStrategy: pkg.HMACStrategy,
AccessTokenStorage: fositeStore,
},
Issuer: issuer,
},
Issuer: issuer,
},
conf.Client(oauth2.NoContext, &oauth2.Token{
AccessToken: tokens[0][1],
Expiry: time.Now().Add(time.Hour),
TokenType: "bearer",
})
conf.Client(oauth2.NoContext, &oauth2.Token{
AccessToken: tokens[0][1],
Expiry: time.Now().Add(time.Hour),
TokenType: "bearer",
})
}
Loading

0 comments on commit 15436d0

Please sign in to comment.