def run(self): db = dbc.session() admin = db.query(User).filter_by( username=settings.ADMIN_USERNAME).first() if not admin: logging.error("can not find admin account (%s)", settings.ADMIN_USERNAME) return app_name = "adminapp" app_secret = randomstring(32) app = db.query(App).filter( and_(App.user_id == admin.id, App.name == app_name)).first() if app: app.set_secret(app_secret) else: app = App(user=admin, name=app_name, app_secret=app_secret) db.add(app) db.commit() print(f"Update admin app success:\n" f"username={admin.username}\n" f"user_id={admin.uuid}\n" f"app_id={app.app_id}\n" f"app_secret={app_secret}")
def insert_initial_users(*args, **kwargs): db = dbc.session() # !important! 用户是否有管理员权限,需要在 authz 服务中增加 admin 角色 db.add( User(username=settings.ADMIN_USERNAME, password=settings.ADMIN_PASSWORD)) db.commit()
def db(self): return dbc.session()
def insert_initial_roles(*args, **kwargs): db = dbc.session() db.add(Role(name=settings.ADMIN_ROLE_NAME)) db.add(Role(name='anonymous')) db.add(Role(name='authenticated')) db.commit()
def insert_initial_perms(*args, **kwargs): db = dbc.session() db.add(Permission(name="admin")) db.commit()