Skip to content

Commit

Permalink
Respect basic auth in import-contest URL.
Browse files Browse the repository at this point in the history
If specified explicitly in the URL, it will take precedence over what is
specified in the `~/.netrc`.

Fixes DOMjudge#2390.
  • Loading branch information
meisterT committed Mar 23, 2024
1 parent 113c18b commit 1e92035
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions misc-tools/dj_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import requests.utils
import subprocess
import sys
from urllib.parse import urlparse

_myself = os.path.basename(sys.argv[0])
_default_user_agent = requests.utils.default_user_agent()
Expand Down Expand Up @@ -76,12 +77,16 @@ def do_api_request(name: str, method: str = 'GET', jsonData: dict = {}):
else:
global ca_check
url = f'{domjudge_webapp_folder_or_api_url}/{name}'
parsed = urlparse(domjudge_webapp_folder_or_api_url)
auth = None
if parsed.username or parsed.password:
auth = (parsed.username, parsed.password)

try:
if method == 'GET':
response = requests.get(url, headers=headers, verify=ca_check)
response = requests.get(url, headers=headers, verify=ca_check, auth=auth)
elif method == 'PUT':
response = requests.put(url, headers=headers, verify=ca_check, json=jsonData)
response = requests.put(url, headers=headers, verify=ca_check, json=jsonData, auth=auth)
except requests.exceptions.SSLError as e:
ca_check = not confirm(
"Can not verify certificate, ignore certificate check?", False)
Expand Down Expand Up @@ -120,6 +125,7 @@ def upload_file(name: str, apifilename: str, file: str, data: dict = {}):

url = f'{domjudge_webapp_folder_or_api_url}/{name}'


try:
response = requests.post(
url, files=files, headers=headers, data=data, verify=ca_check)
Expand Down

0 comments on commit 1e92035

Please sign in to comment.