fixing commands we need

This commit is contained in:
Cayo Puigdefabregas 2021-01-30 14:17:18 +01:00
parent 78db4fb8d5
commit 8da89ae22a
2 changed files with 117 additions and 55 deletions

View File

@ -11,54 +11,117 @@ from orchestra.utils.sys import run, check_root, confirm
class Command(BaseCommand): class Command(BaseCommand):
help = 'Configures nginx + uwsgi to run with your Orchestra instance.'
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(Command, self).__init__(*args, **kwargs) super(Command, self).__init__(*args, **kwargs)
self.option_list = BaseCommand.option_list + (
make_option('--cert', dest='cert', default='', def add_arguments(self, parser):
help='Nginx SSL certificate, one will be created by default.'), parser.add_argument(
make_option('--cert-key', dest='cert_key', default='', '--cert',
help='Nginx SSL certificate key.'), dest='cert',
default='',
make_option('--cert-path', dest='cert_path', help='Nginx SSL certificate, one will be created by default.',
default=os.path.join(paths.get_site_dir(), 'ssl', 'orchestra.crt'), )
help='Nginx SSL certificate, one will be created by default.'), parser.add_argument(
make_option('--cert-key-path', dest='cert_key_path', '--cert-key',
default=os.path.join(paths.get_site_dir(), 'ssl', 'orchestra.key'), dest='cert_key',
help='Nginx SSL certificate key.'), default='',
# Cert options help='Nginx SSL certificate key.'
make_option('--cert-override', dest='cert_override', action='store_true', )
default=False, help='Force override cert and keys if exists.'), parser.add_argument(
make_option('--cert-country', dest='cert_country', default='ES', '--cert-path',
help='Certificate Distinguished Name Country.'), dest='cert_path',
make_option('--cert-state', dest='cert_state', default='Spain', default=os.path.join(paths.get_site_dir(), 'ssl', 'orchestra.crt'),
help='Certificate Distinguished Name STATE.'), help='Nginx SSL certificate, one will be created by default.'
make_option('--cert-locality', dest='cert_locality', default='Barcelona', )
help='Certificate Distinguished Name Country.'), parser.add_argument(
make_option('--cert-org_name', dest='cert_org_name', default='Orchestra', '--cert-key-path',
help='Certificate Distinguished Name Organization Name.'), dest='cert_key_path',
make_option('--cert-org_unit', dest='cert_org_unit', default='DevOps', default=os.path.join(paths.get_site_dir(), 'ssl', 'orchestra.key'),
help='Certificate Distinguished Name Organization Unity.'), help='Nginx SSL certificate key.'
make_option('--cert-email', dest='cert_email', default='orchestra@orchestra.lan', )
help='Certificate Distinguished Name Email Address.'), parser.add_argument(
make_option('--cert-common_name', dest='cert_common_name', default=None, '--cert-override',
help='Certificate Distinguished Name Common Name.'), dest='cert_override',
action='store_true',
make_option('--server-name', dest='server_name', default='', default=False, help='Force override cert and keys if exists.'
help='Nginx SSL certificate key.'), )
make_option('--user', dest='user', default='', parser.add_argument(
help='uWSGI daemon user.'), '--cert-country',
make_option('--group', dest='group', default='', dest='cert_country',
help='uWSGI daemon group.'), default='ES',
make_option('--processes', dest='processes', default=4, help='Certificate Distinguished Name Country.'
help='uWSGI number of processes.'), )
make_option('--noinput', action='store_false', dest='interactive', default=True, parser.add_argument(
help='Tells Django to NOT prompt the user for input of any kind. ' '--cert-state',
'You must use --username with --noinput, and must contain the ' dest='cert_state',
'cleeryd process owner, which is the user how will perform tincd updates'), default='Spain',
) help='Certificate Distinguished Name STATE.'
)
option_list = BaseCommand.option_list parser.add_argument(
help = 'Configures nginx + uwsgi to run with your Orchestra instance.' '--cert-locality',
dest='cert_locality',
default='Barcelona',
help='Certificate Distinguished Name Country.'
)
parser.add_argument(
'--cert-org_name',
dest='cert_org_name',
default='Orchestra',
help='Certificate Distinguished Name Organization Name.'
)
parser.add_argument(
'--cert-org_unit',
dest='cert_org_unit',
default='DevOps',
help='Certificate Distinguished Name Organization Unity.'
)
parser.add_argument(
'--cert-email',
dest='cert_email',
default='orchestra@orchestra.lan',
help='Certificate Distinguished Name Email Address.'
)
parser.add_argument(
'--cert-common_name',
dest='cert_common_name',
default=None,
help='Certificate Distinguished Name Common Name.'
)
parser.add_argument(
'--server-name',
dest='server_name',
default='',
help='Nginx SSL certificate key.'
)
parser.add_argument(
'--user',
dest='user',
default='',
help='uWSGI daemon user.'
)
parser.add_argument(
'--group',
dest='group',
default='',
help='uWSGI daemon group.'
)
parser.add_argument(
'--processes',
dest='processes',
default=4,
help='uWSGI number of processes.'
)
parser.add_argument(
'--noinput',
action='store_false',
dest='interactive',
default=True,
help='''Tells Django to NOT prompt the user for input of any kind.
You must use --username with --noinput, and must contain the
cleeryd process owner, which is the user how will perform tincd updates'''
)
def generate_certificate(self, **options): def generate_certificate(self, **options):
override = options.get('cert_override') override = options.get('cert_override')

View File

@ -49,7 +49,7 @@ class Command(BaseCommand):
parser.add_argument( parser.add_argument(
'--db_host', '--db_host',
dest='db_host', dest='db_host',
default=slef.defaults.get('HOST', 'localhost'), default=self.defaults.get('HOST', 'localhost'),
help='Specifies the database to create.', help='Specifies the database to create.',
type=str type=str
) )
@ -65,10 +65,9 @@ class Command(BaseCommand):
action='store_false', action='store_false',
dest='interactive', dest='interactive',
default=True, default=True,
help='Tells Django to NOT prompt the user for input of any kind. ' help='''Tells Django to NOT prompt the user for input of any kind.
'You must use --username with --noinput, and must contain the ' You must use --username with --noinput, and must contain the
'cleeryd process owner, which is the user how will perform tincd updates', cleeryd process owner, which is the user how will perform tincd updates'''
type=str
) )
def run_postgres(self, cmd, *args, **kwargs): def run_postgres(self, cmd, *args, **kwargs):
@ -79,11 +78,11 @@ class Command(BaseCommand):
interactive = options.get('interactive') interactive = options.get('interactive')
db_password = options.get('db_password') db_password = options.get('db_password')
context = { context = {
'db_name': options.get('db_name', 'orchestra'), 'db_name': options.get('db_name'),
'db_user': options.get('db_user', 'orchestra'), 'db_user': options.get('db_user'),
'db_password': db_password, 'db_password': db_password,
'db_host': options.get('db_host', '127.0.0.1'), 'db_host': options.get('db_host'),
'db_port': options.get('db_port', '5432'), 'db_port': options.get('db_port'),
'default_db_password': db_password or random_ascii(10), 'default_db_password': db_password or random_ascii(10),
} }