def restore(self, user_did):
        clog().info('[restore_main] enter restore().')

        doc = cli.find_one_origin(DID_INFO_DB_NAME, VAULT_BACKUP_INFO_COL,
                                  {USER_DID: user_did})
        if self.is_ipfs:
            self.restore_ipfs_download_dbfiles(user_did,
                                               doc[VAULT_BACKUP_INFO_DRIVE],
                                               doc[VAULT_BACKUP_INFO_TOKEN])
            clog().info(
                '[restore_main: ipfs] success to download database files.')
            cli.import_mongodb(user_did)
            clog().info(
                '[restore_main: ipfs] success to import mongodb database.')
            self.restore_ipfs_pin_cids(user_did)
            clog().info('[restore_main: ipfs] success to pin ipfs cids.')
        else:
            vault_root = get_vault_path(user_did)
            if not vault_root.exists():
                create_full_path_dir(vault_root)
            clog().info(f'[restore_main] success to get vault root path.')
            self.restore_really(vault_root, doc[VAULT_BACKUP_INFO_DRIVE],
                                doc[VAULT_BACKUP_INFO_TOKEN])
            clog().info(f'[restore_main] success to execute restore.')
            self.restore_finish(user_did, doc[VAULT_BACKUP_INFO_DRIVE],
                                doc[VAULT_BACKUP_INFO_TOKEN])
            clog().info(f'[restore_main] success to restore finish.')
            cli.import_mongodb(user_did)

        self.delete_mongodb_data(user_did)
        self.update_backup_state(user_did, VAULT_BACKUP_STATE_STOP,
                                 VAULT_BACKUP_MSG_SUCCESS)
        clog().info('[restore_main] success to restore really.')
예제 #2
0
 def get_receipt_info(self, order_id):
     user_did, app_did = check_auth()
     order = self._check_param_order_id(user_did, order_id)
     receipt = cli.find_one_origin(DID_INFO_DB_NAME, COL_RECEIPTS,
                                   {COL_RECEIPTS_ORDER_ID: order_id}, throw_exception=False)
     if not receipt:
         raise ReceiptNotFoundException(msg='Receipt can not be found by order_id.')
     return self._get_receipt_vo(order, receipt)
 def find_backup_request(self, user_did, throw_exception=True):
     doc = cli.find_one_origin(DID_INFO_DB_NAME,
                               COL_IPFS_BACKUP_SERVER, {USR_DID: user_did},
                               create_on_absence=True,
                               throw_exception=False)
     if throw_exception and not doc:
         raise BackupNotFoundException()
     return doc
예제 #4
0
 def get_checked_vault(self, user_did, throw_exception=True, is_not_exist_raise=True):
     doc = cli.find_one_origin(DID_INFO_DB_NAME, VAULT_SERVICE_COL, {VAULT_SERVICE_DID: user_did},
                               create_on_absence=True, throw_exception=False)
     if throw_exception and is_not_exist_raise and not doc:
         raise VaultNotFoundException()
     if throw_exception and not is_not_exist_raise and doc:
         raise AlreadyExistsException(msg='The vault already exists.')
     return doc
예제 #5
0
    def _check_param_order_id(self, user_did, order_id, is_pay_order=False):
        if not order_id:
            raise InvalidParameterException(msg='Order id MUST be provided.')

        col_filter = {'_id': ObjectId(order_id), USR_DID: user_did}
        if is_pay_order:
            col_filter[COL_ORDERS_STATUS] = COL_ORDERS_STATUS_NORMAL
        order = cli.find_one_origin(DID_INFO_DB_NAME, COL_ORDERS, col_filter, throw_exception=False)
        if not order:
            raise InvalidParameterException(msg='Order id is invalid because of not finding the order.')

        if is_pay_order:
            receipt = cli.find_one_origin(DID_INFO_DB_NAME, COL_RECEIPTS,
                                          {COL_RECEIPTS_ORDER_ID: order_id}, throw_exception=False)
            if receipt:
                raise InvalidParameterException(msg='Order id is invalid because of existing the relating receipt.')

        return order
 def get_state(self, user_did):
     doc = cli.find_one_origin(DID_INFO_DB_NAME,
                               VAULT_BACKUP_INFO_COL, {USER_DID: user_did},
                               create_on_absence=True)
     state, result = 'stop', 'success'
     if doc:
         state, result = doc[VAULT_BACKUP_INFO_STATE], doc[
             VAULT_BACKUP_INFO_MSG]
     return {'state': state, 'result': result}
