arpakitlib 1.6.38__py3-none-any.whl → 1.6.40__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- arpakitlib/ar_fastapi_util.py +28 -24
- {arpakitlib-1.6.38.dist-info → arpakitlib-1.6.40.dist-info}/METADATA +1 -1
- {arpakitlib-1.6.38.dist-info → arpakitlib-1.6.40.dist-info}/RECORD +6 -6
- {arpakitlib-1.6.38.dist-info → arpakitlib-1.6.40.dist-info}/LICENSE +0 -0
- {arpakitlib-1.6.38.dist-info → arpakitlib-1.6.40.dist-info}/NOTICE +0 -0
- {arpakitlib-1.6.38.dist-info → arpakitlib-1.6.40.dist-info}/WHEEL +0 -0
arpakitlib/ar_fastapi_util.py
CHANGED
@@ -436,12 +436,12 @@ class BaseNeedAPIAuthData(BaseModel):
|
|
436
436
|
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True, from_attributes=True)
|
437
437
|
|
438
438
|
token_string: str | None = None
|
439
|
-
|
439
|
+
api_key_string: str | None = None
|
440
440
|
|
441
441
|
|
442
442
|
def base_need_api_auth(
|
443
443
|
*,
|
444
|
-
|
444
|
+
require_api_key_string: bool = False,
|
445
445
|
require_token_string: bool = False,
|
446
446
|
) -> Callable:
|
447
447
|
async def func(
|
@@ -449,32 +449,36 @@ def base_need_api_auth(
|
|
449
449
|
ac: fastapi.security.HTTPAuthorizationCredentials | None = fastapi.Security(
|
450
450
|
fastapi.security.HTTPBearer(auto_error=False)
|
451
451
|
),
|
452
|
-
|
452
|
+
api_key_string: str | None = Security(APIKeyHeader(name="apikey", auto_error=False)),
|
453
453
|
request: fastapi.Request
|
454
454
|
) -> BaseNeedAPIAuthData:
|
455
455
|
|
456
456
|
_error_data = {
|
457
|
-
"
|
457
|
+
"require_api_key_string": require_api_key_string,
|
458
458
|
"require_token_string": require_token_string
|
459
459
|
}
|
460
460
|
|
461
461
|
res = BaseNeedAPIAuthData()
|
462
462
|
|
463
|
-
#
|
463
|
+
# api_key
|
464
464
|
|
465
|
-
res.
|
465
|
+
res.api_key_string = api_key_string
|
466
466
|
|
467
|
-
if not res.
|
468
|
-
res.
|
469
|
-
if not res.
|
470
|
-
res.
|
467
|
+
if not res.api_key_string and "api_key" in request.headers.keys():
|
468
|
+
res.api_key_string = request.headers["api_key"]
|
469
|
+
if not res.api_key_string and "api-key" in request.headers.keys():
|
470
|
+
res.api_key_string = request.headers["api-key"]
|
471
|
+
if not res.api_key_string and "apikey" in request.headers.keys():
|
472
|
+
res.api_key_string = request.headers["apikey"]
|
471
473
|
|
472
|
-
if not res.
|
473
|
-
res.
|
474
|
-
if not res.
|
475
|
-
res.
|
474
|
+
if not res.api_key_string and "api_key" in request.query_params.keys():
|
475
|
+
res.api_key_string = request.query_params["api_key"]
|
476
|
+
if not res.api_key_string and "api-key" in request.query_params.keys():
|
477
|
+
res.api_key_string = request.query_params["api-key"]
|
478
|
+
if not res.api_key_string and "apikey" in request.query_params.keys():
|
479
|
+
res.api_key_string = request.query_params["apikey"]
|
476
480
|
|
477
|
-
_error_data["res.
|
481
|
+
_error_data["res.api_key_string"] = res.api_key_string
|
478
482
|
|
479
483
|
# token
|
480
484
|
|
@@ -483,22 +487,22 @@ def base_need_api_auth(
|
|
483
487
|
if not res.token_string and "token" in request.headers.keys():
|
484
488
|
res.token_string = request.headers["token"]
|
485
489
|
|
486
|
-
if not res.token_string and "token" in request.query_params.keys():
|
487
|
-
res.token_string = request.query_params["token"]
|
488
|
-
|
489
490
|
if not res.token_string and "user_token" in request.headers.keys():
|
490
491
|
res.token_string = request.headers["user_token"]
|
491
|
-
if not res.token_string and "usertoken" in request.headers.keys():
|
492
|
-
res.token_string = request.headers["usertoken"]
|
493
492
|
if not res.token_string and "user-token" in request.headers.keys():
|
494
493
|
res.token_string = request.headers["user-token"]
|
494
|
+
if not res.token_string and "usertoken" in request.headers.keys():
|
495
|
+
res.token_string = request.headers["usertoken"]
|
496
|
+
|
497
|
+
if not res.token_string and "token" in request.query_params.keys():
|
498
|
+
res.token_string = request.query_params["token"]
|
495
499
|
|
496
500
|
if not res.token_string and "user_token" in request.query_params.keys():
|
497
501
|
res.token_string = request.query_params["user_token"]
|
498
|
-
if not res.token_string and "usertoken" in request.query_params.keys():
|
499
|
-
res.token_string = request.query_params["usertoken"]
|
500
502
|
if not res.token_string and "user-token" in request.query_params.keys():
|
501
503
|
res.token_string = request.query_params["user-token"]
|
504
|
+
if not res.token_string and "usertoken" in request.query_params.keys():
|
505
|
+
res.token_string = request.query_params["usertoken"]
|
502
506
|
|
503
507
|
if res.token_string:
|
504
508
|
res.token_string = res.token_string.strip()
|
@@ -507,7 +511,7 @@ def base_need_api_auth(
|
|
507
511
|
|
508
512
|
_error_data["res.token_string"] = res.token_string
|
509
513
|
|
510
|
-
if
|
514
|
+
if require_api_key_string and not res.api_key_string:
|
511
515
|
raise APIException(
|
512
516
|
status_code=starlette.status.HTTP_401_UNAUTHORIZED,
|
513
517
|
error_code=ErrorSO.APIErrorCodes.cannot_authorize,
|
@@ -577,7 +581,7 @@ def create_fastapi_app(
|
|
577
581
|
log_filepath: str | None = "./story.log",
|
578
582
|
handle_exception_: Callable | None = create_handle_exception(),
|
579
583
|
startup_api_events: list[BaseStartupAPIEvent] | None = None,
|
580
|
-
shutdown_api_events: list[
|
584
|
+
shutdown_api_events: list[BaseShutdownAPIEvent] | None = None,
|
581
585
|
transmitted_api_data: BaseTransmittedAPIData = BaseTransmittedAPIData(),
|
582
586
|
main_api_router: APIRouter = simple_api_router_for_testing(),
|
583
587
|
contact: dict[str, Any] | None = None
|
@@ -35,7 +35,7 @@ arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css,sha256=jzPZlgJTFwSdSphk9C
|
|
35
35
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css.map,sha256=5wq8eXMLU6Zxb45orZPL1zAsBFJReFw6GjYqGpUX3hg,262650
|
36
36
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js,sha256=ffrLZHHEQ_g84A-ul3yWa10Kk09waOAxHcQXPuZuavg,339292
|
37
37
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js.map,sha256=9UhIW7MqCOZPAz1Sl1IKfZUuhWU0p-LJqrnjjJD9Xhc,1159454
|
38
|
-
arpakitlib/ar_fastapi_util.py,sha256=
|
38
|
+
arpakitlib/ar_fastapi_util.py,sha256=KPYGcpW2ys0XXipK6yg0lBD1OGgtkbrclRWTLcL551A,20993
|
39
39
|
arpakitlib/ar_file_storage_in_dir_util.py,sha256=D3e3rGuHoI6xqAA5mVvEpVVpOWY1jyjNsjj2UhyHRbE,3674
|
40
40
|
arpakitlib/ar_generate_env_example.py,sha256=R_pdbFZe-mIZxEps2dm-K9m8rAg1pAaMzFOBPTGe4s4,370
|
41
41
|
arpakitlib/ar_hash_util.py,sha256=Iqy6KBAOLBQMFLWv676boI5sV7atT2B-fb7aCdHOmIQ,340
|
@@ -63,8 +63,8 @@ arpakitlib/ar_str_util.py,sha256=xSEzmsDvRiZVaxyqFFjcgzpphktCbXg2FHcvsd1DYpA,188
|
|
63
63
|
arpakitlib/ar_type_util.py,sha256=I6jbTz7_dxR1lkhz1JfUb5ZyLLdXVhG_-hzjdgT6N6s,1932
|
64
64
|
arpakitlib/ar_yookassa_api_client_util.py,sha256=5GMvu8paByni8buhc1vpHB7n6oXe0gPfj1LSvnyZCrQ,5307
|
65
65
|
arpakitlib/ar_zabbix_util.py,sha256=Q-VR4MvoZ9aHwZeYZr9G3LwN-ANx1T5KFmF6pvPM-9M,6402
|
66
|
-
arpakitlib-1.6.
|
67
|
-
arpakitlib-1.6.
|
68
|
-
arpakitlib-1.6.
|
69
|
-
arpakitlib-1.6.
|
70
|
-
arpakitlib-1.6.
|
66
|
+
arpakitlib-1.6.40.dist-info/LICENSE,sha256=1jqWIkbnMxDfs_i0SXP5qbV6PHjBr1g8506oW7uPjfg,11347
|
67
|
+
arpakitlib-1.6.40.dist-info/METADATA,sha256=IiMb0_BoA1n4MS3yVBzrBjcmrSqdIgZ8UKTgL_nQuyI,2320
|
68
|
+
arpakitlib-1.6.40.dist-info/NOTICE,sha256=wHwmiq3wExfFfgMsE5U5TOBP9_l72ocIG82KurEels0,43
|
69
|
+
arpakitlib-1.6.40.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
70
|
+
arpakitlib-1.6.40.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|