Просмотр исходного кода

let the validator do all the validation

Mohammed Nafees 3 лет назад
Родитель
Сommit
70998e2c18

+ 1 - 13
cli/cmd/apply.go

@@ -258,11 +258,6 @@ func (d *DeployDriver) ShouldApply(_ *models.Resource) bool {
 
 func (d *DeployDriver) Apply(resource *models.Resource) (*models.Resource, error) {
 	client := config.GetAPIClient()
-	name := resource.Name
-
-	if name == "" {
-		return nil, fmt.Errorf("empty resource name")
-	}
 
 	_, err := client.GetRelease(
 		context.Background(),
@@ -356,13 +351,6 @@ func (d *DeployDriver) applyApplication(resource *models.Resource, client *api.C
 		return nil, err
 	}
 
-	method := appConfig.Build.Method
-
-	if method != "pack" && method != "docker" && method != "registry" {
-		return nil, fmt.Errorf("for resource %s, config.build.method should either be \"docker\", \"pack\" or \"registry\"",
-			resourceName)
-	}
-
 	fullPath, err := filepath.Abs(appConfig.Build.Context)
 
 	if err != nil {
@@ -407,7 +395,7 @@ func (d *DeployDriver) applyApplication(resource *models.Resource, client *api.C
 		LocalPath:       fullPath,
 		LocalDockerfile: appConfig.Build.Dockerfile,
 		OverrideTag:     tag,
-		Method:          deploy.DeployBuildType(method),
+		Method:          deploy.DeployBuildType(appConfig.Build.Method),
 		EnvGroups:       appConfig.EnvGroups,
 		UseCache:        appConfig.Build.UseCache,
 	}

+ 0 - 4
cli/cmd/preview/build_image_driver.go

@@ -45,10 +45,6 @@ func NewBuildDriver(resource *models.Resource, opts *drivers.SharedDriverOpts) (
 		return nil, err
 	}
 
-	if target.AppName == "" {
-		return nil, fmt.Errorf("target app_name is missing")
-	}
-
 	driver.target = target
 
 	return driver, nil

+ 0 - 4
cli/cmd/preview/push_image_driver.go

@@ -34,10 +34,6 @@ func NewPushDriver(resource *models.Resource, opts *drivers.SharedDriverOpts) (d
 		return nil, err
 	}
 
-	if target.AppName == "" {
-		return nil, fmt.Errorf("target app_name is missing")
-	}
-
 	driver.target = target
 
 	return driver, nil

+ 0 - 4
cli/cmd/preview/update_config_driver.go

@@ -46,10 +46,6 @@ func NewUpdateConfigDriver(resource *models.Resource, opts *drivers.SharedDriver
 		return nil, err
 	}
 
-	if target.AppName == "" {
-		return nil, fmt.Errorf("target app_name is missing")
-	}
-
 	driver.target = target
 
 	return driver, nil

+ 3 - 1
internal/integrations/preview/validate.go

@@ -55,7 +55,9 @@ func Validate(contents string) []error {
 	}
 
 	for _, res := range resGroup.Resources {
-		if errStrs := validation.IsDNS1123Label(res.Name); len(errStrs) > 0 {
+		if len(res.Name) == 0 {
+			errors = append(errors, fmt.Errorf("resource has no name"))
+		} else if errStrs := validation.IsDNS1123Label(res.Name); len(errStrs) > 0 {
 			str := fmt.Sprintf("for resource '%s': invalid characters found in name:", res.Name)
 			for _, errStr := range errStrs {
 				str += fmt.Sprintf("\n  * %s", errStr)