예제 #7
0
 def get_request(self, user_did):
     col_filter = {
         USR_DID: user_did,
         BACKUP_TARGET_TYPE: BACKUP_TARGET_TYPE_HIVE_NODE
     }
     return cli.find_one_origin(DID_INFO_DB_NAME,
                                COL_IPFS_BACKUP_CLIENT,
                                col_filter,
                                create_on_absence=True,
                                throw_exception=False)
    def check_backup_status(self, user_did, is_restore=False):
        doc = cli.find_one_origin(DID_INFO_DB_NAME,
                                  VAULT_BACKUP_INFO_COL, {USER_DID: user_did},
                                  create_on_absence=True)
        if doc and doc[VAULT_BACKUP_INFO_STATE] != VAULT_BACKUP_STATE_STOP \
                and doc[VAULT_BACKUP_INFO_TIME] < (datetime.utcnow().timestamp() - 60 * 60 * 24):
            raise BackupIsInProcessingException(
                'The backup/restore is in process.')

        if is_restore and not (
                doc[VAULT_BACKUP_INFO_STATE] == VAULT_BACKUP_STATE_STOP
                or doc[VAULT_BACKUP_INFO_MSG] == VAULT_BACKUP_MSG_SUCCESS):
            raise BadRequestException(
                msg='No successfully backup for restore.')
 def _check_auth_backup(self,
                        throw_exception=True,
                        create_on_absence=False,
                        is_check_size=False):
     user_did, app_did = check_auth2()
     doc = cli.find_one_origin(DID_INFO_DB_NAME,
                               VAULT_BACKUP_SERVICE_COL,
                               {VAULT_BACKUP_SERVICE_DID: user_did},
                               create_on_absence=create_on_absence,
                               throw_exception=False)
     if throw_exception and not doc:
         raise BackupNotFoundException()
     if throw_exception and is_check_size and doc \
             and doc[VAULT_BACKUP_SERVICE_USE_STORAGE] > doc[VAULT_BACKUP_SERVICE_MAX_STORAGE]:
         raise InsufficientStorageException(
             msg='No more available space for backup.')
     return user_did, app_did, doc
예제 #10
0
    def backup(self, user_did):
        clog().info('[backup_main] enter backup().')
        cli.export_mongodb(user_did)
        clog().info('[backup_main] success to export mongodb data.')

        doc = cli.find_one_origin(DID_INFO_DB_NAME, VAULT_BACKUP_INFO_COL,
                                  {USER_DID: user_did})
        clog().info('[backup_main] success to get backup info.')
        if self.is_ipfs:
            vault_size = fm.get_vault_storage_size(user_did)
            self.update_server_state_to(doc[VAULT_BACKUP_INFO_DRIVE],
                                        doc[VAULT_BACKUP_INFO_TOKEN],
                                        STATE_RUNNING, vault_size)
            clog().info('[backup_main: ipfs] success to start the backup.')
            self.backup_ipfs_upload_dbfiles(user_did,
                                            doc[VAULT_BACKUP_INFO_DRIVE],
                                            doc[VAULT_BACKUP_INFO_TOKEN])
            clog().info(
                '[backup_main: ipfs] success to upload database files.')
            self.backup_ipfs_cids(user_did, doc[VAULT_BACKUP_INFO_DRIVE],
                                  doc[VAULT_BACKUP_INFO_TOKEN])
            clog().info('[backup_main: ipfs] success to backup ipfs cids.')
            self.update_server_state_to(doc[VAULT_BACKUP_INFO_DRIVE],
                                        doc[VAULT_BACKUP_INFO_TOKEN],
                                        STATE_FINISH)
            clog().info(
                '[backup_main: ipfs] success to finish the backup process.')
        else:
            vault_root = get_vault_path(user_did)
            self.backup_files_really(vault_root, doc[VAULT_BACKUP_INFO_DRIVE],
                                     doc[VAULT_BACKUP_INFO_TOKEN])
            clog().info('[backup_main] success to execute backup.')
            checksum_list = get_file_checksum_list(vault_root)
            self.backup_finish(doc[VAULT_BACKUP_INFO_DRIVE],
                               doc[VAULT_BACKUP_INFO_TOKEN], checksum_list)
            clog().info('[backup_main] success to finish backup.')

        self.delete_mongodb_data(user_did)
        self.update_backup_state(user_did, VAULT_BACKUP_STATE_STOP,
                                 VAULT_BACKUP_MSG_SUCCESS)
        clog().info('[backup_main] success to backup really.')
예제 #11
0
 def get_vault_max_size(self, user_did):
     doc = cli.find_one_origin(DID_INFO_DB_NAME, VAULT_SERVICE_COL, {DID: user_did})
     if not doc:
         raise VaultNotFoundException(msg='Vault not found for get max size.')
     return int(doc[VAULT_SERVICE_MAX_STORAGE])
예제 #12
0
 def _check_transaction_id_local(self, transaction_id):
     receipt = cli.find_one_origin(DID_INFO_DB_NAME, COL_RECEIPTS,
                                   {COL_RECEIPTS_TRANSACTION_ID: transaction_id}, throw_exception=False)
     if receipt:
         raise InvalidParameterException(msg=f'Transaction id {transaction_id} has already been used.')