Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility of overriding environment variables in passbolt_inventory.py #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 55 additions & 27 deletions plugins/lookup/passbolt_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,34 @@


class LookupModule(LookupBase):
def _get_env_value(self, selected_variable, environment_variables, default=str()):
if not environment_variables:
return environ.get(selected_variable, default)
def _get_value(
self, selected_variable, variables, environment_variables, default=str()
):
variable = variables.get(selected_variable, None)
if variable is None:
return self._get_env_value(
selected_variable=selected_variable,
environment_variables=environment_variables,
default=default,
)
else:
return self._templar.template(
next(
(
item.get(selected_variable)
for item in environment_variables
if item.get(selected_variable)
),
default,
)
return variable

def _get_env_value(self, selected_variable, environment_variables, default=str()):
os_environ_variable = environ.get(selected_variable, None)
if os_environ_variable is not None:
default = os_environ_variable

return self._templar.template(
next(
(
item.get(selected_variable)
for item in environment_variables
if item.get(selected_variable)
),
default,
)
)

def _format_result(self, resource, resource_secrets):
return {
Expand All @@ -73,28 +87,42 @@ def _format_result(self, resource, resource_secrets):

def _get_config(self, variables):
return {
"base_url": self._get_env_value(
"PASSBOLT_BASE_URL", variables.get("environment")
"base_url": self._get_value(
"PASSBOLT_BASE_URL", variables, variables.get("environment")
),
"private_key": self._get_env_value(
"PASSBOLT_PRIVATE_KEY", variables.get("environment")
"private_key": self._get_value(
"PASSBOLT_PRIVATE_KEY", variables, variables.get("environment")
),
"passphrase": self._get_env_value(
"PASSBOLT_PASSPHRASE", variables.get("environment")
"passphrase": self._get_value(
"PASSBOLT_PASSPHRASE", variables, variables.get("environment")
),
"gpg_binary": self._get_env_value(
"PASSBOLT_GPG_BINARY", variables.get("environment"), default="gpg"
"gpg_binary": self._get_value(
"PASSBOLT_GPG_BINARY", variables, variables.get("environment"), default="gpg"
),
"gpg_library": self._get_env_value(
"PASSBOLT_GPG_LIBRARY", variables.get("environment"), default="PGPy"
"gpg_library": self._get_value(
"PASSBOLT_GPG_LIBRARY", variables, variables.get("environment"), default="PGPy"
),
"fingerprint": self._get_env_value(
"PASSBOLT_FINGERPRINT", variables.get("environment")
"fingerprint": self._get_value(
"PASSBOLT_FINGERPRINT", variables, variables.get("environment")
),
"verify": self._get_env_value(
"PASSBOLT_VERIFY", variables.get("verify"), default=True
"verify": self._get_value(
"PASSBOLT_VERIFY", variables, variables.get("environment"), default=True
),
"create_new_resource": self._get_value(
"PASSBOLT_CREATE_NEW_RESOURCE", variables,
variables.get("environment"),
default=False,
),
"new_resource_password_length": self._get_value(
"PASSBOLT_NEW_RESOURCE_PASSWORD_LENGTH", variables,
variables.get("environment"),
default=20,
),
"new_resource_password_special_chars": self._get_value(
"PASSBOLT_NEW_RESOURCE_PASSWORD_SPECIAL_CHARS", variables,
variables.get("environment"),
default=False,
),

}

def passbolt_init(self, variables, kwargs):
Expand Down