mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-13 10:30:16 +00:00
matrix-synapse: Fix YAML format issues.
/etc/matrix-synapse/homeserver.yaml file has several complex cases of inline comments which are introducing bugs when parsed with ruamel.yaml Eliminated the problem by discarding comments altogether since the YAML data is only read by Plinth and not by a human. Closes #1214 Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
b221e60575
commit
45c23068db
@ -16,14 +16,13 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Configuration helper for Matrix-Synapse server.
|
Configuration helper for Matrix-Synapse server.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from ruamel.yaml import round_trip_dump, round_trip_load
|
import yaml
|
||||||
from ruamel.yaml.scalarstring import DoubleQuotedScalarString
|
|
||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
from plinth.modules.matrixsynapse import CONFIG_FILE_PATH
|
from plinth.modules.matrixsynapse import CONFIG_FILE_PATH
|
||||||
|
|
||||||
@ -37,7 +36,7 @@ def parse_arguments():
|
|||||||
subparsers.add_parser('enable', help='Enable matrix-synapse service')
|
subparsers.add_parser('enable', help='Enable matrix-synapse service')
|
||||||
subparsers.add_parser('disable', help='Disable matrix-synapse service')
|
subparsers.add_parser('disable', help='Disable matrix-synapse service')
|
||||||
help_pubreg = 'Enable/Disable/Status public user registration.'
|
help_pubreg = 'Enable/Disable/Status public user registration.'
|
||||||
pubreg = subparsers.add_parser('public_registration', help=help_pubreg)
|
pubreg = subparsers.add_parser('public-registration', help=help_pubreg)
|
||||||
pubreg.add_argument('command', choices=('enable', 'disable', 'status'),
|
pubreg.add_argument('command', choices=('enable', 'disable', 'status'),
|
||||||
help=help_pubreg)
|
help=help_pubreg)
|
||||||
setup = subparsers.add_parser('setup', help='Set domain name for Matrix')
|
setup = subparsers.add_parser('setup', help='Set domain name for Matrix')
|
||||||
@ -52,7 +51,7 @@ def parse_arguments():
|
|||||||
def subcommand_post_install(_):
|
def subcommand_post_install(_):
|
||||||
"""Perform post installation configuration."""
|
"""Perform post installation configuration."""
|
||||||
with open(CONFIG_FILE_PATH) as config_file:
|
with open(CONFIG_FILE_PATH) as config_file:
|
||||||
config = round_trip_load(config_file)
|
config = yaml.load(config_file)
|
||||||
|
|
||||||
config['max_upload_size'] = '100M'
|
config['max_upload_size'] = '100M'
|
||||||
|
|
||||||
@ -61,24 +60,24 @@ def subcommand_post_install(_):
|
|||||||
listener['bind_address'] = '0.0.0.0'
|
listener['bind_address'] = '0.0.0.0'
|
||||||
|
|
||||||
# Setup ldap parameters
|
# Setup ldap parameters
|
||||||
__ = DoubleQuotedScalarString
|
|
||||||
config['password_providers'] = [{}]
|
config['password_providers'] = [{}]
|
||||||
config['password_providers'][0]['module'] = __(
|
config['password_providers'][0][
|
||||||
'ldap_auth_provider.LdapAuthProvider')
|
'module'] = 'ldap_auth_provider.LdapAuthProvider'
|
||||||
ldap_config = {
|
ldap_config = {
|
||||||
'enabled': True,
|
'enabled': True,
|
||||||
'uri': __('ldap://localhost:389'),
|
'uri': 'ldap://localhost:389',
|
||||||
'start_tls': False,
|
'start_tls': False,
|
||||||
'base': __('ou=users,dc=thisbox'),
|
'base': 'ou=users,dc=thisbox',
|
||||||
'attributes': {
|
'attributes': {
|
||||||
'uid': __('uid'),
|
'uid': 'uid',
|
||||||
'name': __('uid'),
|
'name': 'uid',
|
||||||
'mail': __('')
|
'mail': ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config['password_providers'][0]['config'] = ldap_config
|
config['password_providers'][0]['config'] = ldap_config
|
||||||
|
|
||||||
with open(CONFIG_FILE_PATH, 'w') as config_file:
|
with open(CONFIG_FILE_PATH, 'w') as config_file:
|
||||||
round_trip_dump(config, config_file)
|
yaml.dump(config, config_file)
|
||||||
|
|
||||||
if action_utils.service_is_running('matrix-synapse'):
|
if action_utils.service_is_running('matrix-synapse'):
|
||||||
action_utils.service_restart('matrix-synapse')
|
action_utils.service_restart('matrix-synapse')
|
||||||
@ -87,8 +86,9 @@ def subcommand_post_install(_):
|
|||||||
def subcommand_setup(arguments):
|
def subcommand_setup(arguments):
|
||||||
"""Configure the domain name for matrix-synapse package."""
|
"""Configure the domain name for matrix-synapse package."""
|
||||||
domain_name = arguments.domain_name
|
domain_name = arguments.domain_name
|
||||||
action_utils.dpkg_reconfigure('matrix-synapse',
|
action_utils.dpkg_reconfigure('matrix-synapse', {
|
||||||
{'server-name': domain_name})
|
'server-name': domain_name
|
||||||
|
})
|
||||||
subcommand_enable(arguments)
|
subcommand_enable(arguments)
|
||||||
|
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ def subcommand_disable(_):
|
|||||||
def subcommand_public_registration(argument):
|
def subcommand_public_registration(argument):
|
||||||
"""Enable/Disable/Status public user registration."""
|
"""Enable/Disable/Status public user registration."""
|
||||||
with open(CONFIG_FILE_PATH) as config_file:
|
with open(CONFIG_FILE_PATH) as config_file:
|
||||||
config = round_trip_load(config_file)
|
config = yaml.load(config_file)
|
||||||
|
|
||||||
if argument.command == 'status':
|
if argument.command == 'status':
|
||||||
if config['enable_registration']:
|
if config['enable_registration']:
|
||||||
@ -122,7 +122,7 @@ def subcommand_public_registration(argument):
|
|||||||
config['enable_registration'] = False
|
config['enable_registration'] = False
|
||||||
|
|
||||||
with open(CONFIG_FILE_PATH, 'w') as config_file:
|
with open(CONFIG_FILE_PATH, 'w') as config_file:
|
||||||
round_trip_dump(config, config_file)
|
yaml.dump(config, config_file)
|
||||||
|
|
||||||
if action_utils.service_is_running('matrix-synapse'):
|
if action_utils.service_is_running('matrix-synapse'):
|
||||||
action_utils.service_restart('matrix-synapse')
|
action_utils.service_restart('matrix-synapse')
|
||||||
|
|||||||
2
debian/control
vendored
2
debian/control
vendored
@ -35,6 +35,7 @@ Build-Depends: debhelper (>= 10~)
|
|||||||
, python3-ruamel.yaml
|
, python3-ruamel.yaml
|
||||||
, python3-setuptools
|
, python3-setuptools
|
||||||
, python3-setuptools-git
|
, python3-setuptools-git
|
||||||
|
, python3-yaml
|
||||||
, xmlto
|
, xmlto
|
||||||
Standards-Version: 4.1.2
|
Standards-Version: 4.1.2
|
||||||
Homepage: https://salsa.debian.org/freedombox-team/plinth
|
Homepage: https://salsa.debian.org/freedombox-team/plinth
|
||||||
@ -75,6 +76,7 @@ Depends: ${python3:Depends}
|
|||||||
, python3-psutil
|
, python3-psutil
|
||||||
, python3-requests
|
, python3-requests
|
||||||
, python3-ruamel.yaml
|
, python3-ruamel.yaml
|
||||||
|
, python3-yaml
|
||||||
, sudo
|
, sudo
|
||||||
Description: web front end for administering every aspect of a FreedomBox
|
Description: web front end for administering every aspect of a FreedomBox
|
||||||
The FreedomBox is a net appliance conceived by Eben Moglen. It
|
The FreedomBox is a net appliance conceived by Eben Moglen. It
|
||||||
|
|||||||
@ -158,6 +158,6 @@ def get_configured_domain_name():
|
|||||||
|
|
||||||
def get_public_registration_status():
|
def get_public_registration_status():
|
||||||
"""Return whether public registration is enabled."""
|
"""Return whether public registration is enabled."""
|
||||||
output = actions.superuser_run('matrixsynapse', ['public_registration',
|
output = actions.superuser_run('matrixsynapse',
|
||||||
'status'])
|
['public-registration', 'status'])
|
||||||
return output.strip() == 'enabled'
|
return output.strip() == 'enabled'
|
||||||
|
|||||||
@ -25,13 +25,13 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
from django.views.generic import FormView
|
from django.views.generic import FormView
|
||||||
|
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
from plinth.views import ServiceView
|
|
||||||
from plinth.modules import matrixsynapse
|
|
||||||
from plinth.forms import DomainSelectionForm
|
from plinth.forms import DomainSelectionForm
|
||||||
|
from plinth.modules import matrixsynapse
|
||||||
from plinth.utils import get_domain_names
|
from plinth.utils import get_domain_names
|
||||||
|
from plinth.views import ServiceView
|
||||||
|
|
||||||
from .forms import MatrixSynapseForm
|
|
||||||
from . import get_public_registration_status
|
from . import get_public_registration_status
|
||||||
|
from .forms import MatrixSynapseForm
|
||||||
|
|
||||||
|
|
||||||
class SetupView(FormView):
|
class SetupView(FormView):
|
||||||
@ -111,15 +111,15 @@ class MatrixSynapseServiceView(ServiceView):
|
|||||||
messages.success(self.request, _('Application disabled'))
|
messages.success(self.request, _('Application disabled'))
|
||||||
|
|
||||||
if not pubreg_same:
|
if not pubreg_same:
|
||||||
# note action public_registration restarts, if running now
|
# note action public-registration restarts, if running now
|
||||||
if new_config['enable_public_registration']:
|
if new_config['enable_public_registration']:
|
||||||
actions.superuser_run('matrixsynapse',
|
actions.superuser_run('matrixsynapse',
|
||||||
['public_registration', 'enable'])
|
['public-registration', 'enable'])
|
||||||
messages.success(self.request,
|
messages.success(self.request,
|
||||||
_('Public registration enabled'))
|
_('Public registration enabled'))
|
||||||
else:
|
else:
|
||||||
actions.superuser_run('matrixsynapse',
|
actions.superuser_run('matrixsynapse',
|
||||||
['public_registration', 'disable'])
|
['public-registration', 'disable'])
|
||||||
messages.success(self.request,
|
messages.success(self.request,
|
||||||
_('Public registration disabled'))
|
_('Public registration disabled'))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user