Skip to content

Commit 8899a87

Browse files
Add .env.template. Allow empty auth headers for Judge0 Cloud. Use Judge0 Cloud as preview client.
1 parent 9f852ef commit 8899a87

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

.env.template

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Sulu API Key. Get yours at https://platform.sulu.sh/portal/consumer/dashboard
2+
# Subscribe here: https://platform.sulu.sh/apis/judge0
3+
JUDGE0_SULU_API_KEY=
4+
5+
# Rapid API Key. Get yours at https://rapidapi.com/developer/apps
6+
# Subscribe here: https://rapidapi.com/organization/judge0
7+
JUDGE0_RAPID_API_KEY=
8+
9+
# ATD API Key. Get yours at https://www.allthingsdev.co/account/apps
10+
# Subscribe here: https://www.allthingsdev.co/publisher/profile/Herman%20Zvonimir%20Došilović
11+
JUDGE0_ATD_API_KEY=
12+
13+
# Auth headers for Judge0 Cloud.
14+
# Contact us to get your credentials.
15+
JUDGE0_CLOUD_CE_AUTH_HEADERS=
16+
JUDGE0_CLOUD_EXTRA_CE_AUTH_HEADERS=
17+
18+
# Endpoint and auth headers for custom Judge0 CE instance.
19+
# Use to connect to your own Judge0 CE server.
20+
JUDGE0_CE_ENDPOINT=
21+
JUDGE0_CE_AUTH_HEADERS= # Use "{}" for no auth headers.
22+
23+
# Endpoint and auth headers for custom Judge0 Extra CE instance.
24+
# Use to connect to your own Judge0 Extra CE server.
25+
JUDGE0_EXTRA_CE_ENDPOINT=
26+
JUDGE0_EXTRA_CE_AUTH_HEADERS= # Use "{}" for no auth headers.

src/judge0/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,12 @@ def _get_implicit_client(flavor: Flavor) -> Client:
9494
# Let's check if we can find a self-hosted client.
9595
client = _get_custom_client(flavor)
9696

97-
# Try to find one of the API keys JUDGE0_{SULU,RAPID,ATD}_API_KEY
98-
# for hub clients.
97+
# Try to find one of the API keys for hub clients.
9998
if client is None:
10099
client = _get_hub_client(flavor)
101100

102101
# If we didn't find any of the possible keys, initialize
103-
# the preview Sulu client based on the flavor.
102+
# the preview client based on the flavor.
104103
if client is None:
105104
client = _get_preview_client(flavor)
106105

@@ -120,9 +119,9 @@ def _get_preview_client(flavor: Flavor) -> Union[SuluJudge0CE, SuluJudge0ExtraCE
120119
)
121120

122121
if flavor == Flavor.CE:
123-
return SuluJudge0CE(retry_strategy=RegularPeriodRetry(0.5))
122+
return Judge0CloudCE()
124123
else:
125-
return SuluJudge0ExtraCE(retry_strategy=RegularPeriodRetry(0.5))
124+
return Judge0CloudExtraCE()
126125

127126

128127
def _get_custom_client(flavor: Flavor) -> Union[Client, None]:

src/judge0/clients.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ class Judge0Cloud(Client):
728728
Additional keyword arguments for the base Client.
729729
"""
730730

731-
def __init__(self, endpoint, auth_headers, **kwargs):
731+
def __init__(self, endpoint, auth_headers=None, **kwargs):
732732
if isinstance(auth_headers, str):
733733
from json import loads
734734

@@ -758,7 +758,7 @@ class Judge0CloudCE(Judge0Cloud):
758758
HOME_URL: ClassVar[str] = "https://ce.judge0.com"
759759
API_KEY_ENV: ClassVar[str] = "JUDGE0_CLOUD_CE_AUTH_HEADERS"
760760

761-
def __init__(self, auth_headers, **kwargs):
761+
def __init__(self, auth_headers=None, **kwargs):
762762
super().__init__(
763763
self.DEFAULT_ENDPOINT,
764764
auth_headers,
@@ -783,7 +783,7 @@ class Judge0CloudExtraCE(Judge0Cloud):
783783
HOME_URL: ClassVar[str] = "https://extra-ce.judge0.com"
784784
API_KEY_ENV: ClassVar[str] = "JUDGE0_CLOUD_EXTRA_CE_AUTH_HEADERS"
785785

786-
def __init__(self, auth_headers, **kwargs):
786+
def __init__(self, auth_headers=None, **kwargs):
787787
super().__init__(self.DEFAULT_ENDPOINT, auth_headers, **kwargs)
788788

789789

0 commit comments

Comments
 (0)