Add config linting script that checks for bool casing (#6203)

Add a linting script that enforces all boolean values in the default config be lowercase.

This has annoyed me for a while so I decided to fix it.
This commit is contained in:
Andrew Morgan 2019-10-23 13:22:54 +01:00 committed by GitHub
parent 7b6d99fa5a
commit 409c62b27b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 49 additions and 30 deletions

1
changelog.d/6203.misc Normal file
View File

@ -0,0 +1 @@
Enforce that all boolean configuration values are lowercase in CI.

View File

@ -86,7 +86,7 @@ pid_file: DATADIR/homeserver.pid
# Whether room invites to users on this server should be blocked # Whether room invites to users on this server should be blocked
# (except those sent by local server admins). The default is False. # (except those sent by local server admins). The default is False.
# #
#block_non_admin_invites: True #block_non_admin_invites: true
# Room searching # Room searching
# #
@ -239,7 +239,7 @@ listeners:
# Global blocking # Global blocking
# #
#hs_disabled: False #hs_disabled: false
#hs_disabled_message: 'Human readable reason for why the HS is blocked' #hs_disabled_message: 'Human readable reason for why the HS is blocked'
#hs_disabled_limit_type: 'error code(str), to help clients decode reason' #hs_disabled_limit_type: 'error code(str), to help clients decode reason'
@ -261,7 +261,7 @@ listeners:
# sign up in a short space of time never to return after their initial # sign up in a short space of time never to return after their initial
# session. # session.
# #
#limit_usage_by_mau: False #limit_usage_by_mau: false
#max_mau_value: 50 #max_mau_value: 50
#mau_trial_days: 2 #mau_trial_days: 2
@ -269,7 +269,7 @@ listeners:
# be populated, however no one will be limited. If limit_usage_by_mau # be populated, however no one will be limited. If limit_usage_by_mau
# is true, this is implied to be true. # is true, this is implied to be true.
# #
#mau_stats_only: False #mau_stats_only: false
# Sometimes the server admin will want to ensure certain accounts are # Sometimes the server admin will want to ensure certain accounts are
# never blocked by mau checking. These accounts are specified here. # never blocked by mau checking. These accounts are specified here.
@ -294,7 +294,7 @@ listeners:
# #
# Uncomment the below lines to enable: # Uncomment the below lines to enable:
#limit_remote_rooms: #limit_remote_rooms:
# enabled: True # enabled: true
# complexity: 1.0 # complexity: 1.0
# complexity_error: "This room is too complex." # complexity_error: "This room is too complex."
@ -411,7 +411,7 @@ acme:
# ACME support is disabled by default. Set this to `true` and uncomment # ACME support is disabled by default. Set this to `true` and uncomment
# tls_certificate_path and tls_private_key_path above to enable it. # tls_certificate_path and tls_private_key_path above to enable it.
# #
enabled: False enabled: false
# Endpoint to use to request certificates. If you only want to test, # Endpoint to use to request certificates. If you only want to test,
# use Let's Encrypt's staging url: # use Let's Encrypt's staging url:
@ -786,7 +786,7 @@ uploads_path: "DATADIR/uploads"
# connect to arbitrary endpoints without having first signed up for a # connect to arbitrary endpoints without having first signed up for a
# valid account (e.g. by passing a CAPTCHA). # valid account (e.g. by passing a CAPTCHA).
# #
#turn_allow_guests: True #turn_allow_guests: true
## Registration ## ## Registration ##
@ -829,7 +829,7 @@ uploads_path: "DATADIR/uploads"
# where d is equal to 10% of the validity period. # where d is equal to 10% of the validity period.
# #
#account_validity: #account_validity:
# enabled: True # enabled: true
# period: 6w # period: 6w
# renew_at: 1w # renew_at: 1w
# renew_email_subject: "Renew your %(app)s account" # renew_email_subject: "Renew your %(app)s account"
@ -971,7 +971,7 @@ account_threepid_delegates:
# Enable collection and rendering of performance metrics # Enable collection and rendering of performance metrics
# #
#enable_metrics: False #enable_metrics: false
# Enable sentry integration # Enable sentry integration
# NOTE: While attempts are made to ensure that the logs don't contain # NOTE: While attempts are made to ensure that the logs don't contain
@ -1023,7 +1023,7 @@ metrics_flags:
# Uncomment to enable tracking of application service IP addresses. Implicitly # Uncomment to enable tracking of application service IP addresses. Implicitly
# enables MAU tracking for application service users. # enables MAU tracking for application service users.
# #
#track_appservice_user_ips: True #track_appservice_user_ips: true
# a secret which is used to sign access tokens. If none is specified, # a secret which is used to sign access tokens. If none is specified,
@ -1149,7 +1149,7 @@ saml2_config:
# - url: https://our_idp/metadata.xml # - url: https://our_idp/metadata.xml
# #
# # By default, the user has to go to our login page first. If you'd like # # By default, the user has to go to our login page first. If you'd like
# # to allow IdP-initiated login, set 'allow_unsolicited: True' in a # # to allow IdP-initiated login, set 'allow_unsolicited: true' in a
# # 'service.sp' section: # # 'service.sp' section:
# # # #
# #service: # #service:
@ -1263,13 +1263,13 @@ password_config:
# smtp_port: 25 # SSL: 465, STARTTLS: 587 # smtp_port: 25 # SSL: 465, STARTTLS: 587
# smtp_user: "exampleusername" # smtp_user: "exampleusername"
# smtp_pass: "examplepassword" # smtp_pass: "examplepassword"
# require_transport_security: False # require_transport_security: false
# notif_from: "Your Friendly %(app)s Home Server <noreply@example.com>" # notif_from: "Your Friendly %(app)s Home Server <noreply@example.com>"
# app_name: Matrix # app_name: Matrix
# #
# # Enable email notifications by default # # Enable email notifications by default
# # # #
# notif_for_new_users: True # notif_for_new_users: true
# #
# # Defining a custom URL for Riot is only needed if email notifications # # Defining a custom URL for Riot is only needed if email notifications
# # should contain links to a self-hosted installation of Riot; when set # # should contain links to a self-hosted installation of Riot; when set
@ -1447,11 +1447,11 @@ password_config:
# body: >- # body: >-
# To continue using this homeserver you must review and agree to the # To continue using this homeserver you must review and agree to the
# terms and conditions at %(consent_uri)s # terms and conditions at %(consent_uri)s
# send_server_notice_to_guests: True # send_server_notice_to_guests: true
# block_events_error: >- # block_events_error: >-
# To continue using this homeserver you must review and agree to the # To continue using this homeserver you must review and agree to the
# terms and conditions at %(consent_uri)s # terms and conditions at %(consent_uri)s
# require_at_registration: False # require_at_registration: false
# policy_name: Privacy Policy # policy_name: Privacy Policy
# #

9
scripts-dev/config-lint.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
# Find linting errors in Synapse's default config file.
# Exits with 0 if there are no problems, or another code otherwise.
# Fix non-lowercase true/false values
sed -i -E "s/: +True/: true/g; s/: +False/: false/g;" docs/sample_config.yaml
# Check if anything changed
git diff --exit-code docs/sample_config.yaml

View File

@ -10,3 +10,4 @@ set -e
isort -y -rc synapse tests scripts-dev scripts isort -y -rc synapse tests scripts-dev scripts
flake8 synapse tests flake8 synapse tests
python3 -m black synapse tests scripts-dev scripts python3 -m black synapse tests scripts-dev scripts
./scripts-dev/config-lint.sh

View File

@ -48,7 +48,7 @@ class AppServiceConfig(Config):
# Uncomment to enable tracking of application service IP addresses. Implicitly # Uncomment to enable tracking of application service IP addresses. Implicitly
# enables MAU tracking for application service users. # enables MAU tracking for application service users.
# #
#track_appservice_user_ips: True #track_appservice_user_ips: true
""" """

View File

@ -62,11 +62,11 @@ DEFAULT_CONFIG = """\
# body: >- # body: >-
# To continue using this homeserver you must review and agree to the # To continue using this homeserver you must review and agree to the
# terms and conditions at %(consent_uri)s # terms and conditions at %(consent_uri)s
# send_server_notice_to_guests: True # send_server_notice_to_guests: true
# block_events_error: >- # block_events_error: >-
# To continue using this homeserver you must review and agree to the # To continue using this homeserver you must review and agree to the
# terms and conditions at %(consent_uri)s # terms and conditions at %(consent_uri)s
# require_at_registration: False # require_at_registration: false
# policy_name: Privacy Policy # policy_name: Privacy Policy
# #
""" """

View File

@ -304,13 +304,13 @@ class EmailConfig(Config):
# smtp_port: 25 # SSL: 465, STARTTLS: 587 # smtp_port: 25 # SSL: 465, STARTTLS: 587
# smtp_user: "exampleusername" # smtp_user: "exampleusername"
# smtp_pass: "examplepassword" # smtp_pass: "examplepassword"
# require_transport_security: False # require_transport_security: false
# notif_from: "Your Friendly %(app)s Home Server <noreply@example.com>" # notif_from: "Your Friendly %(app)s Home Server <noreply@example.com>"
# app_name: Matrix # app_name: Matrix
# #
# # Enable email notifications by default # # Enable email notifications by default
# # # #
# notif_for_new_users: True # notif_for_new_users: true
# #
# # Defining a custom URL for Riot is only needed if email notifications # # Defining a custom URL for Riot is only needed if email notifications
# # should contain links to a self-hosted installation of Riot; when set # # should contain links to a self-hosted installation of Riot; when set

View File

@ -70,7 +70,7 @@ class MetricsConfig(Config):
# Enable collection and rendering of performance metrics # Enable collection and rendering of performance metrics
# #
#enable_metrics: False #enable_metrics: false
# Enable sentry integration # Enable sentry integration
# NOTE: While attempts are made to ensure that the logs don't contain # NOTE: While attempts are made to ensure that the logs don't contain

View File

@ -180,7 +180,7 @@ class RegistrationConfig(Config):
# where d is equal to 10%% of the validity period. # where d is equal to 10%% of the validity period.
# #
#account_validity: #account_validity:
# enabled: True # enabled: true
# period: 6w # period: 6w
# renew_at: 1w # renew_at: 1w
# renew_email_subject: "Renew your %%(app)s account" # renew_email_subject: "Renew your %%(app)s account"

View File

@ -176,7 +176,7 @@ class SAML2Config(Config):
# - url: https://our_idp/metadata.xml # - url: https://our_idp/metadata.xml
# #
# # By default, the user has to go to our login page first. If you'd like # # By default, the user has to go to our login page first. If you'd like
# # to allow IdP-initiated login, set 'allow_unsolicited: True' in a # # to allow IdP-initiated login, set 'allow_unsolicited: true' in a
# # 'service.sp' section: # # 'service.sp' section:
# # # #
# #service: # #service:

View File

@ -532,7 +532,7 @@ class ServerConfig(Config):
# Whether room invites to users on this server should be blocked # Whether room invites to users on this server should be blocked
# (except those sent by local server admins). The default is False. # (except those sent by local server admins). The default is False.
# #
#block_non_admin_invites: True #block_non_admin_invites: true
# Room searching # Room searching
# #
@ -673,7 +673,7 @@ class ServerConfig(Config):
# Global blocking # Global blocking
# #
#hs_disabled: False #hs_disabled: false
#hs_disabled_message: 'Human readable reason for why the HS is blocked' #hs_disabled_message: 'Human readable reason for why the HS is blocked'
#hs_disabled_limit_type: 'error code(str), to help clients decode reason' #hs_disabled_limit_type: 'error code(str), to help clients decode reason'
@ -695,7 +695,7 @@ class ServerConfig(Config):
# sign up in a short space of time never to return after their initial # sign up in a short space of time never to return after their initial
# session. # session.
# #
#limit_usage_by_mau: False #limit_usage_by_mau: false
#max_mau_value: 50 #max_mau_value: 50
#mau_trial_days: 2 #mau_trial_days: 2
@ -703,7 +703,7 @@ class ServerConfig(Config):
# be populated, however no one will be limited. If limit_usage_by_mau # be populated, however no one will be limited. If limit_usage_by_mau
# is true, this is implied to be true. # is true, this is implied to be true.
# #
#mau_stats_only: False #mau_stats_only: false
# Sometimes the server admin will want to ensure certain accounts are # Sometimes the server admin will want to ensure certain accounts are
# never blocked by mau checking. These accounts are specified here. # never blocked by mau checking. These accounts are specified here.
@ -728,7 +728,7 @@ class ServerConfig(Config):
# #
# Uncomment the below lines to enable: # Uncomment the below lines to enable:
#limit_remote_rooms: #limit_remote_rooms:
# enabled: True # enabled: true
# complexity: 1.0 # complexity: 1.0
# complexity_error: "This room is too complex." # complexity_error: "This room is too complex."

View File

@ -289,6 +289,9 @@ class TlsConfig(Config):
"http://localhost:8009/.well-known/acme-challenge" "http://localhost:8009/.well-known/acme-challenge"
) )
# flake8 doesn't recognise that variables are used in the below string
_ = tls_enabled, proxypassline, acme_enabled, default_acme_account_file
return ( return (
"""\ """\
## TLS ## ## TLS ##
@ -451,7 +454,11 @@ class TlsConfig(Config):
#tls_fingerprints: [{"sha256": "<base64_encoded_sha256_fingerprint>"}] #tls_fingerprints: [{"sha256": "<base64_encoded_sha256_fingerprint>"}]
""" """
% locals() # Lowercase the string representation of boolean values
% {
x[0]: str(x[1]).lower() if isinstance(x[1], bool) else x[1]
for x in locals().items()
}
) )
def read_tls_certificate(self): def read_tls_certificate(self):

View File

@ -56,5 +56,5 @@ class VoipConfig(Config):
# connect to arbitrary endpoints without having first signed up for a # connect to arbitrary endpoints without having first signed up for a
# valid account (e.g. by passing a CAPTCHA). # valid account (e.g. by passing a CAPTCHA).
# #
#turn_allow_guests: True #turn_allow_guests: true
""" """

View File

@ -118,6 +118,7 @@ deps =
commands = commands =
python -m black --check --diff . python -m black --check --diff .
/bin/sh -c "flake8 synapse tests scripts scripts-dev scripts/hash_password scripts/register_new_matrix_user scripts/synapse_port_db synctl {env:PEP8SUFFIX:}" /bin/sh -c "flake8 synapse tests scripts scripts-dev scripts/hash_password scripts/register_new_matrix_user scripts/synapse_port_db synctl {env:PEP8SUFFIX:}"
{toxinidir}/scripts-dev/config-lint.sh
[testenv:check_isort] [testenv:check_isort]
skip_install = True skip_install = True