Skip to content

Commit 00ac202

Browse files
committed
Cleanup Standalone CLI
1 parent 83faa98 commit 00ac202

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

jupyter_server_proxy/standalone/app.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _validate_prefix(self, proposal):
5858
prefix = prefix[:-1]
5959
return prefix
6060

61-
skip_authentication = Bool(
61+
no_authentication = Bool(
6262
default=False,
6363
help="""
6464
Do not authenticate access to the server via JupyterHub. When set,
@@ -146,11 +146,16 @@ def __init__(self, **kwargs):
146146
{"ServerProcess": {"raw_socket_proxy": True}},
147147
dedent(ServerProcess.raw_socket_proxy.help),
148148
),
149-
"skip-authentication": (
150-
{"StandaloneProxyServer": {"skip_authentication": True}},
151-
dedent(self.__class__.skip_authentication.help),
149+
"no-authentication": (
150+
{"StandaloneProxyServer": {"no_authentication": True}},
151+
dedent(self.__class__.no_authentication.help),
152152
),
153153
}
154+
self.flags.pop("y")
155+
156+
# Some traits in ServerProcess are not defined to be configurable, but we need that for the standalone proxy
157+
for name, trait in ServerProcess.class_own_traits().items():
158+
trait.tag(config=True)
154159

155160
# Create an Alias to all Traits defined in ServerProcess, with some
156161
# exceptions we do not need, for easier use of the CLI
@@ -164,20 +169,20 @@ def __init__(self, **kwargs):
164169
"command",
165170
]
166171
server_process_aliases = {
167-
trait: f"StandaloneProxyServer.{trait}"
172+
trait.replace("_", "-"): f"StandaloneProxyServer.{trait}"
168173
for trait in ServerProcess.class_traits(config=True)
169174
if trait not in ignore_traits and trait not in self.flags
170175
}
171176

172177
self.aliases = {
173178
**super().aliases,
174179
**server_process_aliases,
175-
"base_url": "StandaloneProxyServer.base_url",
180+
"base-url": "StandaloneProxyServer.base_url",
176181
"address": "StandaloneProxyServer.address",
177182
"port": "StandaloneProxyServer.port",
178-
"server_port": "StandaloneProxyServer.server_port",
179-
"activity_interval": "StandaloneProxyServer.activity_interval",
180-
"websocket_max_message_size": "StandaloneProxyServer.websocket_max_message_size",
183+
"server-port": "StandaloneProxyServer.server_port",
184+
"activity-interval": "StandaloneProxyServer.activity_interval",
185+
"websocket-max-message-size": "StandaloneProxyServer.websocket_max_message_size",
181186
}
182187

183188
def emit_alias_help(self):
@@ -206,7 +211,7 @@ def get_proxy_attributes(self) -> dict:
206211
attributes["proxy_base"] = "/"
207212

208213
attributes["requested_port"] = self.server_port
209-
attributes["skip_authentication"] = self.skip_authentication
214+
attributes["no_authentication"] = self.no_authentication
210215

211216
return attributes
212217

@@ -278,7 +283,7 @@ def _configure_ssl(self) -> dict | None:
278283
return ssl_options
279284

280285
def start(self):
281-
if self.skip_authentication:
286+
if self.no_authentication:
282287
self.log.warn("Disabling Authentication with JuypterHub Server!")
283288

284289
app = self.create_app()

jupyter_server_proxy/standalone/proxy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, *args, **kwargs):
3232
super().__init__(*args, **kwargs)
3333
self.environment = {}
3434
self.timeout = 60
35-
self.skip_authentication = False
35+
self.no_authentication = False
3636

3737
@property
3838
def log(self) -> Logger:
@@ -69,7 +69,7 @@ def write_error(self, status_code: int, **kwargs):
6969
return RequestHandler.write_error(self, status_code, **kwargs)
7070

7171
async def proxy(self, port, path):
72-
if self.skip_authentication:
72+
if self.no_authentication:
7373
return await super().proxy(port, path)
7474
else:
7575
return await ensure_async(self.oauth_proxy(port, path))

tests/test_standalone.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class _TestStandaloneBase(testing.AsyncHTTPTestCase):
4040
runTest = None # Required for Tornado 6.1
4141

4242
unix_socket: bool
43-
skip_authentication: bool
43+
no_authentication: bool
4444

4545
def get_app(self):
4646
command = [
@@ -55,7 +55,7 @@ def get_app(self):
5555
base_url="/some/prefix",
5656
unix_socket=self.unix_socket,
5757
timeout=60,
58-
skip_authentication=self.skip_authentication,
58+
no_authentication=self.no_authentication,
5959
log_level=logging.DEBUG,
6060
)
6161

@@ -69,7 +69,7 @@ class TestStandaloneProxyRedirect(_TestStandaloneBase):
6969
"""
7070

7171
unix_socket = False
72-
skip_authentication = True
72+
no_authentication = True
7373

7474
def test_add_slash(self):
7575
response = self.fetch("/some/prefix", follow_redirects=False)
@@ -97,7 +97,7 @@ def test_on_prefix(self):
9797
)
9898
class TestStandaloneProxyWithUnixSocket(_TestStandaloneBase):
9999
unix_socket = True
100-
skip_authentication = True
100+
no_authentication = True
101101

102102
def test_with_unix_socket(self):
103103
response = self.fetch("/some/prefix/")
@@ -115,7 +115,7 @@ class TestStandaloneProxyLogin(_TestStandaloneBase):
115115
"""
116116

117117
unix_socket = False
118-
skip_authentication = False
118+
no_authentication = False
119119

120120
def test_redirect_to_login_url(self):
121121
response = self.fetch("/some/prefix/", follow_redirects=False)

0 commit comments

Comments
 (0)