from depc.extensions.encrypted_dict import FlaskEncryptedDict class ChangeKey(Command): option_list = ( Option("--new-key", type=str, default=None), Option("--old-key", type=str, default=None), ) def run(self, new_key, old_key): if not old_key: old_key = app.config.get("DB_ENCRYPTION_KEY", None) FlaskEncryptedDict.change_key(old_key, new_key) print("Database key has been changed") print("Add this key to depc.{env}.yml as DB_ENCRYPTION_KEY") print(new_key) class GenerateKey(Command): """Generate a 256 bits hex key to encrypt database""" def run(self): print(FlaskEncryptedDict.generate_key()) key_manager = Manager(app) key_manager.__doc__ = "Manager database key" key_manager.add_command("change-key", ChangeKey) key_manager.add_command("generate-key", GenerateKey)
import os import sys import json from flask_script import Manager from yxlib.response import RemoteError from core.models.user.account import Account from core.models.hoard import YixinService, YixinAccount, HoardProfile, HoardOrder from core.models.hoard.profile import ORDER_STATUS_MAP from libs.utils.log import bcolors from jupiter.ext import yixin manager = Manager() manager.__doc__ = 'The commands for yixin services.' @manager.command def init(): """Downloads the product data of Yixin.""" try: response = yixin.query.p2p_service_list() except RemoteError as e: bcolors.fail('%s : %s : %s' % e.args) else: for service_info in response.data: service = YixinService.add(service_info) bcolors.success('YixinService: %s' % service.p2pservice_name) @manager.command
# coding: utf-8 from flask_script import Manager from zslib.errors import BusinessError from jupiter.ext import zslib from libs.utils.log import bcolors from core.models.utils import round_half_up from core.models.wallet.providers import zhongshan from core.models.wallet.annual_rate import WalletAnnualRate manager = Manager() manager.__doc__ = 'The commands for wallet product.' provider = zhongshan @manager.command def init(): """Synchronize the annual rates.""" try: rates = WalletAnnualRate.synchronize(zslib.client, provider.fund_code) except BusinessError as e: bcolors.fail('%s : %s : %s' % e.args) return for rate in rates: bcolors.success('{0}\t{1}\t{2}\t¥{3}'.format( rate.date, rate.fund_code, round_half_up(rate.annual_rate, 2),
# coding: utf-8 from flask_script import Manager from crons.hoarder.cron_updating_sxb_products import fillup_local from libs.utils.log import bcolors from jupiter.ext import sxb from sxblib.consts import ProductType from sxblib.errors import ClientError manager = Manager() manager.__doc__ = 'The commands for sxb services.' @manager.command def init(): """Downloads the product data of sxb.""" try: rs = sxb.query_products(ProductType.ririying) except ClientError as e: bcolors.fail('Fetching Sxb Product Failed:%s' % e) else: for product_info in rs: product = fillup_local(product_info) product = fillup_local(product_info, is_child_product=True) bcolors.success('SxbProduct: %s' % product.name)
# coding: utf-8 from flask_script import Manager from jupiter.ext import zhiwang from zwlib.client import RemoteError from libs.utils.log import bcolors from core.models.hoard.zhiwang import ZhiwangProduct, ZhiwangWrappedProduct manager = Manager() manager.__doc__ = 'The commands for zhiwang services.' @manager.command def init(): """Downloads the product data of Zhiwang.""" try: response = zhiwang.product_list() except RemoteError as e: bcolors.fail('Fetching Zhiwang Product Failed:%s' % e) else: all_products = [] for product_info in response.products: base_product = ZhiwangProduct.add(product_info) bcolors.success('ZhiwangProduct: %s' % base_product.name) wrapped_products = ZhiwangWrappedProduct.get_multi_by_raw(base_product.product_id) for wp in wrapped_products: bcolors.success('ZhiwangWrappedProduct: %s' % wp.name)
# coding: utf-8 from datetime import timedelta from flask_script import Manager from libs.utils.log import bcolors from core.models.oauth import OAuthToken manager = Manager() manager.__doc__ = 'The commands for OAuth 2.0 management.' @manager.command def vacuum_tokens(token_ids='', grace_days=0): """Clean up expired tokens from database.""" grace_time = timedelta(days=int(grace_days)) ids = [id_.strip() for id_ in token_ids.split(',') if id_.strip()] if ids: if all(id_.isdigit() for id_ in ids): OAuthToken.vacuum(ids, grace_time=grace_time) else: bcolors.fail( '"-t" should be comma-splited digits (e.g. "10001,10002")') return else: OAuthToken.vacuum(grace_time=grace_time) # vacuum all tokens