Run `odoo-bin help`, you'll notice that some descriptions are missing, this commit fixes that. Run `odoo-bin shell --help`, you'll notice that the `usage:` line says `odoo-bin [options]` instead of `odoo-bin shell [options]`. Other commands that depend on the server cli are broken too. Fix those too. closes odoo/odoo#121085 X-original-commit: 9c6bac741ff437564e7dbe4d0aa8dbd307b71f8d Signed-off-by: Vincent Schippefilt (vsc) <vsc@odoo.com> Signed-off-by: Julien Castiaux (juc) <juc@odoo.com>
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
import argparse
|
|
import os
|
|
import secrets
|
|
import sys
|
|
import textwrap
|
|
from pathlib import Path
|
|
|
|
from passlib.hash import pbkdf2_sha512
|
|
|
|
from . import Command
|
|
from odoo.tools import config
|
|
|
|
|
|
class GenProxyToken(Command):
|
|
""" Generate and (re)set proxy access token in config file """
|
|
|
|
def generate_token(self, length=16):
|
|
token = secrets.token_hex(int(length / 2))
|
|
split_size = int(length / 4)
|
|
return '-'.join(textwrap.wrap(token, split_size))
|
|
|
|
def run(self, cmdargs):
|
|
parser = argparse.ArgumentParser(
|
|
prog=f'{Path(sys.argv[0]).name} {self.name}',
|
|
description=self.__doc__.strip()
|
|
)
|
|
parser.add_argument('-c', '--config', type=str, help="Specify an alternate config file")
|
|
parser.add_argument('--token-length', type=int, help="Token Length", default=16)
|
|
args, _ = parser.parse_known_args()
|
|
if args.config:
|
|
config.rcfile = args.config
|
|
token = self.generate_token(length=args.token_length)
|
|
config['proxy_access_token'] = pbkdf2_sha512.hash(token)
|
|
config.save()
|
|
sys.stdout.write(f'{token}\n')
|