From 02ef750442d4d4bc85c9df161c39e0763c29e3a8 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 25 Aug 2022 11:55:26 -0700 Subject: [PATCH] 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 Reviewed-by: James Valleroy --- plinth/modules/infinoted/__init__.py | 5 ++- .../modules/infinoted/privileged.py | 34 +++---------------- 2 files changed, 6 insertions(+), 33 deletions(-) rename actions/infinoted => plinth/modules/infinoted/privileged.py (85%) mode change 100755 => 100644 diff --git a/plinth/modules/infinoted/__init__.py b/plinth/modules/infinoted/__init__.py index 315b18161..e70d684f6 100644 --- a/plinth/modules/infinoted/__init__.py +++ b/plinth/modules/infinoted/__init__.py @@ -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() diff --git a/actions/infinoted b/plinth/modules/infinoted/privileged.py old mode 100755 new mode 100644 similarity index 85% rename from actions/infinoted rename to plinth/modules/infinoted/privileged.py index aef33246a..9675030a1 --- a/actions/infinoted +++ b/plinth/modules/infinoted/privileged.py @@ -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()