diff options
Diffstat (limited to 'tools/examples/get-location-segments.py')
-rwxr-xr-x | tools/examples/get-location-segments.py | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/tools/examples/get-location-segments.py b/tools/examples/get-location-segments.py index c084dae..c8b3639 100755 --- a/tools/examples/get-location-segments.py +++ b/tools/examples/get-location-segments.py @@ -21,6 +21,7 @@ # import sys import os +import getpass from svn import client, ra, core def printer(segment, pool): @@ -71,6 +72,42 @@ def parse_args(args): return url, peg_revision, start_revision, end_revision +def prompt_func_ssl_unknown_cert(realm, failures, cert_info, may_save, pool): + print "The certficate details are as follows:" + print "--------------------------------------" + print "Issuer : " + str(cert_info.issuer_dname) + print "Hostname : " + str(cert_info.hostname) + print "ValidFrom : " + str(cert_info.valid_from) + print "ValidUpto : " + str(cert_info.valid_until) + print "Fingerprint: " + str(cert_info.fingerprint) + print "" + ssl_trust = core.svn_auth_cred_ssl_server_trust_t() + if may_save: + choice = raw_input( "accept (t)temporarily (p)permanently: ") + else: + choice = raw_input( "(r)Reject or accept (t)temporarily: ") + if choice[0] == "t" or choice[0] == "T": + ssl_trust.may_save = False + ssl_trust.accepted_failures = failures + elif choice[0] == "p" or choice[0] == "P": + ssl_trust.may_save = True + ssl_trust.accepted_failures = failures + else: + ssl_trust = None + return ssl_trust + +def prompt_func_simple_prompt(realm, username, may_save, pool): + username = raw_input("username: ") + password = getpass.getpass(prompt="password: ") + simple_cred = core.svn_auth_cred_simple_t() + simple_cred.username = username + simple_cred.password = password + simple_cred.may_save = False + return simple_cred + +def prompt_func_gnome_keyring_prompt(keyring, pool): + return getpass.getpass(prompt="Password for '%s' GNOME keyring: " % keyring) + def main(): try: url, peg_revision, start_revision, end_revision = parse_args(sys.argv[1:]) @@ -90,15 +127,17 @@ ERROR: %s sys.exit(1) core.svn_config_ensure(None) - ctx = client.ctx_t() + ctx = client.svn_client_create_context() + ctx.config = core.svn_config_get_config(None) # Make sure that these are at the start of the list, so passwords from # gnome-keyring / kwallet are checked before asking for new passwords. - # Note that we don't pass our config here, since we can't seem to access - # ctx.config.config (ctx.config is opaque). - providers = core.svn_auth_get_platform_specific_client_providers(None, None) + providers = core.svn_auth_get_platform_specific_client_providers(ctx.config['config'], None) providers.extend([ client.get_simple_provider(), + core.svn_auth_get_ssl_server_trust_file_provider(), + core.svn_auth_get_simple_prompt_provider(prompt_func_simple_prompt, 2), + core.svn_auth_get_ssl_server_trust_prompt_provider(prompt_func_ssl_unknown_cert), client.get_username_provider(), client.get_ssl_server_trust_file_provider(), client.get_ssl_client_cert_file_provider(), @@ -106,7 +145,9 @@ ERROR: %s ]) ctx.auth_baton = core.svn_auth_open(providers) - ctx.config = core.svn_config_get_config(None) + + if hasattr(core, 'svn_auth_set_gnome_keyring_unlock_prompt_func'): + core.svn_auth_set_gnome_keyring_unlock_prompt_func(ctx.auth_baton, prompt_func_gnome_keyring_prompt) ra_callbacks = ra.callbacks_t() ra_callbacks.auth_baton = ctx.auth_baton |