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
5a56ff3c
Unverified
Commit
5a56ff3c
authored
Sep 25, 2025
by
Patrick Devine
Committed by
GitHub
Sep 25, 2025
Browse files
cli: add device signin flow when doing ollama push (#12405)
parent
2fba04b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
2 deletions
+51
-2
cmd/cmd.go
cmd/cmd.go
+19
-1
cmd/cmd_test.go
cmd/cmd_test.go
+32
-1
No files found.
cmd/cmd.go
View file @
5a56ff3c
...
@@ -540,6 +540,25 @@ func PushHandler(cmd *cobra.Command, args []string) error {
...
@@ -540,6 +540,25 @@ func PushHandler(cmd *cobra.Command, args []string) error {
return
err
return
err
}
}
n
:=
model
.
ParseName
(
args
[
0
])
if
strings
.
HasSuffix
(
n
.
Host
,
".ollama.ai"
)
||
strings
.
HasSuffix
(
n
.
Host
,
".ollama.com"
)
{
_
,
err
:=
client
.
Whoami
(
cmd
.
Context
())
if
err
!=
nil
{
var
aErr
api
.
AuthorizationError
if
errors
.
As
(
err
,
&
aErr
)
&&
aErr
.
StatusCode
==
http
.
StatusUnauthorized
{
fmt
.
Println
(
"You need to be signed in to push models to ollama.com."
)
fmt
.
Println
()
if
aErr
.
SigninURL
!=
""
{
fmt
.
Printf
(
ConnectInstructions
,
aErr
.
SigninURL
)
}
return
nil
}
return
err
}
}
p
:=
progress
.
NewProgress
(
os
.
Stderr
)
p
:=
progress
.
NewProgress
(
os
.
Stderr
)
defer
p
.
Stop
()
defer
p
.
Stop
()
...
@@ -576,7 +595,6 @@ func PushHandler(cmd *cobra.Command, args []string) error {
...
@@ -576,7 +595,6 @@ func PushHandler(cmd *cobra.Command, args []string) error {
request
:=
api
.
PushRequest
{
Name
:
args
[
0
],
Insecure
:
insecure
}
request
:=
api
.
PushRequest
{
Name
:
args
[
0
],
Insecure
:
insecure
}
n
:=
model
.
ParseName
(
args
[
0
])
if
err
:=
client
.
Push
(
cmd
.
Context
(),
&
request
,
fn
);
err
!=
nil
{
if
err
:=
client
.
Push
(
cmd
.
Context
(),
&
request
,
fn
);
err
!=
nil
{
if
spinner
!=
nil
{
if
spinner
!=
nil
{
spinner
.
Stop
()
spinner
.
Stop
()
...
...
cmd/cmd_test.go
View file @
5a56ff3c
...
@@ -491,9 +491,35 @@ func TestPushHandler(t *testing.T) {
...
@@ -491,9 +491,35 @@ func TestPushHandler(t *testing.T) {
w
.
(
http
.
Flusher
)
.
Flush
()
w
.
(
http
.
Flusher
)
.
Flush
()
}
}
},
},
"/api/me"
:
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
r
.
Method
!=
http
.
MethodPost
{
t
.
Errorf
(
"expected POST request, got %s"
,
r
.
Method
)
}
},
},
},
expectedOutput
:
"
\n
You can find your model at:
\n\n\t
https://ollama.com/test-model
\n
"
,
expectedOutput
:
"
\n
You can find your model at:
\n\n\t
https://ollama.com/test-model
\n
"
,
},
},
{
name
:
"not signed in push"
,
modelName
:
"notsignedin-model"
,
serverResponse
:
map
[
string
]
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
){
"/api/me"
:
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
r
.
Method
!=
http
.
MethodPost
{
t
.
Errorf
(
"expected POST request, got %s"
,
r
.
Method
)
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
w
.
WriteHeader
(
http
.
StatusUnauthorized
)
err
:=
json
.
NewEncoder
(
w
)
.
Encode
(
map
[
string
]
string
{
"error"
:
"unauthorized"
,
"signin_url"
:
"https://somethingsomething"
,
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
},
},
expectedOutput
:
"You need to be signed in to push"
,
},
{
{
name
:
"unauthorized push"
,
name
:
"unauthorized push"
,
modelName
:
"unauthorized-model"
,
modelName
:
"unauthorized-model"
,
...
@@ -508,6 +534,11 @@ func TestPushHandler(t *testing.T) {
...
@@ -508,6 +534,11 @@ func TestPushHandler(t *testing.T) {
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
},
},
"/api/me"
:
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
r
.
Method
!=
http
.
MethodPost
{
t
.
Errorf
(
"expected POST request, got %s"
,
r
.
Method
)
}
},
},
},
expectedError
:
"you are not authorized to push to this namespace, create the model under a namespace you own"
,
expectedError
:
"you are not authorized to push to this namespace, create the model under a namespace you own"
,
},
},
...
@@ -564,7 +595,7 @@ func TestPushHandler(t *testing.T) {
...
@@ -564,7 +595,7 @@ func TestPushHandler(t *testing.T) {
t
.
Errorf
(
"expected no error, got %v"
,
err
)
t
.
Errorf
(
"expected no error, got %v"
,
err
)
}
}
if
tt
.
expectedOutput
!=
""
{
if
tt
.
expectedOutput
!=
""
{
if
got
:=
string
(
stdout
);
got
!=
tt
.
expectedOutput
{
if
got
:=
string
(
stdout
);
!
strings
.
Contains
(
got
,
tt
.
expectedOutput
)
{
t
.
Errorf
(
"expected output %q, got %q"
,
tt
.
expectedOutput
,
got
)
t
.
Errorf
(
"expected output %q, got %q"
,
tt
.
expectedOutput
,
got
)
}
}
}
}
...
...
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