mirror of
https://github.com/josegonzalez/python-github-backup.git
synced 2025-12-06 16:38:03 +01:00
Prompt for password if only username given
This commit is contained in:
@@ -7,6 +7,7 @@ import base64
|
|||||||
import calendar
|
import calendar
|
||||||
import codecs
|
import codecs
|
||||||
import errno
|
import errno
|
||||||
|
import getpass
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@@ -109,7 +110,9 @@ def parse_args():
|
|||||||
parser.add_argument('-p',
|
parser.add_argument('-p',
|
||||||
'--password',
|
'--password',
|
||||||
dest='password',
|
dest='password',
|
||||||
help='password for basic auth')
|
help='password for basic auth. '
|
||||||
|
'If a username is given but not a password, the '
|
||||||
|
'password will be prompted for.')
|
||||||
parser.add_argument('-t',
|
parser.add_argument('-t',
|
||||||
'--token',
|
'--token',
|
||||||
dest='token',
|
dest='token',
|
||||||
@@ -219,17 +222,18 @@ def parse_args():
|
|||||||
|
|
||||||
|
|
||||||
def get_auth(args):
|
def get_auth(args):
|
||||||
auth = None
|
|
||||||
if args.token:
|
if args.token:
|
||||||
auth = base64.b64encode(args.token + ':' + 'x-oauth-basic')
|
return base64.b64encode(args.token + ':' + 'x-oauth-basic')
|
||||||
elif args.username and args.password:
|
|
||||||
auth = base64.b64encode(args.username + ':' + args.password)
|
if args.username:
|
||||||
elif args.username and not args.password:
|
if not args.password:
|
||||||
log_error('You must specify a password for basic auth')
|
args.password = getpass.getpass()
|
||||||
elif args.password and not args.username:
|
return base64.b64encode(args.username + ':' + args.password)
|
||||||
|
|
||||||
|
if args.password:
|
||||||
log_error('You must specify a username for basic auth')
|
log_error('You must specify a username for basic auth')
|
||||||
|
|
||||||
return auth
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_github_api_host(args):
|
def get_github_api_host(args):
|
||||||
|
|||||||
Reference in New Issue
Block a user