mirror of
https://github.com/ansible/awx.git
synced 2026-02-21 13:10:11 -03:30
fixed error in help dialog
This commit is contained in:
@@ -1,35 +0,0 @@
|
|||||||
# Copyright (c) 2015 Ansible, Inc.
|
|
||||||
# All Rights Reserved
|
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
|
||||||
from django.conf import settings
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
|
||||||
"""enable or disable authentication system"""
|
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
|
||||||
"""
|
|
||||||
This adds the --enable functionality to the command using argparse to allow either enable or no-enable
|
|
||||||
"""
|
|
||||||
parser.add_argument('--enable', action=argparse.BooleanOptionalAction, help='to disable local auth --no-enable to enable --enable')
|
|
||||||
|
|
||||||
def _enable_disable_auth(self, enable):
|
|
||||||
"""
|
|
||||||
this method allows the disabling or enabling of local authenication based on the argument passed into the parser
|
|
||||||
if no arguments throw a command error, if --enable set the DISABLE_LOCAL_AUTH to False
|
|
||||||
if --no-enable set to True. Realizing that the flag is counterintuitive to what is expected.
|
|
||||||
"""
|
|
||||||
if enable == None:
|
|
||||||
raise CommandError('Please --enable to allow local auth or --no-enable to disable local auth')
|
|
||||||
if enable:
|
|
||||||
settings.DISABLE_LOCAL_AUTH = False
|
|
||||||
print("Setting has changed to {} allowing local authentication".format(settings.DISABLE_LOCAL_AUTH))
|
|
||||||
return
|
|
||||||
|
|
||||||
settings.DISABLE_LOCAL_AUTH = True
|
|
||||||
print("Setting has changed to {} disallowing local authentication".format(settings.DISABLE_LOCAL_AUTH))
|
|
||||||
|
|
||||||
def handle(self, **options):
|
|
||||||
self._enable_disable_auth(options.get('enable'))
|
|
||||||
35
awx/main/management/commands/enable_local_authentication.py
Normal file
35
awx/main/management/commands/enable_local_authentication.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
"""enable or disable authentication system"""
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
"""
|
||||||
|
This adds the --enable --disable functionalities to the command using mutally_exclusive to avoid situations in which users pass both flags
|
||||||
|
"""
|
||||||
|
group = parser.add_mutually_exclusive_group()
|
||||||
|
group.add_argument('--enable', dest='enable', action='store_true', help='Pass --enable to enable local authentication')
|
||||||
|
group.add_argument('--disable', dest='disable', action='store_true', help='Pass --disable to disable local authentication')
|
||||||
|
|
||||||
|
def _enable_disable_auth(self, enable, disable):
|
||||||
|
"""
|
||||||
|
this method allows the disabling or enabling of local authenication based on the argument passed into the parser
|
||||||
|
if no arguments throw a command error, if --enable set the DISABLE_LOCAL_AUTH to False
|
||||||
|
if --disable it's set to True. Realizing that the flag is counterintuitive to what is expected.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if enable:
|
||||||
|
settings.DISABLE_LOCAL_AUTH = False
|
||||||
|
print("Setting has changed to {} allowing local authentication".format(settings.DISABLE_LOCAL_AUTH))
|
||||||
|
|
||||||
|
elif disable:
|
||||||
|
settings.DISABLE_LOCAL_AUTH = True
|
||||||
|
print("Setting has changed to {} disallowing local authentication".format(settings.DISABLE_LOCAL_AUTH))
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise CommandError('Please pass --enable flag to allow local auth or --disable flag to disable local auth')
|
||||||
|
|
||||||
|
def handle(self, **options):
|
||||||
|
self._enable_disable_auth(options.get('enable'), options.get('disable'))
|
||||||
Reference in New Issue
Block a user