From f794413b68eef3e6af565b7aaf7f7011fdfdcaac Mon Sep 17 00:00:00 2001 From: Sebastian Simon Date: Fri, 23 Jun 2023 08:57:01 +0200 Subject: [PATCH] Update config types in spring and docker-compose plugin --- .../config_types/config_type_inferer.py | 2 +- .../plugins/concept/docker_compose_plugin.py | 119 ++++++++++-------- src/cfgnet/plugins/concept/spring_plugin.py | 64 +++++----- .../plugins/concept/test_postgresql_plugin.py | 4 +- 4 files changed, 96 insertions(+), 93 deletions(-) diff --git a/src/cfgnet/config_types/config_type_inferer.py b/src/cfgnet/config_types/config_type_inferer.py index b0b219d..2939dfb 100644 --- a/src/cfgnet/config_types/config_type_inferer.py +++ b/src/cfgnet/config_types/config_type_inferer.py @@ -50,7 +50,7 @@ class ConfigTypeInferer: ) regex_time_value = re.compile(r"[\d]+ ?(s|min|h|d|ms)*") regex_filepath_option = re.compile( - r"file|path|dir|directory|folder|destination" + r"path|dir|directory|folder|destination" ) # regex_filepath_value = re.compile(r"\/?([^\/]+\/)+[^\/]*") regex_filepath_value = re.compile(r"^([~.\w\d]*\/[.\w\d]+)+(\.[\w\d]+)*$") diff --git a/src/cfgnet/plugins/concept/docker_compose_plugin.py b/src/cfgnet/plugins/concept/docker_compose_plugin.py index 8c6ba9d..e7c9036 100644 --- a/src/cfgnet/plugins/concept/docker_compose_plugin.py +++ b/src/cfgnet/plugins/concept/docker_compose_plugin.py @@ -96,85 +96,96 @@ def get_config_type(self, option_name: str) -> ConfigType: # noqa: C901 if option_name == "version": return ConfigType.VERSION_NUMBER - if option_name in ("ports", "port", "expose", "PORT", "tmpfs"): + if option_name.endswith(("ports", "port", "expose", "PORT", "tmpfs")): return ConfigType.PORT if option_name == "image": return ConfigType.IMAGE - if option_name == ("size", "weight", "height"): + if option_name.endswith(("size", "weight", "height")): return ConfigType.SIZE - if option_name in ("path", "file", "env_file"): + if option_name.endswith(("path", "env_file")): return ConfigType.PATH if option_name == "environment": return ConfigType.ENVIRONMENT - if option_name in ("command", "entrypoint", "test"): + if option_name.endswith(("command", "entrypoint", "test")): return ConfigType.COMMAND - if option_name in ( - "name", - "driver", - "labels", - "hostname", - "cap_add", - "cap_drop", - "cgroup_parent", - "source", - "container_name", - "depends_on", - "registry", - "service", - "external_links", + if option_name.endswith( + ( + "name", + "driver", + "labels", + "hostname", + "cap_add", + "cap_drop", + "cgroup_parent", + "source", + "container_name", + "depends_on", + "registry", + "service", + "external_links", + "build", + ) ): return ConfigType.NAME if option_name == "rate": return ConfigType.SPEED - if option_name in ( - "cpu_rt_runtime", - "cpu_rt_period", - "start_period", - "interval", - "timeout", - "stop_grace_period", + if option_name.endswith( + ( + "cpu_rt_runtime", + "cpu_rt_period", + "start_period", + "interval", + "timeout", + "stop_grace_period", + ) ): return ConfigType.TIME - if option_name in ( - "cpu_count", - "cpu_shares", - "uid", - "gid", - "retries", - "priority", - "pids_limit", - "sysctls", + if option_name.endswith( + ( + "cpu_count", + "cpu_shares", + "uid", + "gid", + "retries", + "priority", + "pids_limit", + "sysctls", + ) ): return ConfigType.NUMBER if option_name == "cpu_percent": return ConfigType.FRACTION - if option_name in ("external", "disable", "init", "attachable"): + if option_name.endswith(("external", "disable", "init", "attachable")): return ConfigType.BOOLEAN - if option_name in ( - "mode", - "condition", - "network_mode", - "restart", - "userns_mode", + if option_name.endswith( + ( + "mode", + "condition", + "network_mode", + "restart", + "userns_mode", + ) ): return ConfigType.MODE - if option_name in ( - "dns", - "ipv4_address", - "ipv6_address", - "subnet", - "link_local_ips", - "host_ip", - "ip_range", - "gateway", - "aux_addresses", + if option_name.endswith( + ( + "dns", + "ipv4_address", + "ipv6_address", + "subnet", + "link_local_ips", + "host_ip", + "ip_range", + "gateway", + "aux_addresses", + ) ): return ConfigType.IP_ADDRESS - if option_name in ("dns_search", "extra_hosts"): + if option_name.endswith(("dns_search", "extra_hosts")): return ConfigType.URL - if any(option_name.endswith(x) for x in ["user", "username"]): + if option_name.endswith(("user", "username")): return ConfigType.USERNAME - if any(option_name.endswith(x) for x in ["password"]): + if option_name.endswith(("password", "pwd")): return ConfigType.PASSWORD if option_name == "platform": return ConfigType.PLATFORM diff --git a/src/cfgnet/plugins/concept/spring_plugin.py b/src/cfgnet/plugins/concept/spring_plugin.py index 71b5a50..e794257 100644 --- a/src/cfgnet/plugins/concept/spring_plugin.py +++ b/src/cfgnet/plugins/concept/spring_plugin.py @@ -224,9 +224,8 @@ def get_config_type(option_name: str) -> ConfigType: :param name: option name :return: ConfigType """ - if any( - option_name.endswith(x) - for x in [ + if option_name.endswith( + ( ".show-sql", ".cache", ".trace", @@ -253,13 +252,12 @@ def get_config_type(option_name: str) -> ConfigType: ".aop.auto", ".proxy-target-class", ".enabled", - ] + ) ): return ConfigType.BOOLEAN - if any( - option_name.endswith(x) - for x in [ + if option_name.endswith( + ( "size", ".max-file-size", ".total-size-cap", @@ -267,31 +265,28 @@ def get_config_type(option_name: str) -> ConfigType: ".max-in-memory-size", ".image.height", ".pool.size", - ] + ) ): return ConfigType.SIZE - if any( - option_name.endswith(x) - for x in [ + if option_name.endswith( + ( ".max-history", ".image.bitdepth", ".image.margin", ".core-size", ".pool.max-size", - ] + ) ): return ConfigType.NUMBER - if any( - option_name.endswith(x) - for x in [".pattern.dateformat", ".pattern.file", ".pattern.level"] + if option_name.endswith( + (".pattern.dateformat", ".pattern.file", ".pattern.level") ): return ConfigType.PATTERN - if any( - option_name.endswith(x) - for x in [ + if option_name.endswith( + ( "platform", "-name", ".database", @@ -304,56 +299,53 @@ def get_config_type(option_name: str) -> ConfigType: ".active", ".basenames", ".profiles.default", - ] + ) ): return ConfigType.NAME - if any( - option_name.endswith(x) - for x in [ + if option_name.endswith( + ( ".location", ".file", ".jdbc.schema", ".config", ".path", ".image", - ] + ) ): return ConfigType.PATH - if any(option_name.endswith(x) for x in [".image.pixelmode"]): + if option_name.endswith(".image.pixelmode"): return ConfigType.MODE - if any( - option_name.endswith(x) - for x in [".default-domain", ".host", ".uri", "url"] + if option_name.endswith( + (".default-domain", ".host", ".uri", "url", "-uri") ): return ConfigType.URL - if any( - option_name.endswith(x) - for x in [ + if option_name.endswith( + ( ".timeout-per-shutdown-phase", ".startup-delay", "pool.keep-alive", ".await-termination-period", - ] + ) ): return ConfigType.TIME - if any(option_name.endswith(x) for x in [".port"]): + if option_name.endswith(".port"): return ConfigType.PORT - if any(option_name.endswith(x) for x in [".username"]): + if option_name.endswith(".username"): return ConfigType.USERNAME - if any(option_name.endswith(x) for x in [".password"]): + if option_name.endswith(".password"): return ConfigType.PASSWORD - if any(option_name.endswith(x) for x in [".protocol"]): + if option_name.endswith(".protocol"): return ConfigType.PROTOCOL - if any(option_name.endswith(x) for x in [".mail"]): + if option_name.endswith(".mail"): return ConfigType.EMAIL return ConfigType.UNKNOWN diff --git a/tests/cfgnet/plugins/concept/test_postgresql_plugin.py b/tests/cfgnet/plugins/concept/test_postgresql_plugin.py index 00ffdd2..a1d6454 100644 --- a/tests/cfgnet/plugins/concept/test_postgresql_plugin.py +++ b/tests/cfgnet/plugins/concept/test_postgresql_plugin.py @@ -72,9 +72,9 @@ def test_config_types(get_plugin): port_node = next(filter(lambda x: x.id == make_id("postgresql.conf", "port", "5432"), nodes)) size_node = next(filter(lambda x: x.id == make_id("postgresql.conf", "effective_cache_size", "512MB"), nodes)) number_node = next(filter(lambda x: x.id == make_id("postgresql.conf", "random_page_cost", "1.1"), nodes)) - path_node = next(filter(lambda x: x.id == make_id("postgresql.conf", "log_filename", "'postgresql-%Y-%m-%d_%H%M%S.log'"), nodes)) + name_node = next(filter(lambda x: x.id == make_id("postgresql.conf", "log_filename", "'postgresql-%Y-%m-%d_%H%M%S.log'"), nodes)) - assert path_node.config_type == ConfigType.PATH + assert name_node.config_type == ConfigType.NAME assert number_node.config_type == ConfigType.NUMBER assert size_node.config_type == ConfigType.SIZE assert port_node.config_type == ConfigType.PORT