Explorar o código

return early if unsupported state is passed

Signed-off-by: Soumik Dutta <shalearkane@gmail.com>
Soumik Dutta %!s(int64=2) %!d(string=hai) anos
pai
achega
4fcfddbe08
Modificáronse 2 ficheiros con 16 adicións e 0 borrados
  1. 8 0
      borgmatic/hooks/cronhub.py
  2. 8 0
      borgmatic/hooks/cronitor.py

+ 8 - 0
borgmatic/hooks/cronhub.py

@@ -27,6 +27,14 @@ def ping_monitor(hook_config, config_filename, state, monitoring_log_level, dry_
     Ping the configured Cronhub URL, modified with the monitor.State. Use the given configuration
     Ping the configured Cronhub URL, modified with the monitor.State. Use the given configuration
     filename in any log entries. If this is a dry run, then don't actually ping anything.
     filename in any log entries. If this is a dry run, then don't actually ping anything.
     '''
     '''
+    if state not in MONITOR_STATE_TO_CRONHUB:
+        logger.debug(
+            '{}: Ignoring unsupported monitoring {} in Cronhub hook'.format(
+                config_filename, state.name.lower()
+            )
+        )
+        return
+
     dry_run_label = ' (dry run; not actually pinging)' if dry_run else ''
     dry_run_label = ' (dry run; not actually pinging)' if dry_run else ''
     formatted_state = '/{}/'.format(MONITOR_STATE_TO_CRONHUB[state])
     formatted_state = '/{}/'.format(MONITOR_STATE_TO_CRONHUB[state])
     ping_url = (
     ping_url = (

+ 8 - 0
borgmatic/hooks/cronitor.py

@@ -27,6 +27,14 @@ def ping_monitor(hook_config, config_filename, state, monitoring_log_level, dry_
     Ping the configured Cronitor URL, modified with the monitor.State. Use the given configuration
     Ping the configured Cronitor URL, modified with the monitor.State. Use the given configuration
     filename in any log entries. If this is a dry run, then don't actually ping anything.
     filename in any log entries. If this is a dry run, then don't actually ping anything.
     '''
     '''
+    if state not in MONITOR_STATE_TO_CRONITOR:
+        logger.debug(
+            '{}: Ignoring unsupported monitoring {} in Cronitor hook'.format(
+                config_filename, state.name.lower()
+            )
+        )
+        return
+
     dry_run_label = ' (dry run; not actually pinging)' if dry_run else ''
     dry_run_label = ' (dry run; not actually pinging)' if dry_run else ''
     ping_url = '{}/{}'.format(hook_config['ping_url'], MONITOR_STATE_TO_CRONITOR[state])
     ping_url = '{}/{}'.format(hook_config['ping_url'], MONITOR_STATE_TO_CRONITOR[state])