示例#1
0
func NewRouter(mx muxer, mom mother, config Config) http.Handler {
	registrar := mom.Registrar()
	notificationsFinder := mom.NotificationsFinder()
	emailStrategy := mom.EmailStrategy()
	userStrategy := mom.UserStrategy()
	spaceStrategy := mom.SpaceStrategy()
	organizationStrategy := mom.OrganizationStrategy()
	everyoneStrategy := mom.EveryoneStrategy()
	uaaScopeStrategy := mom.UAAScopeStrategy()
	notifyObj := notify.NewNotify(mom.NotificationsFinder(), registrar)
	preferencesFinder := mom.PreferencesFinder()
	preferenceUpdater := mom.PreferenceUpdater()
	templateCreator, templateFinder, templateUpdater, templateDeleter, templateLister, templateAssigner, templateAssociationLister := mom.TemplateServiceObjects()
	notificationsUpdater := mom.NotificationsUpdater()
	messageFinder := mom.MessageFinder()
	errorWriter := webutil.NewErrorWriter()

	requestCounter := middleware.NewRequestCounter(mx.GetRouter(), metrics.DefaultLogger)
	logging := middleware.NewRequestLogging(config.Logger)
	notificationsWriteAuthenticator := middleware.NewAuthenticator(config.UAAPublicKey, "notifications.write")
	notificationsManageAuthenticator := middleware.NewAuthenticator(config.UAAPublicKey, "notifications.manage")
	notificationPreferencesReadAuthenticator := middleware.NewAuthenticator(config.UAAPublicKey, "notification_preferences.read")
	notificationPreferencesWriteAuthenticator := middleware.NewAuthenticator(config.UAAPublicKey, "notification_preferences.write")
	notificationPreferencesAdminAuthenticator := middleware.NewAuthenticator(config.UAAPublicKey, "notification_preferences.admin")
	emailsWriteAuthenticator := middleware.NewAuthenticator(config.UAAPublicKey, "emails.write")
	notificationsTemplateWriteAuthenticator := middleware.NewAuthenticator(config.UAAPublicKey, "notification_templates.write")
	notificationsTemplateReadAuthenticator := middleware.NewAuthenticator(config.UAAPublicKey, "notification_templates.read")
	notificationsWriteOrEmailsWriteAuthenticator := middleware.NewAuthenticator(config.UAAPublicKey, "notifications.write", "emails.write")
	databaseAllocator := middleware.NewDatabaseAllocator(mom.SQLDatabase(), config.DBLoggingEnabled)
	cors := middleware.NewCORS(config.CORSOrigin)

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

	preferences.Routes{
		CORS:                                      cors,
		RequestCounter:                            requestCounter,
		RequestLogging:                            logging,
		DatabaseAllocator:                         databaseAllocator,
		NotificationPreferencesReadAuthenticator:  notificationPreferencesReadAuthenticator,
		NotificationPreferencesWriteAuthenticator: notificationPreferencesWriteAuthenticator,
		NotificationPreferencesAdminAuthenticator: notificationPreferencesAdminAuthenticator,

		ErrorWriter:       errorWriter,
		PreferencesFinder: preferencesFinder,
		PreferenceUpdater: preferenceUpdater,
	}.Register(mx)

	clients.Routes{
		RequestCounter:                   requestCounter,
		RequestLogging:                   logging,
		DatabaseAllocator:                databaseAllocator,
		NotificationsManageAuthenticator: notificationsManageAuthenticator,

		ErrorWriter:      errorWriter,
		TemplateAssigner: templateAssigner,
	}.Register(mx)

	messages.Routes{
		RequestCounter:                               requestCounter,
		RequestLogging:                               logging,
		DatabaseAllocator:                            databaseAllocator,
		NotificationsWriteOrEmailsWriteAuthenticator: notificationsWriteOrEmailsWriteAuthenticator,

		ErrorWriter:   errorWriter,
		MessageFinder: messageFinder,
	}.Register(mx)

	templates.Routes{
		RequestCounter:                          requestCounter,
		RequestLogging:                          logging,
		DatabaseAllocator:                       databaseAllocator,
		NotificationTemplatesReadAuthenticator:  notificationsTemplateReadAuthenticator,
		NotificationTemplatesWriteAuthenticator: notificationsTemplateWriteAuthenticator,
		NotificationsManageAuthenticator:        notificationsManageAuthenticator,

		ErrorWriter:               errorWriter,
		TemplateFinder:            templateFinder,
		TemplateUpdater:           templateUpdater,
		TemplateCreator:           templateCreator,
		TemplateDeleter:           templateDeleter,
		TemplateLister:            templateLister,
		TemplateAssociationLister: templateAssociationLister,
	}.Register(mx)

	notifications.Routes{
		RequestCounter:                   requestCounter,
		RequestLogging:                   logging,
		DatabaseAllocator:                databaseAllocator,
		NotificationsWriteAuthenticator:  notificationsWriteAuthenticator,
		NotificationsManageAuthenticator: notificationsManageAuthenticator,

		ErrorWriter:          errorWriter,
		Registrar:            registrar,
		NotificationsFinder:  notificationsFinder,
		NotificationsUpdater: notificationsUpdater,
		TemplateAssigner:     templateAssigner,
	}.Register(mx)

	notify.Routes{
		RequestCounter:                  requestCounter,
		RequestLogging:                  logging,
		NotificationsWriteAuthenticator: notificationsWriteAuthenticator,
		DatabaseAllocator:               databaseAllocator,
		EmailsWriteAuthenticator:        emailsWriteAuthenticator,

		ErrorWriter:          errorWriter,
		Notify:               notifyObj,
		UserStrategy:         userStrategy,
		SpaceStrategy:        spaceStrategy,
		OrganizationStrategy: organizationStrategy,
		EveryoneStrategy:     everyoneStrategy,
		UAAScopeStrategy:     uaaScopeStrategy,
		EmailStrategy:        emailStrategy,
	}.Register(mx)

	return mx
}
示例#2
0
				reqReceivedTime, _ = time.Parse(time.RFC3339Nano, "2015-06-08T14:32:11.660762586-07:00")

				context = stack.NewContext()
				context.Set("token", token)
				context.Set("database", database)
				context.Set(notify.RequestReceivedTime, reqReceivedTime)

				vcapRequestID = "some-request-id"

				conn = mocks.NewConnection()
				strategy = mocks.NewStrategy()
				validator = mocks.NewValidator()
				validator.ValidateCall.Returns.Valid = true

				handler = notify.NewNotify(finder, registrar)
			})

			It("delegates to the strategy", func() {
				_, err := handler.Execute(conn, request, context, "space-001", strategy, validator, vcapRequestID)
				Expect(err).NotTo(HaveOccurred())

				Expect(strategy.DispatchCall.Receives.Dispatch).To(Equal(services.Dispatch{
					GUID:       "space-001",
					Connection: conn,
					Client: services.DispatchClient{
						ID:          "mister-client",
						Description: "Health Monitor",
					},
					Kind: services.DispatchKind{
						ID:          "test_email",