Skip to content

Commit

Permalink
Refactor CredentialsService to skip None values for variables and sec…
Browse files Browse the repository at this point in the history
…rets
  • Loading branch information
arash77 committed Jan 14, 2025
1 parent 8f7e0a9 commit 036de1e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/galaxy/webapps/galaxy/services/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,22 +263,25 @@ def _create_user_credential(
user_vault = UserVaultWrapper(self._app.vault, trans.user)
for variable_payload in group.variables:
variable_name, variable_value = variable_payload.name, variable_payload.value
if variable_value is None:
continue
variable = next(
(var for var in variables if var.name == variable_name),
None,
)
if variable:
variable.value = variable_value or ""
variable.value = variable_value
else:
variable = Variable(
user_credential_group_id=user_credential_group_id,
name=variable_name,
value=variable_value or "",
value=variable_value,
)
session.add(variable)
for secret_payload in group.secrets:
secret_name, secret_value = secret_payload.name, secret_payload.value

if secret_value is None:
continue
secret = next(
(sec for sec in secrets if sec.name == secret_name),
None,
Expand All @@ -293,7 +296,7 @@ def _create_user_credential(
)
session.add(secret)
vault_ref = f"{source_type}|{source_id}|{reference}|{group_name}|{secret_name}"
user_vault.write_secret(vault_ref, secret_value or "")
user_vault.write_secret(vault_ref, secret_value)
if not current_group_id:
raise exceptions.RequestParameterInvalidException(
"No group was selected as the current group.", type="error"
Expand Down

0 comments on commit 036de1e

Please sign in to comment.