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

Commit

Permalink
initialise the use of composeapi
Browse files Browse the repository at this point in the history
  • Loading branch information
paroxp authored and Piotr Komborski committed May 26, 2017
1 parent ff95a96 commit a9b38b9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
13 changes: 11 additions & 2 deletions broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,30 @@ import (

"github.com/alphagov/paas-compose-broker/catalog"
"github.com/alphagov/paas-compose-broker/config"
"github.com/compose/gocomposeapi"
"github.com/pivotal-cf/brokerapi"
)

type Broker struct {
Compose *composeapi.Client
Config *config.Config
Catalog *catalog.Catalog
Logger *lager.Logger
}

func New(config *config.Config, catalog *catalog.Catalog, logger *lager.Logger) *Broker {
return &Broker{
func New(compose *composeapi.Client, config *config.Config, catalog *catalog.Catalog, logger *lager.Logger) (*Broker, error) {
if compose == nil {
return nil, fmt.Errorf("broker: composer should not be nil")
}

broker := Broker{
Compose: compose,
Config: config,
Catalog: catalog,
Logger: logger,
}

return &broker, nil
}

func (b *Broker) Services(context context.Context) []brokerapi.Service {
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
)

type Config struct {
APIToken string
LogLevel lager.LogLevel
ListenPort string
Username string
Expand Down
5 changes: 5 additions & 0 deletions integration_tests/broker_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/alphagov/paas-compose-broker/broker"
"github.com/alphagov/paas-compose-broker/catalog"
"github.com/alphagov/paas-compose-broker/config"
composeapi "github.com/compose/gocomposeapi"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pivotal-cf/brokerapi"
Expand Down Expand Up @@ -92,6 +93,10 @@ func TestSuite(t *testing.T) {
Expect(err).ToNot(HaveOccurred())

broker := broker.New(config, newCatalog, &logger)
compose, err := composeapi.NewClient(config.APIToken)
Expect(err).NotTo(HaveOccurred())
broker, err := broker.New(compose, config, &newCatalog, &logger)
Expect(err).NotTo(HaveOccurred())
credentials := brokerapi.BrokerCredentials{
Username: config.Username,
Password: config.Password,
Expand Down
14 changes: 13 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/alphagov/paas-compose-broker/broker"
"github.com/alphagov/paas-compose-broker/catalog"
"github.com/alphagov/paas-compose-broker/config"
composeapi "github.com/compose/gocomposeapi"
"github.com/pivotal-cf/brokerapi"
)

Expand Down Expand Up @@ -44,7 +45,18 @@ func main() {
os.Exit(1)
}

broker := broker.New(config, newCatalog, &logger)
compose, err := composeapi.NewClient(config.APIToken)
if err != nil {
logger.Error("could not create composeapi client", err)
os.Exit(1)
}

broker, err := broker.New(compose, config, newCatalog, &logger)
if err != nil {
logger.Error("could not initialise broker", err)
os.Exit(1)
}

credentials := brokerapi.BrokerCredentials{
Username: config.Username,
Password: config.Password,
Expand Down

0 comments on commit a9b38b9

Please sign in to comment.