mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 08:21:15 +03:00
Display error message if awx-manage/tower-manage are run as a user other than root or awx.
This commit is contained in:
parent
bb404c24e0
commit
3408ac8f88
@ -74,8 +74,18 @@ def manage():
|
||||
# Prepare the AWX environment.
|
||||
prepare_env()
|
||||
# Now run the command (or display the version).
|
||||
from django.conf import settings
|
||||
from django.core.management import execute_from_command_line
|
||||
if len(sys.argv) >= 2 and sys.argv[1] in ('version', '--version'): # pragma: no cover
|
||||
sys.stdout.write('%s\n' % __version__)
|
||||
# If running as a user without permission to read settings, display an
|
||||
# error message. Allow --help to still work.
|
||||
elif getattr(settings, 'MUST_BE_ROOT_OR_AWX', False):
|
||||
if len(sys.argv) == 1 or len(sys.argv) >= 2 and sys.argv[1] in ('-h', '--help'):
|
||||
execute_from_command_line(sys.argv)
|
||||
sys.stdout.write('\n')
|
||||
prog = os.path.basename(sys.argv[0])
|
||||
sys.stdout.write('%s must be run as root or awx.\n' % prog)
|
||||
sys.exit(1)
|
||||
else:
|
||||
execute_from_command_line(sys.argv)
|
||||
|
@ -4,6 +4,7 @@
|
||||
# Production settings for AWX project.
|
||||
|
||||
# Python
|
||||
import errno
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
@ -74,13 +75,18 @@ try:
|
||||
except ImportError:
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
except IOError:
|
||||
except IOError, e:
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
included_file = locals().get('__included_file__', '')
|
||||
if (not included_file or included_file == settings_file) and not os.path.exists(settings_file):
|
||||
if 'AWX_SETTINGS_FILE' not in os.environ:
|
||||
if e.errno == errno.EACCES:
|
||||
MUST_BE_ROOT_OR_AWX = True
|
||||
elif 'AWX_SETTINGS_FILE' not in os.environ:
|
||||
msg = 'No AWX configuration found at %s.' % settings_file
|
||||
msg += '\nDefine the AWX_SETTINGS_FILE environment variable to '
|
||||
msg += 'specify an alternate path.'
|
||||
raise ImproperlyConfigured(msg)
|
||||
raise
|
||||
else:
|
||||
raise
|
||||
else:
|
||||
raise
|
||||
|
Loading…
Reference in New Issue
Block a user