Skip to content

Commit

Permalink
Merge pull request #571 from syncrou/allow_nulls_in_exist
Browse files Browse the repository at this point in the history
Allow for nulls in the exists method
  • Loading branch information
mkanoor committed Sep 3, 2019
2 parents 3b0e6b2 + b1e6c8d commit 2c6c747
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,18 @@ def decrypt(self, data):
return json.loads(result.read())


def exists(self, path):
def exists(self, path, allow_null=False):
"""
Validate all passed objects before attempting to set or get values from them
Validate via bool() all passed objects before attempting to set or get values from them
Wrap all reduced values in quotes so the bool() method will not
return a False on falsey values
If allow_null is true then return True or fail on a KeyError
"""
list_path = path.split("|")
str = None
try:
reduced_str = functools.reduce(operator.getitem, list_path, self._target)
str = "%s" % (reduced_str)
return bool(str)
if allow_null and not reduced_str:
return True
return bool(reduced_str)
except KeyError as error:
return False

Expand Down Expand Up @@ -181,7 +180,7 @@ def attribute_exists(self, dict_options):
attribute = dict_options['attribute']
path = "workspace|input|objects"
search_path = "|".join([path, obj, attribute])
if self.exists(search_path):
if self.exists(search_path, True):
return dict(changed=False, value=True)
return dict(changed=False, value=False)

Expand Down

0 comments on commit 2c6c747

Please sign in to comment.