Skip to content

Commit b4022a6

Browse files
committed
Break the installation defaults out into their structure.
Add tests that assert the consistency of the options that are accepted by the generateconfs command line with the internal library function. Additionally assert that the library routine itself matches the defaults structure thus making the _structure_ the definitive source of truth. Doing so highlighted the following missing command line options which are added as of this commit: --seafile_secret --seafile_ccnetid
1 parent 7ec746c commit b4022a6

File tree

6 files changed

+292
-17
lines changed

6 files changed

+292
-17
lines changed

mig/install/__init__.py

Whitespace-only changes.

mig/install/generateconfs.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
# NOTE: moved mig imports into try/except to avoid autopep8 moving to top!
4949
try:
5050
from mig.shared.defaults import MIG_BASE, MIG_ENV
51-
from mig.shared.install import generate_confs
51+
from mig.shared.install import generate_confs, _GENERATE_CONFS_PARAMETERS
5252
except ImportError:
5353
print("ERROR: the migrid modules must be in PYTHONPATH")
5454
sys.exit(1)
@@ -65,7 +65,7 @@ def usage(options):
6565
''' % (sys.argv[0], '\n'.join(lines)))
6666

6767

68-
def main(argv, _generate_confs=generate_confs, _print=print):
68+
def _make_parameters():
6969
str_names = [
7070
'source',
7171
'destination',
@@ -248,6 +248,8 @@ def main(argv, _generate_confs=generate_confs, _print=print):
248248
'openid_port',
249249
'openid_show_port',
250250
'openid_session_lifetime',
251+
'seafile_secret',
252+
'seafile_ccnetid',
251253
'seafile_seahub_port',
252254
'seafile_seafhttp_port',
253255
'seafile_client_port',
@@ -305,7 +307,15 @@ def main(argv, _generate_confs=generate_confs, _print=print):
305307
'io_account_expire',
306308
'gdp_email_notify',
307309
]
308-
names = str_names + int_names + bool_names
310+
return (str_names, int_names, bool_names)
311+
312+
313+
str_names, int_names, bool_names = _make_parameters()
314+
_PARAMETERS = str_names + int_names + bool_names
315+
316+
317+
def main(argv, _generate_confs=generate_confs, _print=print):
318+
names = _PARAMETERS
309319
settings, options, result = {}, {}, {}
310320
default_val = 'DEFAULT'
311321
# Force values to expected type

mig/shared/compat.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from past.builtins import basestring
3535

3636
import codecs
37+
import inspect
3738
import io
3839
import sys
3940
# NOTE: StringIO is only available in python2
@@ -93,6 +94,15 @@ def ensure_native_string(string_or_bytes):
9394
return textual_output
9495

9596

97+
def inspect_args(func):
98+
"""Wrapper to return the arguments of a function."""
99+
100+
if PY2:
101+
return inspect.getargspec(func).args
102+
else:
103+
return inspect.getfullargspec(func).args
104+
105+
96106
def NativeStringIO(initial_value=''):
97107
"""Mock StringIO pseudo-class to create a StringIO matching the native
98108
string coding form. That is a BytesIO with utf8 on python 2 and unicode

mig/shared/install.py

Lines changed: 250 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@
5050
import sys
5151

5252
from mig.shared.base import force_native_str, force_utf8
53+
from mig.shared.compat import ensure_native_string, inspect_args, \
54+
SimpleNamespace
5355
from mig.shared.defaults import default_http_port, default_https_port, \
5456
auth_openid_mig_db, auth_openid_ext_db, MIG_BASE, STRONG_TLS_CIPHERS, \
5557
STRONG_TLS_CURVES, STRONG_SSH_HOSTKEYALGOS, STRONG_SSH_KEXALGOS, \
5658
STRONG_SSH_CIPHERS, STRONG_SSH_MACS, LEGACY_SSH_HOSTKEYALGOS, \
5759
LEGACY_SSH_KEXALGOS, LEGACY_SSH_CIPHERS, LEGACY_SSH_MACS, \
5860
FALLBACK_SSH_HOSTKEYALGOS, FALLBACK_SSH_KEXALGOS, FALLBACK_SSH_CIPHERS, \
59-
FALLBACK_SSH_MACS, CRACK_USERNAME_REGEX, CRACK_WEB_REGEX, keyword_any, \
60-
keyword_auto
61-
from mig.shared.compat import ensure_native_string
61+
FALLBACK_SSH_MACS, CRACK_USERNAME_REGEX, CRACK_WEB_REGEX, \
62+
keyword_any, keyword_auto
6263
from mig.shared.fileio import read_file, read_file_lines, write_file, \
6364
write_file_lines
6465
from mig.shared.htmlgen import menu_items
@@ -299,16 +300,7 @@ def template_remove(template_file, remove_pattern):
299300
]
300301

301302

302-
def generate_confs(
303-
generateconfs_output_path,
304-
# NOTE: make sure command line args with white-space are properly wrapped
305-
generateconfs_command=subprocess.list2cmdline(sys.argv),
306-
source=keyword_auto,
307-
destination=keyword_auto,
308-
user=keyword_auto,
309-
group=keyword_auto,
310-
timezone=keyword_auto,
311-
destination_suffix="",
303+
_DEFAULTS = SimpleNamespace(
312304
base_fqdn='',
313305
public_fqdn='',
314306
public_alias_fqdn='',
@@ -538,6 +530,248 @@ def generate_confs(
538530
datasafety_link='',
539531
datasafety_text='',
540532
wwwserve_max_bytes=-1,
533+
)
534+
535+
536+
def generate_confs(
537+
generateconfs_output_path,
538+
# NOTE: make sure command line args with white-space are properly wrapped
539+
generateconfs_command=subprocess.list2cmdline(sys.argv),
540+
source=keyword_auto,
541+
destination=keyword_auto,
542+
user=keyword_auto,
543+
group=keyword_auto,
544+
timezone=keyword_auto,
545+
destination_suffix="",
546+
base_fqdn=_DEFAULTS.base_fqdn,
547+
public_fqdn=_DEFAULTS.public_fqdn,
548+
public_alias_fqdn=_DEFAULTS.public_alias_fqdn,
549+
public_sec_fqdn=_DEFAULTS.public_sec_fqdn,
550+
status_alias_fqdn=_DEFAULTS.status_alias_fqdn,
551+
mig_cert_fqdn=_DEFAULTS.mig_cert_fqdn,
552+
ext_cert_fqdn=_DEFAULTS.ext_cert_fqdn,
553+
mig_oid_fqdn=_DEFAULTS.mig_oid_fqdn,
554+
ext_oid_fqdn=_DEFAULTS.ext_oid_fqdn,
555+
mig_oidc_fqdn=_DEFAULTS.mig_oidc_fqdn,
556+
ext_oidc_fqdn=_DEFAULTS.ext_oidc_fqdn,
557+
sid_fqdn=_DEFAULTS.sid_fqdn,
558+
io_fqdn=_DEFAULTS.io_fqdn,
559+
cert_fqdn_extras=_DEFAULTS.cert_fqdn_extras,
560+
cloud_fqdn=_DEFAULTS.cloud_fqdn,
561+
seafile_fqdn=_DEFAULTS.seafile_fqdn,
562+
seafile_base=_DEFAULTS.seafile_base,
563+
seafmedia_base=_DEFAULTS.seafmedia_base,
564+
seafhttp_base=_DEFAULTS.seafhttp_base,
565+
openid_address=_DEFAULTS.openid_address,
566+
sftp_address=_DEFAULTS.sftp_address,
567+
sftp_subsys_address=_DEFAULTS.sftp_subsys_address,
568+
ftps_address=_DEFAULTS.ftps_address,
569+
davs_address=_DEFAULTS.davs_address,
570+
jupyter_services=_DEFAULTS.jupyter_services,
571+
jupyter_services_desc=_DEFAULTS.jupyter_services_desc,
572+
jupyter_services_enable_proxy_https=_DEFAULTS.jupyter_services_enable_proxy_https,
573+
jupyter_services_proxy_config=_DEFAULTS.jupyter_services_proxy_config,
574+
cloud_services=_DEFAULTS.cloud_services,
575+
cloud_services_desc=_DEFAULTS.cloud_services_desc,
576+
apache_version=_DEFAULTS.apache_version,
577+
apache_etc=_DEFAULTS.apache_etc,
578+
apache_run=_DEFAULTS.apache_run,
579+
apache_lock=_DEFAULTS.apache_lock,
580+
apache_log=_DEFAULTS.apache_log,
581+
apache_worker_procs=_DEFAULTS.apache_worker_procs,
582+
openssh_version=_DEFAULTS.openssh_version,
583+
mig_code=_DEFAULTS.mig_code,
584+
mig_state=_DEFAULTS.mig_state,
585+
mig_certs=_DEFAULTS.mig_certs,
586+
auto_add_cert_user=_DEFAULTS.auto_add_cert_user,
587+
auto_add_oid_user=_DEFAULTS.auto_add_oid_user,
588+
auto_add_oidc_user=_DEFAULTS.auto_add_oidc_user,
589+
auto_add_filter_fields=_DEFAULTS.auto_add_filter_fields,
590+
auto_add_filter_method=_DEFAULTS.auto_add_filter_method,
591+
auto_add_user_permit=_DEFAULTS.auto_add_user_permit,
592+
auto_add_user_with_peer=_DEFAULTS.auto_add_user_with_peer,
593+
cert_valid_days=_DEFAULTS.cert_valid_days,
594+
oid_valid_days=_DEFAULTS.oid_valid_days,
595+
oidc_valid_days=_DEFAULTS.oidc_valid_days,
596+
generic_valid_days=_DEFAULTS.generic_valid_days,
597+
enable_migadmin=_DEFAULTS.enable_migadmin,
598+
enable_sftp=_DEFAULTS.enable_sftp,
599+
enable_sftp_subsys=_DEFAULTS.enable_sftp_subsys,
600+
sftp_subsys_auth_procs=_DEFAULTS.sftp_subsys_auth_procs,
601+
enable_davs=_DEFAULTS.enable_davs,
602+
enable_ftps=_DEFAULTS.enable_ftps,
603+
enable_wsgi=_DEFAULTS.enable_wsgi,
604+
wsgi_procs=_DEFAULTS.wsgi_procs,
605+
enable_gdp=_DEFAULTS.enable_gdp,
606+
enable_jobs=_DEFAULTS.enable_jobs,
607+
enable_resources=_DEFAULTS.enable_resources,
608+
enable_workflows=_DEFAULTS.enable_workflows,
609+
enable_events=_DEFAULTS.enable_events,
610+
enable_sharelinks=_DEFAULTS.enable_sharelinks,
611+
enable_transfers=_DEFAULTS.enable_transfers,
612+
enable_freeze=_DEFAULTS.enable_freeze,
613+
enable_sandboxes=_DEFAULTS.enable_sandboxes,
614+
enable_vmachines=_DEFAULTS.enable_vmachines,
615+
enable_preview=_DEFAULTS.enable_preview,
616+
enable_jupyter=_DEFAULTS.enable_jupyter,
617+
enable_cloud=_DEFAULTS.enable_cloud,
618+
enable_hsts=_DEFAULTS.enable_hsts,
619+
enable_vhost_certs=_DEFAULTS.enable_vhost_certs,
620+
enable_verify_certs=_DEFAULTS.enable_verify_certs,
621+
enable_seafile=_DEFAULTS.enable_seafile,
622+
enable_duplicati=_DEFAULTS.enable_duplicati,
623+
enable_crontab=_DEFAULTS.enable_crontab,
624+
enable_notify=_DEFAULTS.enable_notify,
625+
enable_imnotify=_DEFAULTS.enable_imnotify,
626+
enable_dev_accounts=_DEFAULTS.enable_dev_accounts,
627+
enable_twofactor=_DEFAULTS.enable_twofactor,
628+
twofactor_mandatory_protos=_DEFAULTS.twofactor_mandatory_protos,
629+
enable_twofactor_strict_address=_DEFAULTS.enable_twofactor_strict_address,
630+
twofactor_auth_apps=_DEFAULTS.twofactor_auth_apps,
631+
enable_peers=_DEFAULTS.enable_peers,
632+
peers_mandatory=_DEFAULTS.peers_mandatory,
633+
peers_explicit_fields=_DEFAULTS.peers_explicit_fields,
634+
peers_contact_hint=_DEFAULTS.peers_contact_hint,
635+
enable_cracklib=_DEFAULTS.enable_cracklib,
636+
enable_openid=_DEFAULTS.enable_openid,
637+
enable_gravatars=_DEFAULTS.enable_gravatars,
638+
enable_sitestatus=_DEFAULTS.enable_sitestatus,
639+
enable_quota=_DEFAULTS.enable_quota,
640+
prefer_python3=_DEFAULTS.prefer_python3,
641+
io_account_expire=_DEFAULTS.io_account_expire,
642+
gdp_email_notify=_DEFAULTS.gdp_email_notify,
643+
user_interface=_DEFAULTS.user_interface,
644+
mig_oid_title=_DEFAULTS.mig_oid_title,
645+
mig_oid_provider=_DEFAULTS.mig_oid_provider,
646+
ext_oid_title=_DEFAULTS.ext_oid_title,
647+
ext_oid_provider=_DEFAULTS.ext_oid_provider,
648+
mig_oidc_title=_DEFAULTS.mig_oidc_title,
649+
mig_oidc_provider_meta_url=_DEFAULTS.mig_oidc_provider_meta_url,
650+
ext_oidc_title=_DEFAULTS.ext_oidc_title,
651+
ext_oidc_provider_meta_url=_DEFAULTS.ext_oidc_provider_meta_url,
652+
ext_oidc_provider_issuer=_DEFAULTS.ext_oidc_provider_issuer,
653+
ext_oidc_provider_authorization_endpoint=_DEFAULTS.ext_oidc_provider_authorization_endpoint,
654+
ext_oidc_provider_verify_cert_files=_DEFAULTS.ext_oidc_provider_verify_cert_files,
655+
ext_oidc_provider_token_endpoint=_DEFAULTS.ext_oidc_provider_token_endpoint,
656+
ext_oidc_provider_token_endpoint_auth=_DEFAULTS.ext_oidc_provider_token_endpoint_auth,
657+
ext_oidc_provider_user_info_endpoint=_DEFAULTS.ext_oidc_provider_user_info_endpoint,
658+
ext_oidc_scope=_DEFAULTS.ext_oidc_scope,
659+
ext_oidc_user_info_token_method=_DEFAULTS.ext_oidc_user_info_token_method,
660+
ext_oidc_public_key_files=_DEFAULTS.ext_oidc_public_key_files,
661+
ext_oidc_private_key_files=_DEFAULTS.ext_oidc_private_key_files,
662+
ext_oidc_response_type=_DEFAULTS.ext_oidc_response_type,
663+
ext_oidc_response_mode=_DEFAULTS.ext_oidc_response_mode,
664+
ext_oidc_client_id=_DEFAULTS.ext_oidc_client_id,
665+
ext_oidc_client_name=_DEFAULTS.ext_oidc_client_name,
666+
ext_oidc_pkce_method=_DEFAULTS.ext_oidc_pkce_method,
667+
ext_oidc_id_token_encrypted_response_alg=_DEFAULTS.ext_oidc_id_token_encrypted_response_alg,
668+
ext_oidc_id_token_encrypted_response_enc=_DEFAULTS.ext_oidc_id_token_encrypted_response_enc,
669+
ext_oidc_user_info_signed_response_alg=_DEFAULTS.ext_oidc_user_info_signed_response_alg,
670+
ext_oidc_cookie_same_site=_DEFAULTS.ext_oidc_cookie_same_site,
671+
ext_oidc_pass_cookies=_DEFAULTS.ext_oidc_pass_cookies,
672+
ext_oidc_remote_user_claim=_DEFAULTS.ext_oidc_remote_user_claim,
673+
ext_oidc_pass_claim_as=_DEFAULTS.ext_oidc_pass_claim_as,
674+
ext_oidc_rewrite_cookie=_DEFAULTS.ext_oidc_rewrite_cookie,
675+
dhparams_path=_DEFAULTS.dhparams_path,
676+
daemon_keycert=_DEFAULTS.daemon_keycert,
677+
daemon_keycert_sha256=_DEFAULTS.daemon_keycert_sha256,
678+
daemon_pubkey=_DEFAULTS.daemon_pubkey,
679+
daemon_pubkey_from_dns=_DEFAULTS.daemon_pubkey_from_dns,
680+
daemon_pubkey_md5=_DEFAULTS.daemon_pubkey_md5,
681+
daemon_pubkey_sha256=_DEFAULTS.daemon_pubkey_sha256,
682+
daemon_show_address=_DEFAULTS.daemon_show_address,
683+
alias_field=_DEFAULTS.alias_field,
684+
peers_permit=_DEFAULTS.peers_permit,
685+
vgrid_creators=_DEFAULTS.vgrid_creators,
686+
vgrid_managers=_DEFAULTS.vgrid_managers,
687+
signup_methods=_DEFAULTS.signup_methods,
688+
login_methods=_DEFAULTS.login_methods,
689+
digest_salt=_DEFAULTS.digest_salt,
690+
crypto_salt=_DEFAULTS.crypto_salt,
691+
csrf_protection=_DEFAULTS.csrf_protection,
692+
password_policy=_DEFAULTS.password_policy,
693+
password_legacy_policy=_DEFAULTS.password_legacy_policy,
694+
hg_path=_DEFAULTS.hg_path,
695+
hgweb_scripts=_DEFAULTS.hgweb_scripts,
696+
trac_admin_path=_DEFAULTS.trac_admin_path,
697+
trac_ini_path=_DEFAULTS.trac_ini_path,
698+
public_port=_DEFAULTS.public_port,
699+
public_http_port=_DEFAULTS.public_http_port,
700+
public_https_port=_DEFAULTS.public_https_port,
701+
mig_cert_port=_DEFAULTS.mig_cert_port,
702+
ext_cert_port=_DEFAULTS.ext_cert_port,
703+
mig_oid_port=_DEFAULTS.mig_oid_port,
704+
ext_oid_port=_DEFAULTS.ext_oid_port,
705+
mig_oidc_port=_DEFAULTS.mig_oidc_port,
706+
ext_oidc_port=_DEFAULTS.ext_oidc_port,
707+
sid_port=_DEFAULTS.sid_port,
708+
sftp_port=_DEFAULTS.sftp_port,
709+
sftp_subsys_port=_DEFAULTS.sftp_subsys_port,
710+
sftp_show_port=_DEFAULTS.sftp_show_port,
711+
sftp_max_sessions=_DEFAULTS.sftp_max_sessions,
712+
davs_port=_DEFAULTS.davs_port,
713+
davs_show_port=_DEFAULTS.davs_show_port,
714+
ftps_ctrl_port=_DEFAULTS.ftps_ctrl_port,
715+
ftps_ctrl_show_port=_DEFAULTS.ftps_ctrl_show_port,
716+
ftps_pasv_ports=_DEFAULTS.ftps_pasv_ports,
717+
openid_port=_DEFAULTS.openid_port,
718+
openid_show_port=_DEFAULTS.openid_show_port,
719+
openid_session_lifetime=_DEFAULTS.openid_session_lifetime,
720+
seafile_secret=_DEFAULTS.seafile_secret,
721+
seafile_ccnetid=_DEFAULTS.seafile_ccnetid,
722+
seafile_seahub_port=_DEFAULTS.seafile_seahub_port,
723+
seafile_seafhttp_port=_DEFAULTS.seafile_seafhttp_port,
724+
seafile_client_port=_DEFAULTS.seafile_client_port,
725+
seafile_quota=_DEFAULTS.seafile_quota,
726+
seafile_ro_access=_DEFAULTS.seafile_ro_access,
727+
public_use_https=_DEFAULTS.public_use_https,
728+
user_clause=_DEFAULTS.user_clause,
729+
group_clause=_DEFAULTS.group_clause,
730+
listen_clause=_DEFAULTS.listen_clause,
731+
serveralias_clause=_DEFAULTS.serveralias_clause,
732+
distro=_DEFAULTS.distro,
733+
autolaunch_page=_DEFAULTS.autolaunch_page,
734+
landing_page=_DEFAULTS.landing_page,
735+
skin=_DEFAULTS.skin,
736+
title=_DEFAULTS.title,
737+
short_title=_DEFAULTS.short_title,
738+
extra_userpage_scripts=_DEFAULTS.extra_userpage_scripts,
739+
extra_userpage_styles=_DEFAULTS.extra_userpage_styles,
740+
external_doc=_DEFAULTS.external_doc,
741+
vgrid_label=_DEFAULTS.vgrid_label,
742+
secscan_addr=_DEFAULTS.secscan_addr,
743+
default_menu=_DEFAULTS.default_menu,
744+
user_menu=_DEFAULTS.user_menu,
745+
collaboration_links=_DEFAULTS.collaboration_links,
746+
default_vgrid_links=_DEFAULTS.default_vgrid_links,
747+
advanced_vgrid_links=_DEFAULTS.advanced_vgrid_links,
748+
support_email=_DEFAULTS.support_email,
749+
admin_email=_DEFAULTS.admin_email,
750+
admin_list=_DEFAULTS.admin_list,
751+
smtp_server=_DEFAULTS.smtp_server,
752+
smtp_sender=_DEFAULTS.smtp_sender,
753+
permanent_freeze=_DEFAULTS.permanent_freeze,
754+
log_level=_DEFAULTS.log_level,
755+
freeze_to_tape=_DEFAULTS.freeze_to_tape,
756+
status_system_match=_DEFAULTS.status_system_match,
757+
storage_protocols=_DEFAULTS.storage_protocols,
758+
duplicati_protocols=_DEFAULTS.duplicati_protocols,
759+
imnotify_address=_DEFAULTS.imnotify_address,
760+
imnotify_channel=_DEFAULTS.imnotify_channel,
761+
imnotify_username=_DEFAULTS.imnotify_username,
762+
imnotify_password=_DEFAULTS.imnotify_password,
763+
gdp_data_categories=_DEFAULTS.gdp_data_categories,
764+
gdp_id_scramble=_DEFAULTS.gdp_id_scramble,
765+
gdp_path_scramble=_DEFAULTS.gdp_path_scramble,
766+
quota_backend=_DEFAULTS.quota_backend,
767+
quota_user_limit=_DEFAULTS.quota_user_limit,
768+
quota_vgrid_limit=_DEFAULTS.quota_vgrid_limit,
769+
ca_fqdn=_DEFAULTS.ca_fqdn,
770+
ca_user=_DEFAULTS.ca_user,
771+
ca_smtp=_DEFAULTS.ca_smtp,
772+
datasafety_link=_DEFAULTS.datasafety_link,
773+
datasafety_text=_DEFAULTS.datasafety_text,
774+
wwwserve_max_bytes=_DEFAULTS.wwwserve_max_bytes,
541775
_getpwnam=pwd.getpwnam,
542776
_prepare=None,
543777
_writefiles=None,
@@ -630,6 +864,9 @@ def generate_confs(
630864
return (options, user_dict)
631865

632866

867+
_GENERATE_CONFS_PARAMETERS = set(inspect_args(generate_confs)) - set(_GENERATE_CONFS_NOFORWARD_KEYS)
868+
869+
633870
def _generate_confs_prepare(
634871
options,
635872
# forwarded arguments

tests/test_mig_install_generateconfs.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
from tests.support import MIG_BASE, MigTestCase, testmain, cleanpath
3737

38+
from mig.install.generateconfs import _PARAMETERS
39+
from mig.shared.install import generate_confs, _GENERATE_CONFS_PARAMETERS
3840

3941
def _import_generateconfs():
4042
"""Internal helper to work around non-package import location"""
@@ -65,6 +67,13 @@ def noop(*args):
6567
pass
6668

6769

70+
class MigInstallGenerateconfs(MigTestCase):
71+
def test_consistent_parameters(self):
72+
mismatched = _GENERATE_CONFS_PARAMETERS - set(_PARAMETERS)
73+
self.assertEqual(len(mismatched), 0,
74+
"defined parameters do not match generate_confs()")
75+
76+
6877
class MigInstallGenerateconfs__main(MigTestCase):
6978
"""Unit test helper for the migrid code pointed to in class name"""
7079

0 commit comments

Comments
 (0)