mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-11 09:04:54 +00:00
infinoted: Use privileged decorator for actions
Tests:
- Functional tests work
- Initial setup succeeds
- infinoted user/group is added to the system
- systemd service is created and service is running after install
- Directories /var/lib/infinoted, /etc/infinoted and /var/lib/infinoted/sync
are created with infinoted as owner and group.
- Certificates /etc/infinoted/infinoted-{cert,key}.pem are created with
infinoted as owner and group.
- Enabling/disabling works and enables/disables the service
- Gobby is able to connect to the server and create a document
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
486d56e4cb
commit
02ef750442
@ -6,7 +6,6 @@ FreedomBox app for infinoted.
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from plinth import actions
|
||||
from plinth import app as app_module
|
||||
from plinth import cfg, frontpage, menu
|
||||
from plinth.daemon import Daemon
|
||||
@ -15,7 +14,7 @@ from plinth.modules.firewall.components import Firewall
|
||||
from plinth.package import Packages
|
||||
from plinth.utils import format_lazy
|
||||
|
||||
from . import manifest
|
||||
from . import manifest, privileged
|
||||
|
||||
_description = [
|
||||
_('infinoted is a server for Gobby, a collaborative text editor.'),
|
||||
@ -77,5 +76,5 @@ class InfinotedApp(app_module.App):
|
||||
def setup(self, old_version):
|
||||
"""Install and configure the app."""
|
||||
super().setup(old_version)
|
||||
actions.superuser_run('infinoted', ['setup'])
|
||||
privileged.setup()
|
||||
self.enable()
|
||||
|
||||
34
actions/infinoted → plinth/modules/infinoted/privileged.py
Executable file → Normal file
34
actions/infinoted → plinth/modules/infinoted/privileged.py
Executable file → Normal file
@ -1,10 +1,6 @@
|
||||
#!/usr/bin/python3
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""
|
||||
Configuration helper for infinoted.
|
||||
"""
|
||||
"""Configure infinoted."""
|
||||
|
||||
import argparse
|
||||
import grp
|
||||
import os
|
||||
import pwd
|
||||
@ -13,6 +9,7 @@ import subprocess
|
||||
import time
|
||||
|
||||
from plinth import action_utils
|
||||
from plinth.actions import privileged
|
||||
|
||||
DATA_DIR = '/var/lib/infinoted'
|
||||
KEY_DIR = '/etc/infinoted'
|
||||
@ -103,17 +100,6 @@ WantedBy=multi-user.target
|
||||
'''
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
"""Return parsed command line arguments as dictionary."""
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
subparsers.add_parser('setup', help='Configure infinoted after install')
|
||||
|
||||
subparsers.required = True
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def _kill_daemon():
|
||||
"""Try to kill the infinoted daemon for upto 5 minutes."""
|
||||
end_time = time.time() + 300
|
||||
@ -127,7 +113,8 @@ def _kill_daemon():
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
def subcommand_setup(_):
|
||||
@privileged
|
||||
def setup():
|
||||
"""Configure infinoted after install."""
|
||||
if not os.path.isfile(CONF_PATH):
|
||||
with open(CONF_PATH, 'w', encoding='utf-8') as file_handle:
|
||||
@ -180,16 +167,3 @@ def subcommand_setup(_):
|
||||
group='infinoted')
|
||||
|
||||
action_utils.service_enable('infinoted')
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties."""
|
||||
arguments = parse_arguments()
|
||||
|
||||
subcommand = arguments.subcommand.replace('-', '_')
|
||||
subcommand_method = globals()['subcommand_' + subcommand]
|
||||
subcommand_method(arguments)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
x
Reference in New Issue
Block a user