summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2012-09-14 10:31:42 +0900
committerGerrit Code Review <noreply-gerritcodereview@google.com>2012-09-21 11:20:59 -0700
commitcf76b1bcec6386f9530636e64746502f9856b5cf (patch)
tree15bd204cace8d3d43161f8ef91130984159e9049
parente00aa6b923d28a3c910f85e7726e4ba1d2a9aebd (diff)
downloadgit-repo-cf76b1bcec6386f9530636e64746502f9856b5cf.tar.gz
sync: Support manual authentication to the manifest server
Add two new command line options, -u/--manifest-server-username and -p/--manifest-server-password, which can be used to specify a username and password to authenticate to the manifest server when using the -s/--smart-sync or -t/--smart-tag option. If -u and -p are not specified when using the -s or -t option, use authentication credentials from the .netrc file (if there are any). Authentication credentials from -u/-p or .netrc are not used if the manifest server specified in the manifest file already includes credentials. Change-Id: I6cf9540d28f6cef64c5694e8928cfe367a71d28d
-rw-r--r--subcmds/sync.py71
1 files changed, 52 insertions, 19 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py
index b75bedc1..f573b980 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -83,6 +83,18 @@ build as specified by the manifest-server element in the current
83manifest. The -t/--smart-tag option is similar and allows you to 83manifest. The -t/--smart-tag option is similar and allows you to
84specify a custom tag/label. 84specify a custom tag/label.
85 85
86The -u/--manifest-server-username and -p/--manifest-server-password
87options can be used to specify a username and password to authenticate
88with the manifest server when using the -s or -t option.
89
90If -u and -p are not specified when using the -s or -t option, '%prog'
91will attempt to read authentication credentials for the manifest server
92from the user's .netrc file.
93
94'%prog' will not use authentication credentials from -u/-p or .netrc
95if the manifest server specified in the manifest file already includes
96credentials.
97
86The -f/--force-broken option can be used to proceed with syncing 98The -f/--force-broken option can be used to proceed with syncing
87other projects if a project sync fails. 99other projects if a project sync fails.
88 100
@@ -159,6 +171,12 @@ later is required to fix a server side protocol bug.
159 p.add_option('-t', '--smart-tag', 171 p.add_option('-t', '--smart-tag',
160 dest='smart_tag', action='store', 172 dest='smart_tag', action='store',
161 help='smart sync using manifest from a known tag') 173 help='smart sync using manifest from a known tag')
174 p.add_option('-u', '--manifest-server-username', action='store',
175 dest='manifest_server_username',
176 help='username to authenticate with the manifest server')
177 p.add_option('-p', '--manifest-server-password', action='store',
178 dest='manifest_server_password',
179 help='password to authenticate with the manifest server')
162 180
163 g = p.add_option_group('repo Version options') 181 g = p.add_option_group('repo Version options')
164 g.add_option('--no-repo-verify', 182 g.add_option('--no-repo-verify',
@@ -358,6 +376,14 @@ uncommitted changes are present' % project.relpath
358 if opt.manifest_name and opt.smart_tag: 376 if opt.manifest_name and opt.smart_tag:
359 print >>sys.stderr, 'error: cannot combine -m and -t' 377 print >>sys.stderr, 'error: cannot combine -m and -t'
360 sys.exit(1) 378 sys.exit(1)
379 if opt.manifest_server_username or opt.manifest_server_password:
380 if not (opt.smart_sync or opt.smart_tag):
381 print >>sys.stderr, 'error: -u and -p may only be combined with ' \
382 '-s or -t'
383 sys.exit(1)
384 if None in [opt.manifest_server_username, opt.manifest_server_password]:
385 print >>sys.stderr, 'error: both -u and -p must be given'
386 sys.exit(1)
361 387
362 if opt.manifest_name: 388 if opt.manifest_name:
363 self.manifest.Override(opt.manifest_name) 389 self.manifest.Override(opt.manifest_name)
@@ -369,29 +395,36 @@ uncommitted changes are present' % project.relpath
369 sys.exit(1) 395 sys.exit(1)
370 396
371 manifest_server = self.manifest.manifest_server 397 manifest_server = self.manifest.manifest_server
398
372 if not '@' in manifest_server: 399 if not '@' in manifest_server:
373 try: 400 username = None
374 info = netrc.netrc() 401 password = None
375 except IOError: 402 if opt.manifest_server_username and opt.manifest_server_password:
376 print >>sys.stderr, '.netrc file does not exist or could not be opened' 403 username = opt.manifest_server_username
404 password = opt.manifest_server_password
377 else: 405 else:
378 try: 406 try:
379 parse_result = urlparse.urlparse(manifest_server) 407 info = netrc.netrc()
380 if parse_result.hostname: 408 except IOError:
381 username, _account, password = \ 409 print >>sys.stderr, '.netrc file does not exist or could not be opened'
382 info.authenticators(parse_result.hostname)
383 except TypeError:
384 # TypeError is raised when the given hostname is not present
385 # in the .netrc file.
386 print >>sys.stderr, 'No credentials found for %s in .netrc' % \
387 parse_result.hostname
388 except netrc.NetrcParseError as e:
389 print >>sys.stderr, 'Error parsing .netrc file: %s' % e
390 else: 410 else:
391 if (username and password): 411 try:
392 manifest_server = manifest_server.replace('://', '://%s:%s@' % 412 parse_result = urlparse.urlparse(manifest_server)
393 (username, password), 413 if parse_result.hostname:
394 1) 414 username, _account, password = \
415 info.authenticators(parse_result.hostname)
416 except TypeError:
417 # TypeError is raised when the given hostname is not present
418 # in the .netrc file.
419 print >>sys.stderr, 'No credentials found for %s in .netrc' % \
420 parse_result.hostname
421 except netrc.NetrcParseError, e:
422 print >>sys.stderr, 'Error parsing .netrc file: %s' % e
423
424 if (username and password):
425 manifest_server = manifest_server.replace('://', '://%s:%s@' %
426 (username, password),
427 1)
395 428
396 try: 429 try:
397 server = xmlrpclib.Server(manifest_server) 430 server = xmlrpclib.Server(manifest_server)