Exemple #1
0
func NewHandler(
	logger lager.Logger,
	validator auth.Validator,
	pipelineDBFactory db.PipelineDBFactory,

	configDB db.ConfigDB,

	buildsDB buildserver.BuildsDB,
	workerDB workerserver.WorkerDB,
	pipeDB pipes.PipeDB,
	pipelinesDB db.PipelinesDB,

	configValidator configserver.ConfigValidator,
	peerURL string,
	eventHandlerFactory buildserver.EventHandlerFactory,
	drain <-chan struct{},

	engine engine.Engine,
	workerClient worker.Client,

	sink *lager.ReconfigurableSink,

	cliDownloadsDir string,
) (http.Handler, error) {
	absCLIDownloadsDir, err := filepath.Abs(cliDownloadsDir)
	if err != nil {
		return nil, err
	}

	pipelineHandlerFactory := pipelines.NewHandlerFactory(pipelineDBFactory)

	buildServer := buildserver.NewServer(
		logger,
		engine,
		workerClient,
		buildsDB,
		configDB,
		eventHandlerFactory,
		drain,
		validator,
	)

	hijackServer := hijackserver.NewServer(
		logger,
		workerClient,
	)

	jobServer := jobserver.NewServer(logger)
	resourceServer := resourceserver.NewServer(logger, validator)
	pipeServer := pipes.NewServer(logger, peerURL, pipeDB)

	pipelineServer := pipelineserver.NewServer(logger, pipelinesDB)

	configServer := configserver.NewServer(logger, configDB, configValidator)

	workerServer := workerserver.NewServer(logger, workerDB)

	logLevelServer := loglevelserver.NewServer(logger, sink)

	cliServer := cliserver.NewServer(logger, absCLIDownloadsDir)

	validate := func(handler http.Handler) http.Handler {
		return auth.Handler{
			Handler:   handler,
			Validator: validator,
		}
	}

	handlers := map[string]http.Handler{
		atc.GetConfig:  validate(http.HandlerFunc(configServer.GetConfig)),
		atc.SaveConfig: validate(http.HandlerFunc(configServer.SaveConfig)),

		atc.Hijack: validate(http.HandlerFunc(hijackServer.Hijack)),

		atc.GetBuild:    http.HandlerFunc(buildServer.GetBuild),
		atc.ListBuilds:  http.HandlerFunc(buildServer.ListBuilds),
		atc.CreateBuild: validate(http.HandlerFunc(buildServer.CreateBuild)),
		atc.BuildEvents: http.HandlerFunc(buildServer.BuildEvents),
		atc.AbortBuild:  validate(http.HandlerFunc(buildServer.AbortBuild)),

		atc.ListJobs:      pipelineHandlerFactory.HandlerFor(jobServer.ListJobs),
		atc.GetJob:        pipelineHandlerFactory.HandlerFor(jobServer.GetJob),
		atc.ListJobBuilds: pipelineHandlerFactory.HandlerFor(jobServer.ListJobBuilds),
		atc.GetJobBuild:   pipelineHandlerFactory.HandlerFor(jobServer.GetJobBuild),
		atc.PauseJob:      validate(pipelineHandlerFactory.HandlerFor(jobServer.PauseJob)),
		atc.UnpauseJob:    validate(pipelineHandlerFactory.HandlerFor(jobServer.UnpauseJob)),

		atc.ListPipelines:   http.HandlerFunc(pipelineServer.ListPipelines),
		atc.DeletePipeline:  validate(pipelineHandlerFactory.HandlerFor(pipelineServer.DeletePipeline)),
		atc.OrderPipelines:  validate(http.HandlerFunc(pipelineServer.OrderPipelines)),
		atc.PausePipeline:   validate(pipelineHandlerFactory.HandlerFor(pipelineServer.PausePipeline)),
		atc.UnpausePipeline: validate(pipelineHandlerFactory.HandlerFor(pipelineServer.UnpausePipeline)),

		atc.ListResources:          pipelineHandlerFactory.HandlerFor(resourceServer.ListResources),
		atc.EnableResourceVersion:  validate(pipelineHandlerFactory.HandlerFor(resourceServer.EnableResourceVersion)),
		atc.DisableResourceVersion: validate(pipelineHandlerFactory.HandlerFor(resourceServer.DisableResourceVersion)),
		atc.PauseResource:          validate(pipelineHandlerFactory.HandlerFor(resourceServer.PauseResource)),
		atc.UnpauseResource:        validate(pipelineHandlerFactory.HandlerFor(resourceServer.UnpauseResource)),

		atc.CreatePipe: validate(http.HandlerFunc(pipeServer.CreatePipe)),
		atc.WritePipe:  validate(http.HandlerFunc(pipeServer.WritePipe)),
		atc.ReadPipe:   validate(http.HandlerFunc(pipeServer.ReadPipe)),

		atc.ListWorkers:    validate(http.HandlerFunc(workerServer.ListWorkers)),
		atc.RegisterWorker: validate(http.HandlerFunc(workerServer.RegisterWorker)),

		atc.SetLogLevel: validate(http.HandlerFunc(logLevelServer.SetMinLevel)),
		atc.GetLogLevel: http.HandlerFunc(logLevelServer.GetMinLevel),

		atc.DownloadCLI: http.HandlerFunc(cliServer.Download),
	}

	return rata.NewRouter(atc.Routes, handlers)
}
Exemple #2
0
func NewHandler(
	logger lager.Logger,

	externalURL string,

	wrapper wrappa.Wrappa,

	tokenGenerator auth.TokenGenerator,
	providerFactory auth.ProviderFactory,
	oAuthBaseURL string,

	pipelineDBFactory db.PipelineDBFactory,
	configDB db.ConfigDB,

	authDB authserver.AuthDB,
	buildsDB buildserver.BuildsDB,
	workerDB workerserver.WorkerDB,
	containerDB containerserver.ContainerDB,
	volumesDB volumeserver.VolumesDB,
	pipeDB pipes.PipeDB,
	pipelinesDB db.PipelinesDB,
	teamDB teamserver.TeamDB,

	configValidator configserver.ConfigValidator,
	peerURL string,
	eventHandlerFactory buildserver.EventHandlerFactory,
	drain <-chan struct{},

	engine engine.Engine,
	workerClient worker.Client,

	schedulerFactory jobserver.SchedulerFactory,
	scannerFactory resourceserver.ScannerFactory,

	sink *lager.ReconfigurableSink,

	cliDownloadsDir string,
	version string,
) (http.Handler, error) {
	absCLIDownloadsDir, err := filepath.Abs(cliDownloadsDir)
	if err != nil {
		return nil, err
	}

	pipelineHandlerFactory := pipelines.NewHandlerFactory(pipelineDBFactory)

	authServer := authserver.NewServer(
		logger,
		externalURL,
		oAuthBaseURL,
		tokenGenerator,
		providerFactory,
		authDB,
	)

	buildServer := buildserver.NewServer(
		logger,
		externalURL,
		engine,
		workerClient,
		buildsDB,
		configDB,
		eventHandlerFactory,
		drain,
	)

	jobServer := jobserver.NewServer(logger, schedulerFactory, externalURL)
	resourceServer := resourceserver.NewServer(logger, scannerFactory)
	versionServer := versionserver.NewServer(logger, externalURL)
	pipeServer := pipes.NewServer(logger, peerURL, externalURL, pipeDB)

	pipelineServer := pipelineserver.NewServer(logger, pipelinesDB, configDB)

	configServer := configserver.NewServer(logger, configDB, configValidator)

	workerServer := workerserver.NewServer(logger, workerDB)

	logLevelServer := loglevelserver.NewServer(logger, sink)

	cliServer := cliserver.NewServer(logger, absCLIDownloadsDir)

	containerServer := containerserver.NewServer(logger, workerClient, containerDB)

	volumesServer := volumeserver.NewServer(logger, volumesDB)

	teamServer := teamserver.NewServer(logger, teamDB)

	infoServer := infoserver.NewServer(logger, version)

	handlers := map[string]http.Handler{
		atc.ListAuthMethods: http.HandlerFunc(authServer.ListAuthMethods),
		atc.GetAuthToken:    http.HandlerFunc(authServer.GetAuthToken),

		atc.GetConfig:  http.HandlerFunc(configServer.GetConfig),
		atc.SaveConfig: http.HandlerFunc(configServer.SaveConfig),

		atc.GetBuild:            http.HandlerFunc(buildServer.GetBuild),
		atc.ListBuilds:          http.HandlerFunc(buildServer.ListBuilds),
		atc.CreateBuild:         http.HandlerFunc(buildServer.CreateBuild),
		atc.BuildEvents:         http.HandlerFunc(buildServer.BuildEvents),
		atc.BuildResources:      http.HandlerFunc(buildServer.BuildResources),
		atc.AbortBuild:          http.HandlerFunc(buildServer.AbortBuild),
		atc.GetBuildPlan:        http.HandlerFunc(buildServer.GetBuildPlan),
		atc.GetBuildPreparation: http.HandlerFunc(buildServer.GetBuildPreparation),

		atc.ListJobs:       pipelineHandlerFactory.HandlerFor(jobServer.ListJobs),
		atc.GetJob:         pipelineHandlerFactory.HandlerFor(jobServer.GetJob),
		atc.ListJobBuilds:  pipelineHandlerFactory.HandlerFor(jobServer.ListJobBuilds),
		atc.ListJobInputs:  pipelineHandlerFactory.HandlerFor(jobServer.ListJobInputs),
		atc.GetJobBuild:    pipelineHandlerFactory.HandlerFor(jobServer.GetJobBuild),
		atc.CreateJobBuild: pipelineHandlerFactory.HandlerFor(jobServer.CreateJobBuild),
		atc.PauseJob:       pipelineHandlerFactory.HandlerFor(jobServer.PauseJob),
		atc.UnpauseJob:     pipelineHandlerFactory.HandlerFor(jobServer.UnpauseJob),

		atc.ListPipelines:   http.HandlerFunc(pipelineServer.ListPipelines),
		atc.GetPipeline:     http.HandlerFunc(pipelineServer.GetPipeline),
		atc.DeletePipeline:  pipelineHandlerFactory.HandlerFor(pipelineServer.DeletePipeline),
		atc.OrderPipelines:  http.HandlerFunc(pipelineServer.OrderPipelines),
		atc.PausePipeline:   pipelineHandlerFactory.HandlerFor(pipelineServer.PausePipeline),
		atc.UnpausePipeline: pipelineHandlerFactory.HandlerFor(pipelineServer.UnpausePipeline),
		atc.GetVersionsDB:   pipelineHandlerFactory.HandlerFor(pipelineServer.GetVersionsDB),
		atc.RenamePipeline:  pipelineHandlerFactory.HandlerFor(pipelineServer.RenamePipeline),

		atc.ListResources:   pipelineHandlerFactory.HandlerFor(resourceServer.ListResources),
		atc.GetResource:     pipelineHandlerFactory.HandlerFor(resourceServer.GetResource),
		atc.PauseResource:   pipelineHandlerFactory.HandlerFor(resourceServer.PauseResource),
		atc.UnpauseResource: pipelineHandlerFactory.HandlerFor(resourceServer.UnpauseResource),
		atc.CheckResource:   pipelineHandlerFactory.HandlerFor(resourceServer.CheckResource),

		atc.ListResourceVersions:          pipelineHandlerFactory.HandlerFor(versionServer.ListResourceVersions),
		atc.EnableResourceVersion:         pipelineHandlerFactory.HandlerFor(versionServer.EnableResourceVersion),
		atc.DisableResourceVersion:        pipelineHandlerFactory.HandlerFor(versionServer.DisableResourceVersion),
		atc.ListBuildsWithVersionAsInput:  pipelineHandlerFactory.HandlerFor(versionServer.ListBuildsWithVersionAsInput),
		atc.ListBuildsWithVersionAsOutput: pipelineHandlerFactory.HandlerFor(versionServer.ListBuildsWithVersionAsOutput),

		atc.CreatePipe: http.HandlerFunc(pipeServer.CreatePipe),
		atc.WritePipe:  http.HandlerFunc(pipeServer.WritePipe),
		atc.ReadPipe:   http.HandlerFunc(pipeServer.ReadPipe),

		atc.ListWorkers:    http.HandlerFunc(workerServer.ListWorkers),
		atc.RegisterWorker: http.HandlerFunc(workerServer.RegisterWorker),

		atc.SetLogLevel: http.HandlerFunc(logLevelServer.SetMinLevel),
		atc.GetLogLevel: http.HandlerFunc(logLevelServer.GetMinLevel),

		atc.DownloadCLI: http.HandlerFunc(cliServer.Download),
		atc.GetInfo:     http.HandlerFunc(infoServer.Info),

		atc.ListContainers:  http.HandlerFunc(containerServer.ListContainers),
		atc.GetContainer:    http.HandlerFunc(containerServer.GetContainer),
		atc.HijackContainer: http.HandlerFunc(containerServer.HijackContainer),

		atc.ListVolumes: http.HandlerFunc(volumesServer.ListVolumes),

		atc.SetTeam: http.HandlerFunc(teamServer.SetTeam),
	}

	return rata.NewRouter(atc.Routes, wrapper.Wrap(handlers))
}