Do not perform requests for offline teams

This commit is contained in:
José Valim 2024-03-25 22:19:41 +01:00
parent fdd2d2c2f2
commit b918f8ab47

View file

@ -314,14 +314,22 @@ defmodule Livebook.Teams.Requests do
defp add_team_auth(req, nil), do: req defp add_team_auth(req, nil), do: req
defp add_team_auth(req, team) do defp add_team_auth(req, team) do
token = if team.offline do
if team.user_id do Req.Request.append_request_steps(req,
"#{team.user_id}:#{team.org_id}:#{team.org_key_id}:#{team.session_token}" unauthorized: fn req ->
else {req, Req.Response.new(status: 401)}
"#{team.session_token}:#{Livebook.Config.agent_name()}:#{team.org_id}:#{team.org_key_id}" end
end )
else
token =
if team.user_id do
"#{team.user_id}:#{team.org_id}:#{team.org_key_id}:#{team.session_token}"
else
"#{team.session_token}:#{Livebook.Config.agent_name()}:#{team.org_id}:#{team.org_key_id}"
end
Req.Request.merge_options(req, auth: {:bearer, token}) Req.Request.merge_options(req, auth: {:bearer, token})
end
end end
defp request(req, opts) do defp request(req, opts) do
@ -339,7 +347,7 @@ defmodule Livebook.Teams.Requests do
{:ok, %{status: 401}} -> {:ok, %{status: 401}} ->
{:transport_error, {:transport_error,
"You are not authorized to perform this action, make sure you have the access or you are not in a Livebook Agent instance"} "You are not authorized to perform this action, make sure you have the access or you are not in a Livebook Agent/Offline instance"}
_otherwise -> _otherwise ->
{:transport_error, @error_message} {:transport_error, @error_message}