feat(settings): Add StorageSettings for shared storage configuration#43
Open
feat(settings): Add StorageSettings for shared storage configuration#43
Conversation
Google Cloud Storage 설정을 위한 StorageSettings 클래스 추가. credentials_json 필드를 포함하여 JSON 문자열 기반 인증 지원.
There was a problem hiding this comment.
Code Review
이 PR은 aioia_core에 공용 Google Cloud Storage 설정을 위한 StorageSettings 클래스를 추가합니다. 전반적으로 깔끔하게 작성되었으며, pydantic-settings를 활용하여 환경 변수로부터 설정을 잘 불러오고 있습니다. 다만, enabled가 True일 때 필수 필드인 bucket_name이 설정되었는지 확인하는 유효성 검사 로직을 추가하면 코드가 더욱 견고해질 것입니다. 관련하여 상세한 리뷰 의견을 남겼습니다.
Comment on lines
+126
to
+147
| class StorageSettings(BaseSettings): | ||
| """ | ||
| Storage settings class for configuring storage clients. | ||
|
|
||
| Environment variables: | ||
| STORAGE_ENABLED: Enable/disable Google Cloud Storage (default: False) | ||
| STORAGE_BUCKET_NAME: The name of the Google Cloud Storage bucket to use | ||
| STORAGE_PROJECT_ID: Google Cloud project ID (optional) | ||
| STORAGE_CREDENTIALS_PATH: Path to the Google Cloud service account JSON key file (optional) | ||
| STORAGE_CREDENTIALS_JSON: JSON string of Google Cloud service account credentials (optional) | ||
| """ | ||
|
|
||
| INI_SECTION: ClassVar[str] = "storage" | ||
|
|
||
| enabled: bool = False | ||
| bucket_name: str = "" | ||
| project_id: str | None = None | ||
| credentials_path: str | None = None | ||
| credentials_json: str | None = None | ||
|
|
||
| class Config: | ||
| env_prefix = "STORAGE_" |
There was a problem hiding this comment.
StorageSettings 클래스에 enabled가 True일 때 bucket_name이 설정되었는지 확인하는 유효성 검사기를 추가하는 것이 좋습니다.
현재 enabled가 True이고 bucket_name이 빈 문자열이면, 나중에 GCS 클라이언트를 사용하려고 할 때 런타임 오류가 발생할 수 있습니다.
FishAudioSettings나 HedraSettings의 check_api_key처럼 model_validator를 사용하여 설정이 로드될 때 이를 검증하면 더 안전한 코드가 됩니다.
class StorageSettings(BaseSettings):
"""
Storage settings class for configuring storage clients.
Environment variables:
STORAGE_ENABLED: Enable/disable Google Cloud Storage (default: False)
STORAGE_BUCKET_NAME: The name of the Google Cloud Storage bucket to use
STORAGE_PROJECT_ID: Google Cloud project ID (optional)
STORAGE_CREDENTIALS_PATH: Path to the Google Cloud service account JSON key file (optional)
STORAGE_CREDENTIALS_JSON: JSON string of Google Cloud service account credentials (optional)
"""
INI_SECTION: ClassVar[str] = "storage"
enabled: bool = False
bucket_name: str = ""
project_id: str | None = None
credentials_path: str | None = None
credentials_json: str | None = None
@model_validator(mode="after")
def check_bucket_name(self) -> "StorageSettings":
"""Validate that bucket_name is present if the service is enabled."""
if self.enabled and not self.bucket_name:
raise ValueError("Bucket name is required when storage is enabled.")
return self
class Config:
env_prefix = "STORAGE_"References
- 개발 가이드의 'Guard Clause' 원칙(11번 라인)에 따라, 서비스 활성화 시 필수 값(
bucket_name)을 미리 검증하여 런타임 오류를 방지하는 것이 좋습니다. (link)
Buppy의 기존 구현과 일치시키기 위해 credentials_json 필드 제거. credentials_path만 사용하여 서비스 계정 인증 지원.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
개요
공용 라이브러리로 사용할 Google Cloud Storage 설정을
aioia_core에 추가합니다.변경사항
StorageSettings 클래스 추가
aioia_core/settings.pyenabled(bool): GCS 활성화 여부 (기본값: False)bucket_name(str): GCS 버킷명project_id(str | None): Google Cloud 프로젝트 IDcredentials_path(str | None): 서비스 계정 JSON 키 파일 경로credentials_json(str | None): 서비스 계정 자격증명 JSON 문자열환경변수 설정
STORAGE_프리픽스를 사용하여 다음과 같이 설정:테스트