Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
redirect badge endpoint for compatibility
Browse files Browse the repository at this point in the history
[#129407219]
  • Loading branch information
vito committed Aug 29, 2016
1 parent fc52f04 commit 9bee15e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
2 changes: 2 additions & 0 deletions api/handler.go
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/concourse/atc/auth"
"github.com/concourse/atc/db"
"github.com/concourse/atc/engine"
"github.com/concourse/atc/mainredirect"
"github.com/concourse/atc/worker"
"github.com/concourse/atc/wrappa"
)
Expand Down Expand Up @@ -145,6 +146,7 @@ func NewHandler(
atc.PauseJob: pipelineHandlerFactory.HandlerFor(jobServer.PauseJob),
atc.UnpauseJob: pipelineHandlerFactory.HandlerFor(jobServer.UnpauseJob),
atc.JobBadge: pipelineHandlerFactory.HandlerFor(jobServer.JobBadge),
atc.MainJobBadge: mainredirect.Handler{atc.Routes, atc.JobBadge},

atc.ListAllPipelines: http.HandlerFunc(pipelineServer.ListAllPipelines),
atc.ListPipelines: http.HandlerFunc(pipelineServer.ListPipelines),
Expand Down
10 changes: 4 additions & 6 deletions web/mainwrapper/handler.go → mainredirect/handler.go
@@ -1,17 +1,15 @@
package mainwrapper
package mainredirect

import (
"net/http"
"strings"

"github.com/concourse/atc/web"
"github.com/tedsuo/rata"
)

type Handler struct {
Route string

http.Handler
Routes rata.Routes
Route string
}

func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Expand All @@ -25,7 +23,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}

path, err := web.Routes.CreatePathForRoute(h.Route, params)
path, err := h.Routes.CreatePathForRoute(h.Route, params)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
Expand Down
2 changes: 2 additions & 0 deletions routes.go
Expand Up @@ -25,6 +25,7 @@ const (
UnpauseJob = "UnpauseJob"
GetVersionsDB = "GetVersionsDB"
JobBadge = "JobBadge"
MainJobBadge = "MainJobBadge"

ListResources = "ListResources"
GetResource = "GetResource"
Expand Down Expand Up @@ -98,6 +99,7 @@ var Routes = rata.Routes([]rata.Route{
{Path: "/api/v1/teams/:team_name/pipelines/:pipeline_name/jobs/:job_name/pause", Method: "PUT", Name: PauseJob},
{Path: "/api/v1/teams/:team_name/pipelines/:pipeline_name/jobs/:job_name/unpause", Method: "PUT", Name: UnpauseJob},
{Path: "/api/v1/teams/:team_name/pipelines/:pipeline_name/jobs/:job_name/badge", Method: "GET", Name: JobBadge},
{Path: "/api/v1/pipelines/:pipeline_name/jobs/:job_name/badge", Method: "GET", Name: MainJobBadge},

{Path: "/api/v1/pipelines", Method: "GET", Name: ListAllPipelines},
{Path: "/api/v1/teams/:team_name/pipelines", Method: "GET", Name: ListPipelines},
Expand Down
10 changes: 5 additions & 5 deletions web/webhandler/handler.go
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/elazarl/go-bindata-assetfs"
"github.com/tedsuo/rata"

"github.com/concourse/atc/mainredirect"
"github.com/concourse/atc/web"
"github.com/concourse/atc/web/authredirect"
"github.com/concourse/atc/web/getbuild"
Expand All @@ -17,7 +18,6 @@ import (
"github.com/concourse/atc/web/getresource"
"github.com/concourse/atc/web/index"
"github.com/concourse/atc/web/login"
"github.com/concourse/atc/web/mainwrapper"
"github.com/concourse/atc/web/pipeline"
"github.com/concourse/atc/web/triggerbuild"
"github.com/concourse/atc/wrappa"
Expand Down Expand Up @@ -100,10 +100,10 @@ func NewHandler(
web.LogIn: login.NewHandler(logger, logInTemplate),
web.ProcessBasicAuthLogIn: login.NewProcessBasicAuthHandler(logger, clientFactory),

web.MainPipeline: mainwrapper.Handler{web.Pipeline, authredirect.Handler{pipelineHandler}},
web.MainGetJob: mainwrapper.Handler{web.GetJob, authredirect.Handler{getjob.NewHandler(logger, clientFactory, jobTemplate)}},
web.MainGetResource: mainwrapper.Handler{web.GetResource, authredirect.Handler{getresource.NewHandler(logger, clientFactory, resourceTemplate)}},
web.MainGetBuild: mainwrapper.Handler{web.GetBuild, authredirect.Handler{getbuild.NewHandler(logger, clientFactory, buildTemplate)}},
web.MainPipeline: mainredirect.Handler{web.Routes, web.Pipeline},
web.MainGetJob: mainredirect.Handler{web.Routes, web.GetJob},
web.MainGetResource: mainredirect.Handler{web.Routes, web.GetResource},
web.MainGetBuild: mainredirect.Handler{web.Routes, web.GetBuild},
}

handler, err := rata.NewRouter(web.Routes, wrapper.Wrap(handlers))
Expand Down
3 changes: 2 additions & 1 deletion wrappa/api_auth_wrappa.go
Expand Up @@ -49,7 +49,8 @@ func (wrappa *APIAuthWrappa) Wrap(handlers rata.Handlers) rata.Handlers {
atc.ListTeams,
atc.ListAllPipelines,
atc.ListPipelines,
atc.ListBuilds:
atc.ListBuilds,
atc.MainJobBadge:

// pipeline is public or authorized
case atc.GetBuild,
Expand Down
1 change: 1 addition & 0 deletions wrappa/api_auth_wrappa_test.go
Expand Up @@ -162,6 +162,7 @@ var _ = Describe("APIAuthWrappa", func() {
atc.ListBuilds: unauthenticated(inputHandlers[atc.ListBuilds]),
atc.ListPipelines: unauthenticated(inputHandlers[atc.ListPipelines]),
atc.ListTeams: unauthenticated(inputHandlers[atc.ListTeams]),
atc.MainJobBadge: unauthenticated(inputHandlers[atc.MainJobBadge]),

// authorized or public pipeline
atc.GetBuild: doesNotCheckIfPrivateJob(inputHandlers[atc.GetBuild]),
Expand Down

0 comments on commit 9bee15e

Please sign in to comment.