Ejemplo n.º 1
0
 def insert_request(self,
                    user_did,
                    target_host,
                    target_did,
                    access_token,
                    is_restore=False):
     new_doc = {
         USR_DID:
         user_did,
         BACKUP_TARGET_TYPE:
         BACKUP_TARGET_TYPE_HIVE_NODE,
         BACKUP_REQUEST_ACTION:
         BACKUP_REQUEST_ACTION_RESTORE
         if is_restore else BACKUP_REQUEST_ACTION_BACKUP,
         BACKUP_REQUEST_STATE:
         BACKUP_REQUEST_STATE_INPROGRESS,
         BACKUP_REQUEST_STATE_MSG:
         None,
         BACKUP_REQUEST_TARGET_HOST:
         target_host,
         BACKUP_REQUEST_TARGET_DID:
         target_did,
         BACKUP_REQUEST_TARGET_TOKEN:
         access_token
     }
     cli.insert_one_origin(DID_INFO_DB_NAME,
                           COL_IPFS_BACKUP_CLIENT,
                           new_doc,
                           create_on_absence=True)
Ejemplo n.º 2
0
 def create_vault(self, user_did, price_plan, is_upgraded=False):
     now = datetime.utcnow().timestamp()  # seconds in UTC
     end_time = -1 if price_plan['serviceDays'] == -1 else now + price_plan['serviceDays'] * 24 * 60 * 60
     doc = {VAULT_SERVICE_DID: user_did,
            VAULT_SERVICE_MAX_STORAGE: int(price_plan["maxStorage"]) * 1024 * 1024,
            VAULT_SERVICE_FILE_USE_STORAGE: 0,
            VAULT_SERVICE_DB_USE_STORAGE: 0,
            IS_UPGRADED: is_upgraded,
            VAULT_SERVICE_START_TIME: now,
            VAULT_SERVICE_END_TIME: end_time,
            VAULT_SERVICE_MODIFY_TIME: now,
            VAULT_SERVICE_STATE: VAULT_SERVICE_STATE_RUNNING,
            VAULT_SERVICE_PRICING_USING: price_plan['name']}
     cli.insert_one_origin(DID_INFO_DB_NAME, VAULT_SERVICE_COL, doc, create_on_absence=True, is_extra=False)
     # INFO: user database will create with first collection creation.
     if not fm.create_dir(get_vault_path(user_did)):
         raise BadRequestException('Failed to create folder for the user.')
     return doc
 def _create_backup(self, user_did, price_plan):
     now = datetime.utcnow().timestamp()
     end_time = -1 if price_plan['serviceDays'] == -1 else now + price_plan[
         'serviceDays'] * 24 * 60 * 60
     doc = {
         USR_DID: user_did,
         VAULT_BACKUP_SERVICE_USING: price_plan['name'],
         VAULT_BACKUP_SERVICE_MAX_STORAGE:
         price_plan["maxStorage"] * 1024 * 1024,
         VAULT_BACKUP_SERVICE_USE_STORAGE: 0,
         VAULT_BACKUP_SERVICE_START_TIME: now,
         VAULT_BACKUP_SERVICE_END_TIME: end_time
     }
     cli.insert_one_origin(DID_INFO_DB_NAME,
                           COL_IPFS_BACKUP_SERVER,
                           doc,
                           create_on_absence=True,
                           is_extra=True)
     return doc
Ejemplo n.º 4
0
 def _create_backup(self, user_did, price_plan):
     now = datetime.utcnow().timestamp()  # seconds in UTC
     end_time = -1 if price_plan['serviceDays'] == -1 else now + price_plan[
         'serviceDays'] * 24 * 60 * 60
     # there is no use of database for backup vault.
     doc = {
         VAULT_BACKUP_SERVICE_DID: user_did,
         VAULT_BACKUP_SERVICE_MAX_STORAGE:
         price_plan["maxStorage"] * 1000 * 1000,
         VAULT_BACKUP_SERVICE_USE_STORAGE: 0,
         ORIGINAL_SIZE: 0,
         VAULT_BACKUP_SERVICE_START_TIME: now,
         VAULT_BACKUP_SERVICE_END_TIME: end_time,
         STATE: STATE_RUNNING,
         VAULT_BACKUP_SERVICE_MODIFY_TIME: now,
         VAULT_BACKUP_SERVICE_STATE: VAULT_SERVICE_STATE_RUNNING,
         VAULT_BACKUP_SERVICE_USING: price_plan['name']
     }
     cli.insert_one_origin(DID_INFO_DB_NAME,
                           VAULT_BACKUP_SERVICE_COL,
                           doc,
                           create_on_absence=True)
     return doc
Ejemplo n.º 5
0
    def _create_receipt(self, user_did, order, transaction_id, paid_did):
        now = datetime.utcnow().timestamp()
        receipt = {
            USR_DID: user_did,
            COL_RECEIPTS_ORDER_ID: str(order['_id']),
            COL_RECEIPTS_TRANSACTION_ID: transaction_id,
            COL_RECEIPTS_PAID_DID: paid_did,
            COL_ORDERS_PROOF: '',
            COL_ORDERS_STATUS: COL_ORDERS_STATUS_NORMAL
        }
        res = cli.insert_one_origin(DID_INFO_DB_NAME, COL_RECEIPTS, receipt, create_on_absence=True)

        receipt['_id'] = res['inserted_id']
        receipt[COL_ORDERS_PROOF] = self.auth.create_order_proof(
            user_did, receipt['_id'], amount=order[COL_ORDERS_ELA_AMOUNT], is_receipt=True)
        cli.update_one_origin(DID_INFO_DB_NAME, COL_RECEIPTS, {'_id': ObjectId(receipt['_id'])},
                              {'$set': {COL_ORDERS_PROOF: receipt[COL_ORDERS_PROOF]}}, is_extra=True)
        return receipt
Ejemplo n.º 6
0
    def _create_order(self, user_did, subscription, plan):
        doc = {
            USR_DID: user_did,
            COL_ORDERS_SUBSCRIPTION: subscription,
            COL_ORDERS_PRICING_NAME: plan['name'],
            COL_ORDERS_ELA_AMOUNT: plan['amount'],
            COL_ORDERS_ELA_ADDRESS: self.ela_address,
            COL_ORDERS_PROOF: '',
            COL_ORDERS_STATUS: COL_ORDERS_STATUS_NORMAL
        }

        res = cli.insert_one_origin(DID_INFO_DB_NAME, COL_ORDERS, doc, create_on_absence=True)

        doc['_id'] = res['inserted_id']
        doc[COL_ORDERS_PROOF] = self.auth.create_order_proof(user_did, doc['_id'])
        cli.update_one_origin(DID_INFO_DB_NAME, COL_ORDERS, {'_id': ObjectId(doc['_id'])},
                              {'$set': {COL_ORDERS_PROOF: doc[COL_ORDERS_PROOF]}}, is_extra=True)

        return doc