Merge branch 'develop' into passwd
This commit is contained in:
commit
c3fc2c290c
3 changed files with 36 additions and 0 deletions
|
|
@ -12,6 +12,12 @@ class AppConfig(BaseModel):
|
||||||
reload: bool = True
|
reload: bool = True
|
||||||
|
|
||||||
|
|
||||||
|
class GitConfig(BaseModel):
|
||||||
|
directory: str = "/opt/repo/sample"
|
||||||
|
branch: str = "master"
|
||||||
|
remote: str = "origin"
|
||||||
|
|
||||||
|
|
||||||
class KeePassConfig(BaseModel):
|
class KeePassConfig(BaseModel):
|
||||||
file: str = "database.kdbx"
|
file: str = "database.kdbx"
|
||||||
secret: Path | str = "/run/secrets/kp_secret"
|
secret: Path | str = "/run/secrets/kp_secret"
|
||||||
|
|
@ -20,6 +26,7 @@ class KeePassConfig(BaseModel):
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
model_config = SettingsConfigDict(env_prefix="KARL_", env_nested_delimiter="__")
|
model_config = SettingsConfigDict(env_prefix="KARL_", env_nested_delimiter="__")
|
||||||
app: AppConfig = AppConfig()
|
app: AppConfig = AppConfig()
|
||||||
|
git: GitConfig = GitConfig()
|
||||||
kp: KeePassConfig = KeePassConfig()
|
kp: KeePassConfig = KeePassConfig()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
from git import Repo, Remote
|
||||||
|
|
||||||
|
from app.config import get_settings
|
||||||
|
|
||||||
|
|
||||||
|
class GitService:
|
||||||
|
def __init__(self):
|
||||||
|
self._settings = get_settings()
|
||||||
|
self._repo = Repo(self._settings.git.directory)
|
||||||
|
self._origin: Remote = self._repo.remotes.origin
|
||||||
|
|
||||||
|
def get_modified_compose(self) -> str | None:
|
||||||
|
self._update()
|
||||||
|
return self._diff()
|
||||||
|
|
||||||
|
def _update(self):
|
||||||
|
self._origin.pull()
|
||||||
|
|
||||||
|
def _diff(self) -> str | None:
|
||||||
|
diff = self._repo.head.commit.diff("HEAD~1")
|
||||||
|
composes = [f for f in diff if f.a_path.endswith("docker-compose.yml")]
|
||||||
|
match len(composes):
|
||||||
|
case 0:
|
||||||
|
return None
|
||||||
|
case 1:
|
||||||
|
return composes[0].a_path
|
||||||
|
case _:
|
||||||
|
raise Exception("Multiple compose files modified")
|
||||||
|
|
@ -11,6 +11,7 @@ dependencies = [
|
||||||
"jinja2>=3.1.4",
|
"jinja2>=3.1.4",
|
||||||
"pydantic-settings>=2.4.0",
|
"pydantic-settings>=2.4.0",
|
||||||
"pyyaml>=6.0.2",
|
"pyyaml>=6.0.2",
|
||||||
|
"gitpython>=3.1.45",
|
||||||
"pykeepass>=4.1.1.post1"
|
"pykeepass>=4.1.1.post1"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue