Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion plugins/flows/base/create_cachedb_file_plugin/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def create_cachedb_file_plugin(options: CreateCacheOptions):
match options.flow_action_type:
case CacheFlowAction.CREATE_DATAMART_CACHE:
create_cache_flow(options)
has_snapshot_config = bool(options.snapshot_copy_config)
snap = options.snapshot_copy_config
has_snapshot_config = bool(snap and (snap.timestamp or snap.table_config or snap.patients_to_be_copied))
if options.results_schema_name and options.schema_name != options.results_schema_name and not has_snapshot_config:
create_results_cache_flow(options)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from re import sub
from enum import Enum
from typing import List
Expand Down Expand Up @@ -65,9 +64,6 @@ def create_params(self) -> List:
# path to liquibase executable
liquibase_path = Variable.get("liquibase_path") if Variable.get(
"liquibase_path") else "/app/liquibase/liquibase"
liquibase_dir = os.path.dirname(liquibase_path)
liquibase_properties = os.path.join(
liquibase_dir, 'liquibase.properties')

hana_driver_class_path = Variable.get("hana_driver_class_path") if Variable.get(
"hana_driver_class_path") else "/app/liquibase/lib/ngdbc-latest.jar"
Expand All @@ -83,7 +79,7 @@ def create_params(self) -> List:
classpath = f"{postgres_driver_class_path}:{self.plugin_classpath}"
driver = "org.postgresql.Driver"
connection_base_url = f'jdbc:postgresql://{host}:{port}/{database_name}?'
connection_properties = f'user={admin_user}&password={admin_password}&currentSchema="{self.schema_name.lower()}"'
connection_properties = f'currentSchema="{self.schema_name.lower()}"'

params = [
liquibase_path,
Expand All @@ -94,20 +90,13 @@ def create_params(self) -> List:
f"--logLevel={Variable.get('lb_log_level') if Variable.get('lb_log_level') else 'INFO'}",
f"--defaultSchemaName={self.schema_name}",
f"--liquibaseSchemaName={self.schema_name}",
f"--defaults-file={liquibase_properties}"
f"--url={connection_base_url}{connection_properties}",
f"--password={admin_password}",
]
Comment on lines 91 to 95

if self.tenant_configs.authMode != AuthMode.JWT:
params.append(f"--username={admin_user}")

Comment on lines +93 to 99

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please solve the comment here

# Temporarily create liquibase.properties for sensitive values
# Won't be logged in traceback
with open(liquibase_properties, 'w') as file:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the liquibase.properties is to prevent leaking credentials, why remove it?

file.write(f'''
url: {connection_base_url}{connection_properties}
password: {admin_password}
''')

match self.action:
case LiquibaseAction.STATUS:
params.append("--verbose")
Expand Down Expand Up @@ -140,8 +129,8 @@ def update_schema(self):
liquibase_error_message = self._mask_secrets(self._find_error_message(
liquibase_msg_list), "***")
raise RuntimeError(
# from cpe
f"Liquibase failed to run with return code '{cpe.returncode}': {liquibase_error_message}")
f"Liquibase failed to run with return code '{cpe.returncode}': {liquibase_error_message}"
) from None
else:
print(f"Successfully ran liquibase command '{params[1]}'")

Expand All @@ -162,7 +151,8 @@ def get_latest_available_version(self) -> str:
liquibase_error_message = self._mask_secrets(self._find_error_message(
liquibase_msg_list), "***")
raise RuntimeError(
f"Liquibase failed to run with return code '{cpe.returncode}': {liquibase_error_message}")
f"Liquibase failed to run with return code '{cpe.returncode}': {liquibase_error_message}"
) from None
else:
print(f"Successfully ran liquibase command '{params[1]}'")
liquibase_msg_list = liquibase_msg_masked.split("\n")
Expand All @@ -181,6 +171,8 @@ def _find_error_message(self, liquibase_stdout: List) -> str:
for output in liquibase_stdout:
if LB_ERROR_MESSAGE_REGEX.search(output):
return output
# Output did not match the expected error format
return "No error message found in liquibase output, check the logs above for details"

def _mask_secrets(self, text, replacement):
text = sub(PASSWORD_REGEX, replacement, text) # mask password
Expand Down
Loading