Пример #1
0
func (m *Mother) EveryoneStrategy() services.EveryoneStrategy {
	env := NewEnvironment()
	uaaClient := uaa.NewZonedUAAClient(env.UAAClientID, env.UAAClientSecret, env.VerifySSL, UAAPublicKey)
	tokenLoader := uaa.NewTokenLoader(uaaClient)
	allUsers := services.NewAllUsers(uaaClient)
	enqueuer := m.Enqueuer()

	return services.NewEveryoneStrategy(tokenLoader, allUsers, enqueuer, m.V2Enqueuer())
}
Пример #2
0
func (m *Mother) UAAScopeStrategy() services.UAAScopeStrategy {
	env := NewEnvironment()
	uaaClient := uaa.NewZonedUAAClient(env.UAAClientID, env.UAAClientSecret, env.VerifySSL, UAAPublicKey)
	cloudController := cf.NewCloudController(env.CCHost, !env.VerifySSL)

	tokenLoader := uaa.NewTokenLoader(uaaClient)
	findsUserGUIDs := services.NewFindsUserGUIDs(cloudController, uaaClient)
	enqueuer := m.Enqueuer()

	return services.NewUAAScopeStrategy(tokenLoader, findsUserGUIDs, enqueuer, m.V2Enqueuer(), env.DefaultUAAScopes)
}
Пример #3
0
func (m *Mother) OrganizationStrategy() services.OrganizationStrategy {
	env := NewEnvironment()
	cloudController := cf.NewCloudController(env.CCHost, !env.VerifySSL)

	uaaClient := uaa.NewZonedUAAClient(env.UAAClientID, env.UAAClientSecret, env.VerifySSL, UAAPublicKey)
	tokenLoader := uaa.NewTokenLoader(uaaClient)
	organizationLoader := services.NewOrganizationLoader(cloudController)
	findsUserGUIDs := services.NewFindsUserGUIDs(cloudController, uaaClient)
	enqueuer := m.Enqueuer()

	return services.NewOrganizationStrategy(tokenLoader, organizationLoader, findsUserGUIDs, enqueuer, m.V2Enqueuer())
}
Пример #4
0
func (app Application) RetrieveUAAPublicKey(logger lager.Logger) {
	zonedUAAClient := uaa.NewZonedUAAClient(app.env.UAAClientID, app.env.UAAClientSecret, app.env.VerifySSL, "")

	key, err := zonedUAAClient.GetTokenKey(app.env.UAAHost)
	if err != nil {
		logger.Fatal("uaa-get-token-key-errored", err)
	}

	UAAPublicKey = key
	logger.Info("uaa-public-key", lager.Data{
		"key": UAAPublicKey,
	})
}
Пример #5
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
	})
}