mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-06-10 11:00:22 +00:00
cockpit: Use decorator for privileged actions
Tests: - Login to Cockpit on a freshly setup container. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
c163601b6c
commit
99d8be9d2a
@ -6,7 +6,6 @@ FreedomBox app to configure Cockpit.
|
||||
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
|
||||
@ -16,7 +15,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 = [
|
||||
format_lazy(
|
||||
@ -94,6 +93,6 @@ class CockpitApp(app_module.App):
|
||||
def setup(helper, old_version=None):
|
||||
"""Install and configure the module."""
|
||||
app.setup(old_version)
|
||||
helper.call('post', actions.superuser_run, 'cockpit', ['setup'])
|
||||
helper.call('post', privileged.setup)
|
||||
if not old_version:
|
||||
helper.call('post', app.enable)
|
||||
|
||||
33
actions/cockpit → plinth/modules/cockpit/privileged.py
Executable file → Normal file
33
actions/cockpit → plinth/modules/cockpit/privileged.py
Executable file → Normal file
@ -1,29 +1,16 @@
|
||||
#!/usr/bin/python3
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""
|
||||
Configuration helper for Cockpit.
|
||||
Configure Cockpit.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
|
||||
import augeas
|
||||
|
||||
from plinth import action_utils
|
||||
from plinth.actions import privileged
|
||||
|
||||
CONFIG_FILE = '/etc/cockpit/cockpit.conf'
|
||||
|
||||
|
||||
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='Setup Cockpit configuration')
|
||||
|
||||
subparsers.required = True
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def _load_augeas():
|
||||
"""Initialize Augeas."""
|
||||
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
|
||||
@ -34,7 +21,8 @@ def _load_augeas():
|
||||
return aug
|
||||
|
||||
|
||||
def subcommand_setup(arguments):
|
||||
@privileged
|
||||
def setup():
|
||||
"""Setup Cockpit configuration."""
|
||||
aug = _load_augeas()
|
||||
aug.set('/files' + CONFIG_FILE + '/WebService/UrlRoot', '/_cockpit/')
|
||||
@ -43,16 +31,3 @@ def subcommand_setup(arguments):
|
||||
action_utils.service_restart('cockpit.socket')
|
||||
# Accommodate changes in Apache configuration file from v1 to v2.
|
||||
action_utils.service_reload('apache2')
|
||||
|
||||
|
||||
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