mirror of
https://github.com/Dictionarry-Hub/profilarr.git
synced 2026-01-22 02:41:11 +01:00
fix: update PAT status on startup
- now allows transition from non dev -> dev environments or vice versa
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from .connection import get_db
|
||||
from .queries.settings import get_settings, get_secret_key, save_settings
|
||||
from .queries.settings import get_settings, get_secret_key, save_settings, update_pat_status
|
||||
from .queries.arr import (get_unique_arrs, update_arr_config_on_rename,
|
||||
update_arr_config_on_delete)
|
||||
from .queries.format_renames import (add_format_to_renames,
|
||||
@@ -11,5 +11,5 @@ __all__ = [
|
||||
'get_db', 'get_settings', 'get_secret_key', 'save_settings',
|
||||
'get_unique_arrs', 'update_arr_config_on_rename',
|
||||
'update_arr_config_on_delete', 'run_migrations', 'add_format_to_renames',
|
||||
'remove_format_from_renames', 'is_format_in_renames'
|
||||
'remove_format_from_renames', 'is_format_in_renames', 'update_pat_status'
|
||||
]
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# backend/app/db/queries/settings.py
|
||||
from ..connection import get_db
|
||||
import logging
|
||||
import os
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_settings():
|
||||
@@ -30,3 +34,32 @@ def save_settings(settings_dict):
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
''', (key, value))
|
||||
conn.commit()
|
||||
|
||||
|
||||
def update_pat_status():
|
||||
"""Update the has_profilarr_pat setting based on current environment."""
|
||||
with get_db() as conn:
|
||||
profilarr_pat = os.environ.get('PROFILARR_PAT')
|
||||
pat_exists = str(bool(profilarr_pat)).lower()
|
||||
|
||||
# Get current value
|
||||
current = conn.execute('SELECT value FROM settings WHERE key = ?',
|
||||
('has_profilarr_pat', )).fetchone()
|
||||
|
||||
conn.execute(
|
||||
'''
|
||||
INSERT INTO settings (key, value, updated_at)
|
||||
VALUES ('has_profilarr_pat', ?, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT(key) DO UPDATE SET
|
||||
value = ?,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
''', (pat_exists, pat_exists))
|
||||
conn.commit()
|
||||
|
||||
if current is None:
|
||||
logger.info(f"PAT status created: {pat_exists}")
|
||||
elif current[0] != pat_exists:
|
||||
logger.info(
|
||||
f"PAT status updated from {current[0]} to {pat_exists}")
|
||||
else:
|
||||
logger.debug("PAT status unchanged")
|
||||
|
||||
@@ -4,7 +4,7 @@ import subprocess
|
||||
import logging
|
||||
import logging.config
|
||||
from .config import config
|
||||
from .db import get_secret_key
|
||||
from .db import get_secret_key, update_pat_status
|
||||
|
||||
|
||||
def setup_logging():
|
||||
@@ -103,7 +103,7 @@ def setup_logging():
|
||||
|
||||
|
||||
def init_git_user():
|
||||
"""Initialize Git user configuration globally."""
|
||||
"""Initialize Git user configuration globally and update PAT status."""
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.info("Starting Git user configuration")
|
||||
|
||||
@@ -124,6 +124,9 @@ def init_git_user():
|
||||
subprocess.run(['git', 'config', '--global', 'user.email', git_email],
|
||||
check=True)
|
||||
|
||||
# Update PAT status in database
|
||||
update_pat_status()
|
||||
|
||||
# Verify configuration
|
||||
configured_name = subprocess.run(
|
||||
['git', 'config', '--global', 'user.name'],
|
||||
|
||||
Reference in New Issue
Block a user