-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(config): rename env to config and use pydantic manage config
- Loading branch information
Showing
12 changed files
with
267 additions
and
124 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[owner] | ||
name = "podmaker" | ||
email = "[email protected]" | ||
|
||
[s3] | ||
access_key = "123" | ||
access_secret = "456" | ||
bucket = "podmake" | ||
endpoint = "https://s3.amazonaws.com" | ||
# must be public-read | ||
cdn_prefix = "https://s3.amazonaws.com" |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import annotations | ||
|
||
import sys | ||
from pathlib import PurePath | ||
|
||
from pydantic import BaseModel, EmailStr, Field, HttpUrl | ||
|
||
if sys.version_info >= (3, 11): | ||
import tomllib as toml | ||
else: | ||
import tomlkit as toml | ||
|
||
|
||
class OwnerConfig(BaseModel): | ||
name: str = Field(min_length=1, frozen=True) | ||
email: EmailStr = Field(frozen=True) | ||
|
||
|
||
class S3Config(BaseModel): | ||
access_key: str = Field(min_length=1, frozen=True) | ||
access_secret: str = Field(min_length=1, frozen=True) | ||
bucket: str = Field(min_length=1, frozen=True) | ||
endpoint: HttpUrl = Field(frozen=True) | ||
cdn_prefix: HttpUrl = Field(frozen=True) | ||
|
||
|
||
class PMConfig(BaseModel): | ||
owner: OwnerConfig = Field(frozen=True) | ||
s3: S3Config = Field(frozen=True) | ||
|
||
@classmethod | ||
def from_file(cls, path: PurePath) -> PMConfig: | ||
with open(path, 'rb') as f: | ||
data = toml.load(f) | ||
return cls(**data) |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.