|
@@ -7,6 +7,8 @@ import (
|
|
|
|
|
|
|
|
"github.com/go-chi/chi"
|
|
"github.com/go-chi/chi"
|
|
|
|
|
|
|
|
|
|
+ "fmt"
|
|
|
|
|
+
|
|
|
"github.com/porter-dev/porter/internal/analytics"
|
|
"github.com/porter-dev/porter/internal/analytics"
|
|
|
"github.com/porter-dev/porter/internal/forms"
|
|
"github.com/porter-dev/porter/internal/forms"
|
|
|
"github.com/porter-dev/porter/internal/kubernetes"
|
|
"github.com/porter-dev/porter/internal/kubernetes"
|
|
@@ -20,7 +22,6 @@ import (
|
|
|
// container pod
|
|
// container pod
|
|
|
func (app *App) HandleProvisionTestInfra(w http.ResponseWriter, r *http.Request) {
|
|
func (app *App) HandleProvisionTestInfra(w http.ResponseWriter, r *http.Request) {
|
|
|
projID, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
|
|
projID, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
|
|
|
- userID, err := app.getUserIDFromRequest(r)
|
|
|
|
|
|
|
|
|
|
if err != nil || projID == 0 {
|
|
if err != nil || projID == 0 {
|
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
@@ -45,8 +46,6 @@ func (app *App) HandleProvisionTestInfra(w http.ResponseWriter, r *http.Request)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- infra.CreatedByUserID = userID
|
|
|
|
|
-
|
|
|
|
|
// handle write to the database
|
|
// handle write to the database
|
|
|
infra, err = app.Repo.Infra.CreateInfra(infra)
|
|
infra, err = app.Repo.Infra.CreateInfra(infra)
|
|
|
|
|
|
|
@@ -148,7 +147,6 @@ func (app *App) HandleDestroyTestInfra(w http.ResponseWriter, r *http.Request) {
|
|
|
// HandleProvisionAWSECRInfra provisions a new aws ECR instance for a project
|
|
// HandleProvisionAWSECRInfra provisions a new aws ECR instance for a project
|
|
|
func (app *App) HandleProvisionAWSECRInfra(w http.ResponseWriter, r *http.Request) {
|
|
func (app *App) HandleProvisionAWSECRInfra(w http.ResponseWriter, r *http.Request) {
|
|
|
projID, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
|
|
projID, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
|
|
|
- userID, err := app.getUserIDFromRequest(r)
|
|
|
|
|
|
|
|
|
|
if err != nil || projID == 0 {
|
|
if err != nil || projID == 0 {
|
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
@@ -179,8 +177,6 @@ func (app *App) HandleProvisionAWSECRInfra(w http.ResponseWriter, r *http.Reques
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- infra.CreatedByUserID = userID
|
|
|
|
|
-
|
|
|
|
|
// handle write to the database
|
|
// handle write to the database
|
|
|
infra, err = app.Repo.Infra.CreateInfra(infra)
|
|
infra, err = app.Repo.Infra.CreateInfra(infra)
|
|
|
|
|
|
|
@@ -223,14 +219,6 @@ func (app *App) HandleProvisionAWSECRInfra(w http.ResponseWriter, r *http.Reques
|
|
|
|
|
|
|
|
app.Logger.Info().Msgf("New aws ecr infra created: %d", infra.ID)
|
|
app.Logger.Info().Msgf("New aws ecr infra created: %d", infra.ID)
|
|
|
|
|
|
|
|
- app.AnalyticsClient.Track(analytics.RegistryProvisioningStartTrack(
|
|
|
|
|
- &analytics.RegistryProvisioningStartTrackOpts{
|
|
|
|
|
- ProjectScopedTrackOpts: analytics.GetProjectScopedTrackOpts(userID, uint(projID)),
|
|
|
|
|
- RegistryType: models.InfraECR,
|
|
|
|
|
- InfraID: infra.ID,
|
|
|
|
|
- },
|
|
|
|
|
- ))
|
|
|
|
|
-
|
|
|
|
|
w.WriteHeader(http.StatusCreated)
|
|
w.WriteHeader(http.StatusCreated)
|
|
|
|
|
|
|
|
infraExt := infra.Externalize()
|
|
infraExt := infra.Externalize()
|
|
@@ -348,8 +336,6 @@ func (app *App) HandleProvisionAWSEKSInfra(w http.ResponseWriter, r *http.Reques
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- infra.CreatedByUserID = userID
|
|
|
|
|
-
|
|
|
|
|
// handle write to the database
|
|
// handle write to the database
|
|
|
infra, err = app.Repo.Infra.CreateInfra(infra)
|
|
infra, err = app.Repo.Infra.CreateInfra(infra)
|
|
|
|
|
|
|
@@ -392,12 +378,13 @@ func (app *App) HandleProvisionAWSEKSInfra(w http.ResponseWriter, r *http.Reques
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
app.Logger.Info().Msgf("New aws eks infra created: %d", infra.ID)
|
|
app.Logger.Info().Msgf("New aws eks infra created: %d", infra.ID)
|
|
|
-
|
|
|
|
|
- app.AnalyticsClient.Track(analytics.ClusterProvisioningStartTrack(
|
|
|
|
|
- &analytics.ClusterProvisioningStartTrackOpts{
|
|
|
|
|
- ProjectScopedTrackOpts: analytics.GetProjectScopedTrackOpts(userID, uint(projID)),
|
|
|
|
|
- ClusterType: models.InfraEKS,
|
|
|
|
|
- InfraID: infra.ID,
|
|
|
|
|
|
|
+ app.analyticsClient.Track(analytics.CreateSegmentNewClusterEvent(
|
|
|
|
|
+ &analytics.NewClusterEventOpts{
|
|
|
|
|
+ UserId: fmt.Sprintf("%d", userID),
|
|
|
|
|
+ ProjId: fmt.Sprintf("%d", infra.ProjectID),
|
|
|
|
|
+ ClusterName: form.EKSName,
|
|
|
|
|
+ ClusterType: "EKS",
|
|
|
|
|
+ EventType: "provisioned",
|
|
|
},
|
|
},
|
|
|
))
|
|
))
|
|
|
|
|
|
|
@@ -415,7 +402,7 @@ func (app *App) HandleProvisionAWSEKSInfra(w http.ResponseWriter, r *http.Reques
|
|
|
func (app *App) HandleDestroyAWSEKSInfra(w http.ResponseWriter, r *http.Request) {
|
|
func (app *App) HandleDestroyAWSEKSInfra(w http.ResponseWriter, r *http.Request) {
|
|
|
// get path parameters
|
|
// get path parameters
|
|
|
infraID, err := strconv.ParseUint(chi.URLParam(r, "infra_id"), 10, 64)
|
|
infraID, err := strconv.ParseUint(chi.URLParam(r, "infra_id"), 10, 64)
|
|
|
- // userID, err := app.getUserIDFromRequest(r)
|
|
|
|
|
|
|
+ userID, err := app.getUserIDFromRequest(r)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
@@ -482,6 +469,15 @@ func (app *App) HandleDestroyAWSEKSInfra(w http.ResponseWriter, r *http.Request)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
app.Logger.Info().Msgf("AWS EKS infra marked for destruction: %d", infra.ID)
|
|
app.Logger.Info().Msgf("AWS EKS infra marked for destruction: %d", infra.ID)
|
|
|
|
|
+ app.analyticsClient.Track(analytics.CreateSegmentNewClusterEvent(
|
|
|
|
|
+ &analytics.NewClusterEventOpts{
|
|
|
|
|
+ UserId: fmt.Sprintf("%d", userID),
|
|
|
|
|
+ ProjId: fmt.Sprintf("%d", infra.ProjectID),
|
|
|
|
|
+ ClusterName: form.EKSName,
|
|
|
|
|
+ ClusterType: "EKS",
|
|
|
|
|
+ EventType: "destroyed",
|
|
|
|
|
+ },
|
|
|
|
|
+ ))
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
w.WriteHeader(http.StatusOK)
|
|
|
}
|
|
}
|
|
@@ -489,7 +485,6 @@ func (app *App) HandleDestroyAWSEKSInfra(w http.ResponseWriter, r *http.Request)
|
|
|
// HandleProvisionGCPGCRInfra enables GCR for a project
|
|
// HandleProvisionGCPGCRInfra enables GCR for a project
|
|
|
func (app *App) HandleProvisionGCPGCRInfra(w http.ResponseWriter, r *http.Request) {
|
|
func (app *App) HandleProvisionGCPGCRInfra(w http.ResponseWriter, r *http.Request) {
|
|
|
projID, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
|
|
projID, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
|
|
|
- userID, err := app.getUserIDFromRequest(r)
|
|
|
|
|
|
|
|
|
|
if err != nil || projID == 0 {
|
|
if err != nil || projID == 0 {
|
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
@@ -520,8 +515,6 @@ func (app *App) HandleProvisionGCPGCRInfra(w http.ResponseWriter, r *http.Reques
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- infra.CreatedByUserID = userID
|
|
|
|
|
-
|
|
|
|
|
// handle write to the database
|
|
// handle write to the database
|
|
|
infra, err = app.Repo.Infra.CreateInfra(infra)
|
|
infra, err = app.Repo.Infra.CreateInfra(infra)
|
|
|
|
|
|
|
@@ -563,14 +556,6 @@ func (app *App) HandleProvisionGCPGCRInfra(w http.ResponseWriter, r *http.Reques
|
|
|
|
|
|
|
|
app.Logger.Info().Msgf("New gcp gcr infra created: %d", infra.ID)
|
|
app.Logger.Info().Msgf("New gcp gcr infra created: %d", infra.ID)
|
|
|
|
|
|
|
|
- app.AnalyticsClient.Track(analytics.RegistryProvisioningStartTrack(
|
|
|
|
|
- &analytics.RegistryProvisioningStartTrackOpts{
|
|
|
|
|
- ProjectScopedTrackOpts: analytics.GetProjectScopedTrackOpts(userID, uint(projID)),
|
|
|
|
|
- RegistryType: models.InfraGCR,
|
|
|
|
|
- InfraID: infra.ID,
|
|
|
|
|
- },
|
|
|
|
|
- ))
|
|
|
|
|
-
|
|
|
|
|
w.WriteHeader(http.StatusCreated)
|
|
w.WriteHeader(http.StatusCreated)
|
|
|
|
|
|
|
|
infraExt := infra.Externalize()
|
|
infraExt := infra.Externalize()
|
|
@@ -615,8 +600,6 @@ func (app *App) HandleProvisionGCPGKEInfra(w http.ResponseWriter, r *http.Reques
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- infra.CreatedByUserID = userID
|
|
|
|
|
-
|
|
|
|
|
// handle write to the database
|
|
// handle write to the database
|
|
|
infra, err = app.Repo.Infra.CreateInfra(infra)
|
|
infra, err = app.Repo.Infra.CreateInfra(infra)
|
|
|
|
|
|
|
@@ -658,12 +641,13 @@ func (app *App) HandleProvisionGCPGKEInfra(w http.ResponseWriter, r *http.Reques
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
app.Logger.Info().Msgf("New gcp gke infra created: %d", infra.ID)
|
|
app.Logger.Info().Msgf("New gcp gke infra created: %d", infra.ID)
|
|
|
-
|
|
|
|
|
- app.AnalyticsClient.Track(analytics.ClusterProvisioningStartTrack(
|
|
|
|
|
- &analytics.ClusterProvisioningStartTrackOpts{
|
|
|
|
|
- ProjectScopedTrackOpts: analytics.GetProjectScopedTrackOpts(userID, uint(projID)),
|
|
|
|
|
- ClusterType: models.InfraGKE,
|
|
|
|
|
- InfraID: infra.ID,
|
|
|
|
|
|
|
+ app.analyticsClient.Track(analytics.CreateSegmentNewClusterEvent(
|
|
|
|
|
+ &analytics.NewClusterEventOpts{
|
|
|
|
|
+ UserId: fmt.Sprintf("%d", userID),
|
|
|
|
|
+ ProjId: fmt.Sprintf("%d", infra.ProjectID),
|
|
|
|
|
+ ClusterName: form.GKEName,
|
|
|
|
|
+ ClusterType: "GKE",
|
|
|
|
|
+ EventType: "provisioned",
|
|
|
},
|
|
},
|
|
|
))
|
|
))
|
|
|
|
|
|
|
@@ -681,7 +665,7 @@ func (app *App) HandleProvisionGCPGKEInfra(w http.ResponseWriter, r *http.Reques
|
|
|
func (app *App) HandleDestroyGCPGKEInfra(w http.ResponseWriter, r *http.Request) {
|
|
func (app *App) HandleDestroyGCPGKEInfra(w http.ResponseWriter, r *http.Request) {
|
|
|
// get path parameters
|
|
// get path parameters
|
|
|
infraID, err := strconv.ParseUint(chi.URLParam(r, "infra_id"), 10, 64)
|
|
infraID, err := strconv.ParseUint(chi.URLParam(r, "infra_id"), 10, 64)
|
|
|
- // userID, err := app.getUserIDFromRequest(r)
|
|
|
|
|
|
|
+ userID, err := app.getUserIDFromRequest(r)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
@@ -747,6 +731,15 @@ func (app *App) HandleDestroyGCPGKEInfra(w http.ResponseWriter, r *http.Request)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
app.Logger.Info().Msgf("GCP GKE infra marked for destruction: %d", infra.ID)
|
|
app.Logger.Info().Msgf("GCP GKE infra marked for destruction: %d", infra.ID)
|
|
|
|
|
+ app.analyticsClient.Track(analytics.CreateSegmentNewClusterEvent(
|
|
|
|
|
+ &analytics.NewClusterEventOpts{
|
|
|
|
|
+ UserId: fmt.Sprintf("%d", userID),
|
|
|
|
|
+ ProjId: fmt.Sprintf("%d", infra.ProjectID),
|
|
|
|
|
+ ClusterName: form.GKEName,
|
|
|
|
|
+ ClusterType: "GKE",
|
|
|
|
|
+ EventType: "destroyed",
|
|
|
|
|
+ },
|
|
|
|
|
+ ))
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
w.WriteHeader(http.StatusOK)
|
|
|
}
|
|
}
|
|
@@ -798,7 +791,6 @@ func (app *App) HandleGetProvisioningLogs(w http.ResponseWriter, r *http.Request
|
|
|
// HandleProvisionDODOCRInfra provisions a new digitalocean DOCR instance for a project
|
|
// HandleProvisionDODOCRInfra provisions a new digitalocean DOCR instance for a project
|
|
|
func (app *App) HandleProvisionDODOCRInfra(w http.ResponseWriter, r *http.Request) {
|
|
func (app *App) HandleProvisionDODOCRInfra(w http.ResponseWriter, r *http.Request) {
|
|
|
projID, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
|
|
projID, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
|
|
|
- userID, err := app.getUserIDFromRequest(r)
|
|
|
|
|
|
|
|
|
|
if err != nil || projID == 0 {
|
|
if err != nil || projID == 0 {
|
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
@@ -829,8 +821,6 @@ func (app *App) HandleProvisionDODOCRInfra(w http.ResponseWriter, r *http.Reques
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- infra.CreatedByUserID = userID
|
|
|
|
|
-
|
|
|
|
|
// handle write to the database
|
|
// handle write to the database
|
|
|
infra, err = app.Repo.Infra.CreateInfra(infra)
|
|
infra, err = app.Repo.Infra.CreateInfra(infra)
|
|
|
|
|
|
|
@@ -875,14 +865,6 @@ func (app *App) HandleProvisionDODOCRInfra(w http.ResponseWriter, r *http.Reques
|
|
|
|
|
|
|
|
app.Logger.Info().Msgf("New do docr infra created: %d", infra.ID)
|
|
app.Logger.Info().Msgf("New do docr infra created: %d", infra.ID)
|
|
|
|
|
|
|
|
- app.AnalyticsClient.Track(analytics.RegistryProvisioningStartTrack(
|
|
|
|
|
- &analytics.RegistryProvisioningStartTrackOpts{
|
|
|
|
|
- ProjectScopedTrackOpts: analytics.GetProjectScopedTrackOpts(userID, uint(projID)),
|
|
|
|
|
- RegistryType: models.InfraDOCR,
|
|
|
|
|
- InfraID: infra.ID,
|
|
|
|
|
- },
|
|
|
|
|
- ))
|
|
|
|
|
-
|
|
|
|
|
w.WriteHeader(http.StatusCreated)
|
|
w.WriteHeader(http.StatusCreated)
|
|
|
|
|
|
|
|
infraExt := infra.Externalize()
|
|
infraExt := infra.Externalize()
|
|
@@ -1002,8 +984,6 @@ func (app *App) HandleProvisionDODOKSInfra(w http.ResponseWriter, r *http.Reques
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- infra.CreatedByUserID = userID
|
|
|
|
|
-
|
|
|
|
|
// handle write to the database
|
|
// handle write to the database
|
|
|
infra, err = app.Repo.Infra.CreateInfra(infra)
|
|
infra, err = app.Repo.Infra.CreateInfra(infra)
|
|
|
|
|
|
|
@@ -1047,12 +1027,13 @@ func (app *App) HandleProvisionDODOKSInfra(w http.ResponseWriter, r *http.Reques
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
app.Logger.Info().Msgf("New do doks infra created: %d", infra.ID)
|
|
app.Logger.Info().Msgf("New do doks infra created: %d", infra.ID)
|
|
|
-
|
|
|
|
|
- app.AnalyticsClient.Track(analytics.ClusterProvisioningStartTrack(
|
|
|
|
|
- &analytics.ClusterProvisioningStartTrackOpts{
|
|
|
|
|
- ProjectScopedTrackOpts: analytics.GetProjectScopedTrackOpts(userID, uint(projID)),
|
|
|
|
|
- ClusterType: models.InfraDOKS,
|
|
|
|
|
- InfraID: infra.ID,
|
|
|
|
|
|
|
+ app.analyticsClient.Track(analytics.CreateSegmentNewClusterEvent(
|
|
|
|
|
+ &analytics.NewClusterEventOpts{
|
|
|
|
|
+ UserId: fmt.Sprintf("%d", userID),
|
|
|
|
|
+ ProjId: fmt.Sprintf("%d", infra.ProjectID),
|
|
|
|
|
+ ClusterName: form.DOKSName,
|
|
|
|
|
+ ClusterType: "DOKS",
|
|
|
|
|
+ EventType: "provisioned",
|
|
|
},
|
|
},
|
|
|
))
|
|
))
|
|
|
|
|
|
|
@@ -1070,6 +1051,7 @@ func (app *App) HandleProvisionDODOKSInfra(w http.ResponseWriter, r *http.Reques
|
|
|
func (app *App) HandleDestroyDODOKSInfra(w http.ResponseWriter, r *http.Request) {
|
|
func (app *App) HandleDestroyDODOKSInfra(w http.ResponseWriter, r *http.Request) {
|
|
|
// get path parameters
|
|
// get path parameters
|
|
|
infraID, err := strconv.ParseUint(chi.URLParam(r, "infra_id"), 10, 64)
|
|
infraID, err := strconv.ParseUint(chi.URLParam(r, "infra_id"), 10, 64)
|
|
|
|
|
+ userID, err := app.getUserIDFromRequest(r)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
@@ -1137,6 +1119,15 @@ func (app *App) HandleDestroyDODOKSInfra(w http.ResponseWriter, r *http.Request)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
app.Logger.Info().Msgf("DO DOKS infra marked for destruction: %d", infra.ID)
|
|
app.Logger.Info().Msgf("DO DOKS infra marked for destruction: %d", infra.ID)
|
|
|
|
|
+ app.analyticsClient.Track(analytics.CreateSegmentNewClusterEvent(
|
|
|
|
|
+ &analytics.NewClusterEventOpts{
|
|
|
|
|
+ UserId: fmt.Sprintf("%d", userID),
|
|
|
|
|
+ ProjId: fmt.Sprintf("%d", infra.ProjectID),
|
|
|
|
|
+ ClusterName: form.DOKSName,
|
|
|
|
|
+ ClusterType: "DOKS",
|
|
|
|
|
+ EventType: "destroyed",
|
|
|
|
|
+ },
|
|
|
|
|
+ ))
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
w.WriteHeader(http.StatusOK)
|
|
|
}
|
|
}
|