github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/atc/api/handler.go (about)

     1  package api
     2  
     3  import (
     4  	"net/http"
     5  	"path/filepath"
     6  	"time"
     7  
     8  	"code.cloudfoundry.org/clock"
     9  	"code.cloudfoundry.org/lager"
    10  	"github.com/pf-qiu/concourse/v6/atc"
    11  	"github.com/pf-qiu/concourse/v6/atc/api/artifactserver"
    12  	"github.com/pf-qiu/concourse/v6/atc/api/buildserver"
    13  	"github.com/pf-qiu/concourse/v6/atc/api/ccserver"
    14  	"github.com/pf-qiu/concourse/v6/atc/api/cliserver"
    15  	"github.com/pf-qiu/concourse/v6/atc/api/configserver"
    16  	"github.com/pf-qiu/concourse/v6/atc/api/containerserver"
    17  	"github.com/pf-qiu/concourse/v6/atc/api/infoserver"
    18  	"github.com/pf-qiu/concourse/v6/atc/api/jobserver"
    19  	"github.com/pf-qiu/concourse/v6/atc/api/loglevelserver"
    20  	"github.com/pf-qiu/concourse/v6/atc/api/pipelineserver"
    21  	"github.com/pf-qiu/concourse/v6/atc/api/resourceserver"
    22  	"github.com/pf-qiu/concourse/v6/atc/api/resourceserver/versionserver"
    23  	"github.com/pf-qiu/concourse/v6/atc/api/teamserver"
    24  	"github.com/pf-qiu/concourse/v6/atc/api/usersserver"
    25  	"github.com/pf-qiu/concourse/v6/atc/api/volumeserver"
    26  	"github.com/pf-qiu/concourse/v6/atc/api/wallserver"
    27  	"github.com/pf-qiu/concourse/v6/atc/api/workerserver"
    28  	"github.com/pf-qiu/concourse/v6/atc/creds"
    29  	"github.com/pf-qiu/concourse/v6/atc/db"
    30  	"github.com/pf-qiu/concourse/v6/atc/gc"
    31  	"github.com/pf-qiu/concourse/v6/atc/mainredirect"
    32  	"github.com/pf-qiu/concourse/v6/atc/worker"
    33  	"github.com/pf-qiu/concourse/v6/atc/wrappa"
    34  	"github.com/tedsuo/rata"
    35  )
    36  
    37  func NewHandler(
    38  	logger lager.Logger,
    39  
    40  	externalURL string,
    41  	clusterName string,
    42  
    43  	wrapper wrappa.Wrappa,
    44  
    45  	dbTeamFactory db.TeamFactory,
    46  	dbPipelineFactory db.PipelineFactory,
    47  	dbJobFactory db.JobFactory,
    48  	dbResourceFactory db.ResourceFactory,
    49  	dbWorkerFactory db.WorkerFactory,
    50  	workerTeamFactory db.TeamFactory,
    51  	volumeRepository db.VolumeRepository,
    52  	containerRepository db.ContainerRepository,
    53  	destroyer gc.Destroyer,
    54  	dbBuildFactory db.BuildFactory,
    55  	dbCheckFactory db.CheckFactory,
    56  	dbResourceConfigFactory db.ResourceConfigFactory,
    57  	dbUserFactory db.UserFactory,
    58  
    59  	eventHandlerFactory buildserver.EventHandlerFactory,
    60  
    61  	workerClient worker.Client,
    62  
    63  	sink *lager.ReconfigurableSink,
    64  
    65  	isTLSEnabled bool,
    66  
    67  	cliDownloadsDir string,
    68  	version string,
    69  	workerVersion string,
    70  	secretManager creds.Secrets,
    71  	varSourcePool creds.VarSourcePool,
    72  	credsManagers creds.Managers,
    73  	interceptTimeoutFactory containerserver.InterceptTimeoutFactory,
    74  	interceptUpdateInterval time.Duration,
    75  	dbWall db.Wall,
    76  	clock clock.Clock,
    77  ) (http.Handler, error) {
    78  
    79  	absCLIDownloadsDir, err := filepath.Abs(cliDownloadsDir)
    80  	if err != nil {
    81  		return nil, err
    82  	}
    83  
    84  	pipelineHandlerFactory := pipelineserver.NewScopedHandlerFactory(dbTeamFactory)
    85  	buildHandlerFactory := buildserver.NewScopedHandlerFactory(logger)
    86  	teamHandlerFactory := NewTeamScopedHandlerFactory(logger, dbTeamFactory)
    87  
    88  	buildServer := buildserver.NewServer(logger, externalURL, dbTeamFactory, dbBuildFactory, eventHandlerFactory)
    89  	jobServer := jobserver.NewServer(logger, externalURL, secretManager, dbJobFactory, dbCheckFactory)
    90  	resourceServer := resourceserver.NewServer(logger, secretManager, varSourcePool, dbCheckFactory, dbResourceFactory, dbResourceConfigFactory)
    91  
    92  	versionServer := versionserver.NewServer(logger, externalURL)
    93  	pipelineServer := pipelineserver.NewServer(logger, dbTeamFactory, dbPipelineFactory, externalURL)
    94  	configServer := configserver.NewServer(logger, dbTeamFactory, secretManager)
    95  	ccServer := ccserver.NewServer(logger, dbTeamFactory, externalURL)
    96  	workerServer := workerserver.NewServer(logger, workerTeamFactory, dbWorkerFactory)
    97  	logLevelServer := loglevelserver.NewServer(logger, sink)
    98  	cliServer := cliserver.NewServer(logger, absCLIDownloadsDir)
    99  	containerServer := containerserver.NewServer(logger, workerClient, secretManager, varSourcePool, interceptTimeoutFactory, interceptUpdateInterval, containerRepository, destroyer, clock)
   100  	volumesServer := volumeserver.NewServer(logger, volumeRepository, destroyer)
   101  	teamServer := teamserver.NewServer(logger, dbTeamFactory, externalURL)
   102  	infoServer := infoserver.NewServer(logger, version, workerVersion, externalURL, clusterName, credsManagers)
   103  	artifactServer := artifactserver.NewServer(logger, workerClient)
   104  	usersServer := usersserver.NewServer(logger, dbUserFactory)
   105  	wallServer := wallserver.NewServer(dbWall, logger)
   106  
   107  	handlers := map[string]http.Handler{
   108  		atc.GetConfig:  http.HandlerFunc(configServer.GetConfig),
   109  		atc.SaveConfig: http.HandlerFunc(configServer.SaveConfig),
   110  
   111  		atc.GetCC: http.HandlerFunc(ccServer.GetCC),
   112  
   113  		atc.ListBuilds:          http.HandlerFunc(buildServer.ListBuilds),
   114  		atc.CreateBuild:         teamHandlerFactory.HandlerFor(buildServer.CreateBuild),
   115  		atc.GetBuild:            buildHandlerFactory.HandlerFor(buildServer.GetBuild),
   116  		atc.BuildResources:      buildHandlerFactory.HandlerFor(buildServer.BuildResources),
   117  		atc.AbortBuild:          buildHandlerFactory.HandlerFor(buildServer.AbortBuild),
   118  		atc.GetBuildPlan:        buildHandlerFactory.HandlerFor(buildServer.GetBuildPlan),
   119  		atc.GetBuildPreparation: buildHandlerFactory.HandlerFor(buildServer.GetBuildPreparation),
   120  		atc.BuildEvents:         buildHandlerFactory.HandlerFor(buildServer.BuildEvents),
   121  		atc.ListBuildArtifacts:  buildHandlerFactory.HandlerFor(buildServer.GetBuildArtifacts),
   122  
   123  		atc.ListAllJobs:    http.HandlerFunc(jobServer.ListAllJobs),
   124  		atc.ListJobs:       pipelineHandlerFactory.HandlerFor(jobServer.ListJobs),
   125  		atc.GetJob:         pipelineHandlerFactory.HandlerFor(jobServer.GetJob),
   126  		atc.ListJobBuilds:  pipelineHandlerFactory.HandlerFor(jobServer.ListJobBuilds),
   127  		atc.ListJobInputs:  pipelineHandlerFactory.HandlerFor(jobServer.ListJobInputs),
   128  		atc.GetJobBuild:    pipelineHandlerFactory.HandlerFor(jobServer.GetJobBuild),
   129  		atc.CreateJobBuild: pipelineHandlerFactory.HandlerFor(jobServer.CreateJobBuild),
   130  		atc.RerunJobBuild:  pipelineHandlerFactory.HandlerFor(jobServer.RerunJobBuild),
   131  		atc.PauseJob:       pipelineHandlerFactory.HandlerFor(jobServer.PauseJob),
   132  		atc.UnpauseJob:     pipelineHandlerFactory.HandlerFor(jobServer.UnpauseJob),
   133  		atc.ScheduleJob:    pipelineHandlerFactory.HandlerFor(jobServer.ScheduleJob),
   134  		atc.JobBadge:       pipelineHandlerFactory.HandlerFor(jobServer.JobBadge),
   135  		atc.MainJobBadge: mainredirect.Handler{
   136  			Routes: atc.Routes,
   137  			Route:  atc.JobBadge,
   138  		},
   139  
   140  		atc.ClearTaskCache: pipelineHandlerFactory.HandlerFor(jobServer.ClearTaskCache),
   141  
   142  		atc.ListAllPipelines:    http.HandlerFunc(pipelineServer.ListAllPipelines),
   143  		atc.ListPipelines:       http.HandlerFunc(pipelineServer.ListPipelines),
   144  		atc.GetPipeline:         pipelineHandlerFactory.HandlerFor(pipelineServer.GetPipeline),
   145  		atc.DeletePipeline:      pipelineHandlerFactory.HandlerFor(pipelineServer.DeletePipeline),
   146  		atc.OrderPipelines:      http.HandlerFunc(pipelineServer.OrderPipelines),
   147  		atc.PausePipeline:       pipelineHandlerFactory.HandlerFor(pipelineServer.PausePipeline),
   148  		atc.ArchivePipeline:     pipelineHandlerFactory.HandlerFor(pipelineServer.ArchivePipeline),
   149  		atc.UnpausePipeline:     pipelineHandlerFactory.HandlerFor(pipelineServer.UnpausePipeline),
   150  		atc.ExposePipeline:      pipelineHandlerFactory.HandlerFor(pipelineServer.ExposePipeline),
   151  		atc.HidePipeline:        pipelineHandlerFactory.HandlerFor(pipelineServer.HidePipeline),
   152  		atc.GetVersionsDB:       pipelineHandlerFactory.HandlerFor(pipelineServer.GetVersionsDB),
   153  		atc.RenamePipeline:      pipelineHandlerFactory.HandlerFor(pipelineServer.RenamePipeline),
   154  		atc.ListPipelineBuilds:  pipelineHandlerFactory.HandlerFor(pipelineServer.ListPipelineBuilds),
   155  		atc.CreatePipelineBuild: pipelineHandlerFactory.HandlerFor(pipelineServer.CreateBuild),
   156  		atc.PipelineBadge:       pipelineHandlerFactory.HandlerFor(pipelineServer.PipelineBadge),
   157  
   158  		atc.ListAllResources:        http.HandlerFunc(resourceServer.ListAllResources),
   159  		atc.ListResources:           pipelineHandlerFactory.HandlerFor(resourceServer.ListResources),
   160  		atc.ListResourceTypes:       pipelineHandlerFactory.HandlerFor(resourceServer.ListVersionedResourceTypes),
   161  		atc.GetResource:             pipelineHandlerFactory.HandlerFor(resourceServer.GetResource),
   162  		atc.UnpinResource:           pipelineHandlerFactory.HandlerFor(resourceServer.UnpinResource),
   163  		atc.SetPinCommentOnResource: pipelineHandlerFactory.HandlerFor(resourceServer.SetPinCommentOnResource),
   164  		atc.CheckResource:           pipelineHandlerFactory.HandlerFor(resourceServer.CheckResource),
   165  		atc.CheckResourceWebHook:    pipelineHandlerFactory.HandlerFor(resourceServer.CheckResourceWebHook),
   166  		atc.CheckResourceType:       pipelineHandlerFactory.HandlerFor(resourceServer.CheckResourceType),
   167  
   168  		atc.ListResourceVersions:          pipelineHandlerFactory.HandlerFor(versionServer.ListResourceVersions),
   169  		atc.GetResourceVersion:            pipelineHandlerFactory.HandlerFor(versionServer.GetResourceVersion),
   170  		atc.EnableResourceVersion:         pipelineHandlerFactory.HandlerFor(versionServer.EnableResourceVersion),
   171  		atc.DisableResourceVersion:        pipelineHandlerFactory.HandlerFor(versionServer.DisableResourceVersion),
   172  		atc.PinResourceVersion:            pipelineHandlerFactory.HandlerFor(versionServer.PinResourceVersion),
   173  		atc.ListBuildsWithVersionAsInput:  pipelineHandlerFactory.HandlerFor(versionServer.ListBuildsWithVersionAsInput),
   174  		atc.ListBuildsWithVersionAsOutput: pipelineHandlerFactory.HandlerFor(versionServer.ListBuildsWithVersionAsOutput),
   175  		atc.GetResourceCausality:          pipelineHandlerFactory.HandlerFor(versionServer.GetCausality),
   176  
   177  		atc.ListWorkers:     http.HandlerFunc(workerServer.ListWorkers),
   178  		atc.RegisterWorker:  http.HandlerFunc(workerServer.RegisterWorker),
   179  		atc.LandWorker:      http.HandlerFunc(workerServer.LandWorker),
   180  		atc.RetireWorker:    http.HandlerFunc(workerServer.RetireWorker),
   181  		atc.PruneWorker:     http.HandlerFunc(workerServer.PruneWorker),
   182  		atc.HeartbeatWorker: http.HandlerFunc(workerServer.HeartbeatWorker),
   183  		atc.DeleteWorker:    http.HandlerFunc(workerServer.DeleteWorker),
   184  
   185  		atc.SetLogLevel: http.HandlerFunc(logLevelServer.SetMinLevel),
   186  		atc.GetLogLevel: http.HandlerFunc(logLevelServer.GetMinLevel),
   187  
   188  		atc.DownloadCLI:  http.HandlerFunc(cliServer.Download),
   189  		atc.GetInfo:      http.HandlerFunc(infoServer.Info),
   190  		atc.GetInfoCreds: http.HandlerFunc(infoServer.Creds),
   191  
   192  		atc.GetUser:              http.HandlerFunc(usersServer.GetUser),
   193  		atc.ListActiveUsersSince: http.HandlerFunc(usersServer.GetUsersSince),
   194  
   195  		atc.ListContainers:           teamHandlerFactory.HandlerFor(containerServer.ListContainers),
   196  		atc.GetContainer:             teamHandlerFactory.HandlerFor(containerServer.GetContainer),
   197  		atc.HijackContainer:          teamHandlerFactory.HandlerFor(containerServer.HijackContainer),
   198  		atc.ListDestroyingContainers: http.HandlerFunc(containerServer.ListDestroyingContainers),
   199  		atc.ReportWorkerContainers:   http.HandlerFunc(containerServer.ReportWorkerContainers),
   200  
   201  		atc.ListVolumes:           teamHandlerFactory.HandlerFor(volumesServer.ListVolumes),
   202  		atc.ListDestroyingVolumes: http.HandlerFunc(volumesServer.ListDestroyingVolumes),
   203  		atc.ReportWorkerVolumes:   http.HandlerFunc(volumesServer.ReportWorkerVolumes),
   204  
   205  		atc.ListTeams:      http.HandlerFunc(teamServer.ListTeams),
   206  		atc.GetTeam:        http.HandlerFunc(teamServer.GetTeam),
   207  		atc.SetTeam:        http.HandlerFunc(teamServer.SetTeam),
   208  		atc.RenameTeam:     http.HandlerFunc(teamServer.RenameTeam),
   209  		atc.DestroyTeam:    http.HandlerFunc(teamServer.DestroyTeam),
   210  		atc.ListTeamBuilds: http.HandlerFunc(teamServer.ListTeamBuilds),
   211  
   212  		atc.CreateArtifact: teamHandlerFactory.HandlerFor(artifactServer.CreateArtifact),
   213  		atc.GetArtifact:    teamHandlerFactory.HandlerFor(artifactServer.GetArtifact),
   214  
   215  		atc.GetWall:   http.HandlerFunc(wallServer.GetWall),
   216  		atc.SetWall:   http.HandlerFunc(wallServer.SetWall),
   217  		atc.ClearWall: http.HandlerFunc(wallServer.ClearWall),
   218  	}
   219  
   220  	return rata.NewRouter(atc.Routes, wrapper.Wrap(handlers))
   221  }