]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/functions/functions.zone
zone: new function zone_config_get_hook_from_id
[people/ms/network.git] / src / functions / functions.zone
index b44d3b5edfe20d569e19563ca5badbb4cf510a14..90d7e115275e99b318e530440111a6fc63a5c4f8 100644 (file)
@@ -1048,6 +1048,39 @@ zone_config_hook_is_configured() {
        return ${EXIT_FALSE}
 }
 
+zone_config_id_is_valid() {
+       # This function checks if a given id is valid for a zone
+       # Return True when yes and false when no
+
+       assert [ $# -eq 2 ]
+       local zone=${1}
+       local id=${2}
+
+       local zone_path=$(zone_dir ${zone})
+
+       [ -f ${zone_path}/configs/*.${id} ];
+}
+
+zone_config_get_hook_from_id() {
+       # Returns the hook for a given id
+       assert [ $# -eq 2 ]
+       local zone=${1}
+       local id=${2}
+
+       local config
+       for config in $(zone_configs_list "${zone}"); do
+               if [[ ${config} == *.${id} ]]; then
+                       local config_hook="$(zone_config_get_hook "${zone}" "${config}")"
+                       assert isset config_hook
+                       print "${config_hook}"
+                       return "${EXIT_OK}"
+               fi
+       done
+
+       # If we get here the zone has no config with the given id
+       return ${EXIT_ERROR}
+}
+
 zone_has_ip() {
        device_has_ip $@
 }