Handle missing config in a nicer manner

This commit is contained in:
Joseph Schorr 2014-11-05 17:17:38 -05:00
parent 3e79379942
commit d7efb7cf7a

View file

@ -3,7 +3,7 @@ import urlparse
class OAuthConfig(object):
def __init__(self, app, key_name):
self.key_name = key_name
self.config = app.config.get(key_name, {})
self.config = app.config.get(key_name) or {}
def service_name(self):
raise NotImplementedError
@ -24,9 +24,6 @@ class OAuthConfig(object):
return self.config.get('CLIENT_SECRET')
def _get_url(self, endpoint, *args):
if not endpoint:
raise Exception('Missing endpoint configuration for OAuth config %s', self.key_name)
for arg in args:
endpoint = urlparse.urljoin(endpoint, arg)
@ -41,15 +38,15 @@ class GithubOAuthConfig(OAuthConfig):
return 'GitHub'
def authorize_endpoint(self):
endpoint = self.config.get('GITHUB_ENDPOINT')
endpoint = self.config.get('GITHUB_ENDPOINT', 'https://github.com')
return self._get_url(endpoint, '/login/oauth/authorize') + '?'
def token_endpoint(self):
endpoint = self.config.get('GITHUB_ENDPOINT')
endpoint = self.config.get('GITHUB_ENDPOINT', 'https://github.com')
return self._get_url(endpoint, '/login/oauth/access_token')
def _api_endpoint(self):
endpoint = self.config.get('GITHUB_ENDPOINT')
endpoint = self.config.get('GITHUB_ENDPOINT', 'https://github.com')
return self.config.get('API_ENDPOINT', self._get_url(endpoint, '/api/v3/'))
def user_endpoint(self):