From f552df336395bd3598d789446607eb227c339e26 Mon Sep 17 00:00:00 2001 From: Stephen Sanchez Date: Mon, 16 Mar 2015 20:21:12 +0000 Subject: [PATCH] Modify commerce view to work without ecommerce configuration. --- lms/djangoapps/commerce/views.py | 7 +++---- lms/envs/aws.py | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lms/djangoapps/commerce/views.py b/lms/djangoapps/commerce/views.py index e029998e9e..adde3d06c5 100644 --- a/lms/djangoapps/commerce/views.py +++ b/lms/djangoapps/commerce/views.py @@ -54,17 +54,16 @@ class OrdersView(APIView): return True, course_key, None - def _get_jwt(self, user): + def _get_jwt(self, user, ecommerce_api_signing_key): """ Returns a JWT object with the specified user's info. - Raises AttributeError if settings.ECOMMERCE_API_SIGNING_KEY is not set. """ data = { 'username': user.username, 'email': user.email } - return jwt.encode(data, getattr(settings, 'ECOMMERCE_API_SIGNING_KEY')) + return jwt.encode(data, ecommerce_api_signing_key) def _enroll(self, course_key, user): """ Enroll the user in the course. """ @@ -104,7 +103,7 @@ class OrdersView(APIView): # Contact external API headers = { 'Content-Type': 'application/json', - 'Authorization': 'JWT {}'.format(self._get_jwt(user)) + 'Authorization': 'JWT {}'.format(self._get_jwt(user, ecommerce_api_signing_key)) } url = '{}/orders/'.format(ecommerce_api_url.strip('/')) diff --git a/lms/envs/aws.py b/lms/envs/aws.py index 37741bd0c5..b0a2580ea0 100644 --- a/lms/envs/aws.py +++ b/lms/envs/aws.py @@ -560,6 +560,6 @@ PERFORMANCE_GRAPHITE_URL = ENV_TOKENS.get('PERFORMANCE_GRAPHITE_URL', PERFORMANC CDN_VIDEO_URLS = ENV_TOKENS.get('CDN_VIDEO_URLS', CDN_VIDEO_URLS) ##### ECOMMERCE API CONFIGURATION SETTINGS ##### -ECOMMERCE_API_URL = ENV_TOKENS.get('ECOMMERCE_API_URL') -ECOMMERCE_API_SIGNING_KEY = AUTH_TOKENS.get('ECOMMERCE_API_SIGNING_KEY') -ECOMMERCE_API_TIMEOUT = ENV_TOKENS.get('ECOMMERCE_API_TIMEOUT', 5) +ECOMMERCE_API_URL = ENV_TOKENS.get('ECOMMERCE_API_URL', ECOMMERCE_API_URL) +ECOMMERCE_API_SIGNING_KEY = AUTH_TOKENS.get('ECOMMERCE_API_SIGNING_KEY', ECOMMERCE_API_SIGNING_KEY) +ECOMMERCE_API_TIMEOUT = ENV_TOKENS.get('ECOMMERCE_API_TIMEOUT', ECOMMERCE_API_TIMEOUT)