|
1 | 1 | # Python Version: 3.x
|
2 | 2 | import hashlib
|
| 3 | +import json |
3 | 4 | import math
|
4 | 5 | import os
|
5 | 6 | import pathlib
|
|
9 | 10 | from logging import getLogger
|
10 | 11 | from typing import *
|
11 | 12 |
|
| 13 | +import requests |
| 14 | + |
12 | 15 | import onlinejudge
|
13 | 16 | import onlinejudge_verify.languages.list
|
14 | 17 | import onlinejudge_verify.marker
|
@@ -47,6 +50,19 @@ def exec_command(command: List[str]):
|
47 | 50 | os.chdir(str(cwd))
|
48 | 51 |
|
49 | 52 |
|
| 53 | +def get_fresh_dropbox_token() -> str: |
| 54 | + data = { |
| 55 | + 'grant_type': 'refresh_token', |
| 56 | + 'refresh_token': os.environ['DROPBOX_REFRESH_TOKEN'], |
| 57 | + } |
| 58 | + response = requests.post('https://api.dropbox.com/oauth2/token', data=data, auth=(os.environ['DROPBOX_APP_KEY'], os.environ['DROPBOX_APP_SECRET']), timeout=30) |
| 59 | + try: |
| 60 | + data = response.json() |
| 61 | + return data.get('access_token', '') |
| 62 | + except json.JSONDecodeError: |
| 63 | + return '' |
| 64 | + |
| 65 | + |
50 | 66 | def verify_file(path: pathlib.Path, *, compilers: List[str], tle: float, jobs: int) -> Optional[bool]:
|
51 | 67 | logger.info('verify: %s', path)
|
52 | 68 |
|
@@ -81,6 +97,9 @@ def verify_file(path: pathlib.Path, *, compilers: List[str], tle: float, jobs: i
|
81 | 97 |
|
82 | 98 | if os.environ.get('DROPBOX_TOKEN'):
|
83 | 99 | command += ['--dropbox-token', os.environ['DROPBOX_TOKEN']]
|
| 100 | + # 短期間で失効するDROPBOX_TOKENを新規に取得するオプションを用意する |
| 101 | + elif os.environ.get('DROPBOX_REFRESH_TOKEN') and os.environ.get('DROPBOX_APP_KEY') and os.environ.get('DROPBOX_APP_SECRET'): |
| 102 | + command += ['--dropbox-token', get_fresh_dropbox_token()] |
84 | 103 | if os.environ.get('YUKICODER_TOKEN'):
|
85 | 104 | command += ['--yukicoder-token', os.environ['YUKICODER_TOKEN']]
|
86 | 105 | try:
|
|
0 commit comments