Skip to content

Commit

Permalink
Update config types in spring and docker-compose plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Simon authored and simisimon committed Jun 23, 2023
1 parent 29dc785 commit f794413
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 93 deletions.
2 changes: 1 addition & 1 deletion src/cfgnet/config_types/config_type_inferer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]+)*$")
Expand Down
119 changes: 65 additions & 54 deletions src/cfgnet/plugins/concept/docker_compose_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 28 additions & 36 deletions src/cfgnet/plugins/concept/spring_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -253,45 +252,41 @@ 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",
".image.width",
".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",
Expand All @@ -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
4 changes: 2 additions & 2 deletions tests/cfgnet/plugins/concept/test_postgresql_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f794413

Please sign in to comment.