-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoptions.py
More file actions
56 lines (41 loc) · 1.34 KB
/
options.py
File metadata and controls
56 lines (41 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
from typing import NotRequired, Optional, TypedDict
from httpx import URL
from .errors import MissingApiToken
class Options(TypedDict):
token: NotRequired[str | None]
regions: NotRequired[list[str] | None]
class InternalOptions(TypedDict):
sandbox_ws_url: URL
sandbox_url: URL
console_url: URL
token: str
regions: list[str]
def get_internal_options(options: Optional[Options] = None) -> InternalOptions:
sandbox_url = URL(
os.environ.get("DENO_SANDBOX_ENDPOINT", "https://ams.sandbox-api.deno.net")
)
token = (
options is not None
and options.get("token")
or os.environ.get("DENO_DEPLOY_TOKEN", None)
)
if token is None:
raise MissingApiToken({"message": "DENO_DEPLOY_TOKEN is not set"})
scheme = sandbox_url.scheme.replace("http", "ws")
sandbox_ws_url = URL(f"{scheme}://{sandbox_url.netloc.decode()}")
console_url = URL(
os.environ.get("DENO_DEPLOY_ENDPOINT", "https://console.deno.com")
)
regions = (
options is not None
and options.get("regions")
or os.environ.get("DENO_AVAILABLE_REGIONS", "ams1,ord").split(",")
)
return InternalOptions(
console_url=console_url,
sandbox_ws_url=sandbox_ws_url,
sandbox_url=sandbox_url,
token=token,
regions=regions,
)