Skip to content

Commit

Permalink
fix(api): hooks uservice calls getWorkflowRunHandler (#6134)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamin authored Apr 5, 2022
1 parent 3a70613 commit f9a5b4d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 41 deletions.
2 changes: 1 addition & 1 deletion engine/api/api_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (api *API) InitRouter() {
r.Handle("/project/{key}/workflows/{permWorkflowName}/runs/latest", Scope(sdk.AuthConsumerScopeRun), r.GET(api.getLatestWorkflowRunHandler))
r.Handle("/project/{key}/workflows/{permWorkflowName}/runs/tags", Scope(sdk.AuthConsumerScopeRun), r.GET(api.getWorkflowRunTagsHandler))
r.Handle("/project/{key}/workflows/{permWorkflowName}/runs/num", Scope(sdk.AuthConsumerScopeRun), r.GET(api.getWorkflowRunNumHandler), r.POST(api.postWorkflowRunNumHandler))
r.Handle("/project/{key}/workflows/{permWorkflowName}/runs/{number}", Scopes(sdk.AuthConsumerScopeRun, sdk.AuthConsumerScopeRunExecution), r.GET(api.getWorkflowRunHandler), r.DELETE(api.deleteWorkflowRunHandler))
r.Handle("/project/{key}/workflows/{permWorkflowNameAdvanced}/runs/{number}", Scopes(sdk.AuthConsumerScopeRun, sdk.AuthConsumerScopeRunExecution), r.GET(api.getWorkflowRunHandler), r.DELETE(api.deleteWorkflowRunHandler))
r.Handle("/project/{key}/workflows/{permWorkflowName}/runs/{number}/stop", Scope(sdk.AuthConsumerScopeRun), r.POSTEXECUTE(api.stopWorkflowRunHandler, MaintenanceAware()))
r.Handle("/project/{key}/workflows/{permWorkflowName}/runs/{number}/vcs/resync", Scope(sdk.AuthConsumerScopeRun), r.POSTEXECUTE(api.postResyncVCSWorkflowRunHandler))
r.Handle("/project/{key}/workflows/{permWorkflowNameAdvanced}/runs/{number}/artifacts/links", Scopes(sdk.AuthConsumerScopeRun, sdk.AuthConsumerScopeRunExecution), r.GET(api.getWorkflowRunArtifactLinksHandler))
Expand Down
4 changes: 2 additions & 2 deletions engine/api/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (api *API) getWorkflowsHandler() service.Handler {
}

func (api *API) setWorkflowURLs(w1 *sdk.Workflow) {
w1.URLs.APIURL = api.Config.URL.API + api.Router.GetRoute("GET", api.getWorkflowHandler, map[string]string{"key": w1.ProjectKey, "permWorkflowName": w1.Name})
w1.URLs.APIURL = api.Config.URL.API + api.Router.GetRoute("GET", api.getWorkflowHandler, map[string]string{"key": w1.ProjectKey, "permWorkflowNameAdvanced": w1.Name})
w1.URLs.UIURL = api.Config.URL.UI + "/project/" + w1.ProjectKey + "/workflow/" + w1.Name

for j := range w1.Runs {
Expand All @@ -94,7 +94,7 @@ func (api *API) setWorkflowURLs(w1 *sdk.Workflow) {
}

func (api *API) setWorkflowRunURLs(r1 *sdk.WorkflowRun) {
r1.URLs.APIURL = api.Config.URL.API + api.Router.GetRoute("GET", api.getWorkflowRunHandler, map[string]string{"key": r1.Workflow.ProjectKey, "permWorkflowName": r1.Workflow.Name, "number": strconv.FormatInt(r1.Number, 10)})
r1.URLs.APIURL = api.Config.URL.API + api.Router.GetRoute("GET", api.getWorkflowRunHandler, map[string]string{"key": r1.Workflow.ProjectKey, "permWorkflowNameAdvanced": r1.Workflow.Name, "number": strconv.FormatInt(r1.Number, 10)})
r1.URLs.UIURL = api.Config.URL.UI + "/project/" + r1.Workflow.ProjectKey + "/workflow/" + r1.Workflow.Name + "/run/" + strconv.FormatInt(r1.Number, 10)
}

Expand Down
12 changes: 6 additions & 6 deletions engine/api/workflow_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ func testRunWorkflowForProject(t *testing.T, api *API, router *Router, proj *sdk
cpt := 0
for {
varsGet := map[string]string{
"key": proj.Key,
"permWorkflowName": w1.Name,
"number": fmt.Sprintf("%d", wr.Number),
"key": proj.Key,
"permWorkflowNameAdvanced": w1.Name,
"number": fmt.Sprintf("%d", wr.Number),
}
uriGet := router.GetRoute("GET", api.getWorkflowRunHandler, varsGet)
require.NotEmpty(t, uriGet)
Expand Down Expand Up @@ -765,9 +765,9 @@ func Test_postWorkflowJobResultHandler(t *testing.T) {
require.Equal(t, 204, rec.Code)

uri = router.GetRoute("GET", api.getWorkflowRunHandler, map[string]string{
"key": ctx.project.Key,
"permWorkflowName": ctx.workflow.Name,
"number": fmt.Sprintf("%d", ctx.run.Number),
"key": ctx.project.Key,
"permWorkflowNameAdvanced": ctx.workflow.Name,
"number": fmt.Sprintf("%d", ctx.run.Number),
})
req = assets.NewJWTAuthentifiedRequest(t, ctx.userToken, "GET", uri+"?withDetails=true", res)

Expand Down
8 changes: 6 additions & 2 deletions engine/api/workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (api *API) getWorkflowRunHandler() service.Handler {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
vars := mux.Vars(r)
key := vars["key"]
name := vars["permWorkflowName"]
name := vars["permWorkflowNameAdvanced"]
number, err := requestVarInt(r, "number")
if err != nil {
return err
Expand Down Expand Up @@ -311,9 +311,13 @@ func (api *API) getWorkflowRunHandler() service.Handler {

func (api *API) deleteWorkflowRunHandler() service.Handler {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
if isHooks(ctx) {
return sdk.WithStack(sdk.ErrForbidden)
}

vars := mux.Vars(r)
key := vars["key"]
name := vars["permWorkflowName"]
name := vars["permWorkflowNameAdvanced"]
number, err := requestVarInt(r, "number")
if err != nil {
return err
Expand Down
60 changes: 30 additions & 30 deletions engine/api/workflow_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,9 +667,9 @@ func Test_getWorkflowRunHandler(t *testing.T) {

//Prepare request
vars := map[string]string{
"key": proj.Key,
"permWorkflowName": w1.Name,
"number": "9",
"key": proj.Key,
"permWorkflowNameAdvanced": w1.Name,
"number": "9",
}
uri := router.GetRoute("GET", api.getWorkflowRunHandler, vars)
test.NotEmpty(t, uri)
Expand Down Expand Up @@ -1429,9 +1429,9 @@ func Test_postWorkflowRunAsyncFailedHandler(t *testing.T) {
for {
t.Logf("Attempt getWorkflowRunHandler #%d", cpt)
varsGet := map[string]string{
"key": proj.Key,
"permWorkflowName": w1.Name,
"number": "1",
"key": proj.Key,
"permWorkflowNameAdvanced": w1.Name,
"number": "1",
}
uriGet := router.GetRoute("GET", api.getWorkflowRunHandler, varsGet)
reqGet := assets.NewAuthentifiedRequest(t, u, pass, "GET", uriGet, nil)
Expand Down Expand Up @@ -1969,9 +1969,9 @@ func Test_postWorkflowRunHandlerMutexRelease(t *testing.T) {
try++
t.Logf("Attempt #%d on getWorkflowRunHandler for run 1", try)
uri := router.GetRoute("GET", api.getWorkflowRunHandler, map[string]string{
"key": proj.Key,
"permWorkflowName": wkf.Name,
"number": "1",
"key": proj.Key,
"permWorkflowNameAdvanced": wkf.Name,
"number": "1",
})
req := assets.NewAuthentifiedRequest(t, u, jwt, "GET", uri, nil)
rec := httptest.NewRecorder()
Expand Down Expand Up @@ -2015,9 +2015,9 @@ func Test_postWorkflowRunHandlerMutexRelease(t *testing.T) {
try++
t.Logf("Attempt #%d on getWorkflowRunHandler for run 2", try)
uri := router.GetRoute("GET", api.getWorkflowRunHandler, map[string]string{
"key": proj.Key,
"permWorkflowName": wkf.Name,
"number": "2",
"key": proj.Key,
"permWorkflowNameAdvanced": wkf.Name,
"number": "2",
})
req := assets.NewAuthentifiedRequest(t, u, jwt, "GET", uri, nil)
rec := httptest.NewRecorder()
Expand Down Expand Up @@ -2064,9 +2064,9 @@ func Test_postWorkflowRunHandlerMutexRelease(t *testing.T) {
try++
t.Logf("Attempt #%d on getWorkflowRunHandler for run 3", try)
uri := router.GetRoute("GET", api.getWorkflowRunHandler, map[string]string{
"key": proj.Key,
"permWorkflowName": wkf.Name,
"number": "3",
"key": proj.Key,
"permWorkflowNameAdvanced": wkf.Name,
"number": "3",
})
req := assets.NewAuthentifiedRequest(t, u, jwt, "GET", uri, nil)
rec := httptest.NewRecorder()
Expand Down Expand Up @@ -2110,9 +2110,9 @@ func Test_postWorkflowRunHandlerMutexRelease(t *testing.T) {
try++
t.Logf("Attempt #%d on getWorkflowRunHandler for run 1", try)
uri := router.GetRoute("GET", api.getWorkflowRunHandler, map[string]string{
"key": proj.Key,
"permWorkflowName": wkf.Name,
"number": "1",
"key": proj.Key,
"permWorkflowNameAdvanced": wkf.Name,
"number": "1",
})
req := assets.NewAuthentifiedRequest(t, u, jwt, "GET", uri, nil)
rec := httptest.NewRecorder()
Expand Down Expand Up @@ -2142,9 +2142,9 @@ func Test_postWorkflowRunHandlerMutexRelease(t *testing.T) {
try++
t.Logf("Attempt #%d on getWorkflowRunHandler for run 2", try)
uri := router.GetRoute("GET", api.getWorkflowRunHandler, map[string]string{
"key": proj.Key,
"permWorkflowName": wkf.Name,
"number": "2",
"key": proj.Key,
"permWorkflowNameAdvanced": wkf.Name,
"number": "2",
})
req := assets.NewAuthentifiedRequest(t, u, jwt, "GET", uri, nil)
rec := httptest.NewRecorder()
Expand Down Expand Up @@ -2174,9 +2174,9 @@ func Test_postWorkflowRunHandlerMutexRelease(t *testing.T) {
try++
t.Logf("Attempt #%d on getWorkflowRunHandler for run 3", try)
uri := router.GetRoute("GET", api.getWorkflowRunHandler, map[string]string{
"key": proj.Key,
"permWorkflowName": wkf.Name,
"number": "3",
"key": proj.Key,
"permWorkflowNameAdvanced": wkf.Name,
"number": "3",
})
req := assets.NewAuthentifiedRequest(t, u, jwt, "GET", uri, nil)
rec := httptest.NewRecorder()
Expand Down Expand Up @@ -2812,9 +2812,9 @@ func Test_deleteWorkflowRunHandler(t *testing.T) {
assert.NoError(t, err)
//Prepare request
vars := map[string]string{
"key": proj.Key,
"permWorkflowName": w1.Name,
"number": fmt.Sprintf("%d", wr.Number),
"key": proj.Key,
"permWorkflowNameAdvanced": w1.Name,
"number": fmt.Sprintf("%d", wr.Number),
}
uri := router.GetRoute("DELETE", api.deleteWorkflowRunHandler, vars)
test.NotEmpty(t, uri)
Expand All @@ -2827,9 +2827,9 @@ func Test_deleteWorkflowRunHandler(t *testing.T) {

//Prepare request
vars = map[string]string{
"key": proj.Key,
"permWorkflowName": w1.Name,
"number": fmt.Sprintf("%d", wr.Number),
"key": proj.Key,
"permWorkflowNameAdvanced": w1.Name,
"number": fmt.Sprintf("%d", wr.Number),
}
uri = router.GetRoute("GET", api.getWorkflowRunHandler, vars)
test.NotEmpty(t, uri)
Expand Down

0 comments on commit f9a5b4d

Please sign in to comment.