Exemplo n.º 1
0
def get_token():
    data = request.get_json(silent=True)
    username = data.get('username')
    password = data.get('password')
    user = User.get_item_by_name(name=username)
    if not user or not user.verify_password(password):
        return AuthFailedException(msg='user or secret error')
    return Success(msg={
        'token': user.generate_api_auth_token(current_app.config['TOKEN_EXPIRATION'])
    })
Exemplo n.º 2
0
def deploy():
    db.drop_all()
    db.create_all()
    users = [
        {
            'name': '*****@*****.**',
            'password': '******'
        },
    ]
    roles = [
        {
            'name': 'admin'
        },
    ]
    with db.auto_commit():
        for user in users:
            User.save(**user)
        for role in roles:
            Role.save(**role)
        for item in app.url_map.iter_rules():
            if item.endpoint != 'static':
                Permission.save(endpoint=item.endpoint)
    with db.auto_commit():
        admin_user = User.get_item_by_name(name='*****@*****.**')
        admin_role = Role.get_item_by_name(name='admin')
        admin_role.update(
            permissions=[permission for permission in Permission.list_items()])
        admin_user.update(roles=[admin_role])
    with db.auto_commit():
        # Zone.save(name='test')
        zone = Zone.save(name='公网')
        Zone.save(name='私有云', parent_uid=zone.uid)
        Zone.save(name='公有云', parent_uid=zone.uid)
        Zone.save(name='内网')
    zone = Zone.query.filter(Zone.name == '公有云').first()
    import json
    with open('domain.txt') as f:
        domain_list = json.loads(f.read())
    with db.auto_commit():
        for domain in domain_list:
            Domain.save(zone_uid=zone.uid, **domain)
    with open('host.txt') as f:
        host_list = json.loads(f.read())
    with db.auto_commit():
        for host in host_list:
            Host.save(zone_uid=zone.uid, **host)
    with open('service.txt') as f:
        service_list = json.loads(f.read())
    with db.auto_commit():
        for service in service_list:
            Service.save(zone_uid=zone.uid, **service)