Przeglądaj źródła

Don't check for hosts and clients limits, but for machines instead

gabrielseibel1 2 lat temu
rodzic
commit
2802c6a9cf
2 zmienionych plików z 7 dodań i 25 usunięć
  1. 0 18
      controllers/limits.go
  2. 7 7
      logic/hosts.go

+ 0 - 18
controllers/limits.go

@@ -12,8 +12,6 @@ import (
 const (
 	limitChoiceNetworks = iota
 	limitChoiceUsers
-	limitChoiceHosts
-	limitChoiceClients
 	limitChoiceMachines
 	limitChoiceIngress
 	limitChoiceEgress
@@ -43,22 +41,6 @@ func checkFreeTierLimits(limitChoice int, next http.Handler) http.HandlerFunc {
 					logic.ReturnErrorResponse(w, r, errorResponse)
 					return
 				}
-			case limitChoiceClients:
-				clients, err := logic.GetAllExtClients()
-				if (err != nil && !database.IsEmptyRecord(err)) ||
-					len(clients) >= logic.ClientsLimit {
-					errorResponse.Message += "clients"
-					logic.ReturnErrorResponse(w, r, errorResponse)
-					return
-				}
-			case limitChoiceHosts:
-				hosts, err := logic.GetAllHosts()
-				if (err != nil && !database.IsEmptyRecord(err)) ||
-					len(hosts) >= logic.HostsLimit {
-					errorResponse.Message += "hosts"
-					logic.ReturnErrorResponse(w, r, errorResponse)
-					return
-				}
 			case limitChoiceMachines:
 				hosts, hErr := logic.GetAllHosts()
 				clients, cErr := logic.GetAllExtClients()

+ 7 - 7
logic/hosts.go

@@ -158,14 +158,14 @@ func GetHost(hostid string) (*models.Host, error) {
 
 // CreateHost - creates a host if not exist
 func CreateHost(h *models.Host) error {
-	hosts, err := GetAllHosts()
-	if err != nil && !database.IsEmptyRecord(err) {
-		return err
+	hosts, hErr := GetAllHosts()
+	clients, cErr := GetAllExtClients()
+	if (hErr != nil && !database.IsEmptyRecord(hErr)) ||
+		(cErr != nil && !database.IsEmptyRecord(cErr)) ||
+		len(hosts)+len(clients) >= MachinesLimit {
+		return errors.New("free tier limits exceeded on machines")
 	}
-	if len(hosts) >= HostsLimit {
-		return errors.New("free tier limits exceeded on hosts")
-	}
-	_, err = GetHost(h.ID.String())
+	_, err := GetHost(h.ID.String())
 	if (err != nil && !database.IsEmptyRecord(err)) || (err == nil) {
 		return ErrHostExists
 	}