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:
Sunil Mohan Adapa 2022-08-25 11:55:26 -07:00 committed by James Valleroy
parent 486d56e4cb
commit 02ef750442
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 6 additions and 33 deletions

View File

@ -6,7 +6,6 @@ FreedomBox app for infinoted.
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from plinth import actions
from plinth import app as app_module from plinth import app as app_module
from plinth import cfg, frontpage, menu from plinth import cfg, frontpage, menu
from plinth.daemon import Daemon from plinth.daemon import Daemon
@ -15,7 +14,7 @@ from plinth.modules.firewall.components import Firewall
from plinth.package import Packages from plinth.package import Packages
from plinth.utils import format_lazy from plinth.utils import format_lazy
from . import manifest from . import manifest, privileged
_description = [ _description = [
_('infinoted is a server for Gobby, a collaborative text editor.'), _('infinoted is a server for Gobby, a collaborative text editor.'),
@ -77,5 +76,5 @@ class InfinotedApp(app_module.App):
def setup(self, old_version): def setup(self, old_version):
"""Install and configure the app.""" """Install and configure the app."""
super().setup(old_version) super().setup(old_version)
actions.superuser_run('infinoted', ['setup']) privileged.setup()
self.enable() self.enable()

View File

@ -1,10 +1,6 @@
#!/usr/bin/python3
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
""" """Configure infinoted."""
Configuration helper for infinoted.
"""
import argparse
import grp import grp
import os import os
import pwd import pwd
@ -13,6 +9,7 @@ import subprocess
import time import time
from plinth import action_utils from plinth import action_utils
from plinth.actions import privileged
DATA_DIR = '/var/lib/infinoted' DATA_DIR = '/var/lib/infinoted'
KEY_DIR = '/etc/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(): def _kill_daemon():
"""Try to kill the infinoted daemon for upto 5 minutes.""" """Try to kill the infinoted daemon for upto 5 minutes."""
end_time = time.time() + 300 end_time = time.time() + 300
@ -127,7 +113,8 @@ def _kill_daemon():
time.sleep(1) time.sleep(1)
def subcommand_setup(_): @privileged
def setup():
"""Configure infinoted after install.""" """Configure infinoted after install."""
if not os.path.isfile(CONF_PATH): if not os.path.isfile(CONF_PATH):
with open(CONF_PATH, 'w', encoding='utf-8') as file_handle: with open(CONF_PATH, 'w', encoding='utf-8') as file_handle:
@ -180,16 +167,3 @@ def subcommand_setup(_):
group='infinoted') group='infinoted')
action_utils.service_enable('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()