@@ -18,6 +18,7 @@ import (
18
18
. "web/src/common"
19
19
"web/src/dbs"
20
20
"web/src/model"
21
+ "web/src/utils"
21
22
22
23
"github.com/go-macaron/session"
23
24
macaron "gopkg.in/macaron.v1"
@@ -36,7 +37,7 @@ func FileExist(filename string) bool {
36
37
return ! os .IsNotExist (err )
37
38
}
38
39
39
- func (a * ImageAdmin ) Create (ctx context.Context , osCode , name , osVersion , virtType , userName , url , architecture string , qaEnabled bool , instID int64 ) (image * model.Image , err error ) {
40
+ func (a * ImageAdmin ) Create (ctx context.Context , osCode , name , osVersion , virtType , userName , url , architecture string , qaEnabled bool , instID int64 , uuid string ) (image * model.Image , err error ) {
40
41
logger .Debugf ("Creating image %s %s %s %s %s %s %s %t %d" , osCode , name , osVersion , virtType , userName , url , architecture , qaEnabled , instID )
41
42
memberShip := GetMemberShip (ctx )
42
43
ctx , db , newTransaction := StartTransaction (ctx )
@@ -78,6 +79,10 @@ func (a *ImageAdmin) Create(ctx context.Context, osCode, name, osVersion, virtTy
78
79
Architecture : architecture ,
79
80
QAEnabled : qaEnabled ,
80
81
}
82
+ if uuid != "" {
83
+ logger .Debugf ("Creating image with UUID %s" , uuid )
84
+ image .UUID = uuid
85
+ }
81
86
}
82
87
logger .Debugf ("Creating image %+v" , image )
83
88
err = db .Create (image ).Error
@@ -344,6 +349,12 @@ func (v *ImageView) Create(c *macaron.Context, store session.Store) {
344
349
}
345
350
redirectTo := "../images"
346
351
osCode := c .QueryTrim ("osCode" )
352
+ uuid := c .QueryTrim ("uuid" )
353
+ if uuid != "" && ! utils .IsUUID (uuid ) {
354
+ c .Data ["ErrorMsg" ] = "Invalid UUID"
355
+ c .HTML (http .StatusBadRequest , "error" )
356
+ return
357
+ }
347
358
name := c .QueryTrim ("name" )
348
359
url := c .QueryTrim ("url" )
349
360
instance := c .QueryInt64 ("instance" )
@@ -352,7 +363,7 @@ func (v *ImageView) Create(c *macaron.Context, store session.Store) {
352
363
userName := c .QueryTrim ("userName" )
353
364
qaEnabled := true
354
365
architecture := "x86_64"
355
- _ , err := imageAdmin .Create (c .Req .Context (), osCode , name , osVersion , virtType , userName , url , architecture , qaEnabled , instance )
366
+ _ , err := imageAdmin .Create (c .Req .Context (), osCode , name , osVersion , virtType , userName , url , architecture , qaEnabled , instance , uuid )
356
367
if err != nil {
357
368
logger .Error ("Create image failed" , err )
358
369
c .Data ["ErrorMsg" ] = err .Error ()
0 commit comments