From b918f8ab475b94f778afa1c0839da7c9285e633b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 25 Mar 2024 22:19:41 +0100 Subject: [PATCH] Do not perform requests for offline teams --- lib/livebook/teams/requests.ex | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/livebook/teams/requests.ex b/lib/livebook/teams/requests.ex index 6fa60be0c..bece82805 100644 --- a/lib/livebook/teams/requests.ex +++ b/lib/livebook/teams/requests.ex @@ -314,14 +314,22 @@ defmodule Livebook.Teams.Requests do defp add_team_auth(req, nil), do: req defp add_team_auth(req, team) do - 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 + if team.offline do + Req.Request.append_request_steps(req, + unauthorized: fn req -> + {req, Req.Response.new(status: 401)} + 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 defp request(req, opts) do @@ -339,7 +347,7 @@ defmodule Livebook.Teams.Requests do {:ok, %{status: 401}} -> {: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 -> {:transport_error, @error_message}