|
|
@@ -7,6 +7,9 @@ import (
|
|
|
|
|
|
"github.com/go-chi/chi"
|
|
|
|
|
|
+ "fmt"
|
|
|
+
|
|
|
+ "github.com/porter-dev/porter/internal/analytics"
|
|
|
"github.com/porter-dev/porter/internal/forms"
|
|
|
"github.com/porter-dev/porter/internal/kubernetes"
|
|
|
"github.com/porter-dev/porter/internal/kubernetes/provisioner"
|
|
|
@@ -302,6 +305,7 @@ func (app *App) HandleDestroyAWSECRInfra(w http.ResponseWriter, r *http.Request)
|
|
|
// HandleProvisionAWSEKSInfra provisions a new aws EKS instance for a project
|
|
|
func (app *App) HandleProvisionAWSEKSInfra(w http.ResponseWriter, r *http.Request) {
|
|
|
projID, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
|
|
|
+ userID, err := app.getUserIDFromRequest(r)
|
|
|
|
|
|
if err != nil || projID == 0 {
|
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
|
@@ -374,6 +378,15 @@ func (app *App) HandleProvisionAWSEKSInfra(w http.ResponseWriter, r *http.Reques
|
|
|
}
|
|
|
|
|
|
app.Logger.Info().Msgf("New aws eks infra created: %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: "provisioned",
|
|
|
+ },
|
|
|
+ ))
|
|
|
|
|
|
w.WriteHeader(http.StatusCreated)
|
|
|
|
|
|
@@ -389,6 +402,7 @@ func (app *App) HandleProvisionAWSEKSInfra(w http.ResponseWriter, r *http.Reques
|
|
|
func (app *App) HandleDestroyAWSEKSInfra(w http.ResponseWriter, r *http.Request) {
|
|
|
// get path parameters
|
|
|
infraID, err := strconv.ParseUint(chi.URLParam(r, "infra_id"), 10, 64)
|
|
|
+ userID, err := app.getUserIDFromRequest(r)
|
|
|
|
|
|
if err != nil {
|
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
|
@@ -455,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.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)
|
|
|
}
|
|
|
@@ -546,6 +569,7 @@ func (app *App) HandleProvisionGCPGCRInfra(w http.ResponseWriter, r *http.Reques
|
|
|
// HandleProvisionGCPGKEInfra provisions a new GKE instance for a project
|
|
|
func (app *App) HandleProvisionGCPGKEInfra(w http.ResponseWriter, r *http.Request) {
|
|
|
projID, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
|
|
|
+ userID, err := app.getUserIDFromRequest(r)
|
|
|
|
|
|
if err != nil || projID == 0 {
|
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
|
@@ -617,6 +641,15 @@ func (app *App) HandleProvisionGCPGKEInfra(w http.ResponseWriter, r *http.Reques
|
|
|
}
|
|
|
|
|
|
app.Logger.Info().Msgf("New gcp gke infra created: %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: "provisioned",
|
|
|
+ },
|
|
|
+ ))
|
|
|
|
|
|
w.WriteHeader(http.StatusCreated)
|
|
|
|
|
|
@@ -632,6 +665,7 @@ func (app *App) HandleProvisionGCPGKEInfra(w http.ResponseWriter, r *http.Reques
|
|
|
func (app *App) HandleDestroyGCPGKEInfra(w http.ResponseWriter, r *http.Request) {
|
|
|
// get path parameters
|
|
|
infraID, err := strconv.ParseUint(chi.URLParam(r, "infra_id"), 10, 64)
|
|
|
+ userID, err := app.getUserIDFromRequest(r)
|
|
|
|
|
|
if err != nil {
|
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
|
@@ -697,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.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)
|
|
|
}
|
|
|
@@ -910,6 +953,7 @@ func (app *App) HandleDestroyDODOCRInfra(w http.ResponseWriter, r *http.Request)
|
|
|
// HandleProvisionDODOKSInfra provisions a new DO DOKS instance for a project
|
|
|
func (app *App) HandleProvisionDODOKSInfra(w http.ResponseWriter, r *http.Request) {
|
|
|
projID, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
|
|
|
+ userID, err := app.getUserIDFromRequest(r)
|
|
|
|
|
|
if err != nil || projID == 0 {
|
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
|
@@ -983,6 +1027,15 @@ func (app *App) HandleProvisionDODOKSInfra(w http.ResponseWriter, r *http.Reques
|
|
|
}
|
|
|
|
|
|
app.Logger.Info().Msgf("New do doks infra created: %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: "provisioned",
|
|
|
+ },
|
|
|
+ ))
|
|
|
|
|
|
w.WriteHeader(http.StatusCreated)
|
|
|
|
|
|
@@ -998,6 +1051,7 @@ func (app *App) HandleProvisionDODOKSInfra(w http.ResponseWriter, r *http.Reques
|
|
|
func (app *App) HandleDestroyDODOKSInfra(w http.ResponseWriter, r *http.Request) {
|
|
|
// get path parameters
|
|
|
infraID, err := strconv.ParseUint(chi.URLParam(r, "infra_id"), 10, 64)
|
|
|
+ userID, err := app.getUserIDFromRequest(r)
|
|
|
|
|
|
if err != nil {
|
|
|
app.handleErrorFormDecoding(err, ErrProjectDecode, w)
|
|
|
@@ -1065,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.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)
|
|
|
}
|