66from .api_utils import (
77 _decode_unknown_from_base64 ,
88 outside_root_to_404 ,
9- prefix_dirs ,
109 reads_base64 ,
1110 to_b64 ,
1211 writes_base64 ,
1615 delete_remote_checkpoints ,
1716 delete_single_remote_checkpoint ,
1817 get_remote_checkpoint ,
19- latest_remote_checkpoints ,
2018 list_remote_checkpoints ,
2119 move_remote_checkpoints ,
2220 purge_remote_checkpoints ,
@@ -40,7 +38,14 @@ def create_notebook_checkpoint(self, nb, path):
4038 """
4139 b64_content = writes_base64 (nb )
4240 with self .engine .begin () as db :
43- return save_remote_checkpoint (db , self .user_id , path , b64_content )
41+ return save_remote_checkpoint (
42+ db ,
43+ self .user_id ,
44+ path ,
45+ b64_content ,
46+ self .crypto .encrypt ,
47+ self .max_file_size_bytes ,
48+ )
4449
4550 @outside_root_to_404
4651 def create_file_checkpoint (self , content , format , path ):
@@ -53,7 +58,14 @@ def create_file_checkpoint(self, content, format, path):
5358 except ValueError as e :
5459 self .do_400 (str (e ))
5560 with self .engine .begin () as db :
56- return save_remote_checkpoint (db , self .user_id , path , b64_content )
61+ return save_remote_checkpoint (
62+ db ,
63+ self .user_id ,
64+ path ,
65+ b64_content ,
66+ self .crypto .encrypt ,
67+ self .max_file_size_bytes ,
68+ )
5769
5870 @outside_root_to_404
5971 def delete_checkpoint (self , checkpoint_id , path ):
@@ -63,27 +75,28 @@ def delete_checkpoint(self, checkpoint_id, path):
6375 db , self .user_id , path , checkpoint_id ,
6476 )
6577
66- def _get_checkpoint (self , checkpoint_id , path ):
78+ def get_checkpoint_content (self , checkpoint_id , path ):
6779 """Get the content of a checkpoint."""
6880 with self .engine .begin () as db :
6981 return get_remote_checkpoint (
7082 db ,
7183 self .user_id ,
7284 path ,
7385 checkpoint_id ,
86+ self .crypto .decrypt ,
7487 )['content' ]
7588
7689 @outside_root_to_404
7790 def get_notebook_checkpoint (self , checkpoint_id , path ):
78- b64_content = self ._get_checkpoint (checkpoint_id , path )
91+ b64_content = self .get_checkpoint_content (checkpoint_id , path )
7992 return {
8093 'type' : 'notebook' ,
8194 'content' : reads_base64 (b64_content ),
8295 }
8396
8497 @outside_root_to_404
8598 def get_file_checkpoint (self , checkpoint_id , path ):
86- b64_content = self ._get_checkpoint (checkpoint_id , path )
99+ b64_content = self .get_checkpoint_content (checkpoint_id , path )
87100 content , format = _decode_unknown_from_base64 (path , b64_content )
88101 return {
89102 'type' : 'file' ,
@@ -120,30 +133,3 @@ def purge_db(self):
120133 """
121134 with self .engine .begin () as db :
122135 purge_remote_checkpoints (db , self .user_id )
123-
124- def dump (self , contents_mgr ):
125- """
126- Synchronize the state of our database with the specified
127- ContentsManager.
128-
129- Gets the most recent checkpoint for each file and passes it to the
130- supplied ContentsManager to be saved.
131- """
132- with self .engine .begin () as db :
133- records = latest_remote_checkpoints (db , self .user_id )
134- for record in records :
135- path = record ['path' ]
136- if not path .endswith ('.ipynb' ):
137- self .log .warn ('Ignoring non-notebook file: {}' , path )
138- continue
139- for dirname in prefix_dirs (path ):
140- self .log .info ("Ensuring directory [%s]" % dirname )
141- contents_mgr .save (
142- model = {'type' : 'directory' },
143- path = dirname ,
144- )
145- self .log .info ("Writing notebook [%s]" % path )
146- contents_mgr .save (
147- self .get_notebook_checkpoint (record ['id' ], path ),
148- path ,
149- )
0 commit comments