@@ -42,11 +42,27 @@ defmodule Livebook.Teams.AppDeployment do
4242 @ doc """
4343 Creates a new app deployment from notebook.
4444 """
45- @ spec new ( Livebook.Notebook . t ( ) , Livebook.FileSystem.File . t ( ) ) ::
45+ @ spec new ( Livebook.Notebook . t ( ) | String . t ( ) , Livebook.FileSystem.File . t ( ) ) ::
4646 { :ok , t ( ) } | { :warning , list ( String . t ( ) ) } | { :error , FileSystem . error ( ) }
47- def new ( notebook , files_dir ) do
48- with { :ok , source } <- fetch_notebook_source ( notebook ) ,
49- { :ok , files } <- build_and_check_file_entries ( notebook , source , files_dir ) ,
47+ def new ( % Livebook.Notebook { } = notebook , files_dir ) do
48+ case Livebook.LiveMarkdown . notebook_to_livemd ( notebook ) do
49+ { source , [ ] } -> new ( notebook , source , files_dir )
50+ { _ , warnings } -> { :warning , warnings }
51+ end
52+ end
53+
54+ @ stamp_error "notebook does not have a stamp, disabling access to secrets and remote files"
55+
56+ def new ( source , files_dir ) when is_binary ( source ) do
57+ case Livebook.LiveMarkdown . notebook_from_livemd ( source ) do
58+ { notebook , % { warnings: [ ] , stamp_verified?: true } } -> new ( notebook , source , files_dir )
59+ { _ , % { warnings: [ ] , stamp_verified?: false } } -> { :warning , [ @ stamp_error ] }
60+ { _ , % { warnings: warnings } } -> { :warning , warnings }
61+ end
62+ end
63+
64+ def new ( % Livebook.Notebook { } = notebook , source , files_dir ) do
65+ with { :ok , files } <- build_and_check_file_entries ( notebook , source , files_dir ) ,
5066 { :ok , { _ , zip_content } } <- :zip . create ( ~c" app_deployment.zip" , files , [ :memory ] ) ,
5167 :ok <- validate_size ( zip_content ) do
5268 md5_hash = :crypto . hash ( :md5 , zip_content )
@@ -66,13 +82,6 @@ defmodule Livebook.Teams.AppDeployment do
6682 end
6783 end
6884
69- defp fetch_notebook_source ( notebook ) do
70- case Livebook.LiveMarkdown . notebook_to_livemd ( notebook ) do
71- { source , [ ] } -> { :ok , source }
72- { _ , warnings } -> { :warning , warnings }
73- end
74- end
75-
7685 defp build_and_check_file_entries ( notebook , source , files_dir ) do
7786 notebook . file_entries
7887 |> Enum . filter ( & ( & 1 . type == :attachment ) )
0 commit comments