# HG changeset patch # User Marcin Kuzminski # Date 2018-02-15 19:21:24 # Node ID 39fd91d9401be1ca20b060f2b8eb1ab0363ce79a # Parent ccf582796b72e977106b7715029c71cdef3790c7 integrations: extract get_auth to common shared code. diff --git a/rhodecode/integrations/types/base.py b/rhodecode/integrations/types/base.py --- a/rhodecode/integrations/types/base.py +++ b/rhodecode/integrations/types/base.py @@ -111,3 +111,15 @@ class EEIntegration(IntegrationTypeBase) def __init__(self, name, key, settings=None): self.display_name = name self.key = key + super(EEIntegration, self).__init__(settings) + + +# Helpers + +def get_auth(settings): + from requests.auth import HTTPBasicAuth + username = settings.get('username') + password = settings.get('password') + if username and password: + return HTTPBasicAuth(username, password) + return None diff --git a/rhodecode/integrations/types/webhook.py b/rhodecode/integrations/types/webhook.py --- a/rhodecode/integrations/types/webhook.py +++ b/rhodecode/integrations/types/webhook.py @@ -33,7 +33,7 @@ from requests.packages.urllib3.util.retr import rhodecode from rhodecode import events from rhodecode.translation import _ -from rhodecode.integrations.types.base import IntegrationTypeBase +from rhodecode.integrations.types.base import IntegrationTypeBase, get_auth from rhodecode.lib.celerylib import run_task, async_task, RequestContextTask log = logging.getLogger(__name__) @@ -64,15 +64,6 @@ WEBHOOK_URL_VARS = [ URL_VARS = ', '.join('${' + x + '}' for x in WEBHOOK_URL_VARS) -def get_auth(settings): - from requests.auth import HTTPBasicAuth - username = settings.get('username') - password = settings.get('password') - if username and password: - return HTTPBasicAuth(username, password) - return None - - class WebhookHandler(object): def __init__(self, template_url, secret_token, headers): self.template_url = template_url