-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
整理:
verify_mutability()
で mutability チェックを置き換え (#1363)
* refactor: `verify_mutability()` で mutability チェックを置き換え * refactor: `verify_mutability` → `verify_mutability_allowed` へリネーム * Update voicevox_engine/app/dependencies.py * 更新 --------- Co-authored-by: Hiroshiba <[email protected]> Co-authored-by: Hiroshiba Kazuyuki <[email protected]>
- Loading branch information
1 parent
95f218a
commit c15dd34
Showing
6 changed files
with
54 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
"""FastAPI dependencies""" | ||
|
||
from dataclasses import dataclass | ||
from typing import Any, Callable, Coroutine, TypeAlias | ||
|
||
from fastapi import HTTPException | ||
|
||
VerifyMutabilityAllowed: TypeAlias = Callable[[], Coroutine[Any, Any, None]] | ||
|
||
# 許可されていないAPIを無効化する | ||
@dataclass | ||
class MutableAPI: | ||
enable: bool = True | ||
|
||
def generate_mutability_allowed_verifier( | ||
disable_mutable_api: bool, | ||
) -> VerifyMutabilityAllowed: | ||
"""verify_mutability_allowed 関数(データ変更の許可を確認する関数)を生成する。""" | ||
|
||
# FIXME: グローバル変数が複数ファイルに分散しているため、DI 等で局所化する | ||
deprecated_mutable_api = MutableAPI() | ||
async def verify_mutability_allowed() -> None: | ||
if disable_mutable_api: | ||
msg = "エンジンの静的なデータを変更するAPIは無効化されています" | ||
raise HTTPException(status_code=403, detail=msg) | ||
else: | ||
pass | ||
|
||
|
||
async def check_disabled_mutable_api() -> None: | ||
if not deprecated_mutable_api.enable: | ||
raise HTTPException( | ||
status_code=403, | ||
detail="エンジンの静的なデータを変更するAPIは無効化されています", | ||
) | ||
return verify_mutability_allowed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters