From f12b8775093630b1acc088b349d8dcaca1955d4c Mon Sep 17 00:00:00 2001 From: Halvor Holsten Strand Date: Fri, 29 Sep 2023 14:01:53 +0200 Subject: [PATCH] Keep backwards compatability by going back to "--token" for classic. Allow "file://" uri for "--token-fine". --- README.rst | 7 ++++--- github_backup/github_backup.py | 8 +++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index aadd645..7e9e592 100644 --- a/README.rst +++ b/README.rst @@ -58,9 +58,10 @@ CLI Usage is as follows:: -p PASSWORD, --password PASSWORD password for basic auth. If a username is given but not a password, the password will be prompted for. - -f TOKEN_FINE, --token-fine TOKEN - fine-grained personal access token - -t TOKEN_CLASSIC, --token-classic TOKEN + -f TOKEN_FINE, --token-fine TOKEN_FINE + fine-grained personal access token or path to token + (file://...) + -t TOKEN_CLASSIC, --token TOKEN_CLASSIC personal access, OAuth, or JSON Web token, or path to token (file://...) --as-app authenticate as github app instead of as a user. diff --git a/github_backup/github_backup.py b/github_backup/github_backup.py index a024cc5..bc1387b 100644 --- a/github_backup/github_backup.py +++ b/github_backup/github_backup.py @@ -150,7 +150,7 @@ def parse_args(args=None): 'If a username is given but not a password, the ' 'password will be prompted for.') parser.add_argument('-t', - '--token-classic', + '--token', dest='token_classic', help='personal access, OAuth, or JSON Web token, or path to token (file://...)') # noqa parser.add_argument('-f', @@ -362,6 +362,11 @@ def get_auth(args, encode=True, for_git_cli=False): elif args.osx_keychain_item_account: raise Exception('You must specify both name and account fields for osx keychain password items') elif args.token_fine: + _path_specifier = 'file://' + if args.token_fine.startswith(_path_specifier): + args.token_fine = open(args.token_fine[len(_path_specifier):], + 'rt').readline().strip() + if args.token_fine.startswith("github_pat_"): auth = args.token_fine else: @@ -371,6 +376,7 @@ def get_auth(args, encode=True, for_git_cli=False): if args.token_classic.startswith(_path_specifier): args.token_classic = open(args.token_classic[len(_path_specifier):], 'rt').readline().strip() + if not args.as_app: auth = args.token_classic + ':' + 'x-oauth-basic' else: