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

Commit

Permalink
refactor: use token pkg from fabric8-common (#14)
Browse files Browse the repository at this point in the history
* refactor: use `token` pkg from `fabric8-common`

fixes #6

Signed-off-by: Xavier Coulon <xcoulon@redhat.com>

* go fmt

Signed-off-by: Xavier Coulon <xcoulon@redhat.com>

* Reuse the latest token manager from common

* remove key duplication

* Init defult token manager
  • Loading branch information
xcoulon authored and alexeykazakov committed Oct 28, 2018
1 parent 2d0a3fd commit 146b784
Show file tree
Hide file tree
Showing 25 changed files with 31 additions and 1,308 deletions.
11 changes: 8 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ required = [

[[constraint]]
name = "github.com/fabric8-services/fabric8-common"
revision = "51e44b47e514721ddaa3fca99e5fb5bc1a6e7eb2"
revision = "85e11c21982767f47d3da5e6f59d5b638f8b0313"
3 changes: 2 additions & 1 deletion configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/fabric8-services/fabric8-cluster/rest"
commoncfg "github.com/fabric8-services/fabric8-common/configuration"

"github.com/fsnotify/fsnotify"
"github.com/pkg/errors"
Expand Down Expand Up @@ -673,7 +674,7 @@ func (c *ConfigurationData) GetEnvironment() string {
// GetDevModePrivateKey returns the private key and its ID used in tests
func (c *ConfigurationData) GetDevModePrivateKey() []byte {
if c.DeveloperModeEnabled() {
return []byte(devModePrivateKey)
return []byte(commoncfg.DevModeRsaPrivateKey)
}
return nil
}
28 changes: 0 additions & 28 deletions configuration/defaults.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,6 @@
package configuration

const (
devModePrivateKey = `-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA40yB6SNoU4SpWxTfG5ilu+BlLYikRyyEcJIGg//w/GyqtjvT
/CVo92DRTh/Dl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gPdykiQNQ+UQt
WmVcdPgA5WNCqUu7QGK0Joer52AXnkAacYHwdtHXPRkKf66n01rKK2wZexvan91A
m0gcJcFs5IYbZZy9ecvNdB8CgYEAo4JZ5Vay93j1YGnLWcrixDCp/wXYUJbOidGC
QBpZZQf3Hh11JkT7O2uSm2T727yAmw63uC2B3VotNOCLI8ZMHRLsjQ8vOCFAjqdF
rLeg3iQss/bFfkA9b1Y8VNoiVJbGC3fbWu/WDoWXxa12fL/jruG43hsGEUnJL6Q5
K8tOdskCgYABpoHFRxsvJ5Sp9CUS3BBTicVSkpAjoX2O3+cS9XL8IsIqZEMW7VKb
16/H2BRvI0uUq12t+UCc0P0SyrWRGxwGR5zSYHVDOot5EDHqE8aYSbX4jiXtAAiu
qCn3Rug8QWyBjjxnU3CxPRiLSmEllQAAVlzfRWn6kL4RKSyruUhZaA==
-----END RSA PRIVATE KEY-----`

defaultDBPassword = "mysecretpassword"

defaultLogLevel = "info"
Expand Down
3 changes: 1 addition & 2 deletions controller/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"github.com/fabric8-services/fabric8-cluster/configuration"
"github.com/fabric8-services/fabric8-cluster/jsonapi"
"github.com/fabric8-services/fabric8-cluster/rest"
"github.com/fabric8-services/fabric8-cluster/token"

"github.com/fabric8-services/fabric8-common/errors"
"github.com/fabric8-services/fabric8-common/log"
"github.com/fabric8-services/fabric8-common/token"

"github.com/goadesign/goa"
)
Expand Down
15 changes: 8 additions & 7 deletions controller/clusters_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/fabric8-services/fabric8-cluster/app/test"
. "github.com/fabric8-services/fabric8-cluster/controller"
"github.com/fabric8-services/fabric8-cluster/rest"
testsupport "github.com/fabric8-services/fabric8-cluster/test"
testsuite "github.com/fabric8-services/fabric8-cluster/test/suite"
"github.com/fabric8-services/fabric8-common/test/auth"

"github.com/goadesign/goa"
"github.com/satori/go.uuid"
Expand All @@ -23,8 +23,9 @@ func TestRunClustersREST(t *testing.T) {
suite.Run(t, &ClustersTestSuite{UnitTestSuite: testsuite.NewUnitTestSuite()})
}

func (s *ClustersTestSuite) SecuredControllerWithServiceAccount(serviceAccount *testsupport.Identity) (*goa.Service, *ClustersController) {
svc := testsupport.ServiceAsServiceAccountUser("Token-Service", serviceAccount)
func (s *ClustersTestSuite) SecuredControllerWithServiceAccount(serviceAccount *auth.Identity) (*goa.Service, *ClustersController) {
svc, err := auth.ServiceAsServiceAccountUser("Token-Service", serviceAccount)
require.NoError(s.T(), err)
return svc, NewClustersController(svc, s.Config)
}

Expand All @@ -38,7 +39,7 @@ func (s *ClustersTestSuite) TestShowForServiceAccountsOK() {
}

func (s *ClustersTestSuite) checkShowForServiceAccount(saName string) {
sa := &testsupport.Identity{
sa := &auth.Identity{
Username: saName,
ID: uuid.NewV4(),
}
Expand All @@ -61,7 +62,7 @@ func (s *ClustersTestSuite) checkShowForServiceAccount(saName string) {
}

func (s *ClustersTestSuite) TestShowForUnknownSAFails() {
sa := &testsupport.Identity{
sa := &auth.Identity{
Username: "unknown-sa",
ID: uuid.NewV4(),
}
Expand All @@ -75,7 +76,7 @@ func (s *ClustersTestSuite) TestShowForAuthServiceAccountsOK() {
}

func (s *ClustersTestSuite) TestShowAuthForUnknownSAFails() {
sa := &testsupport.Identity{
sa := &auth.Identity{
Username: "fabric8-tenant",
ID: uuid.NewV4(),
}
Expand All @@ -84,7 +85,7 @@ func (s *ClustersTestSuite) TestShowAuthForUnknownSAFails() {
}

func (s *ClustersTestSuite) checkShowAuthForServiceAccount(saName string) {
sa := &testsupport.Identity{
sa := &auth.Identity{
Username: saName,
ID: uuid.NewV4(),
}
Expand Down
3 changes: 0 additions & 3 deletions goamiddleware/doc.go

This file was deleted.

51 changes: 0 additions & 51 deletions goamiddleware/jwt_token_context.go

This file was deleted.

75 changes: 0 additions & 75 deletions goamiddleware/jwt_token_context_whitebox_test.go

This file was deleted.

10 changes: 0 additions & 10 deletions gormtestsupport/db_test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"github.com/fabric8-services/fabric8-cluster/resource"
"github.com/fabric8-services/fabric8-common/log"

"github.com/fabric8-services/fabric8-cluster/test/graph"

"github.com/jinzhu/gorm"
_ "github.com/lib/pq" // need to import postgres driver
"github.com/stretchr/testify/suite"
Expand All @@ -36,7 +34,6 @@ type DBTestSuite struct {
cleanTest func()
cleanSuite func()
Ctx context.Context
Graph *graph.TestGraph
}

// SetupSuite implements suite.SetupAllSuite
Expand Down Expand Up @@ -69,8 +66,6 @@ func (s *DBTestSuite) SetupSuite() {
// SetupTest implements suite.SetupTest
func (s *DBTestSuite) SetupTest() {
s.cleanTest = cleaner.DeleteCreatedEntities(s.DB)
g := s.NewTestGraph()
s.Graph = &g
}

// TearDownTest implements suite.TearDownTest
Expand All @@ -81,7 +76,6 @@ func (s *DBTestSuite) TearDownTest() {
if s.Configuration.IsCleanTestDataEnabled() {
s.cleanTest()
}
s.Graph = nil
}

// PopulateDBTestSuite populates the DB with common values
Expand Down Expand Up @@ -119,7 +113,3 @@ func (s *DBTestSuite) DisableGormCallbacks() func() {
s.DB.Callback().Update().Register(gormCallbackName, oldUpdateCallback)
}
}

func (s *DBTestSuite) NewTestGraph() graph.TestGraph {
return graph.NewTestGraph(s.T(), s.Application, s.Ctx, s.DB)
}
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"github.com/fabric8-services/fabric8-cluster/application/transaction"
"github.com/fabric8-services/fabric8-cluster/configuration"
"github.com/fabric8-services/fabric8-cluster/controller"
"github.com/fabric8-services/fabric8-cluster/goamiddleware"
"github.com/fabric8-services/fabric8-cluster/jsonapi"
"github.com/fabric8-services/fabric8-cluster/migration"
"github.com/fabric8-services/fabric8-cluster/sentry"
"github.com/fabric8-services/fabric8-cluster/token"
"github.com/fabric8-services/fabric8-common/goamiddleware"
"github.com/fabric8-services/fabric8-common/log"
"github.com/fabric8-services/fabric8-common/token"

"github.com/goadesign/goa"
"github.com/goadesign/goa/logging/logrus"
Expand Down Expand Up @@ -149,7 +149,7 @@ func main() {
//appDB := gormapplication.NewGormDB(db, config)

// Setup Security
tokenManager, err := token.NewManager(config)
tokenManager, err := token.DefaultManager(config)
if err != nil {
log.Panic(nil, map[string]interface{}{
"err": err,
Expand Down
2 changes: 1 addition & 1 deletion sentry/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"fmt"

"github.com/fabric8-services/fabric8-cluster/token"
"github.com/fabric8-services/fabric8-common/sentry"
"github.com/fabric8-services/fabric8-common/token"

"github.com/getsentry/raven-go"
"github.com/goadesign/goa/middleware/security/jwt"
Expand Down
Loading

0 comments on commit 146b784

Please sign in to comment.