Example #1
0
    def backup_to_vault(self):
        did, content, err = did_post_json_param_pre_proc(self.response)
        if err:
            return self.response.response_err(
                UNAUTHORIZED, "Backup backup_to_vault auth failed")

        vault_service = get_vault_service(did)
        if not vault_service:
            return self.response.response_err(
                BAD_REQUEST, f"There is not vault service of {did} to active")

        backup_service = get_vault_backup_service(did)
        if not backup_service:
            return self.response.response_err(
                BAD_REQUEST, f"There is not vault backup service of {did}")

        freeze_vault(did)
        delete_user_vault(did)

        app_id_list = backup_service[VAULT_BACKUP_SERVICE_DATA]
        for app_id in app_id_list:
            import_files_from_backup(did, app_id)
            import_mongo_db_from_backup(did, app_id)
        unfreeze_vault(did)
        return self.response.response_ok()
Example #2
0
def create_vault_of_did(did):
    service = get_vault_service(did)
    if service:
        return

    free_info = PaymentConfig.get_free_vault_info()

    setup_vault_service(did, free_info["maxStorage"], free_info["serviceDays"])
def vault_order_success(info):
    service = get_vault_service(info[VAULT_ORDER_DID])
    if not service:
        setup_vault_service(info[VAULT_ORDER_DID],
                            info[VAULT_ORDER_PACKAGE_INFO]["maxStorage"],
                            info[VAULT_ORDER_PACKAGE_INFO]["serviceDays"],
                            info[VAULT_ORDER_PACKAGE_INFO]["name"])
    else:
        update_vault_service(info[VAULT_ORDER_DID],
                             info[VAULT_ORDER_PACKAGE_INFO]["maxStorage"],
                             info[VAULT_ORDER_PACKAGE_INFO]["serviceDays"],
                             info[VAULT_ORDER_PACKAGE_INFO]["name"])
    def create_free_vault(self):
        did, app_id, err = pre_proc(self.response)
        if err:
            return err

        service = get_vault_service(did)
        if service:
            return self.response.response_ok()

        free_info = PaymentConfig.get_free_vault_info()

        setup_vault_service(did, free_info["maxStorage"], free_info["serviceDays"])
        return self.response.response_ok()
    def get_vault_service_info(self):
        did, app_id, err = pre_proc(self.response)
        if err:
            return err
        info = get_vault_service(did)
        if not info:
            return self.response.response_err(NOT_FOUND, "vault service not found")
        else:
            del info["_id"]
            data = dict()
            info[VAULT_SERVICE_FILE_USE_STORAGE] = info[VAULT_SERVICE_FILE_USE_STORAGE] / (1024 * 1024)
            info[VAULT_SERVICE_DB_USE_STORAGE] = info[VAULT_SERVICE_DB_USE_STORAGE] / (1024 * 1024)
            data["vault_service_info"] = info

            return self.response.response_ok(data)
    def activate_to_vault(self):
        did, content, err = did_post_json_param_pre_proc(self.response)
        if err:
            return self.response.response_err(
                UNAUTHORIZED, "Backup backup_to_vault auth failed")

        vault_service = get_vault_service(did)
        if not vault_service:
            return self.response.response_err(
                BAD_REQUEST, f"There is not vault service of {did} to active")

        backup_service = get_vault_backup_service(did)
        if not backup_service:
            return self.response.response_err(
                BAD_REQUEST, f"There is not vault backup service of {did}")

        freeze_vault(did)
        delete_user_vault_data(did)
        copy_local_backup_to_vault(did)
        import_mongo_db(did)
        delete_mongo_db_export(did)
        unfreeze_vault(did)
        return self.response.response_ok()