Skip to content

Commit

Permalink
Fix: is_not_empty function to handle dict and align with cwcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
idrissneumann committed Sep 16, 2024
1 parent a02fa0b commit 18c2ab8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.5
4.0.6
8 changes: 4 additions & 4 deletions src/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import re

def is_not_empty (var):
if (isinstance(var, bool)):
if isinstance(var, bool):
return var
elif (isinstance(var, int)):
elif isinstance(var, int):
return not var == 0
elif (isinstance(var, list)):
elif isinstance(var, list) or isinstance(var, dict):
return len(var) > 0
empty_chars = ["", "null", "nil", "false", "none"]
return var is not None and not any(c == "{}".format(var).lower() for c in empty_chars)
Expand All @@ -29,7 +29,7 @@ def is_empty_key(vdict, key):
def is_not_empty_key(vdict, key):
return not is_empty_key(vdict, key)

def remove_key_safely(vdict, key):
def del_key_if_exists(vdict, key):
if is_not_empty_key(vdict, key):
del vdict[key]

Expand Down
6 changes: 3 additions & 3 deletions src/utils/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from time import sleep
from requests.auth import HTTPBasicAuth

from utils.common import is_empty_key, get_or_else, is_not_empty, is_not_empty_key, remove_key_safely
from utils.common import is_empty_key, get_or_else, is_not_empty, is_not_empty_key, del_key_if_exists
from utils.gauge import create_gauge, set_gauge
from utils.heartbit import WAIT_TIME
from utils.logger import log_msg
Expand Down Expand Up @@ -51,8 +51,8 @@ def check_http_monitor(monitor, gauges):

if is_not_empty_key(monitor, 'username') and is_not_empty_key(monitor, 'password'):
auth = HTTPBasicAuth(monitor['username'], monitor['password'])
remove_key_safely(monitor, 'username')
remove_key_safely(monitor, 'password')
del_key_if_exists(monitor, 'username')
del_key_if_exists(monitor, 'password')

try:
if method == "GET":
Expand Down

0 comments on commit 18c2ab8

Please sign in to comment.