Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: add limit for environment count (#3504)
Danny Xu32b01c2a8584
diff --git a/api/plan.go b/api/plan.goindex 29499c55b8..7765410a1f 100644--- a/api/plan.go+++ b/api/plan.go@@ -333,11 +333,14 @@ type PlanLimit intconst (// PlanLimitMaximumTask is the key name for maximum number of tasks for a plan.PlanLimitMaximumTask PlanLimit = iota+ // PlanLimitMaximumEnvironment is the key name for maximum number of environments for a plan.+ PlanLimitMaximumEnvironment)// PlanLimitValues is the plan limit value mapping.var PlanLimitValues = map[PlanLimit][3]int64{- PlanLimitMaximumTask: {4, math.MaxInt64, math.MaxInt64},+ PlanLimitMaximumTask: {4, math.MaxInt64, math.MaxInt64},+ PlanLimitMaximumEnvironment: {2, 3, math.MaxInt64},}// Feature returns whether a particular feature is available in a particular plan.diff --git a/server/environment.go b/server/environment.goindex a57237f3a7..008c2455f8 100644--- a/server/environment.go+++ b/server/environment.go@@ -18,6 +18,20 @@ import (func (s *Server) registerEnvironmentRoutes(g *echo.Group) {g.POST("/environment", func(c echo.Context) error {ctx := c.Request().Context()+ normalRowStatus := api.Normal+ envFind := &api.EnvironmentFind{+ RowStatus: &normalRowStatus,+ }+ envList, err := s.store.FindEnvironment(ctx, envFind)+ if err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find environment list").SetInternal(err)+ }++ maximumEnvironmentLimit := s.getPlanLimitValue(api.PlanLimitMaximumEnvironment)+ if int64(len(envList)) >= maximumEnvironmentLimit {+ return echo.NewHTTPError(http.StatusForbidden, fmt.Sprintf("Effective plan %s can create up to %d environments.", s.getEffectivePlan(), maximumEnvironmentLimit))+ }+envCreate := &api.EnvironmentCreate{}if err := jsonapi.UnmarshalPayload(c.Request().Body, envCreate); err != nil {return echo.NewHTTPError(http.StatusBadRequest, "Malformed create environment request").SetInternal(err)