From 07dddf8d459db1ac6abab59f8441337b7cff6cd7 Mon Sep 17 00:00:00 2001 From: shenshuo <191715030@qq.com> Date: Fri, 14 Jun 2024 16:25:12 +0800 Subject: [PATCH] =?UTF-8?q?2024=E5=B9=B46=E6=9C=8814=E6=97=A5=20=20feat(ma?= =?UTF-8?q?nage.py)=20=E5=88=9D=E5=A7=8B=E5=8C=96token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manage.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/manage.py b/manage.py index 501a0b9..85be514 100644 --- a/manage.py +++ b/manage.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + import sys import getpass from datetime import datetime @@ -7,8 +10,11 @@ from sqlalchemy import create_engine, text from websdk2.consts import const - +from websdk2.jwt_token import AuthToken from settings import settings as app_settings +from websdk2.configs import configs + +if configs.can_import: configs.import_dict(**app_settings) default_configs = app_settings[const.DB_CONFIG_ITEM][const.DEFAULT_DB_KEY] @@ -112,6 +118,24 @@ def handle(self): print(f"Create SuperUser Success: {username}") +class AuthKeyInit(BaseCommand): + """ + Token初始化 + """ + + def handle(self): + auth_token = AuthToken() + token = auth_token.encode_auth_token_v2( + exp_days=1825, # 五年 + user_id=99999, # You should replace this with the actual user_id + username="codo", + nickname="系统用户", + email="codo@opendevops.cn", + is_superuser=True + ) + print(token) + + def execute_from_command_line(argv): """解析命令行参数并执行相应的命令""" if len(argv) < 2: @@ -132,6 +156,10 @@ def execute_from_command_line(argv): goodbye_parser = subparsers.add_parser('db_init', help='used to db init.') goodbye_parser.set_defaults(func=DBInit.handle) + # 添加子命令 'token_init' + key_parser = subparsers.add_parser('token_init', help='used to auth key init.') + key_parser.set_defaults(func=AuthKeyInit.handle) + # 解析命令行参数 args = parser.parse_args() # 调用相应的子命令处理函数