File tree 2 files changed +21
-2
lines changed
2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,20 @@ func ParseModelPath(name string) ModelPath {
67
67
return mp
68
68
}
69
69
70
+ var errModelPathInvalid = errors .New ("invalid model path" )
71
+
72
+ func (mp ModelPath ) Validate () error {
73
+ if mp .Repository == "" {
74
+ return fmt .Errorf ("%w: model repository name is required" , errModelPathInvalid )
75
+ }
76
+
77
+ if strings .Contains (mp .Tag , ":" ) {
78
+ return fmt .Errorf ("%w: ':' (colon) is not allowed in tag names" , errModelPathInvalid )
79
+ }
80
+
81
+ return nil
82
+ }
83
+
70
84
func (mp ModelPath ) GetNamespaceRepository () string {
71
85
return fmt .Sprintf ("%s/%s" , mp .Namespace , mp .Repository )
72
86
}
Original file line number Diff line number Diff line change @@ -416,8 +416,8 @@ func CreateModelHandler(c *gin.Context) {
416
416
return
417
417
}
418
418
419
- if strings . Count (req .Name , ":" ) > 1 {
420
- c .AbortWithStatusJSON (http .StatusBadRequest , gin.H {"error" : "':' (colon) is not allowed in tag names" })
419
+ if err := ParseModelPath (req .Name ). Validate (); err != nil {
420
+ c .AbortWithStatusJSON (http .StatusBadRequest , gin.H {"error" : err . Error () })
421
421
return
422
422
}
423
423
@@ -645,6 +645,11 @@ func CopyModelHandler(c *gin.Context) {
645
645
return
646
646
}
647
647
648
+ if err := ParseModelPath (req .Destination ).Validate (); err != nil {
649
+ c .AbortWithStatusJSON (http .StatusBadRequest , gin.H {"error" : err .Error ()})
650
+ return
651
+ }
652
+
648
653
if err := CopyModel (req .Source , req .Destination ); err != nil {
649
654
if os .IsNotExist (err ) {
650
655
c .JSON (http .StatusNotFound , gin.H {"error" : fmt .Sprintf ("model '%s' not found" , req .Source )})
You can’t perform that action at this time.
0 commit comments