mirror of
https://github.com/ansible/awx.git
synced 2026-03-07 19:51:08 -03:30
Consoldating similar methods
This commit is contained in:
committed by
Hao Liu
parent
51e19d9d0b
commit
e60869e653
@@ -131,25 +131,11 @@ class AnalyticsGenericView(APIView):
|
|||||||
return analytics_url
|
return analytics_url
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _check_upload_enabled():
|
def _get_setting(setting_name, default, error_message):
|
||||||
state = getattr(settings, 'INSIGHTS_TRACKING_STATE', False)
|
setting = getattr(settings, setting_name, default)
|
||||||
if not state:
|
if not setting:
|
||||||
raise MissingSettings(ERROR_UPLOAD_NOT_ENABLED)
|
raise MissingSettings(error_message)
|
||||||
return True
|
return setting
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _get_rh_user():
|
|
||||||
user = getattr(settings, 'REDHAT_USERNAME', None)
|
|
||||||
if not user:
|
|
||||||
raise MissingSettings(ERROR_MISSING_USER)
|
|
||||||
return user
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _get_rh_password():
|
|
||||||
password = getattr(settings, 'REDHAT_PASSWORD', None)
|
|
||||||
if not password:
|
|
||||||
raise MissingSettings(ERROR_MISSING_PASSWORD)
|
|
||||||
return password
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _error_response(keyword, message=None, remote=True, remote_status_code=None, status_code=status.HTTP_403_FORBIDDEN):
|
def _error_response(keyword, message=None, remote=True, remote_status_code=None, status_code=status.HTTP_403_FORBIDDEN):
|
||||||
@@ -200,10 +186,10 @@ class AnalyticsGenericView(APIView):
|
|||||||
try:
|
try:
|
||||||
headers = self._request_headers(request)
|
headers = self._request_headers(request)
|
||||||
|
|
||||||
self._check_upload_enabled()
|
self._get_setting('INSIGHTS_TRACKING_STATE', False, ERROR_UPLOAD_NOT_ENABLED)
|
||||||
url = self._get_analytics_url(request.path)
|
url = self._get_analytics_url(request.path)
|
||||||
rh_user = self._get_rh_user()
|
rh_user = self._get_setting('REDHAT_USERNAME', None, ERROR_MISSING_USER)
|
||||||
rh_password = self._get_rh_password()
|
rh_password = self._get_setting('REDHAT_PASSWORD', None, ERROR_MISSING_PASSWORD)
|
||||||
|
|
||||||
if method not in ["GET", "POST", "OPTIONS"]:
|
if method not in ["GET", "POST", "OPTIONS"]:
|
||||||
return self._error_response(ERROR_UNSUPPORTED_METHOD, method, remote=False, status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
return self._error_response(ERROR_UNSUPPORTED_METHOD, method, remote=False, status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||||
|
|||||||
Reference in New Issue
Block a user