Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use $YUKICODER_TOKEN and $DROPBOX_TOKEN envvar for a security reason #917

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions onlinejudge_command/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import os
import pathlib
import sys
import traceback
Expand Down Expand Up @@ -86,6 +87,11 @@ def main(args: Optional[List[str]] = None) -> 'NoReturn':
parser = get_parser()
parsed = parser.parse_args(args=args)

if parsed.yukicoder_token:
os.environ['YUKICODER_TOKEN'] = parsed.yukicoder_token
if parsed.dropbox_token:
os.environ['DROPBOX_TOKEN'] = parsed.dropbox_token

# configure the logger
level = INFO
if parsed.verbose:
Expand Down
12 changes: 6 additions & 6 deletions onlinejudge_command/subcommand/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def add_subparser(subparsers: argparse.Action) -> None:
subparser.add_argument('-n', '--dry-run', action='store_true', help='don\'t write to files')
subparser.add_argument('-a', '--system', action='store_true', help='download system testcases')
subparser.add_argument('-s', '--silent', action='store_true')
subparser.add_argument('--yukicoder-token', type=str)
subparser.add_argument('--dropbox-token', type=str)
subparser.add_argument('--yukicoder-token', type=str, help='[deprecated] specify the token of yukicoder. For a security reason, use the $YUKICODER_TOKEN envvar. (default: $YUKICODER_TOKEN)')
subparser.add_argument('--dropbox-token', type=str, help='[deprecated] specify the token of dropbox. For a security reason, use the $DROPBOX_TOKEN envvar. (default: $DROPBOX_TOKEN)')
subparser.add_argument('--log-file', type=pathlib.Path, help=argparse.SUPPRESS)


Expand Down Expand Up @@ -96,7 +96,7 @@ def run(args: argparse.Namespace) -> bool:
# get samples from the server
with utils.new_session_with_our_user_agent(path=args.cookie) as sess:
if isinstance(problem, AtCoderProblem) and args.system:
if not args.dropbox_token:
if 'DROPBOX_TOKEN' not in os.environ:
logger.info(utils.HINT + 'You need to give the access token. Please do the following:\n%s', textwrap.dedent("""
1. Open the following URL in your browser:
https://www.dropbox.com/oauth2/authorize?client_id=153gig8dqgk3ujg&response_type=code
Expand All @@ -110,9 +110,9 @@ def run(args: argparse.Namespace) -> bool:
(Please take care that the access code and the access token are CONFIDENTIAL information. DON'T SHARE with other people!)
"""))
raise SampleParseError("--dropbox-token is not given")
sess.headers['Authorization'] = 'Bearer {}'.format(args.dropbox_token)
if args.yukicoder_token and isinstance(problem, YukicoderProblem):
sess.headers['Authorization'] = 'Bearer {}'.format(args.yukicoder_token)
sess.headers['Authorization'] = 'Bearer {}'.format(os.getenv('DROPBOX_TOKEN'))
if 'YUKICODER_TOKEN' in os.environ and isinstance(problem, YukicoderProblem):
sess.headers['Authorization'] = 'Bearer {}'.format(os.getenv('YUKICODER_TOKEN'))
try:
if args.system:
samples = problem.download_system_cases(session=sess)
Expand Down