def __init__(self, config_dir, repopath, username=None, password=None): super(Client, self).__init__(config_dir, repopath, username, password) self.repopath = B(self.repopath) self.config_dir = B(config_dir) self._ssl_trust_prompt_cb = None auth_providers = [ ra.get_simple_provider(), ra.get_username_provider(), ] if repopath.startswith('https:'): auth_providers += [ ra.get_ssl_client_cert_file_provider(), ra.get_ssl_client_cert_pw_file_provider(), ra.get_ssl_server_trust_file_provider(), ra.get_ssl_server_trust_prompt_provider(self.ssl_trust_prompt), ] self.auth = ra.Auth(auth_providers) if username: self.auth.set_parameter(B('svn:auth:username'), B(username)) if password: self.auth.set_parameter(B('svn:auth:password'), B(password)) cfg = get_config(self.config_dir) self.client = SVNClient(cfg, auth=self.auth)
def __init__(self, config_dir, repopath, username=None, password=None): super(Client, self).__init__(config_dir, repopath, username, password) self.repopath = B(self.repopath) self.config_dir = B(config_dir) self._ssl_trust_prompt_cb = None auth_providers = [ ra.get_simple_provider(), ra.get_username_provider(), ] if repopath.startswith('https:'): auth_providers += [ ra.get_ssl_client_cert_file_provider(), ra.get_ssl_client_cert_pw_file_provider(), ra.get_ssl_server_trust_file_provider(), ra.get_ssl_server_trust_prompt_provider(self.ssl_trust_prompt), ] self.auth = ra.Auth(auth_providers) if username: self.auth.set_parameter(B('svn:auth:username'), B(username)) if password: self.auth.set_parameter(B('svn:auth:password'), B(password)) cfg = get_config(self.config_dir) self.client = SVNClient(cfg, auth=self.auth)
def accept_ssl_certificate(self, path, on_failure=None): """If the repository uses SSL, this method is used to determine whether the SSL certificate can be automatically accepted. If the cert cannot be accepted, the ``on_failure`` callback is executed. ``on_failure`` signature:: void on_failure(e:Exception, path:str, cert:dict) """ self._accept_cert = {} self._accept_on_failure = on_failure auth = ra.Auth([ ra.get_simple_provider(), ra.get_username_provider(), ra.get_ssl_server_trust_prompt_provider(self._accept_trust_prompt), ]) cfg = get_config(self.config_dir) client = SVNClient(cfg, auth) try: info = client.info(path) logging.debug('SVN: Got repository information for %s: %s' % (path, info)) except SubversionException as e: if on_failure: on_failure(e, path, self._accept_cert)
def accept_ssl_certificate(self, path, on_failure=None): """If the repository uses SSL, this method is used to determine whether the SSL certificate can be automatically accepted. If the cert cannot be accepted, the ``on_failure`` callback is executed. ``on_failure`` signature:: void on_failure(e:Exception, path:str, cert:dict) """ self._accept_cert = {} self._accept_on_failure = on_failure auth = ra.Auth([ ra.get_simple_provider(), ra.get_username_provider(), ra.get_ssl_server_trust_prompt_provider(self._accept_trust_prompt), ]) cfg = get_config(self.config_dir) client = SVNClient(cfg, auth) try: info = client.info(path) logging.debug('SVN: Got repository information for %s: %s' % (path, info)) except SubversionException as e: if on_failure: on_failure(e, path, self._accept_cert)
def test_server_trust(self): auth = ra.Auth([ra.get_ssl_server_trust_prompt_provider( lambda realm, failures, certinfo, may_save: (42, False))]) auth.set_parameter("svn:auth:ssl:failures", 23) creds = auth.credentials("svn.ssl.server", "MyRealm") self.assertEqual((42, 0), next(creds)) self.assertRaises(StopIteration, next, creds)
def test_server_untrust(self): auth = ra.Auth([ ra.get_ssl_server_trust_prompt_provider( lambda realm, failures, certinfo, may_save: None) ]) auth.set_parameter("svn:auth:ssl:failures", 23) creds = auth.credentials("svn.ssl.server", "MyRealm") self.assertRaises(StopIteration, next, creds)
def accept_ssl_certificate(self, path, on_failure=None): """If the repository uses SSL, this method is used to determine whether the SSL certificate can be automatically accepted. If the cert cannot be accepted, the ``on_failure`` callback is executed. ``on_failure`` signature:: void on_failure(e:Exception, path:str, cert:dict) """ cert = {} def _accept_trust_prompt(realm, failures, certinfo, may_save): cert.update({ 'realm': realm, 'failures': failures, 'hostname': certinfo[0], 'finger_print': certinfo[1], 'valid_from': certinfo[2], 'valid_until': certinfo[3], 'issuer_dname': certinfo[4], }) if on_failure: return 0, False else: del cert['failures'] return failures, True auth = ra.Auth([ ra.get_simple_provider(), ra.get_username_provider(), ra.get_ssl_client_cert_file_provider(), ra.get_ssl_client_cert_pw_file_provider(), ra.get_ssl_server_trust_file_provider(), ra.get_ssl_server_trust_prompt_provider(_accept_trust_prompt), ]) if self.username: auth.set_parameter(AUTH_PARAM_DEFAULT_USERNAME, self.username) if self.password: auth.set_parameter(AUTH_PARAM_DEFAULT_PASSWORD, self.password) cfg = get_config(self.config_dir) client = SVNClient(cfg, auth) try: info = client.info(path) logging.debug('SVN: Got repository information for %s: %s' % (path, info)) except SubversionException as e: if on_failure: on_failure(e, path, cert) return cert
def accept_ssl_certificate(self, path, on_failure=None): """If the repository uses SSL, this method is used to determine whether the SSL certificate can be automatically accepted. If the cert cannot be accepted, the ``on_failure`` callback is executed. ``on_failure`` signature:: void on_failure(e:Exception, path:str, cert:dict) """ cert = {} def _accept_trust_prompt(realm, failures, certinfo, may_save): cert.update({ 'realm': realm, 'failures': failures, 'hostname': certinfo[0], 'finger_print': certinfo[1], 'valid_from': certinfo[2], 'valid_until': certinfo[3], 'issuer_dname': certinfo[4], }) if on_failure: return 0, False else: del cert['failures'] return failures, True auth = ra.Auth([ ra.get_simple_provider(), ra.get_username_provider(), ra.get_ssl_client_cert_file_provider(), ra.get_ssl_client_cert_pw_file_provider(), ra.get_ssl_server_trust_file_provider(), ra.get_ssl_server_trust_prompt_provider(_accept_trust_prompt), ]) if self.username: auth.set_parameter(AUTH_PARAM_DEFAULT_USERNAME, B(self.username)) if self.password: auth.set_parameter(AUTH_PARAM_DEFAULT_PASSWORD, B(self.password)) cfg = get_config(self.config_dir) client = SVNClient(cfg, auth) try: info = client.info(path) logging.debug('SVN: Got repository information for %s: %s' % (path, info)) except SubversionException as e: if on_failure: on_failure(e, path, cert) return cert
def accept_ssl_certificate(self, path, on_failure=None): """If the repository uses SSL, this method is used to determine whether the SSL certificate can be automatically accepted. If the cert cannot be accepted, the ``on_failure`` callback is executed. ``on_failure`` signature:: void on_failure(e:Exception, path:str, cert:dict) """ cert = {} def _accept_trust_prompt(realm, failures, certinfo, may_save): cert.update( { "realm": realm, "failures": failures, "hostname": certinfo[0], "finger_print": certinfo[1], "valid_from": certinfo[2], "valid_until": certinfo[3], "issuer_dname": certinfo[4], } ) if on_failure: return 0, False else: del cert["failures"] return failures, True auth = ra.Auth( [ ra.get_simple_provider(), ra.get_username_provider(), ra.get_ssl_client_cert_file_provider(), ra.get_ssl_client_cert_pw_file_provider(), ra.get_ssl_server_trust_file_provider(), ra.get_ssl_server_trust_prompt_provider(_accept_trust_prompt), ] ) cfg = get_config(self.config_dir) client = SVNClient(cfg, auth) try: info = client.info(path) logging.debug("SVN: Got repository information for %s: %s" % (path, info)) except SubversionException as e: if on_failure: on_failure(e, path, cert) return cert
def __init__(self, config_dir, repopath, username=None, password=None): """Initialize the client. Args: config_dir (unicode): The Subversion configuration directory. repopath (unicode): The path to the Subversion repository. username (unicode, optional): The username used to authenticate with the repository. password (unicode, optional): The password used to authenticate with the repository. """ super(Client, self).__init__(config_dir, repopath, username, password) self.repopath = self.repopath self.config_dir = config_dir self._ssl_trust_prompt_cb = None auth_providers = [ ra.get_simple_provider(), ra.get_username_provider(), ] if repopath.startswith('https:'): auth_providers += [ ra.get_ssl_client_cert_file_provider(), ra.get_ssl_client_cert_pw_file_provider(), ra.get_ssl_server_trust_file_provider(), ra.get_ssl_server_trust_prompt_provider(self.ssl_trust_prompt), ] self.auth = ra.Auth(auth_providers) self.username = None self.password = None if username: self.username = username self.auth.set_parameter(AUTH_PARAM_DEFAULT_USERNAME, self.username) if password: self.password = password self.auth.set_parameter(AUTH_PARAM_DEFAULT_PASSWORD, self.password) cfg = get_config(self.config_dir) self.client = SVNClient(cfg, auth=self.auth)
def __init__(self, config_dir, repopath, username=None, password=None): super(Client, self).__init__(config_dir, repopath, username, password) self.repopath = B(self.repopath) self.config_dir = B(config_dir) auth_providers = [ra.get_simple_provider(), ra.get_username_provider()] if repopath.startswith("https:"): auth_providers.append(ra.get_ssl_server_trust_prompt_provider(self.ssl_trust_prompt)) self.auth = ra.Auth(auth_providers) if username: self.auth.set_parameter(B("svn:auth:username"), B(username)) if password: self.auth.set_parameter(B("svn:auth:password"), B(password)) cfg = get_config(self.config_dir) self.client = SVNClient(cfg, auth=self.auth)
def __init__(self, config_dir, repopath, username=None, password=None): super(Client, self).__init__(config_dir, repopath, username, password) self.repopath = B(self.repopath) self.config_dir = B(config_dir) self._ssl_trust_prompt_cb = None auth_providers = [ ra.get_simple_provider(), ra.get_username_provider(), ] if repopath.startswith('https:'): auth_providers += [ ra.get_ssl_client_cert_file_provider(), ra.get_ssl_client_cert_pw_file_provider(), ra.get_ssl_server_trust_file_provider(), ra.get_ssl_server_trust_prompt_provider(self.ssl_trust_prompt), ] self.auth = ra.Auth(auth_providers) self.username = None self.password = None if username: self.username = username self.auth.set_parameter(AUTH_PARAM_DEFAULT_USERNAME, B(self.username)) if password: self.password = password self.auth.set_parameter(AUTH_PARAM_DEFAULT_PASSWORD, B(self.password)) cfg = get_config(self.config_dir) self.client = SVNClient(cfg, auth=self.auth)
def init_ra_and_client(self): """ Initializes the RA and client layers. With the SWIG bindings, getting unified diffs runs the remote server sometimes runs out of open files. It is not known whether the Subvertpy is affected by this. """ def getclientstring(): return 'hgsubversion' def simple(realm, username, may_save): return _prompt.simple(realm, username, may_save) def username(realm, may_save): return _prompt.username(realm, may_save) def ssl_client_cert(realm, may_save): return _prompt.ssl_client_cert(realm, may_save) def ssl_client_cert_pw(realm, may_save): return _prompt.ssl_client_cert_pw(realm, may_save) def ssl_server_trust(realm, failures, cert_info, may_save): creds = _prompt.ssl_server_trust(realm, failures, cert_info, may_save) if creds is None: # We need to reject the certificate, but subvertpy doesn't # handle None as a return value here, and requires # we instead return a tuple of (int, bool). Because of that, # we return (0, False) instead. creds = (0, False) return creds providers = ra.get_platform_specific_client_providers() providers += [ ra.get_simple_provider(), ra.get_username_provider(), ra.get_ssl_client_cert_file_provider(), ra.get_ssl_client_cert_pw_file_provider(), ra.get_ssl_server_trust_file_provider(), ] if _prompt: providers += [ ra.get_simple_prompt_provider(simple, 2), ra.get_username_prompt_provider(username, 2), ra.get_ssl_client_cert_prompt_provider(ssl_client_cert, 2), ra.get_ssl_client_cert_pw_prompt_provider(ssl_client_cert_pw, 2), ra.get_ssl_server_trust_prompt_provider(ssl_server_trust), ] auth = ra.Auth(providers) if self.username: auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_USERNAME, self.username) if self.password: auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_PASSWORD, self.password) try: self.remote = ra.RemoteAccess(url=self.svn_url, client_string_func=getclientstring, auth=auth) except SubversionException, e: # e.child contains a detailed error messages msglist = [] svn_exc = e while svn_exc: if svn_exc.args[0]: msglist.append(svn_exc.args[0]) svn_exc = svn_exc.child msg = '\n'.join(msglist) raise common.SubversionConnectionException(msg)
def get_svn_ssl_server_trust_prompt_provider(self): """Return a Subversion auth provider for checking whether a SSL server is trusted.""" return ra.get_ssl_server_trust_prompt_provider( self.get_svn_ssl_server_trust)
def init_ra_and_client(self): """ Initializes the RA and client layers. With the SWIG bindings, getting unified diffs runs the remote server sometimes runs out of open files. It is not known whether the Subvertpy is affected by this. """ def getclientstring(): return 'hgsubversion' def simple(realm, username, may_save): return _prompt.simple(realm, username, may_save) def username(realm, may_save): return _prompt.username(realm, may_save) def ssl_client_cert(realm, may_save): return _prompt.ssl_client_cert(realm, may_save) def ssl_client_cert_pw(realm, may_save): return _prompt.ssl_client_cert_pw(realm, may_save) def ssl_server_trust(realm, failures, cert_info, may_save): creds = _prompt.ssl_server_trust(realm, failures, cert_info, may_save) if creds is None: # We need to reject the certificate, but subvertpy doesn't # handle None as a return value here, and requires # we instead return a tuple of (int, bool). Because of that, # we return (0, False) instead. creds = (0, False) return creds providers = ra.get_platform_specific_client_providers() providers += [ ra.get_simple_provider(), ra.get_username_provider(), ra.get_ssl_client_cert_file_provider(), ra.get_ssl_client_cert_pw_file_provider(), ra.get_ssl_server_trust_file_provider(), ] if _prompt: providers += [ ra.get_simple_prompt_provider(simple, 2), ra.get_username_prompt_provider(username, 2), ra.get_ssl_client_cert_prompt_provider(ssl_client_cert, 2), ra.get_ssl_client_cert_pw_prompt_provider(ssl_client_cert_pw, 2), ra.get_ssl_server_trust_prompt_provider(ssl_server_trust), ] auth = ra.Auth(providers) if self.username: auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_USERNAME, self.username) if self.password: auth.set_parameter(subvertpy.AUTH_PARAM_DEFAULT_PASSWORD, self.password) try: self.remote = ra.RemoteAccess(url=self.svn_url, client_string_func=getclientstring, auth=auth) except SubversionException, e: # e.child contains a detailed error messages msglist = [] svn_exc = e while svn_exc: if svn_exc.args[0]: msglist.append(svn_exc.args[0]) svn_exc = svn_exc.child msg = '\n'.join(msglist) raise common.SubversionConnectionException(msg)