1
1
"""Module to interact with Postgres database.
2
+
3
+ Dynamic SQL is used in this module to allow customized schema names for storing
4
+ data. At a glance, this is vulnerable to SQLi (SQL Injection) considering the
5
+ ``schema_name`` variable is technically "user input". This is not considered
6
+ a concern for this project because the user inputting the ``schema_name`` value
7
+ is considered a trusted user.
2
8
"""
3
9
import logging
4
10
import os
@@ -607,7 +613,7 @@ def run_pg_dump(export_path, skip_qgis_style):
607
613
fix_pg_dump_create_public (export_path )
608
614
609
615
610
- def fix_pg_dump_create_public (export_path ):
616
+ def fix_pg_dump_create_public (export_path : str ):
611
617
"""Using pg_dump with `--schema=public` results in
612
618
a .sql script containing `CREATE SCHEMA public;`, nearly always breaks
613
619
in target DB. Replaces with `CREATE SCHEMA IF NOT EXISTS public;`
@@ -623,10 +629,10 @@ def fix_pg_dump_create_public(export_path):
623
629
LOGGER .debug (result )
624
630
625
631
626
- def log_import_message (import_id , msg , schema_name ):
632
+ def log_import_message (import_id : int , msg : str , schema_name : str ):
627
633
"""Logs msg to database in osm.pgosm_flex for import_uuid.
628
634
629
- Overwrites `osm_date` IF `pbf_timestamp` is set.
635
+ Overwrites `osm_date` if `pbf_timestamp` is set.
630
636
631
637
Parameters
632
638
-------------------------------
@@ -638,6 +644,7 @@ def log_import_message(import_id, msg, schema_name):
638
644
pbf_timestamp = os .environ ['PBF_TIMESTAMP' ]
639
645
except KeyError :
640
646
pbf_timestamp = os .environ ['PGOSM_DATE' ]
647
+
641
648
sql_raw = """
642
649
UPDATE {schema_name}.pgosm_flex
643
650
SET import_status = %(msg)s ,
0 commit comments