6
6
import requests
7
7
from aiohttp import hdrs , web
8
8
from google .protobuf import json_format
9
+ from jwt import PyJWK
9
10
from jwt .algorithms import RSAAlgorithm
10
11
from temporalio .api .cloud .cloudservice .v1 import GetUsersRequest
11
12
from temporalio .api .common .v1 import Payloads
18
19
19
20
TEMPORAL_CLIENT_CLOUD_API_VERSION = "2024-05-13-00"
20
21
21
- temporal_ops_address = "saas-api.tmprl.cloud:443"
22
- if os .environ .get ("TEMPORAL_OPS_ADDRESS" ):
23
- temporal_ops_address = os . environ . get ( "TEMPORAL_OPS_ADDRESS" )
22
+ temporal_ops_address = (
23
+ os .environ .get ("TEMPORAL_OPS_ADDRESS" ) or "saas-api.tmprl.cloud:443"
24
+ )
24
25
25
26
26
27
def build_codec_server () -> web .Application :
@@ -76,8 +77,8 @@ async def decryption_authorized(email: str, namespace: str) -> bool:
76
77
77
78
def make_handler (fn : str ):
78
79
async def handler (req : web .Request ):
79
- namespace = req .headers .get ("x-namespace" )
80
- auth_header = req .headers .get ("Authorization" )
80
+ namespace = req .headers .get ("x-namespace" ) or "default"
81
+ auth_header = req .headers .get ("Authorization" ) or ""
81
82
_bearer , encoded = auth_header .split (" " )
82
83
83
84
# Extract the kid from the Auth header
@@ -90,20 +91,20 @@ async def handler(req: web.Request):
90
91
jwks = requests .get (jwks_url ).json ()
91
92
92
93
# Extract Temporal Cloud's public key
93
- public_key = None
94
+ pyjwk = None
94
95
for key in jwks ["keys" ]:
95
96
if key ["kid" ] == kid :
96
97
# Convert JWKS key to PEM format
97
- public_key = RSAAlgorithm . from_jwk (key )
98
+ pyjwk = PyJWK . from_dict (key )
98
99
break
99
100
100
- if public_key is None :
101
+ if pyjwk is None :
101
102
raise ValueError ("Public key not found in JWKS" )
102
103
103
104
# Decode the jwt, verifying against Temporal Cloud's public key
104
105
decoded = jwt .decode (
105
106
encoded ,
106
- public_key ,
107
+ pyjwk . key ,
107
108
algorithms = [algorithm ],
108
109
audience = [
109
110
"https://saas-api.tmprl.cloud" ,
@@ -156,7 +157,7 @@ async def handler(req: web.Request):
156
157
ssl_context = ssl .create_default_context (ssl .Purpose .CLIENT_AUTH )
157
158
ssl_context .check_hostname = False
158
159
ssl_context .load_cert_chain (
159
- os .environ .get ("SSL_PEM" ), os .environ .get ("SSL_KEY" )
160
+ os .environ .get ("SSL_PEM" ) or "" , os .environ .get ("SSL_KEY" ) or ""
160
161
)
161
162
162
163
web .run_app (
0 commit comments