Exemplo n.º 1
0
package util_test

import (
	"time"

	"github.com/cloudfoundry-incubator/notifications/v2/util"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Clock", func() {
	Describe("Now", func() {
		It("should return the current time", func() {
			clock := util.NewClock()

			currentTime := clock.Now()
			Expect(currentTime).To(BeTemporally("~", time.Now()))
		})
	})
})
Exemplo n.º 2
0
func (m *Mother) V2Enqueuer() queue.JobEnqueuer {
	return queue.NewJobEnqueuer(m.Queue(), uuid.NewV4, v2models.NewMessagesRepository(util.NewClock()))
}
Exemplo n.º 3
0
func (app Application) StartWorkers() {
	zonedUAAClient := uaa.NewZonedUAAClient(app.env.UAAClientID, app.env.UAAClientSecret, app.env.VerifySSL, UAAPublicKey)

	WorkerGenerator{
		InstanceIndex: app.env.VCAPApplication.InstanceIndex,
		Count:         WorkerCount,
	}.Work(func(i int) Worker {
		cloak, err := conceal.NewCloak(app.env.EncryptionKey)
		if err != nil {
			panic(err)
		}
		v1Workflow := postal.NewV1Process(postal.V1ProcessConfig{
			DBTrace: app.env.DBLoggingEnabled,
			UAAHost: app.env.UAAHost,
			Sender:  app.env.Sender,
			Domain:  app.env.Domain,

			Packager:    postal.NewPackager(app.mother.TemplatesLoader(), cloak),
			MailClient:  app.mother.MailClient(),
			Database:    app.mother.Database(),
			TokenLoader: uaa.NewTokenLoader(zonedUAAClient),
			UserLoader:  postal.NewUserLoader(zonedUAAClient),

			KindsRepo:              app.mother.KindsRepo(),
			ReceiptsRepo:           app.mother.ReceiptsRepo(),
			UnsubscribesRepo:       app.mother.UnsubscribesRepo(),
			GlobalUnsubscribesRepo: app.mother.GlobalUnsubscribesRepo(),
			MessageStatusUpdater:   postal.NewMessageStatusUpdater(app.mother.MessagesRepo()),
			DeliveryFailureHandler: postal.NewDeliveryFailureHandler(),
		})

		database := v2models.NewDatabase(app.mother.SQLDatabase(), v2models.Config{})
		messageStatusUpdater := postal.NewV2MessageStatusUpdater(v2models.NewMessagesRepository(util.NewClock()))
		v2Workflow := postal.NewV2Workflow(app.mother.MailClient(), postal.NewPackager(app.mother.TemplatesLoader(), cloak), postal.NewUserLoader(zonedUAAClient), uaa.NewTokenLoader(zonedUAAClient), messageStatusUpdater, database, app.env.Sender, app.env.Domain, app.env.UAAHost)

		worker := postal.NewDeliveryWorker(v1Workflow, v2Workflow, postal.DeliveryWorkerConfig{
			ID:                     i,
			UAAHost:                app.env.UAAHost,
			Logger:                 app.mother.Logger(),
			Queue:                  app.mother.Queue(),
			DBTrace:                app.env.DBLoggingEnabled,
			Database:               database,
			StrategyDeterminer:     strategy.NewStrategyDeterminer(app.mother.UserStrategy(), app.mother.SpaceStrategy(), app.mother.OrganizationStrategy(), app.mother.EmailStrategy()),
			DeliveryFailureHandler: postal.NewDeliveryFailureHandler(),
			MessageStatusUpdater:   messageStatusUpdater,
		})
		return &worker
	})
}
Exemplo n.º 4
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
}