mirror of
https://github.com/ansible/awx.git
synced 2026-03-02 01:08:48 -03:30
Better detection of permission denied when reading /etc/awx/settings.py to display appropriate error message.
This commit is contained in:
@@ -80,12 +80,12 @@ def manage():
|
|||||||
sys.stdout.write('%s\n' % __version__)
|
sys.stdout.write('%s\n' % __version__)
|
||||||
# If running as a user without permission to read settings, display an
|
# If running as a user without permission to read settings, display an
|
||||||
# error message. Allow --help to still work.
|
# error message. Allow --help to still work.
|
||||||
elif getattr(settings, 'MUST_BE_ROOT_OR_AWX', False):
|
elif settings.SECRET_KEY == 'permission-denied':
|
||||||
if len(sys.argv) == 1 or len(sys.argv) >= 2 and sys.argv[1] in ('-h', '--help'):
|
if len(sys.argv) == 1 or len(sys.argv) >= 2 and sys.argv[1] in ('-h', '--help', 'help'):
|
||||||
execute_from_command_line(sys.argv)
|
execute_from_command_line(sys.argv)
|
||||||
sys.stdout.write('\n')
|
sys.stdout.write('\n')
|
||||||
prog = os.path.basename(sys.argv[0])
|
prog = os.path.basename(sys.argv[0])
|
||||||
sys.stdout.write('%s must be run as root or awx.\n' % prog)
|
sys.stdout.write('Permission denied: %s must be run as root or awx.\n' % prog)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
execute_from_command_line(sys.argv)
|
execute_from_command_line(sys.argv)
|
||||||
|
|||||||
@@ -75,18 +75,24 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except IOError, e:
|
except IOError:
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
included_file = locals().get('__included_file__', '')
|
included_file = locals().get('__included_file__', '')
|
||||||
if (not included_file or included_file == settings_file) and not os.path.exists(settings_file):
|
if (not included_file or included_file == settings_file):
|
||||||
if e.errno == errno.EACCES:
|
# The import doesn't always give permission denied, so try to open the
|
||||||
MUST_BE_ROOT_OR_AWX = True
|
# settings file directly.
|
||||||
elif 'AWX_SETTINGS_FILE' not in os.environ:
|
try:
|
||||||
|
e = None
|
||||||
|
open(settings_file)
|
||||||
|
except IOError, e:
|
||||||
|
pass
|
||||||
|
if e and e.errno == errno.EACCES:
|
||||||
|
SECRET_KEY = 'permission-denied'
|
||||||
|
LOGGING = {}
|
||||||
|
else:
|
||||||
msg = 'No AWX configuration found at %s.' % settings_file
|
msg = 'No AWX configuration found at %s.' % settings_file
|
||||||
msg += '\nDefine the AWX_SETTINGS_FILE environment variable to '
|
msg += '\nDefine the AWX_SETTINGS_FILE environment variable to '
|
||||||
msg += 'specify an alternate path.'
|
msg += 'specify an alternate path.'
|
||||||
raise ImproperlyConfigured(msg)
|
raise ImproperlyConfigured(msg)
|
||||||
else:
|
|
||||||
raise
|
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|||||||
Reference in New Issue
Block a user