@@ -34,6 +34,14 @@ def serve_directory(
34
34
"this option selected."
35
35
),
36
36
),
37
+ api_key : str = typer .Option (
38
+ None ,
39
+ "--api-key" ,
40
+ help = (
41
+ "Set the single-user API key. "
42
+ "By default, a random key is generated at startup and printed."
43
+ ),
44
+ ),
37
45
keep_ext : bool = typer .Option (
38
46
False ,
39
47
"--keep-ext" ,
@@ -182,7 +190,10 @@ def serve_directory(
182
190
register_logger .setLevel ("INFO" )
183
191
web_app = build_app (
184
192
catalog_adapter ,
185
- {"allow_anonymous_access" : public },
193
+ {
194
+ "allow_anonymous_access" : public ,
195
+ "single_user_api_key" : api_key ,
196
+ },
186
197
server_settings ,
187
198
)
188
199
if watch :
@@ -270,6 +281,14 @@ def serve_catalog(
270
281
"this option selected."
271
282
),
272
283
),
284
+ api_key : str = typer .Option (
285
+ None ,
286
+ "--api-key" ,
287
+ help = (
288
+ "Set the single-user API key. "
289
+ "By default, a random key is generated at startup and printed."
290
+ ),
291
+ ),
273
292
host : str = typer .Option (
274
293
"127.0.0.1" ,
275
294
help = (
@@ -388,7 +407,13 @@ def serve_catalog(
388
407
init_if_not_exists = init ,
389
408
)
390
409
web_app = build_app (
391
- tree , {"allow_anonymous_access" : public }, server_settings , scalable = scalable
410
+ tree ,
411
+ {
412
+ "allow_anonymous_access" : public ,
413
+ "single_user_api_key" : api_key ,
414
+ },
415
+ server_settings ,
416
+ scalable = scalable ,
392
417
)
393
418
print_admin_api_key_if_generated (web_app , host = host , port = port )
394
419
@@ -414,6 +439,14 @@ def serve_pyobject(
414
439
"option selected."
415
440
),
416
441
),
442
+ api_key : str = typer .Option (
443
+ None ,
444
+ "--api-key" ,
445
+ help = (
446
+ "Set the single-user API key. "
447
+ "By default, a random key is generated at startup and printed."
448
+ ),
449
+ ),
417
450
host : str = typer .Option (
418
451
"127.0.0.1" ,
419
452
help = (
@@ -453,7 +486,13 @@ def serve_pyobject(
453
486
"available_bytes"
454
487
] = object_cache_available_bytes
455
488
web_app = build_app (
456
- tree , {"allow_anonymous_access" : public }, server_settings , scalable = scalable
489
+ tree ,
490
+ {
491
+ "allow_anonymous_access" : public ,
492
+ "single_user_api_key" : api_key ,
493
+ },
494
+ server_settings ,
495
+ scalable = scalable ,
457
496
)
458
497
print_admin_api_key_if_generated (web_app , host = host , port = port )
459
498
@@ -507,6 +546,14 @@ def serve_config(
507
546
"option selected."
508
547
),
509
548
),
549
+ api_key : str = typer .Option (
550
+ None ,
551
+ "--api-key" ,
552
+ help = (
553
+ "Set the single-user API key. "
554
+ "By default, a random key is generated at startup and printed."
555
+ ),
556
+ ),
510
557
host : str = typer .Option (
511
558
None ,
512
559
help = (
@@ -543,6 +590,11 @@ def serve_config(
543
590
if "authentication" not in parsed_config :
544
591
parsed_config ["authentication" ] = {}
545
592
parsed_config ["authentication" ]["allow_anonymous_access" ] = True
593
+ # Let --api-key flag override config.
594
+ if api_key :
595
+ if "authentication" not in parsed_config :
596
+ parsed_config ["authentication" ] = {}
597
+ parsed_config ["authentication" ]["single_user_api_key" ] = api_key
546
598
547
599
# Delay this import so that we can fail faster if config-parsing fails above.
548
600
0 commit comments