Skip to content

Commit 05d7aaf

Browse files
committed
Support 'import_package' key in POST /v1/vault API (closes #28)
1 parent 0f37d3d commit 05d7aaf

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

syncrypt/api/resources.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,24 +228,25 @@ def dispatch_export(self, request):
228228

229229
@asyncio.coroutine
230230
def post_obj(self, request):
231+
232+
@asyncio.coroutine
233+
def pull_and_watch(vault):
234+
yield from self.app.pull_vault(vault)
235+
yield from self.app.watch(vault)
236+
231237
content = yield from request.content.read()
232238
request_dict = json.loads(content.decode())
239+
233240
if 'id' in request_dict:
234241
vault = yield from self.app.clone(request_dict['id'], request_dict['folder'])
235-
236-
@asyncio.coroutine
237-
def pull_and_watch(vault):
238-
yield from self.app.pull_vault(vault)
239-
yield from self.app.watch(vault)
242+
asyncio.get_event_loop().create_task(pull_and_watch(vault))
243+
elif 'import_package' in request_dict:
244+
vault = yield from self.app.import_package(
245+
request_dict['import_package'], request_dict['folder'])
240246
asyncio.get_event_loop().create_task(pull_and_watch(vault))
241247
else:
242248
vault = self.app.add_vault_by_path(request_dict['folder'])
243249
yield from self.app.open_or_init(vault)
244-
245-
@asyncio.coroutine
246-
def push_and_watch(vault):
247-
yield from self.app.push_vault(vault)
248-
yield from self.app.watch(vault)
249250
asyncio.get_event_loop().create_task(push_and_watch(vault))
250251
return vault
251252

syncrypt/app/syncrypt.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,12 @@ def import_package(self, filename, target_folder, pull_vault=False):
555555

556556
logger.info('Imported vault into "%s"', target_folder)
557557

558+
vault = Vault(target_folder)
559+
yield from self.open_or_init(vault)
560+
558561
if pull_vault:
559-
vault = Vault(target_folder)
560562
yield from self.pull_vault(vault)
563+
return vault
561564

562565
@asyncio.coroutine
563566
def export_package(self, filename):

0 commit comments

Comments
 (0)