From a2cd92c70ba3e12faafb17935d4cfeb0384bf7fc Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Wed, 3 Apr 2019 15:11:50 +0200 Subject: [PATCH] webhook: use provided userID --- internal/services/gateway/webhook.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/services/gateway/webhook.go b/internal/services/gateway/webhook.go index 2347ee6..e9e5aa7 100644 --- a/internal/services/gateway/webhook.go +++ b/internal/services/gateway/webhook.go @@ -120,6 +120,11 @@ func (h *webhooksHandler) handleWebhook(r *http.Request) (int, string, error) { ctx := r.Context() projectID := r.URL.Query().Get("projectid") + userID := r.URL.Query().Get("userid") + if projectID == "" && userID == "" { + return http.StatusBadRequest, "", errors.Errorf("bad webhook url %q. Missing projectid or userid", r.URL) + } + isUserBuild := false if projectID == "" { isUserBuild = true @@ -132,7 +137,6 @@ func (h *webhooksHandler) handleWebhook(r *http.Request) (int, string, error) { var cloneURL string var skipSSHHostKeyCheck bool var runType types.RunType - var userID string variables := map[string]string{} var gitSource gitsource.GitSource @@ -220,9 +224,9 @@ func (h *webhooksHandler) handleWebhook(r *http.Request) (int, string, error) { return http.StatusBadRequest, "", errors.Wrapf(err, "failed to parse webhook") } - user, _, err := h.configstoreClient.GetUserByName(ctx, webhookData.Repo.Owner) + user, _, err := h.configstoreClient.GetUser(ctx, userID) if err != nil { - return http.StatusBadRequest, "", errors.Wrapf(err, "failed to get project %s", projectID) + return http.StatusBadRequest, "", errors.Wrapf(err, "failed to get user with id %q", userID) } h.log.Debugf("user: %s", util.Dump(user)) userID = user.ID