runservice/gateway: return run on run action
This commit is contained in:
parent
83273489e0
commit
e4e7de4ad2
|
@ -115,17 +115,17 @@ type RunActionsRequest struct {
|
||||||
FromStart bool
|
FromStart bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ActionHandler) RunAction(ctx context.Context, req *RunActionsRequest) error {
|
func (h *ActionHandler) RunAction(ctx context.Context, req *RunActionsRequest) (*rsapi.RunResponse, error) {
|
||||||
runResp, resp, err := h.runserviceClient.GetRun(ctx, req.RunID, nil)
|
runResp, resp, err := h.runserviceClient.GetRun(ctx, req.RunID, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrFromRemote(resp, err)
|
return nil, ErrFromRemote(resp, err)
|
||||||
}
|
}
|
||||||
canGetRun, err := h.CanDoRunActions(ctx, runResp.RunConfig.Group)
|
canGetRun, err := h.CanDoRunActions(ctx, runResp.RunConfig.Group)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to determine permissions")
|
return nil, errors.Wrapf(err, "failed to determine permissions")
|
||||||
}
|
}
|
||||||
if !canGetRun {
|
if !canGetRun {
|
||||||
return util.NewErrForbidden(errors.Errorf("user not authorized"))
|
return nil, util.NewErrForbidden(errors.Errorf("user not authorized"))
|
||||||
}
|
}
|
||||||
|
|
||||||
switch req.ActionType {
|
switch req.ActionType {
|
||||||
|
@ -135,9 +135,9 @@ func (h *ActionHandler) RunAction(ctx context.Context, req *RunActionsRequest) e
|
||||||
FromStart: req.FromStart,
|
FromStart: req.FromStart,
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := h.runserviceClient.CreateRun(ctx, rsreq)
|
runResp, resp, err = h.runserviceClient.CreateRun(ctx, rsreq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrFromRemote(resp, err)
|
return nil, ErrFromRemote(resp, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
case RunActionTypeStop:
|
case RunActionTypeStop:
|
||||||
|
@ -145,16 +145,16 @@ func (h *ActionHandler) RunAction(ctx context.Context, req *RunActionsRequest) e
|
||||||
ActionType: rsapi.RunActionTypeStop,
|
ActionType: rsapi.RunActionTypeStop,
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := h.runserviceClient.RunActions(ctx, req.RunID, rsreq)
|
resp, err = h.runserviceClient.RunActions(ctx, req.RunID, rsreq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrFromRemote(resp, err)
|
return nil, ErrFromRemote(resp, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return util.NewErrBadRequest(errors.Errorf("wrong run action type %q", req.ActionType))
|
return nil, util.NewErrBadRequest(errors.Errorf("wrong run action type %q", req.ActionType))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return runResp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type RunTaskActionType string
|
type RunTaskActionType string
|
||||||
|
|
|
@ -407,11 +407,16 @@ func (h *RunActionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
FromStart: req.FromStart,
|
FromStart: req.FromStart,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := h.ah.RunAction(ctx, areq)
|
runResp, err := h.ah.RunAction(ctx, areq)
|
||||||
if httpError(w, err) {
|
if httpError(w, err) {
|
||||||
h.log.Errorf("err: %+v", err)
|
h.log.Errorf("err: %+v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res := createRunResponse(runResp.Run, runResp.RunConfig)
|
||||||
|
if err := httpResponse(w, http.StatusOK, res); err != nil {
|
||||||
|
h.log.Errorf("err: %+v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type RunTaskActionsRequest struct {
|
type RunTaskActionsRequest struct {
|
||||||
|
|
|
@ -370,7 +370,7 @@ func (h *webhooksHandler) createRuns(ctx context.Context, filename string, confi
|
||||||
Annotations: annotations,
|
Annotations: annotations,
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := h.runserviceClient.CreateRun(ctx, createRunReq); err != nil {
|
if _, _, err := h.runserviceClient.CreateRun(ctx, createRunReq); err != nil {
|
||||||
log.Errorf("failed to create run: %+v", err)
|
log.Errorf("failed to create run: %+v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -391,7 +391,7 @@ func (h *webhooksHandler) createRuns(ctx context.Context, filename string, confi
|
||||||
Annotations: annotations,
|
Annotations: annotations,
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := h.runserviceClient.CreateRun(ctx, createRunReq); err != nil {
|
if _, _, err := h.runserviceClient.CreateRun(ctx, createRunReq); err != nil {
|
||||||
log.Errorf("failed to create run: %+v", err)
|
log.Errorf("failed to create run: %+v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,13 +214,15 @@ func (c *Client) GetGroupFirstQueuedRuns(ctx context.Context, group string, chan
|
||||||
return c.GetRuns(ctx, []string{"queued"}, []string{group}, false, changeGroups, "", 1, true)
|
return c.GetRuns(ctx, []string{"queued"}, []string{group}, false, changeGroups, "", 1, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) CreateRun(ctx context.Context, req *RunCreateRequest) (*http.Response, error) {
|
func (c *Client) CreateRun(ctx context.Context, req *RunCreateRequest) (*RunResponse, *http.Response, error) {
|
||||||
reqj, err := json.Marshal(req)
|
reqj, err := json.Marshal(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.getResponse(ctx, "POST", "/runs", nil, -1, jsonContent, bytes.NewReader(reqj))
|
res := new(RunResponse)
|
||||||
|
resp, err := c.getParsedResponse(ctx, "POST", "/runs", nil, jsonContent, bytes.NewReader(reqj), res)
|
||||||
|
return res, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) RunActions(ctx context.Context, runID string, req *RunActionsRequest) (*http.Response, error) {
|
func (c *Client) RunActions(ctx context.Context, runID string, req *RunActionsRequest) (*http.Response, error) {
|
||||||
|
|
Loading…
Reference in New Issue