diff --git a/broker/broker.go b/broker/broker.go index c2f34cd..702c401 100644 --- a/broker/broker.go +++ b/broker/broker.go @@ -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 { diff --git a/config/config.go b/config/config.go index afdd20f..220d127 100644 --- a/config/config.go +++ b/config/config.go @@ -18,6 +18,7 @@ var ( ) type Config struct { + APIToken string LogLevel lager.LogLevel ListenPort string Username string diff --git a/integration_tests/broker_suite_test.go b/integration_tests/broker_suite_test.go index 87e061a..13e01f5 100644 --- a/integration_tests/broker_suite_test.go +++ b/integration_tests/broker_suite_test.go @@ -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" @@ -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, diff --git a/main.go b/main.go index 9b8280b..e95f4d9 100644 --- a/main.go +++ b/main.go @@ -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" ) @@ -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,