Skip to content

Commit

Permalink
Move null check to _get_secrets
Browse files Browse the repository at this point in the history
The check for "None" is better placed inside the get_secrets function,
with this, get_secrets will always return a list, either empty list, or
the list with the secrets from the yaml. Changed checks accordingly.
Changed default get to be an empty list if the "secret" key is not
present in the secret values file.
  • Loading branch information
darkdoc committed Oct 9, 2024
1 parent c09634c commit f397882
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions plugins/module_utils/parse_secrets_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def _get_vault_policies(self, enable_default_vp_policies=True):
return policies

def _get_secrets(self):
return self.syaml.get("secrets", {})
secrets = self.syaml.get("secrets", [])
# We check for "None" here because the yaml file is filtered thru' from_yaml
return [] if secrets == "None" else secrets

def _get_field_on_missing_value(self, f):
# By default if 'onMissingValue' is missing we assume we need to
Expand Down Expand Up @@ -195,7 +197,7 @@ def parse(self):

total_secrets = 0 # Counter for all the secrets uploaded

if secrets == "None" or len(secrets) == 0:
if len(secrets) == 0:
self.module.warn("No secrets were parsed")
return total_secrets

Expand Down Expand Up @@ -327,7 +329,7 @@ def _validate_field(self, f):
def _validate_secrets(self):
backing_store = self._get_backingstore()
secrets = self._get_secrets()
if secrets == "None" or len(secrets) == 0:
if len(secrets) == 0:
self.module.warn("No secrets found")
return (True, "")

Expand Down

0 comments on commit f397882

Please sign in to comment.