-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fedc6cb
commit 16ca10a
Showing
7 changed files
with
76 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"base": { | ||
"cache_expire": 7200000, | ||
"cache_dir": "~/.cache/swm" | ||
}, | ||
|
||
"azure": { | ||
"storage": { | ||
"container_name": "" | ||
} | ||
}, | ||
|
||
"openstack": { | ||
} | ||
} |
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,19 +1,37 @@ | ||
import os | ||
import json | ||
from pathlib import Path | ||
from functools import lru_cache | ||
|
||
from pydantic import BaseSettings | ||
from pydantic import Field, BaseModel, ConfigDict, BaseSettings | ||
|
||
USER_DIR = os.path.expanduser("~") | ||
|
||
class AzureStorage(BaseModel): | ||
account: str | ||
token: str | ||
|
||
class Settings(BaseSettings): | ||
cache_expire: int = 14 * 24 * 3600 | ||
cache_dir: str | ||
|
||
class Config: | ||
env_file = f"{USER_DIR}/.swm/cloud-gate.conf" | ||
class AzureSettings(BaseModel): | ||
storage: AzureStorage | ||
|
||
|
||
class OpenStackSettings(BaseModel): | ||
pass | ||
|
||
|
||
class BaseConfig(BaseModel): | ||
cache_expire: int = Field(14 * 24 * 3600) | ||
cache_dir: str = Field(os.path.expanduser("~/.cache/swm")) | ||
|
||
|
||
class Settings(BaseSettings): | ||
base: BaseConfig | ||
azure: AzureSettings | None = None | ||
openstack: OpenStackSettings | None = None | ||
|
||
|
||
@lru_cache() | ||
def get_settings(cache_dir: str = f"{USER_DIR}/.cache/swm") -> Settings: | ||
return Settings(cache_dir=cache_dir) | ||
def get_settings(config_file: Path) -> Settings: | ||
with open(config_file, "r") as file: | ||
config_data = json.load(file) | ||
return Settings(**config_data) |
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