Change from manual URL construction to using a lib
Makes the code cleaner to read and more resilient to changes Fixes https://jira.coreos.com/browse/QUAY-940
This commit is contained in:
parent
e33760fcd2
commit
648590c356
13 changed files with 85 additions and 56 deletions
|
@ -25,14 +25,7 @@ class OAuthEndpoint(object):
|
|||
params_copy = copy.copy(self.params)
|
||||
params_copy.update(parameters)
|
||||
return OAuthEndpoint(self.base_url, params_copy)
|
||||
|
||||
def to_url_prefix(self):
|
||||
prefix = self.to_url()
|
||||
if self.params:
|
||||
return prefix + '&'
|
||||
else:
|
||||
return prefix + '?'
|
||||
|
||||
|
||||
def to_url(self):
|
||||
(scheme, netloc, path, _, fragment) = urlparse.urlsplit(self.base_url)
|
||||
updated_query = urllib.urlencode(self.params)
|
||||
|
|
|
@ -113,7 +113,7 @@ class GithubOAuthService(OAuthLoginService):
|
|||
def get_public_config(self):
|
||||
return {
|
||||
'CLIENT_ID': self.client_id(),
|
||||
'AUTHORIZE_ENDPOINT': self.authorize_endpoint().to_url_prefix(),
|
||||
'AUTHORIZE_ENDPOINT': self.authorize_endpoint().to_url(),
|
||||
'GITHUB_ENDPOINT': self._endpoint(),
|
||||
'ORG_RESTRICT': self.config.get('ORG_RESTRICT', False)
|
||||
}
|
||||
|
|
|
@ -55,6 +55,6 @@ class GitLabOAuthService(OAuthService):
|
|||
def get_public_config(self):
|
||||
return {
|
||||
'CLIENT_ID': self.client_id(),
|
||||
'AUTHORIZE_ENDPOINT': self.authorize_endpoint().to_url_prefix(),
|
||||
'AUTHORIZE_ENDPOINT': self.authorize_endpoint().to_url(),
|
||||
'GITLAB_ENDPOINT': self._endpoint(),
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ class GoogleOAuthService(OAuthLoginService):
|
|||
def get_public_config(self):
|
||||
return {
|
||||
'CLIENT_ID': self.client_id(),
|
||||
'AUTHORIZE_ENDPOINT': self.authorize_endpoint().to_url_prefix()
|
||||
'AUTHORIZE_ENDPOINT': self.authorize_endpoint().to_url()
|
||||
}
|
||||
|
||||
def get_login_service_id(self, user_info):
|
||||
|
|
|
@ -29,7 +29,6 @@ def test_basic_enterprise_config(trigger_config, domain, api_endpoint, is_enterp
|
|||
assert github_trigger.is_enterprise() == is_enterprise
|
||||
|
||||
assert github_trigger.authorize_endpoint().to_url() == '%s/login/oauth/authorize' % domain
|
||||
assert github_trigger.authorize_endpoint().to_url_prefix() == '%s/login/oauth/authorize?' % domain
|
||||
|
||||
assert github_trigger.token_endpoint().to_url() == '%s/login/oauth/access_token' % domain
|
||||
|
||||
|
|
Reference in a new issue