gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.2KB

  1. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  2. import argparse
  3. import os
  4. import secrets
  5. import sys
  6. import textwrap
  7. from pathlib import Path
  8. from passlib.hash import pbkdf2_sha512
  9. from . import Command
  10. from odoo.tools import config
  11. class GenProxyToken(Command):
  12. """ Generate and (re)set proxy access token in config file """
  13. def generate_token(self, length=16):
  14. token = secrets.token_hex(int(length / 2))
  15. split_size = int(length / 4)
  16. return '-'.join(textwrap.wrap(token, split_size))
  17. def run(self, cmdargs):
  18. parser = argparse.ArgumentParser(
  19. prog=f'{Path(sys.argv[0]).name} {self.name}',
  20. description=self.__doc__.strip()
  21. )
  22. parser.add_argument('-c', '--config', type=str, help="Specify an alternate config file")
  23. parser.add_argument('--token-length', type=int, help="Token Length", default=16)
  24. args, _ = parser.parse_known_args()
  25. if args.config:
  26. config.rcfile = args.config
  27. token = self.generate_token(length=args.token_length)
  28. config['proxy_access_token'] = pbkdf2_sha512.hash(token)
  29. config.save()
  30. sys.stdout.write(f'{token}\n')
上海开阖软件有限公司 沪ICP备12045867号-1