})

		Context("when the response status is unexpected", func() {
			It("returns an error", func() {
				err := service.Delete("very-bad-guid", token)
				Expect(err).To(BeAssignableToTypeOf(rainmaker.Error{}))
			})
		})
	})

	Context("when listing related spaces", func() {
		var space1, space2 rainmaker.Space

		BeforeEach(func() {
			var err error
			spacesService := rainmaker.NewSpacesService(config)

			space1, err = spacesService.Create("space-123", organization.GUID, token)
			Expect(err).NotTo(HaveOccurred())

			space2, err = spacesService.Create("space-456", organization.GUID, token)
			Expect(err).NotTo(HaveOccurred())
		})

		Describe("ListSpaces", func() {
			It("returns the spaces belonging to the organization", func() {
				list, err := service.ListSpaces(organization.GUID, token)
				Expect(err).NotTo(HaveOccurred())
				Expect(list.TotalResults).To(Equal(2))
				Expect(list.TotalPages).To(Equal(1))
				Expect(list.Spaces).To(HaveLen(2))
Ejemplo n.º 2
0
	var (
		config    rainmaker.Config
		service   rainmaker.SpacesService
		token     string
		spaceName string
		org1      rainmaker.Organization
		org2      rainmaker.Organization
	)

	BeforeEach(func() {
		var err error
		token = "token-asd"
		config = rainmaker.Config{
			Host: fakeCloudController.URL(),
		}
		service = rainmaker.NewSpacesService(config)
		spaceName = "my-space"

		org1, err = rainmaker.NewOrganizationsService(config).Create("org-123", token)
		Expect(err).NotTo(HaveOccurred())

		org2, err = rainmaker.NewOrganizationsService(config).Create("org-456", token)
		Expect(err).NotTo(HaveOccurred())
	})

	Describe("Create/Get", func() {
		It("creates a space and allows it to be fetched from the cloud controller", func() {
			space, err := service.Create(spaceName, org1.GUID, token)
			Expect(err).NotTo(HaveOccurred())
			Expect(space.Name).To(Equal(spaceName))
			Expect(space.OrganizationGUID).To(Equal(org1.GUID))
Ejemplo n.º 3
0
func NewRouter(mx muxer, config Config) http.Handler {
	requestCounter := middleware.NewRequestCounter(mx.GetRouter(), metrics.DefaultLogger)
	logging := middleware.NewRequestLogging(config.Logger)
	notificationsWriteAuthenticator := middleware.NewAuthenticator(config.UAAPublicKey, "notifications.write")
	databaseAllocator := middleware.NewDatabaseAllocator(config.SQLDB, config.DBLoggingEnabled)

	warrantConfig := warrant.Config{
		Host:          config.UAAHost,
		SkipVerifySSL: config.SkipVerifySSL,
	}
	warrantUsersService := warrant.NewUsersService(warrantConfig)
	warrantClientsService := warrant.NewClientsService(warrantConfig)

	rainmakerConfig := rainmaker.Config{
		Host:          config.CCHost,
		SkipVerifySSL: config.SkipVerifySSL,
	}
	rainmakerSpacesService := rainmaker.NewSpacesService(rainmakerConfig)
	rainmakerOrganizationsService := rainmaker.NewOrganizationsService(rainmakerConfig)

	userFinder := uaa.NewUserFinder(config.UAAClientID, config.UAAClientSecret, warrantUsersService, warrantClientsService)
	spaceFinder := cf.NewSpaceFinder(config.UAAClientID, config.UAAClientSecret, warrantClientsService, rainmakerSpacesService)
	orgFinder := cf.NewOrgFinder(config.UAAClientID, config.UAAClientSecret, warrantClientsService, rainmakerOrganizationsService)

	campaignEnqueuer := queue.NewCampaignEnqueuer(config.Queue)

	sendersRepository := models.NewSendersRepository(uuid.NewV4)
	campaignTypesRepository := models.NewCampaignTypesRepository(uuid.NewV4)
	templatesRepository := models.NewTemplatesRepository(uuid.NewV4)
	campaignsRepository := models.NewCampaignsRepository(uuid.NewV4)
	messagesRepository := models.NewMessagesRepository(util.NewClock())

	sendersCollection := collections.NewSendersCollection(sendersRepository, campaignTypesRepository)
	templatesCollection := collections.NewTemplatesCollection(templatesRepository)
	campaignTypesCollection := collections.NewCampaignTypesCollection(campaignTypesRepository, sendersRepository, templatesRepository)
	campaignsCollection := collections.NewCampaignsCollection(campaignEnqueuer, campaignsRepository, campaignTypesRepository, templatesRepository, sendersRepository, userFinder, spaceFinder, orgFinder)
	campaignStatusesCollection := collections.NewCampaignStatusesCollection(campaignsRepository, messagesRepository)

	info.Routes{
		RequestCounter: requestCounter,
		RequestLogging: logging,
	}.Register(mx)

	senders.Routes{
		RequestLogging:    logging,
		Authenticator:     notificationsWriteAuthenticator,
		DatabaseAllocator: databaseAllocator,
		SendersCollection: sendersCollection,
	}.Register(mx)

	campaigntypes.Routes{
		RequestLogging:          logging,
		Authenticator:           notificationsWriteAuthenticator,
		DatabaseAllocator:       databaseAllocator,
		CampaignTypesCollection: campaignTypesCollection,
	}.Register(mx)

	templates.Routes{
		RequestLogging:      logging,
		Authenticator:       notificationsWriteAuthenticator,
		DatabaseAllocator:   databaseAllocator,
		TemplatesCollection: templatesCollection,
	}.Register(mx)

	campaigns.Routes{
		Clock:                      util.NewClock(),
		RequestLogging:             logging,
		Authenticator:              notificationsWriteAuthenticator,
		DatabaseAllocator:          databaseAllocator,
		CampaignsCollection:        campaignsCollection,
		CampaignStatusesCollection: campaignStatusesCollection,
	}.Register(mx)

	return mx
}