25
26
svn_auth_get_username_prompt_provider,
26
27
svn_auth_get_simple_prompt_provider,
27
28
svn_auth_get_ssl_server_trust_prompt_provider,
28
svn_auth_get_ssl_client_cert_pw_prompt_provider)
29
svn_auth_get_ssl_client_cert_pw_prompt_provider,
31
35
class SubversionAuthenticationConfig(AuthenticationConfig):
32
36
"""Simple extended version of AuthenticationConfig that can provide
33
37
the information Subversion requires.
35
def __init__(self, file=None, scheme="svn", host=None):
39
def __init__(self, scheme, host, port, path, file=None):
36
40
super(SubversionAuthenticationConfig, self).__init__(file)
37
41
self.scheme = scheme
40
46
def get_svn_username(self, realm, may_save, pool=None):
41
47
"""Look up a Subversion user name in the Bazaar authentication cache.
43
49
:param realm: Authentication realm (optional)
44
50
:param may_save: Whether or not the username should be saved.
45
51
:param pool: Allocation pool, is ignored.
52
:param default: Assumed username
47
54
username_cred = svn_auth_cred_username_t()
48
55
username_cred.username = self.get_user(self.scheme,
49
host=self.host, realm=realm)
56
host=self.host, path=self.path,
50
58
username_cred.may_save = False
51
59
return username_cred
60
68
:param pool: Allocation pool, is ignored.
62
70
simple_cred = svn_auth_cred_simple_t()
63
simple_cred.username = username or self.get_username(realm, may_save,
64
pool, prompt="%s password" % realm)
71
simple_cred.username = self.get_user(self.scheme,
72
host=self.host, path=self.path, realm=realm) or username
65
73
simple_cred.password = self.get_password(self.scheme, host=self.host,
66
user=simple_cred.username, realm=realm,
67
prompt="%s password" % realm)
74
path=self.path, user=simple_cred.username,
75
realm=realm, prompt="%s %s password" % (realm, simple_cred.username))
68
76
simple_cred.may_save = False
71
79
def get_svn_ssl_server_trust(self, realm, failures, cert_info, may_save,
73
81
"""Return a Subversion auth provider that verifies SSL server trust.
75
83
:param realm: Realm name (optional)
113
121
def get_svn_ssl_server_trust_prompt_provider(self):
114
122
"""Return a Subversion auth provider for checking
115
123
whether a SSL server is trusted."""
116
return svn_auth_get_ssl_server_trust_prompt_provider(
117
self.get_svn_ssl_server_trust)
124
return svn_auth_get_ssl_server_trust_prompt_provider(self.get_svn_ssl_server_trust)
119
126
def get_svn_auth_providers(self):
120
127
"""Return a list of auth providers for this authentication file.
141
147
return svn_auth_get_ssl_client_cert_pw_prompt_provider(
142
148
get_ssl_client_cert_pw, tries)
151
def get_stock_svn_providers():
152
providers = [svn.client.get_simple_provider(),
153
svn.client.get_username_provider(),
154
svn.client.get_ssl_client_cert_file_provider(),
155
svn.client.get_ssl_client_cert_pw_file_provider(),
156
svn.client.get_ssl_server_trust_file_provider(),
159
if hasattr(svn.client, 'get_windows_simple_provider'):
160
providers.append(svn.client.get_windows_simple_provider())
162
if hasattr(svn.client, 'get_keychain_simple_provider'):
163
providers.append(svn.client.get_keychain_simple_provider())
165
if hasattr(svn.client, 'get_windows_ssl_server_trust_provider'):
166
providers.append(svn.client.get_windows_ssl_server_trust_provider())
171
def create_auth_baton(url):
172
"""Create an authentication baton for the specified URL."""
173
assert isinstance(url, str)
174
(scheme, netloc, path, _, _) = urlparse.urlsplit(url)
175
(creds, host) = urllib.splituser(netloc)
176
(host, port) = urllib.splitport(host)
178
auth_config = SubversionAuthenticationConfig(scheme, host, port, path)
180
# Specify Subversion providers first, because they use file data
181
# rather than prompting the user.
182
providers = get_stock_svn_providers()
184
if svn.core.SVN_VER_MAJOR == 1 and svn.core.SVN_VER_MINOR >= 5:
185
providers += auth_config.get_svn_auth_providers()
186
providers += [get_ssl_client_cert_pw_provider(1)]
188
auth_baton = svn.core.svn_auth_open(providers)
189
if creds is not None:
190
(auth_baton.user, auth_baton.password) = urllib.splitpasswd(creds)
191
if auth_baton.user is not None:
192
svn.core.svn_auth_set_parameter(auth_baton,
193
svn.core.SVN_AUTH_PARAM_DEFAULT_USERNAME, auth_baton.user)
194
if auth_baton.password is not None:
195
svn.core.svn_auth_set_parameter(auth_baton,
196
svn.core.SVN_AUTH_PARAM_DEFAULT_PASSWORD, auth_baton.password)