Пример #1
0
def save_info():
    data = request.get_json(silent=True)
    name = data.get('name')
    roles = data.get('roles')
    password = data.get('password')
    with db.auto_commit():
        User.save(name=name, roles=Role.list_items_by_uids(roles), password=password)
    return Success()
Пример #2
0
 def get(self, **kwargs):
     parser = reqparse.RequestParser()
     parser.add_argument('username', required=True)
     parser.add_argument('password', required=True)
     args = parser.parse_args()
     args = hash_pass(args)
     user = User.from_sql('select * from User where username=?',
                          (args['username'], ))
     if len(user) != 0:
         return Response('Username already exist.', status=400)
     user = User(**args)
     user.save()
     return {'status': 'OK'}
Пример #3
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)