Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
96122b72
Unverified
Commit
96122b72
authored
Nov 29, 2023
by
Bruce MacDonald
Committed by
GitHub
Nov 29, 2023
Browse files
validate model tags on copy (#1323)
parent
39be7fdb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
2 deletions
+21
-2
server/modelpath.go
server/modelpath.go
+14
-0
server/routes.go
server/routes.go
+7
-2
No files found.
server/modelpath.go
View file @
96122b72
...
@@ -67,6 +67,20 @@ func ParseModelPath(name string) ModelPath {
...
@@ -67,6 +67,20 @@ func ParseModelPath(name string) ModelPath {
return
mp
return
mp
}
}
var
errModelPathInvalid
=
errors
.
New
(
"invalid model path"
)
func
(
mp
ModelPath
)
Validate
()
error
{
if
mp
.
Repository
==
""
{
return
fmt
.
Errorf
(
"%w: model repository name is required"
,
errModelPathInvalid
)
}
if
strings
.
Contains
(
mp
.
Tag
,
":"
)
{
return
fmt
.
Errorf
(
"%w: ':' (colon) is not allowed in tag names"
,
errModelPathInvalid
)
}
return
nil
}
func
(
mp
ModelPath
)
GetNamespaceRepository
()
string
{
func
(
mp
ModelPath
)
GetNamespaceRepository
()
string
{
return
fmt
.
Sprintf
(
"%s/%s"
,
mp
.
Namespace
,
mp
.
Repository
)
return
fmt
.
Sprintf
(
"%s/%s"
,
mp
.
Namespace
,
mp
.
Repository
)
}
}
...
...
server/routes.go
View file @
96122b72
...
@@ -416,8 +416,8 @@ func CreateModelHandler(c *gin.Context) {
...
@@ -416,8 +416,8 @@ func CreateModelHandler(c *gin.Context) {
return
return
}
}
if
strings
.
Count
(
req
.
Name
,
":"
)
>
1
{
if
err
:=
ParseModelPath
(
req
.
Name
)
.
Validate
();
err
!=
nil
{
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"':' (colon) is not allowed in tag names"
})
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()
})
return
return
}
}
...
@@ -645,6 +645,11 @@ func CopyModelHandler(c *gin.Context) {
...
@@ -645,6 +645,11 @@ func CopyModelHandler(c *gin.Context) {
return
return
}
}
if
err
:=
ParseModelPath
(
req
.
Destination
)
.
Validate
();
err
!=
nil
{
c
.
AbortWithStatusJSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
if
err
:=
CopyModel
(
req
.
Source
,
req
.
Destination
);
err
!=
nil
{
if
err
:=
CopyModel
(
req
.
Source
,
req
.
Destination
);
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
if
os
.
IsNotExist
(
err
)
{
c
.
JSON
(
http
.
StatusNotFound
,
gin
.
H
{
"error"
:
fmt
.
Sprintf
(
"model '%s' not found"
,
req
.
Source
)})
c
.
JSON
(
http
.
StatusNotFound
,
gin
.
H
{
"error"
:
fmt
.
Sprintf
(
"model '%s' not found"
,
req
.
Source
)})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment