Feroze Mohideen пре 2 година
родитељ
комит
b32fc2f5fd
3 измењених фајлова са 24 додато и 24 уклоњено
  1. 1 0
      internal/porter_app/parse.go
  2. 4 24
      internal/porter_app/v1/types.go
  3. 19 0
      internal/porter_app/v1/yaml.go

+ 1 - 0
internal/porter_app/parse.go

@@ -18,6 +18,7 @@ type PorterYamlVersion string
 const (
 	// PorterYamlVersion_V2 is the v2 version of the porter yaml
 	PorterYamlVersion_V2 PorterYamlVersion = "v2"
+	// PorterYamlVersion_V1 is the v1, legacy version of the porter yaml
 	PorterYamlVersion_V1 PorterYamlVersion = "v1stack"
 )
 

+ 4 - 24
internal/porter_app/v1/types.go

@@ -124,25 +124,16 @@ type Service struct {
 }
 
 type v1_PorterYAML struct {
-	Applications map[string]*Application `yaml:"applications" validate:"required_without=Services Apps"`
-	Version      *string                 `yaml:"version"`
-	Build        *Build                  `yaml:"build"`
-	Env          map[string]string       `yaml:"env"`
-	SyncedEnv    []*SyncedEnvSection     `yaml:"synced_env"`
-	Apps         map[string]v1_Service   `yaml:"apps" validate:"required_without=Applications Services"`
-	Services     map[string]v1_Service   `yaml:"services" validate:"required_without=Applications Apps"`
-
-	Release *v1_Service `yaml:"release"`
-}
-
-type Application struct {
-	Services map[string]v1_Service `yaml:"services" validate:"required"`
+	Version  *string               `yaml:"version"`
 	Build    *Build                `yaml:"build"`
 	Env      map[string]string     `yaml:"env"`
+	Apps     map[string]v1_Service `yaml:"apps" validate:"required_without=Applications Services"`
+	Services map[string]v1_Service `yaml:"services" validate:"required_without=Applications Apps"`
 
 	Release *v1_Service `yaml:"release"`
 }
 
+// Build represents the build settings for a Porter app
 type Build struct {
 	Context    string   `yaml:"context" validate:"dir"`
 	Method     string   `yaml:"method" validate:"required,oneof=pack docker registry"`
@@ -157,14 +148,3 @@ type v1_Service struct {
 	Config v1_ServiceConfig `yaml:"config"`
 	Type   string           `yaml:"type" validate:"required, oneof=web worker job"`
 }
-
-type SyncedEnvSection struct {
-	Name    string                `json:"name" yaml:"name"`
-	Version uint                  `json:"version" yaml:"version"`
-	Keys    []SyncedEnvSectionKey `json:"keys" yaml:"keys"`
-}
-
-type SyncedEnvSectionKey struct {
-	Name   string `json:"name" yaml:"name"`
-	Secret bool   `json:"secret" yaml:"secret"`
-}

+ 19 - 0
internal/porter_app/v1/yaml.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"errors"
 	"fmt"
+	"math"
 	"strconv"
 	"strings"
 
@@ -143,6 +144,9 @@ func serviceProtoFromConfig(service v1_Service, serviceType porterv1.ServiceType
 
 	// if the revision number cannot be converted, it will default to 0
 	replicaCount, _ := strconv.Atoi(service.Config.ReplicaCount)
+	if replicaCount < math.MinInt32 || replicaCount > math.MaxInt32 {
+		return nil, fmt.Errorf("replica count is out of range")
+	}
 	serviceProto.Instances = int32(replicaCount)
 
 	if service.Config.Resources.Requests.Cpu != "" {
@@ -178,6 +182,9 @@ func serviceProtoFromConfig(service v1_Service, serviceType porterv1.ServiceType
 		if err != nil {
 			return nil, fmt.Errorf("invalid port '%s'", service.Config.Container.Port)
 		}
+		if port < math.MinInt32 || port > math.MaxInt32 {
+			return nil, fmt.Errorf("port is out of range")
+		}
 		serviceProto.Port = int32(port)
 	}
 
@@ -195,12 +202,24 @@ func serviceProtoFromConfig(service v1_Service, serviceType porterv1.ServiceType
 				Enabled: service.Config.Autoscaling.Enabled,
 			}
 			minReplicas, _ := strconv.Atoi(service.Config.Autoscaling.MinReplicas)
+			if minReplicas < math.MinInt32 || minReplicas > math.MaxInt32 {
+				return nil, fmt.Errorf("minReplicas is out of range")
+			}
 			autoscaling.MinInstances = int32(minReplicas)
 			maxReplicas, _ := strconv.Atoi(service.Config.Autoscaling.MaxReplicas)
+			if maxReplicas < math.MinInt32 || maxReplicas > math.MaxInt32 {
+				return nil, fmt.Errorf("maxReplicas is out of range")
+			}
 			autoscaling.MaxInstances = int32(maxReplicas)
 			cpuThresholdPercent, _ := strconv.Atoi(service.Config.Autoscaling.TargetCPUUtilizationPercentage)
+			if cpuThresholdPercent < math.MinInt32 || cpuThresholdPercent > math.MaxInt32 {
+				return nil, fmt.Errorf("cpuThresholdPercent is out of range")
+			}
 			autoscaling.CpuThresholdPercent = int32(cpuThresholdPercent)
 			memoryThresholdPercent, _ := strconv.Atoi(service.Config.Autoscaling.TargetMemoryUtilizationPercentage)
+			if memoryThresholdPercent < math.MinInt32 || memoryThresholdPercent > math.MaxInt32 {
+				return nil, fmt.Errorf("memoryThresholdPercent is out of range")
+			}
 			autoscaling.MemoryThresholdPercent = int32(memoryThresholdPercent)
 		}
 		webConfig.Autoscaling = autoscaling