(w http.ResponseWriter, r *http.Request)
| 1132 | } |
| 1133 | |
| 1134 | func (s *Server) HandleWebhook(w http.ResponseWriter, r *http.Request) { |
| 1135 | vars := mux.Vars(r) |
| 1136 | webhookIDFromRequest := vars["webhookID"] |
| 1137 | webhookID, err := uuid.Parse(webhookIDFromRequest) |
| 1138 | if err != nil { |
| 1139 | http.Error(w, "webhook not found", http.StatusNotFound) |
| 1140 | return |
| 1141 | } |
| 1142 | |
| 1143 | _, err = models.FindWebhook(webhookID) |
| 1144 | if err != nil { |
| 1145 | http.Error(w, "webhook not found", http.StatusNotFound) |
| 1146 | return |
| 1147 | } |
| 1148 | |
| 1149 | r.Body = http.MaxBytesReader(w, r.Body, MaxEventSize) |
| 1150 | defer r.Body.Close() |
| 1151 | |
| 1152 | body, err := io.ReadAll(r.Body) |
| 1153 | if err != nil { |
| 1154 | if _, ok := err.(*http.MaxBytesError); ok { |
| 1155 | http.Error( |
| 1156 | w, |
| 1157 | fmt.Sprintf("Request body is too large - must be up to %d bytes", MaxEventSize), |
| 1158 | http.StatusRequestEntityTooLarge, |
| 1159 | ) |
| 1160 | |
| 1161 | return |
| 1162 | } |
| 1163 | |
| 1164 | http.Error(w, "Error reading request body", http.StatusBadRequest) |
| 1165 | return |
| 1166 | } |
| 1167 | |
| 1168 | nodes, err := models.FindActiveWebhookNodes(webhookID) |
| 1169 | if err != nil || len(nodes) == 0 { |
| 1170 | http.Error(w, "webhook not found", http.StatusNotFound) |
| 1171 | return |
| 1172 | } |
| 1173 | |
| 1174 | newEvents := []models.CanvasEvent{} |
| 1175 | onNewEvents := func(events []models.CanvasEvent) { |
| 1176 | newEvents = append(newEvents, events...) |
| 1177 | } |
| 1178 | |
| 1179 | touchedExecutions := map[uuid.UUID]uuid.UUID{} |
| 1180 | recordExecution := func(workflowID, executionID uuid.UUID) { |
| 1181 | touchedExecutions[executionID] = workflowID |
| 1182 | } |
| 1183 | |
| 1184 | var firstResponse *core.WebhookResponseBody |
| 1185 | |
| 1186 | for _, node := range nodes { |
| 1187 | code, response, err := s.executeWebhookNode(r.Context(), body, r.Header, node, onNewEvents, recordExecution) |
| 1188 | if err != nil { |
| 1189 | http.Error(w, fmt.Sprintf("error handling webhook: %v", err), code) |
| 1190 | return |
| 1191 | } |
nothing calls this directly
no test coverage detected