Skip to content

Commit

Permalink
sirepo_uri is not needed - can do local redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
e-carlin committed Jun 15, 2022
1 parent b824893 commit 579a421
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
7 changes: 4 additions & 3 deletions sirepo/jupyterhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _cookies(response):

def _maybe_html_redirect(response):
m = re.search(r'window.location = "(.*)"', pkcompat.from_bytes(response.content))
m and self._redirect(handler, f'{self.sirepo_uri}{m.group(1)}')
m and self._redirect(handler, m.group(1))

def _maybe_srexception_redirect(response):
if 'srException' not in response:
Expand All @@ -70,8 +70,7 @@ def _maybe_srexception_redirect(response):
_SIM_TYPE,
route_name=e.routeName,
params=e.params,
external=True,
sirepo_uri=self.sirepo_uri,
external=False,
)
)

Expand All @@ -87,6 +86,8 @@ def _maybe_srexception_redirect(response):
_maybe_html_redirect(r)
res = PKDict(r.json())
_maybe_srexception_redirect(res)
assert 'username' in res, \
f'unexpected response={res}'
return res

def _redirect(self, handler, uri):
Expand Down
12 changes: 3 additions & 9 deletions sirepo/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
#: optional parameter that consumes rest of parameters
PATH_INFO_CHAR = '*'

def app_root(sim_type, external=False, sirepo_uri=None):
def app_root(sim_type, external=False):
"""Generate uri for application root
Args:
sim_type (str): application name
external (bool): if True, make the uri absolute [False]
sirepo_uri (str): Base uri for sirepo (ex https://sirepo.com)
Returns:
str: formatted URI
"""
Expand All @@ -32,7 +31,6 @@ def app_root(sim_type, external=False, sirepo_uri=None):
'root',
params=PKDict(path_info=t) if t else None,
external=external,
sirepo_uri=sirepo_uri,
)


Expand All @@ -46,7 +44,7 @@ def init(**imports):
sirepo.util.setattr_imports(imports)


def local_route(sim_type, route_name=None, params=None, query=None, external=False, sirepo_uri=None):
def local_route(sim_type, route_name=None, params=None, query=None, external=False):
"""Generate uri for local route with params
Args:
Expand All @@ -55,13 +53,9 @@ def local_route(sim_type, route_name=None, params=None, query=None, external=Fal
params (dict): paramters to pass to route
query (dict): query values (joined and escaped)
external (bool): if True, make the uri absolute [False]
sirepo_uri (str): Base uri for sirepo (ex https://sirepo.com)
Returns:
str: formatted URI
"""
if sirepo_uri:
assert external, \
f'if sirepo_uri={sirepo_uri} then external={external} must be True'
t = http_request.sim_type(sim_type)
s = simulation_db.get_schema(t)
if not route_name:
Expand All @@ -74,7 +68,7 @@ def local_route(sim_type, route_name=None, params=None, query=None, external=Fal
if not params or p not in params:
continue
u += '/' + _to_uri(params[p])
return app_root(t, external=external, sirepo_uri=sirepo_uri) + '#' + u + _query(query)
return app_root(t, external=external) + '#' + u + _query(query)


def server_route(route_or_uri, params, query):
Expand Down
5 changes: 2 additions & 3 deletions sirepo/uri_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,20 @@ def _is_api_func(cls, name, obj):
_api_funcs[n] = _Route(func=o, cls=c, func_name=n)


def uri_for_api(api_name, params=None, external=True, sirepo_uri=None):
def uri_for_api(api_name, params=None, external=True):
"""Generate uri for api method
Args:
api_name (str): full name of api
params (PKDict): paramters to pass to uri
external (bool): if True, make the uri absolute [True]
sirepo_uri (str): Base uri for sirepo (ex https://sirepo.com)
Returns:
str: formmatted external URI
"""
if params is None:
params = PKDict()
r = _api_to_route[api_name]
s = sirepo_uri if sirepo_uri else flask.url_for('_dispatch_empty', _external=external)
s = flask.url_for('_dispatch_empty', _external=external) if external else '/'
res = (s + r.base_uri).rstrip('/')
for p in r.params:
if p.name in params:
Expand Down

0 comments on commit 579a421

Please sign in to comment.