2021-03-04 05:56:28 +08:00
|
|
|
defmodule LivebookWeb.Router do
|
|
|
|
use LivebookWeb, :router
|
2021-04-15 02:10:25 +08:00
|
|
|
import Phoenix.LiveDashboard.Router
|
2021-01-08 03:55:45 +08:00
|
|
|
|
|
|
|
pipeline :browser do
|
|
|
|
plug :accepts, ["html"]
|
|
|
|
plug :fetch_session
|
2021-01-08 04:16:54 +08:00
|
|
|
plug :fetch_live_flash
|
2023-02-23 02:34:54 +08:00
|
|
|
plug :put_root_layout, {LivebookWeb.Layouts, :root}
|
2022-11-22 23:38:49 +08:00
|
|
|
# Because LIVEBOOK_SECRET_KEY_BASE authentication is randomly
|
|
|
|
# generated, the odds of getting a CSRFProtection is quite high
|
|
|
|
# and exceptions can lead to a poor user experience.
|
|
|
|
#
|
|
|
|
# During authentication, configure_session(renew: true) will
|
|
|
|
# override the configure_session(ignore: true) but the session
|
|
|
|
# will be cleared anyway. This means an attacker can authenticate
|
|
|
|
# someone in a given Livebook instance but they wouldn't be able
|
|
|
|
# to do anything once the authentication goes through.
|
|
|
|
plug :protect_from_forgery, with: :clear_session
|
2021-01-08 03:55:45 +08:00
|
|
|
plug :put_secure_browser_headers
|
2022-11-10 23:02:59 +08:00
|
|
|
plug :within_iframe_secure_headers
|
2021-04-15 20:15:56 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
pipeline :auth do
|
2023-10-18 07:06:28 +08:00
|
|
|
# If identity provider is enabled and we don't have access
|
|
|
|
# we don't want to show Livebook's authentication
|
2021-05-04 02:03:19 +08:00
|
|
|
plug LivebookWeb.UserPlug
|
2023-10-18 07:06:28 +08:00
|
|
|
plug LivebookWeb.AuthPlug
|
2021-01-08 03:55:45 +08:00
|
|
|
end
|
|
|
|
|
2023-02-18 08:16:42 +08:00
|
|
|
pipeline :user do
|
|
|
|
plug LivebookWeb.UserPlug
|
|
|
|
end
|
|
|
|
|
2022-02-28 20:53:33 +08:00
|
|
|
pipeline :js_view_assets do
|
2021-12-24 21:18:34 +08:00
|
|
|
plug :put_secure_browser_headers
|
2022-11-10 23:02:59 +08:00
|
|
|
plug :within_iframe_secure_headers
|
2021-12-24 21:18:34 +08:00
|
|
|
end
|
|
|
|
|
2022-02-04 00:48:16 +08:00
|
|
|
# The /public namespace includes routes with no authentication.
|
|
|
|
# When exposing Livebook through an authentication proxy, this
|
|
|
|
# namespace should be configured as publicly available, in order
|
|
|
|
# for all features to work as expected.
|
|
|
|
|
|
|
|
scope "/public", LivebookWeb do
|
|
|
|
pipe_through :browser
|
|
|
|
|
|
|
|
get "/health", HealthController, :index
|
|
|
|
end
|
|
|
|
|
|
|
|
# The following routes are public, but should be treated as opaque
|
|
|
|
scope "/public", LivebookWeb do
|
2022-02-28 20:53:33 +08:00
|
|
|
pipe_through [:js_view_assets]
|
2021-12-24 21:18:34 +08:00
|
|
|
|
|
|
|
get "/sessions/:id/assets/:hash/*file_parts", SessionController, :show_asset
|
2024-05-17 21:15:27 +08:00
|
|
|
get "/sessions/node/:node_id/assets/:hash/*file_parts", SessionController, :show_cached_asset
|
2024-06-14 15:43:00 +08:00
|
|
|
get "/sessions/audio-input/:token", SessionController, :show_input_audio
|
|
|
|
get "/sessions/image-input/:token", SessionController, :show_input_image
|
2021-12-24 21:18:34 +08:00
|
|
|
end
|
|
|
|
|
2023-05-11 00:23:08 +08:00
|
|
|
live_session :default,
|
|
|
|
on_mount: [LivebookWeb.AuthHook, LivebookWeb.UserHook, LivebookWeb.Confirm] do
|
2021-11-02 02:33:43 +08:00
|
|
|
scope "/", LivebookWeb do
|
|
|
|
pipe_through [:browser, :auth]
|
2021-01-08 03:55:45 +08:00
|
|
|
|
2021-11-02 02:33:43 +08:00
|
|
|
live "/", HomeLive, :page
|
2021-07-09 01:35:11 +08:00
|
|
|
|
2023-03-07 01:14:33 +08:00
|
|
|
live "/open/:tab", OpenLive, :page
|
|
|
|
|
2021-11-02 02:33:43 +08:00
|
|
|
live "/settings", SettingsLive, :page
|
|
|
|
live "/settings/add-file-system", SettingsLive, :add_file_system
|
2022-09-12 22:34:39 +08:00
|
|
|
live "/settings/env-var/new", SettingsLive, :add_env_var
|
|
|
|
live "/settings/env-var/edit/:env_var_id", SettingsLive, :edit_env_var
|
2021-08-14 03:17:43 +08:00
|
|
|
|
2022-09-21 18:06:22 +08:00
|
|
|
live "/learn", LearnLive, :page
|
|
|
|
live "/learn/notebooks/:slug", LearnLive, :notebook
|
2021-07-09 01:35:11 +08:00
|
|
|
|
2023-11-06 16:08:28 +08:00
|
|
|
live "/apps-dashboard", AppsDashboardLive, :page
|
2023-02-28 22:08:49 +08:00
|
|
|
|
2024-03-30 17:02:27 +08:00
|
|
|
live "/hub", Hub.NewLive, :new
|
|
|
|
live "/hub/:id", Hub.EditLive, :edit
|
|
|
|
live "/hub/:id/env-var/new", Hub.EditLive, :add_env_var
|
|
|
|
live "/hub/:id/env-var/edit/:env_var_id", Hub.EditLive, :edit_env_var
|
|
|
|
live "/hub/:id/secrets/new", Hub.EditLive, :new_secret
|
|
|
|
live "/hub/:id/secrets/edit/:secret_name", Hub.EditLive, :edit_secret
|
|
|
|
live "/hub/:id/file-systems/new", Hub.EditLive, :new_file_system
|
|
|
|
live "/hub/:id/file-systems/edit/:file_system_id", Hub.EditLive, :edit_file_system
|
|
|
|
live "/hub/:id/groups/new", Hub.EditLive, :new_deployment_group
|
|
|
|
|
|
|
|
live "/hub/:id/groups/:deployment_group_id/agents/new",
|
|
|
|
Hub.EditLive,
|
|
|
|
:new_deployment_group_agent
|
|
|
|
|
|
|
|
live "/hub/:id/groups/:deployment_group_id/apps/new",
|
|
|
|
Hub.EditLive,
|
|
|
|
:new_deployment_group_app
|
|
|
|
|
|
|
|
live "/hub/:id/groups/:deployment_group_id/secrets/new",
|
|
|
|
Hub.EditLive,
|
|
|
|
:new_deployment_group_secret
|
|
|
|
|
|
|
|
live "/hub/:id/groups/:deployment_group_id/secrets/edit/:secret_name",
|
|
|
|
Hub.EditLive,
|
|
|
|
:edit_deployment_group_secret
|
2023-12-07 05:53:49 +08:00
|
|
|
|
2021-11-02 02:33:43 +08:00
|
|
|
live "/sessions/:id", SessionLive, :page
|
|
|
|
live "/sessions/:id/shortcuts", SessionLive, :shortcuts
|
2022-08-26 04:24:24 +08:00
|
|
|
live "/sessions/:id/secrets", SessionLive, :secrets
|
2021-11-02 02:33:43 +08:00
|
|
|
live "/sessions/:id/settings/runtime", SessionLive, :runtime_settings
|
|
|
|
live "/sessions/:id/settings/file", SessionLive, :file_settings
|
2023-05-22 03:21:10 +08:00
|
|
|
live "/sessions/:id/settings/app", SessionLive, :app_settings
|
2023-10-17 21:04:47 +08:00
|
|
|
live "/sessions/:id/app-docker", SessionLive, :app_docker
|
2024-03-20 21:16:30 +08:00
|
|
|
live "/sessions/:id/app-teams", SessionLive, :app_teams
|
2024-05-14 19:20:14 +08:00
|
|
|
live "/sessions/:id/app-teams-hub-info", SessionLive, :app_teams_hub_info
|
2023-07-06 02:01:12 +08:00
|
|
|
live "/sessions/:id/add-file/:tab", SessionLive, :add_file_entry
|
2023-08-18 04:13:39 +08:00
|
|
|
live "/sessions/:id/rename-file/:name", SessionLive, :rename_file_entry
|
2021-11-02 02:33:43 +08:00
|
|
|
live "/sessions/:id/bin", SessionLive, :bin
|
2023-07-26 02:07:13 +08:00
|
|
|
get "/sessions/:id/download/export/:format", SessionController, :download_source
|
2021-11-02 02:33:43 +08:00
|
|
|
live "/sessions/:id/export/:tab", SessionLive, :export
|
|
|
|
live "/sessions/:id/cell-settings/:cell_id", SessionLive, :cell_settings
|
2023-07-06 02:01:12 +08:00
|
|
|
live "/sessions/:id/insert-image", SessionLive, :insert_image
|
2023-07-22 02:11:11 +08:00
|
|
|
live "/sessions/:id/insert-file", SessionLive, :insert_file
|
2022-04-30 23:14:10 +08:00
|
|
|
live "/sessions/:id/package-search", SessionLive, :package_search
|
2023-07-06 02:01:12 +08:00
|
|
|
get "/sessions/:id/files/:name", SessionController, :show_file
|
2023-07-26 02:07:13 +08:00
|
|
|
get "/sessions/:id/download/files/:name", SessionController, :download_file
|
2023-07-24 20:20:42 +08:00
|
|
|
live "/sessions/:id/settings/custom-view", SessionLive, :custom_view_settings
|
2021-11-02 02:33:43 +08:00
|
|
|
live "/sessions/:id/*path_parts", SessionLive, :catch_all
|
|
|
|
end
|
2021-04-15 02:10:25 +08:00
|
|
|
|
2021-11-02 02:33:43 +08:00
|
|
|
# Public authenticated URLs that people may be directed to
|
|
|
|
scope "/", LivebookWeb do
|
|
|
|
pipe_through [:browser, :auth]
|
|
|
|
|
2023-07-04 20:46:19 +08:00
|
|
|
live "/new", HomeLive, :public_new_notebook
|
2023-03-07 01:14:33 +08:00
|
|
|
live "/import", OpenLive, :public_import
|
|
|
|
live "/open", OpenLive, :public_open
|
2021-11-02 02:33:43 +08:00
|
|
|
end
|
2021-01-08 03:55:45 +08:00
|
|
|
end
|
2021-04-15 20:15:56 +08:00
|
|
|
|
2023-05-11 00:23:08 +08:00
|
|
|
live_session :apps,
|
|
|
|
on_mount: [LivebookWeb.AppAuthHook, LivebookWeb.UserHook, LivebookWeb.Confirm] do
|
2023-02-18 08:16:42 +08:00
|
|
|
scope "/", LivebookWeb do
|
|
|
|
pipe_through [:browser, :user]
|
|
|
|
|
|
|
|
live "/apps/:slug", AppLive, :page
|
2023-07-11 19:57:50 +08:00
|
|
|
live "/apps/:slug/new", AppLive, :new_session
|
2023-02-18 08:16:42 +08:00
|
|
|
live "/apps/:slug/authenticate", AppAuthLive, :page
|
2023-05-20 01:40:56 +08:00
|
|
|
|
|
|
|
live "/apps/:slug/:id", AppSessionLive, :page
|
|
|
|
live "/apps/:slug/:id/source", AppSessionLive, :source
|
2023-11-06 16:08:28 +08:00
|
|
|
|
|
|
|
live "/apps", AppsLive, :page
|
2023-02-18 08:16:42 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-02 02:33:43 +08:00
|
|
|
scope "/" do
|
2021-10-16 18:23:08 +08:00
|
|
|
pipe_through [:browser, :auth]
|
|
|
|
|
2021-11-02 02:33:43 +08:00
|
|
|
live_dashboard "/dashboard",
|
|
|
|
metrics: LivebookWeb.Telemetry,
|
2021-12-25 02:05:19 +08:00
|
|
|
home_app: {"Livebook", :livebook},
|
|
|
|
ecto_repos: []
|
2021-10-16 18:23:08 +08:00
|
|
|
end
|
|
|
|
|
2021-04-15 20:15:56 +08:00
|
|
|
scope "/authenticate", LivebookWeb do
|
2023-10-18 07:06:28 +08:00
|
|
|
pipe_through [:browser, :user]
|
2021-04-15 20:15:56 +08:00
|
|
|
|
|
|
|
get "/", AuthController, :index
|
|
|
|
post "/", AuthController, :authenticate
|
|
|
|
end
|
2022-11-10 23:02:59 +08:00
|
|
|
|
|
|
|
defp within_iframe_secure_headers(conn, _opts) do
|
|
|
|
if Livebook.Config.within_iframe?() do
|
|
|
|
delete_resp_header(conn, "x-frame-options")
|
|
|
|
else
|
|
|
|
conn
|
|
|
|
end
|
|
|
|
end
|
2021-01-08 03:55:45 +08:00
|
|
|
end
|