-
Notifications
You must be signed in to change notification settings - Fork 126
[FLPATH-3327] Add GCP self-hosted/on-prem support #5943
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,7 +112,7 @@ def populate_line_item_daily_summary_table_trino(self, start_date, end_date, sou | |
|
|
||
| """ | ||
| sql = pkgutil.get_data( | ||
| "masu.database", f"{self.trino_sql_folder_name}/aws/reporting_awscostentrylineitem_daily_summary.sql" | ||
| "masu.database", f"{self.get_sql_folder_name()}/aws/reporting_awscostentrylineitem_daily_summary.sql" | ||
| ) | ||
| sql = sql.decode("utf-8") | ||
| uuid_str = str(uuid.uuid4()).replace("-", "_") | ||
|
|
@@ -174,7 +174,7 @@ def populate_ocp_on_aws_ui_summary_tables_trino( | |
|
|
||
| for table_name in tables: | ||
| sql = pkgutil.get_data( | ||
| "masu.database", f"{self.trino_sql_folder_name}/aws/openshift/ui_summary/{table_name}.sql" | ||
| "masu.database", f"{self.get_sql_folder_name()}/aws/openshift/ui_summary/{table_name}.sql" | ||
| ) | ||
| sql = sql.decode("utf-8") | ||
| sql_params = { | ||
|
|
@@ -277,12 +277,7 @@ def populate_ocp_on_aws_cost_daily_summary_trino( | |
| bill_id, | ||
| report_period_id, | ||
| ) | ||
| managed_path = f"{self.trino_sql_folder_name}/aws/openshift/populate_daily_summary" | ||
| prepare_sql, prepare_params = sql_metadata.prepare_template( | ||
| f"{managed_path}/0_prepare_daily_summary_tables.sql" | ||
| ) | ||
| LOG.info(log_json(msg="Preparing tables for OCP on AWS flow", **prepare_params)) | ||
| self._execute_trino_multipart_sql_query(prepare_sql, bind_params=prepare_params) | ||
| managed_path = f"{self.get_sql_folder_name()}/aws/openshift/populate_daily_summary" | ||
| self.delete_ocp_on_aws_hive_partition_by_day( | ||
| sql_metadata.days_tup, | ||
| sql_metadata.cloud_provider_uuid, | ||
|
|
@@ -444,7 +439,7 @@ def get_openshift_on_cloud_matched_tags_trino( | |
| ): | ||
| """Return a list of matched tags.""" | ||
| sql = pkgutil.get_data( | ||
| "masu.database", f"{self.trino_sql_folder_name}/aws/openshift/reporting_ocpaws_matched_tags.sql" | ||
| "masu.database", f"{self.get_sql_folder_name()}/aws/openshift/reporting_ocpaws_matched_tags.sql" | ||
| ) | ||
| sql = sql.decode("utf-8") | ||
|
|
||
|
|
@@ -511,7 +506,7 @@ def populate_ec2_compute_summary_table_trino(self, source_uuid, start_date, bill | |
| } | ||
| LOG.info(log_json(msg=msg, context=context)) | ||
|
|
||
| sql = pkgutil.get_data("masu.database", f"{self.trino_sql_folder_name}/aws/{table_name}.sql") | ||
| sql = pkgutil.get_data("masu.database", f"{self.get_sql_folder_name()}/aws/{table_name}.sql") | ||
| sql = sql.decode("utf-8") | ||
| sql_params = { | ||
| "schema": self.schema, | ||
|
|
@@ -523,3 +518,33 @@ def populate_ec2_compute_summary_table_trino(self, source_uuid, start_date, bill | |
| } | ||
|
|
||
| self._execute_trino_raw_sql_query(sql, sql_params=sql_params, log_ref=f"{table_name}.sql") | ||
|
|
||
| def delete_self_hosted_data_by_source(self, provider_uuid): | ||
| """Delete data from all self-hosted tables by source UUID (for on-prem). | ||
|
|
||
| This deletes data from the line item tables when a source is deleted. | ||
|
|
||
| Args: | ||
| provider_uuid: The provider UUID to delete data for | ||
| """ | ||
| from reporting.provider.aws.self_hosted_models import get_self_hosted_models | ||
|
|
||
| provider_uuid_str = str(provider_uuid) | ||
| total_deleted = 0 | ||
|
|
||
| with schema_context(self.schema): | ||
| for model in get_self_hosted_models(): | ||
| deleted_count, _ = model.objects.filter(source=provider_uuid_str).delete() | ||
|
|
||
| if deleted_count: | ||
| LOG.info( | ||
| log_json( | ||
| msg="deleted self-hosted data by source", | ||
| table=model._meta.db_table, | ||
| provider_uuid=provider_uuid_str, | ||
| deleted_count=deleted_count, | ||
| ) | ||
| ) | ||
| total_deleted += deleted_count | ||
|
|
||
| return total_deleted | ||
|
Comment on lines
+522
to
+550
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method constructs a raw SQL query using an f-string, which is a potential SQL injection vulnerability. Although the values might be system-generated, it is a security best practice to use parameterized queries. Please consider modifying this method to return a SQL template and a list of parameters, and then use
cursor.execute(sql, params)at the call site to safely execute the query. This would provide protection against SQL injection.