mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-04 12:04:20 +08:00
Show more prominent warning for app servers (#2962)
This commit is contained in:
parent
64b10e055f
commit
ce76af9432
8 changed files with 49 additions and 20 deletions
|
@ -35,7 +35,7 @@ config :livebook,
|
|||
plugs: [],
|
||||
rewrite_on: [],
|
||||
shutdown_callback: nil,
|
||||
teams_auth?: false,
|
||||
teams_auth: nil,
|
||||
teams_url: "https://teams.livebook.dev",
|
||||
github_release_info: %{repo: "livebook-dev/livebook", version: Mix.Project.config()[:version]},
|
||||
update_instructions_url: nil,
|
||||
|
|
|
@ -293,15 +293,16 @@ defmodule Livebook.Application do
|
|||
|
||||
cond do
|
||||
teams_key && auth ->
|
||||
Application.put_env(:livebook, :teams_auth?, true)
|
||||
|
||||
{hub_id, fun} =
|
||||
case String.split(auth, ":") do
|
||||
["offline", name, public_key] ->
|
||||
Application.put_env(:livebook, :teams_auth, :offline)
|
||||
hub_id = "team-#{name}"
|
||||
|
||||
{hub_id, fn -> create_offline_hub(teams_key, hub_id, name, public_key) end}
|
||||
|
||||
["online", name, org_id, org_key_id, agent_key] ->
|
||||
Application.put_env(:livebook, :teams_auth, :online)
|
||||
hub_id = "team-" <> name
|
||||
|
||||
with :error <- Application.fetch_env(:livebook, :identity_provider) do
|
||||
|
|
|
@ -195,9 +195,9 @@ defmodule Livebook.Config do
|
|||
Returns if this instance is running with teams auth,
|
||||
i.e. if there an online or offline hub created on boot.
|
||||
"""
|
||||
@spec teams_auth?() :: boolean()
|
||||
def teams_auth?() do
|
||||
Application.fetch_env!(:livebook, :teams_auth?)
|
||||
@spec teams_auth() :: :online | :offline | nil
|
||||
def teams_auth() do
|
||||
Application.fetch_env!(:livebook, :teams_auth)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -308,7 +308,7 @@ defmodule Livebook.Hubs do
|
|||
@doc """
|
||||
Gets a list of hub app specs.
|
||||
"""
|
||||
@spec get_app_specs() :: list(Livebook.AppSpec.t())
|
||||
@spec get_app_specs() :: list(Livebook.Apps.AppSpec.t())
|
||||
def get_app_specs() do
|
||||
for hub <- get_hubs(),
|
||||
app_spec <- Provider.get_app_specs(hub),
|
||||
|
|
|
@ -143,18 +143,8 @@ defimpl Livebook.Hubs.Provider, for: Livebook.Hubs.Team do
|
|||
def disconnect(team), do: TeamClient.stop(team.id)
|
||||
|
||||
def connection_status(team) do
|
||||
cond do
|
||||
team.offline ->
|
||||
"You are running an offline Workspace for deployment. You cannot modify its settings."
|
||||
|
||||
team.user_id == nil ->
|
||||
"You are running a Livebook app server. This workspace is in read-only mode."
|
||||
|
||||
reason = TeamClient.get_connection_status(team.id) ->
|
||||
"Cannot connect to Teams: #{reason}.\nWill attempt to reconnect automatically..."
|
||||
|
||||
true ->
|
||||
nil
|
||||
if reason = TeamClient.get_connection_status(team.id) do
|
||||
"Cannot connect to Teams: #{reason}.\nWill attempt to reconnect automatically..."
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -23,6 +23,13 @@ defmodule LivebookWeb.LayoutComponents do
|
|||
<.sidebar current_page={@current_page} current_user={@current_user} saved_hubs={@saved_hubs} />
|
||||
</div>
|
||||
<div class="grow overflow-y-auto">
|
||||
<.topbar :if={Livebook.Config.teams_auth() == :online} variant="warning">
|
||||
This Livebook instance has been configured for notebook deployment and is in read-only mode.
|
||||
</.topbar>
|
||||
<.topbar :if={Livebook.Config.teams_auth() == :offline} variant="warning">
|
||||
You are running an offline Workspace for deployment. You cannot modify its settings.
|
||||
</.topbar>
|
||||
|
||||
<div class="md:hidden sticky flex items-center justify-between h-14 px-4 top-0 left-0 z-[500] bg-white border-b border-gray-200">
|
||||
<div class="pt-1 text-xl text-gray-400 hover:text-gray-600 focus:text-gray-600">
|
||||
<button
|
||||
|
|
|
@ -78,7 +78,7 @@ defmodule LivebookWeb.AuthPlug do
|
|||
defp redirect_to_authenticate(%{path_info: []} = conn) do
|
||||
path =
|
||||
if Livebook.Apps.list_apps() != [] or Livebook.Config.apps_path() != nil or
|
||||
Livebook.Config.teams_auth?() do
|
||||
Livebook.Config.teams_auth() != nil do
|
||||
~p"/apps"
|
||||
else
|
||||
~p"/authenticate"
|
||||
|
|
31
test/livebook_teams/web/admin_live_test.exs
Normal file
31
test/livebook_teams/web/admin_live_test.exs
Normal file
|
@ -0,0 +1,31 @@
|
|||
defmodule LivebookWeb.Integration.AdminLiveTest do
|
||||
# Not async, because we alter global config (app server instance)
|
||||
use Livebook.TeamsIntegrationCase, async: false
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
|
||||
setup %{teams_auth: teams_auth} do
|
||||
Application.put_env(:livebook, :teams_auth, teams_auth)
|
||||
on_exit(fn -> Application.delete_env(:livebook, :teams_auth) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
for page <- ["/", "/settings", "/learn", "/hub", "/apps-dashboard"] do
|
||||
@tag page: page, teams_auth: :online
|
||||
test "GET #{page} shows the app server instance topbar warning", %{conn: conn, page: page} do
|
||||
{:ok, view, _} = live(conn, page)
|
||||
|
||||
assert render(view) =~
|
||||
"This Livebook instance has been configured for notebook deployment and is in read-only mode."
|
||||
end
|
||||
|
||||
@tag page: page, teams_auth: :offline
|
||||
test "GET #{page} shows the offline hub topbar warning", %{conn: conn, page: page} do
|
||||
{:ok, view, _} = live(conn, page)
|
||||
|
||||
assert render(view) =~
|
||||
"You are running an offline Workspace for deployment. You cannot modify its settings."
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue