mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
miniflux: Get credentials from dbconfig-common directly
Fixes: #2562 Newer miniflux package does not create a separate file called /etc/miniflux/database. Instead it write the database URL directly into /etc/miniflux/miniflux.conf. It is easier to create the database settings from dbconfig-common that to read them from miniflux.conf. Signed-off-by: Frederico Gomes <fredericojfgomes@gmail.com> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
9a524b331b
commit
af6d1d9a4c
@ -5,13 +5,12 @@ import json
|
|||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
from urllib.parse import urlparse
|
|
||||||
|
|
||||||
import pexpect
|
import pexpect
|
||||||
|
|
||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
from plinth.actions import privileged, secret_str
|
from plinth.actions import privileged, secret_str
|
||||||
from plinth.db import postgres
|
from plinth.db import postgres, dbconfig
|
||||||
from plinth.utils import is_non_empty_file
|
from plinth.utils import is_non_empty_file
|
||||||
|
|
||||||
STATIC_SETTINGS = {
|
STATIC_SETTINGS = {
|
||||||
@ -21,7 +20,7 @@ STATIC_SETTINGS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ENV_VARS_FILE = '/etc/miniflux/freedombox.conf'
|
ENV_VARS_FILE = '/etc/miniflux/freedombox.conf'
|
||||||
DATABASE_FILE = '/etc/miniflux/database'
|
DBCONFIG_PATH = '/etc/dbconfig-common/miniflux.conf'
|
||||||
DB_BACKUP_FILE = '/var/lib/plinth/backups-data/miniflux-database.sql'
|
DB_BACKUP_FILE = '/var/lib/plinth/backups-data/miniflux-database.sql'
|
||||||
|
|
||||||
|
|
||||||
@ -117,28 +116,16 @@ def uninstall():
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
def _get_database_config():
|
|
||||||
"""Retrieve database credentials."""
|
|
||||||
db_connection_string = pathlib.Path(DATABASE_FILE).read_text().strip()
|
|
||||||
parsed_url = urlparse(db_connection_string)
|
|
||||||
return {
|
|
||||||
'user': parsed_url.username,
|
|
||||||
'password': parsed_url.password,
|
|
||||||
'database': parsed_url.path.lstrip('/'),
|
|
||||||
'host': parsed_url.hostname,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@privileged
|
@privileged
|
||||||
def dump_database():
|
def dump_database():
|
||||||
"""Dump database to file."""
|
"""Dump database to file."""
|
||||||
config = _get_database_config()
|
config = dbconfig.get_credentials(DBCONFIG_PATH)
|
||||||
postgres.dump_database(DB_BACKUP_FILE, config['database'])
|
postgres.dump_database(DB_BACKUP_FILE, config['database'])
|
||||||
|
|
||||||
|
|
||||||
@privileged
|
@privileged
|
||||||
def restore_database():
|
def restore_database():
|
||||||
"""Restore database from file."""
|
"""Restore database from file."""
|
||||||
config = _get_database_config()
|
config = dbconfig.get_credentials(DBCONFIG_PATH)
|
||||||
postgres.restore_database(DB_BACKUP_FILE, config['database'],
|
postgres.restore_database(DB_BACKUP_FILE, config['database'],
|
||||||
config['user'], config['password'])
|
config['user'], config['password'])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user