forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline_execution.go
66 lines (52 loc) · 1.77 KB
/
pipeline_execution.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package pipeline
import (
"fmt"
"github.com/pkg/errors"
"github.com/rancher/norman/api/access"
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/types"
"github.com/rancher/types/client/management/v3"
"net/http"
)
type ExecutionHandler struct {
}
func (h ExecutionHandler) ExecutionFormatter(apiContext *types.APIContext, resource *types.RawResource) {
resource.AddAction(apiContext, "rerun")
resource.AddAction(apiContext, "stop")
resource.Links["log"] = apiContext.URLBuilder.Link("log", resource)
}
func (h ExecutionHandler) LinkHandler(apiContext *types.APIContext, next types.RequestHandler) error {
if apiContext.Link == "log" {
return h.log(apiContext)
}
return httperror.NewAPIError(httperror.NotFound, "Link not found")
}
func (h *ExecutionHandler) ActionHandler(actionName string, action *types.Action, apiContext *types.APIContext) error {
switch actionName {
case "rerun":
return h.rerun(apiContext)
case "stop":
return h.stop(apiContext)
}
return httperror.NewAPIError(httperror.InvalidAction, "unsupported action")
}
func (h *ExecutionHandler) rerun(apiContext *types.APIContext) error {
return nil
}
func (h *ExecutionHandler) stop(apiContext *types.APIContext) error {
return nil
}
func (h *ExecutionHandler) log(apiContext *types.APIContext) error {
stage := apiContext.Request.URL.Query().Get("stage")
step := apiContext.Request.URL.Query().Get("step")
if stage == "" || step == "" {
return errors.New("Step index for log is not provided")
}
logID := fmt.Sprintf("%s-%s-%s", apiContext.ID, stage, step)
data := map[string]interface{}{}
if err := access.ByID(apiContext, apiContext.Version, client.PipelineExecutionLogType, logID, &data); err != nil {
return err
}
apiContext.WriteResponse(http.StatusOK, data)
return nil
}