arpakitlib 1.6.88__py3-none-any.whl → 1.6.89__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 +55 -50
- {arpakitlib-1.6.88.dist-info → arpakitlib-1.6.89.dist-info}/METADATA +1 -1
- {arpakitlib-1.6.88.dist-info → arpakitlib-1.6.89.dist-info}/RECORD +7 -7
- {arpakitlib-1.6.88.dist-info → arpakitlib-1.6.89.dist-info}/LICENSE +0 -0
- {arpakitlib-1.6.88.dist-info → arpakitlib-1.6.89.dist-info}/NOTICE +0 -0
- {arpakitlib-1.6.88.dist-info → arpakitlib-1.6.89.dist-info}/WHEEL +0 -0
- {arpakitlib-1.6.88.dist-info → arpakitlib-1.6.89.dist-info}/entry_points.txt +0 -0
arpakitlib/ar_fastapi_util.py
CHANGED
@@ -421,14 +421,19 @@ def get_transmitted_api_data(request: starlette.requests.Request) -> BaseTransmi
|
|
421
421
|
class BaseAPIAuthData(BaseModel):
|
422
422
|
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True, from_attributes=True)
|
423
423
|
|
424
|
+
require_api_key_string: bool = False
|
425
|
+
require_token_string: bool = None
|
426
|
+
|
424
427
|
token_string: str | None = None
|
425
428
|
api_key_string: str | None = None
|
426
429
|
|
427
430
|
|
428
|
-
def
|
431
|
+
def api_auth(
|
429
432
|
*,
|
430
433
|
require_api_key_string: bool = False,
|
431
434
|
require_token_string: bool = False,
|
435
|
+
api_key_string_validator: Callable | None = None,
|
436
|
+
token_string_validator: Callable | None = None,
|
432
437
|
) -> Callable:
|
433
438
|
async def func(
|
434
439
|
*,
|
@@ -439,79 +444,79 @@ def base_api_auth(
|
|
439
444
|
request: fastapi.Request
|
440
445
|
) -> BaseAPIAuthData:
|
441
446
|
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
res = BaseAPIAuthData()
|
447
|
+
api_auth_data = BaseAPIAuthData(
|
448
|
+
require_api_key_string=require_api_key_string,
|
449
|
+
require_token_string=require_token_string
|
450
|
+
)
|
448
451
|
|
449
452
|
# api_key
|
450
453
|
|
451
|
-
|
452
|
-
|
453
|
-
if not res.api_key_string and "api_key" in request.headers.keys():
|
454
|
-
res.api_key_string = request.headers["api_key"]
|
455
|
-
if not res.api_key_string and "api-key" in request.headers.keys():
|
456
|
-
res.api_key_string = request.headers["api-key"]
|
457
|
-
if not res.api_key_string and "apikey" in request.headers.keys():
|
458
|
-
res.api_key_string = request.headers["apikey"]
|
454
|
+
api_auth_data.api_key_string = api_key_string
|
459
455
|
|
460
|
-
if not
|
461
|
-
|
462
|
-
if not
|
463
|
-
|
464
|
-
if not
|
465
|
-
|
456
|
+
if not api_auth_data.api_key_string and "api_key" in request.headers.keys():
|
457
|
+
api_auth_data.api_key_string = request.headers["api_key"]
|
458
|
+
if not api_auth_data.api_key_string and "api-key" in request.headers.keys():
|
459
|
+
api_auth_data.api_key_string = request.headers["api-key"]
|
460
|
+
if not api_auth_data.api_key_string and "apikey" in request.headers.keys():
|
461
|
+
api_auth_data.api_key_string = request.headers["apikey"]
|
466
462
|
|
467
|
-
|
463
|
+
if not api_auth_data.api_key_string and "api_key" in request.query_params.keys():
|
464
|
+
api_auth_data.api_key_string = request.query_params["api_key"]
|
465
|
+
if not api_auth_data.api_key_string and "api-key" in request.query_params.keys():
|
466
|
+
api_auth_data.api_key_string = request.query_params["api-key"]
|
467
|
+
if not api_auth_data.api_key_string and "apikey" in request.query_params.keys():
|
468
|
+
api_auth_data.api_key_string = request.query_params["apikey"]
|
468
469
|
|
469
470
|
# token
|
470
471
|
|
471
|
-
|
472
|
+
api_auth_data.token_string = ac.credentials if ac and ac.credentials and ac.credentials.strip() else None
|
472
473
|
|
473
|
-
if not
|
474
|
-
|
474
|
+
if not api_auth_data.token_string and "token" in request.headers.keys():
|
475
|
+
api_auth_data.token_string = request.headers["token"]
|
475
476
|
|
476
|
-
if not
|
477
|
-
|
478
|
-
if not
|
479
|
-
|
480
|
-
if not
|
481
|
-
|
477
|
+
if not api_auth_data.token_string and "user_token" in request.headers.keys():
|
478
|
+
api_auth_data.token_string = request.headers["user_token"]
|
479
|
+
if not api_auth_data.token_string and "user-token" in request.headers.keys():
|
480
|
+
api_auth_data.token_string = request.headers["user-token"]
|
481
|
+
if not api_auth_data.token_string and "usertoken" in request.headers.keys():
|
482
|
+
api_auth_data.token_string = request.headers["usertoken"]
|
482
483
|
|
483
|
-
if not
|
484
|
-
|
484
|
+
if not api_auth_data.token_string and "token" in request.query_params.keys():
|
485
|
+
api_auth_data.token_string = request.query_params["token"]
|
485
486
|
|
486
|
-
if not
|
487
|
-
|
488
|
-
if not
|
489
|
-
|
490
|
-
if not
|
491
|
-
|
487
|
+
if not api_auth_data.token_string and "user_token" in request.query_params.keys():
|
488
|
+
api_auth_data.token_string = request.query_params["user_token"]
|
489
|
+
if not api_auth_data.token_string and "user-token" in request.query_params.keys():
|
490
|
+
api_auth_data.token_string = request.query_params["user-token"]
|
491
|
+
if not api_auth_data.token_string and "usertoken" in request.query_params.keys():
|
492
|
+
api_auth_data.token_string = request.query_params["usertoken"]
|
492
493
|
|
493
|
-
if
|
494
|
-
|
495
|
-
if not
|
496
|
-
|
494
|
+
if api_auth_data.token_string:
|
495
|
+
api_auth_data.token_string = api_auth_data.token_string.strip()
|
496
|
+
if not api_auth_data.token_string:
|
497
|
+
api_auth_data.token_string = None
|
497
498
|
|
498
|
-
|
499
|
-
|
500
|
-
if require_api_key_string and not res.api_key_string:
|
499
|
+
if require_api_key_string and not api_auth_data.api_key_string:
|
501
500
|
raise APIException(
|
502
501
|
status_code=starlette.status.HTTP_401_UNAUTHORIZED,
|
503
502
|
error_code=ErrorSO.APIErrorCodes.cannot_authorize,
|
504
|
-
error_data=
|
503
|
+
error_data=safely_transfer_to_json_str_to_json_obj(api_auth_data.model_dump())
|
505
504
|
)
|
506
505
|
|
507
|
-
if require_token_string and not
|
506
|
+
if require_token_string and not api_auth_data.token_string:
|
508
507
|
raise APIException(
|
509
508
|
status_code=starlette.status.HTTP_401_UNAUTHORIZED,
|
510
509
|
error_code=ErrorSO.APIErrorCodes.cannot_authorize,
|
511
|
-
error_data=
|
510
|
+
error_data=safely_transfer_to_json_str_to_json_obj(api_auth_data.model_dump())
|
512
511
|
)
|
513
512
|
|
514
|
-
|
513
|
+
if api_key_string_validator is not None:
|
514
|
+
api_auth_data = api_key_string_validator(api_auth_data=api_auth_data)
|
515
|
+
|
516
|
+
if token_string_validator is not None:
|
517
|
+
api_auth_data = token_string_validator(api_auth_data=api_auth_data)
|
518
|
+
|
519
|
+
return api_auth_data
|
515
520
|
|
516
521
|
return func
|
517
522
|
|
@@ -95,7 +95,7 @@ arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css,sha256=jzPZlgJTFwSdSphk9C
|
|
95
95
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.css.map,sha256=5wq8eXMLU6Zxb45orZPL1zAsBFJReFw6GjYqGpUX3hg,262650
|
96
96
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js,sha256=ffrLZHHEQ_g84A-ul3yWa10Kk09waOAxHcQXPuZuavg,339292
|
97
97
|
arpakitlib/ar_fastapi_static/swagger-ui/swagger-ui.js.map,sha256=9UhIW7MqCOZPAz1Sl1IKfZUuhWU0p-LJqrnjjJD9Xhc,1159454
|
98
|
-
arpakitlib/ar_fastapi_util.py,sha256=
|
98
|
+
arpakitlib/ar_fastapi_util.py,sha256=X72pf0JsPBLla6Q1WYBUrf2w_F7ukKwUYSRZCnw2Yi0,21465
|
99
99
|
arpakitlib/ar_file_storage_in_dir_util.py,sha256=D3e3rGuHoI6xqAA5mVvEpVVpOWY1jyjNsjj2UhyHRbE,3674
|
100
100
|
arpakitlib/ar_file_util.py,sha256=XiwmeycxoLqtYnGOu5q6IEaJJXilZvtLvsKDKtwqSLY,137
|
101
101
|
arpakitlib/ar_hash_util.py,sha256=Iqy6KBAOLBQMFLWv676boI5sV7atT2B-fb7aCdHOmIQ,340
|
@@ -126,9 +126,9 @@ arpakitlib/ar_str_util.py,sha256=AhcdrEm-pXRilCaDWCdTfVkQSy0SnbE52ur43Ltr6cI,212
|
|
126
126
|
arpakitlib/ar_type_util.py,sha256=5nDnXL5Oyozlg8XvxMrogsoYiG8_atItg46A0mtv-pk,2025
|
127
127
|
arpakitlib/ar_yookassa_api_client_util.py,sha256=5GMvu8paByni8buhc1vpHB7n6oXe0gPfj1LSvnyZCrQ,5307
|
128
128
|
arpakitlib/ar_zabbix_util.py,sha256=Q-VR4MvoZ9aHwZeYZr9G3LwN-ANx1T5KFmF6pvPM-9M,6402
|
129
|
-
arpakitlib-1.6.
|
130
|
-
arpakitlib-1.6.
|
131
|
-
arpakitlib-1.6.
|
132
|
-
arpakitlib-1.6.
|
133
|
-
arpakitlib-1.6.
|
134
|
-
arpakitlib-1.6.
|
129
|
+
arpakitlib-1.6.89.dist-info/LICENSE,sha256=GPEDQMam2r7FSTYqM1mm7aKnxLaWcBotH7UvQtea-ec,11355
|
130
|
+
arpakitlib-1.6.89.dist-info/METADATA,sha256=Wg3XKaZEYazWZ6UtVettl0ZZEu3y3mvlwwFsE9vgpYM,2739
|
131
|
+
arpakitlib-1.6.89.dist-info/NOTICE,sha256=95aUzaPJjVpDsGAsNzVnq7tHTxAl0s5UFznCTkVCau4,763
|
132
|
+
arpakitlib-1.6.89.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
133
|
+
arpakitlib-1.6.89.dist-info/entry_points.txt,sha256=VHkTDXDOMrgcNzGfKhEhoOIIz6T8Kkt46hy95Zc1iL0,74
|
134
|
+
arpakitlib-1.6.89.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|