From 2de00f2ff8091902ca015aebac5e700a5cb24a19 Mon Sep 17 00:00:00 2001 From: zhuzhih2017 Date: Fri, 2 Jun 2017 16:47:50 +0800 Subject: [PATCH] add check rule for image_name --- builder/alicloud/ecs/image_config.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/builder/alicloud/ecs/image_config.go b/builder/alicloud/ecs/image_config.go index cbf1f3f91..c7fed2af6 100644 --- a/builder/alicloud/ecs/image_config.go +++ b/builder/alicloud/ecs/image_config.go @@ -5,6 +5,8 @@ import ( "github.com/denverdino/aliyungo/common" "github.com/hashicorp/packer/template/interpolate" + "regexp" + "strings" ) type AlicloudDiskDevice struct { @@ -40,6 +42,15 @@ func (c *AlicloudImageConfig) Prepare(ctx *interpolate.Context) []error { var errs []error if c.AlicloudImageName == "" { errs = append(errs, fmt.Errorf("image_name must be specified")) + } else if len(c.AlicloudImageName) < 2 || len(c.AlicloudImageName) > 128 { + errs = append(errs, fmt.Errorf("image_name must less than 128 letters and more than 1 letters")) + } else if strings.HasPrefix(c.AlicloudImageName, "http://") || + strings.HasPrefix(c.AlicloudImageName, "https://") { + errs = append(errs, fmt.Errorf("image_name can't start with 'http://' or 'https://'")) + } + reg := regexp.MustCompile("\\s+") + if reg.FindString(c.AlicloudImageName) != "" { + errs = append(errs, fmt.Errorf("image_name can't include spaces")) } if len(c.AlicloudImageDestinationRegions) > 0 {