Skip to content

Commit

Permalink
setup: migrate to jupyter server 2
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-sanders committed May 18, 2023
1 parent 1ae2196 commit c49bb31
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
strategy:
matrix:
os: ['ubuntu-latest']
python: ['3.7', '3.8', '3.9']
python: ['3.8', '3.9']
include:
- os: 'macos-latest'
python: '3.7'
python: '3.8'
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
strategy:
matrix:
os: ['ubuntu-latest']
python: ['3.7', '3.8', '3.9']
python: ['3.8', '3.9']
include:
- os: 'macos-latest'
python: '3.7'
python: '3.8'
env:
PYTEST_ADDOPTS: --cov --color=yes

Expand Down
18 changes: 8 additions & 10 deletions cylc/uiserver/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _inner(
dict, # hub auth
str, # token auth or anonymous

] = handler.get_current_user()
] = handler.current_user
if user is None or user == 'anonymous':
# user is not authenticated - calls should not get this far
# but the extra safety doesn't hurt
Expand Down Expand Up @@ -157,7 +157,7 @@ class CylcAppHandler(JupyterHandler):
"""Base handler for Cylc endpoints.
This handler adds the Cylc authorisation layer which is triggered by
calling CylcAppHandler.get_current_user which is called by
accessing CylcAppHandler.current_user which is called by
web.authenticated.
When running as a Hub application the make_singleuser_app method patches
Expand All @@ -171,11 +171,13 @@ class CylcAppHandler(JupyterHandler):

def initialize(self, auth):
self.auth = auth
super().initialize()

# Without this, there is no xsrf token from the GET which causes a 403 and
# a missing _xsrf argument error on the first POST.
def prepare(self):
_ = self.xsrf_token
super().prepare()

@property
def hub_users(self):
Expand Down Expand Up @@ -268,8 +270,7 @@ def set_default_headers(self) -> None:
@web.authenticated
@authorised
def get(self):
user_info = self.get_current_user()

user_info = self.current_user
user_info = parse_current_user(user_info)

# add an entry for the workflow owner
Expand Down Expand Up @@ -338,13 +339,12 @@ def context(self):
'request': self.request,
'resolvers': self.resolvers,
'current_user': parse_current_user(
self.get_current_user()
self.current_user
).get('name'),
}

@web.authenticated
def prepare(self):
super().prepare()
return super(CylcAppHandler, self).prepare()

@web.authenticated # type: ignore[arg-type]
async def execute(self, *args, **kwargs) -> 'ExecutionResult':
Expand Down Expand Up @@ -411,9 +411,7 @@ def context(self):
return {
'request': self.request,
'resolvers': self.resolvers,
'current_user': parse_current_user(
self.get_current_user()
).get('name'),
'current_user': parse_current_user(self.current_user).get('name'),
'ops_queue': {},
'sub_statuses': self.sub_statuses
}
4 changes: 2 additions & 2 deletions cylc/uiserver/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ def mock_redirect(*args):
)

monkeypatch.setattr(
'cylc.uiserver.handlers.CylcAppHandler.get_current_user',
lambda x: ret
'cylc.uiserver.handlers.CylcAppHandler.current_user',
ret,
)
monkeypatch.setattr(
'cylc.uiserver.handlers.CylcAppHandler.get_login_url',
Expand Down
4 changes: 2 additions & 2 deletions cylc/uiserver/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ async def test_authorised_and_authenticated(
[
pytest.param(
('cylc', 'graphql'),
403,
'login redirect replaced by 403 for test purposes',
400,
'Bad Request',
None,
id='cylc/graphql',
),
Expand Down
2 changes: 1 addition & 1 deletion cylc/uiserver/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _create_handler(self, logged_in=True):
handler.get
_current_user = lambda: {'name': getuser()}
else:
handler.get_current_user = lambda: None
handler.current_user = None
return handler

@pytest.mark.usefixtures("mock_authentication")
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ classifiers =
License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Operating System :: POSIX
Programming Language :: Python
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: Implementation :: CPython

[options]
packages = find_namespace:
python_requires = >=3.7
python_requires = >=3.8
include_package_data = True
install_requires =
# NB: We have cylc-flow at the top to force it to install its transitive
Expand All @@ -55,7 +54,7 @@ install_requires =
graphene
graphene-tornado==2.6.*
graphql-ws==0.4.4
jupyter_server>=1.10.2,<2.0
jupyter_server>=2.0
requests
tornado>=6.1.0 # matches jupyter_server value
traitlets>=5.2.1 # required for logging_config (5.2.0 had bugs)
Expand Down Expand Up @@ -95,6 +94,7 @@ tests =
flake8-mutable>=1.2.0
flake8-simplify>=0.14.0
flake8>=3.0.0
jupyter_server[test]
mypy>=0.900
pytest-cov>=2.8.0
pytest-tornasync>=0.5.0
Expand Down

0 comments on commit c49bb31

Please sign in to comment.