-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprovision_github_installation_data.go
More file actions
61 lines (49 loc) · 1.7 KB
/
provision_github_installation_data.go
File metadata and controls
61 lines (49 loc) · 1.7 KB
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
package handler
import (
"encoding/json"
"fmt"
"net/http"
"strconv"
api "github.com/dxta-dev/app/internal/internal-api"
"github.com/dxta-dev/app/internal/onboarding/workflows"
"github.com/dxta-dev/app/internal/util"
"github.com/go-chi/chi/v5"
)
type ProvisionGithubInstallationDataResponse struct {
Message string `json:"message"`
}
func (t *OnboardingTemporal) ProvisionGithubInstallationData(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
installationId, err := strconv.ParseInt(chi.URLParam(r, "installation_id"), 10, 64)
if err != nil {
fmt.Printf("Issue while parsing installation id URL param. Error: %s", err.Error())
util.JSONError(w, util.ErrorParam{Error: "Bad Request"}, http.StatusBadRequest)
return
}
authId := ctx.Value(util.AuthIdCtxKey).(string)
tenantData, err := api.GetTenantDBUrlByAuthId(ctx, authId)
if err != nil {
util.JSONError(w, util.ErrorParam{Error: "Internal Server Error"}, http.StatusInternalServerError)
return
}
workflows.ExecuteGithubInstallationDataProvision(
ctx,
t.temporalClient,
workflows.ExecuteGithubInstallationDataProvisionParams{
TemporalOnboardingQueueName: t.config.TemporalOnboardingNamespace,
InstallationId: installationId,
AuthId: authId,
DBUrl: tenantData.DBUrl,
})
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(ProvisionGithubInstallationDataResponse{Message: "Success"}); err != nil {
fmt.Printf("Issue while formatting response. Error: %s", err.Error())
util.JSONError(
w,
util.ErrorParam{Error: "Internal Server Error"},
http.StatusInternalServerError,
)
return
}
}