mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-09 21:16:26 +08:00
Improve invalid notebook stamp messaging
This commit is contained in:
parent
eba249d045
commit
b5092c1f9f
2 changed files with 11 additions and 15 deletions
|
@ -600,10 +600,9 @@ defmodule Livebook.LiveMarkdown.Import do
|
||||||
defp take_stamp_data([{:stamp, data} | elements]), do: {data, elements}
|
defp take_stamp_data([{:stamp, data} | elements]), do: {data, elements}
|
||||||
defp take_stamp_data(elements), do: {nil, elements}
|
defp take_stamp_data(elements), do: {nil, elements}
|
||||||
|
|
||||||
@invalid_stamp_message "invalid notebook stamp, disabling default access to secrets and remote files "
|
@personal_stamp_message "this notebook can only access environment variables defined in this machine (the notebook was either authored in another machine or changed outside of Livebook)"
|
||||||
@personal_stamp_context "(you are either not the author of this notebook or changed its source outside of Livebook)"
|
@org_stamp_message "invalid notebook stamp, disabling access to secrets and remote files (this may happen if you made changes to the notebook source outside of Livebook)"
|
||||||
@org_stamp_context "(this may happen if you made changes to the notebook source outside of Livebook)"
|
@too_recent_stamp_message "invalid notebook stamp, disabling access to secrets and remote files (the stamp has been generated using a more recent Livebook version, you need to upgrade)"
|
||||||
@too_recent_stamp_context "(the stamp has been generated using a more recent Livebook version, you need to upgrade)"
|
|
||||||
|
|
||||||
defp postprocess_stamp(notebook, _notebook_source, nil), do: {notebook, []}
|
defp postprocess_stamp(notebook, _notebook_source, nil), do: {notebook, []}
|
||||||
|
|
||||||
|
@ -618,19 +617,14 @@ defmodule Livebook.LiveMarkdown.Import do
|
||||||
{true, notebook, []}
|
{true, notebook, []}
|
||||||
else
|
else
|
||||||
error ->
|
error ->
|
||||||
extra =
|
message =
|
||||||
cond do
|
cond do
|
||||||
error == {:error, :too_recent_version} ->
|
error == {:error, :too_recent_version} -> @too_recent_stamp_message
|
||||||
@too_recent_stamp_context
|
notebook.hub_id == "personal-hub" -> @personal_stamp_message
|
||||||
|
true -> @org_stamp_message
|
||||||
notebook.hub_id == "personal-hub" ->
|
|
||||||
@personal_stamp_context
|
|
||||||
|
|
||||||
true ->
|
|
||||||
@org_stamp_context
|
|
||||||
end
|
end
|
||||||
|
|
||||||
{false, notebook, [@invalid_stamp_message <> extra]}
|
{false, notebook, [message]}
|
||||||
end
|
end
|
||||||
|
|
||||||
# If the hub is online, then by definition it is a valid hub,
|
# If the hub is online, then by definition it is a valid hub,
|
||||||
|
|
|
@ -1165,7 +1165,9 @@ defmodule Livebook.LiveMarkdown.ImportTest do
|
||||||
{notebook, messages} = Import.notebook_from_livemd(markdown)
|
{notebook, messages} = Import.notebook_from_livemd(markdown)
|
||||||
|
|
||||||
assert %Notebook{hub_secret_names: []} = notebook
|
assert %Notebook{hub_secret_names: []} = notebook
|
||||||
assert ["invalid notebook stamp" <> _] = messages
|
|
||||||
|
assert ["this notebook can only access environment variables defined in this machine" <> _] =
|
||||||
|
messages
|
||||||
end
|
end
|
||||||
|
|
||||||
test "restores hub secret names from notebook stamp using offline hub" do
|
test "restores hub secret names from notebook stamp using offline hub" do
|
||||||
|
|
Loading…
Add table
Reference in a new issue