Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
Imported reused functions & added whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
edujosemena committed Jul 7, 2023
1 parent 9c2122b commit f2aedef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/pe_reports/data/db_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def sanitize_string(string):

def sanitize_uid(string):
"""Remove special characters from uids."""
return re.sub(r"[^a-zA-Z0-9\-]", "", string)
return re.sub(r"[^a-zA-Z0-9\-\s]", "", string)


def show_psycopg2_exception(err):
Expand Down
14 changes: 5 additions & 9 deletions src/pe_source/data/pe_db/db_query_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# cisagov Libraries
from pe_reports import app
from pe_reports.data.config import config
from pe_reports.data.db_query import sanitize_uid

# Setup logging to central file
LOGGER = app.config["LOGGER"]
Expand Down Expand Up @@ -44,12 +45,7 @@ def close(conn):
conn.close()


def sanitize_uid(string):
"""Remove special characters from uids."""
return re.sub(r"[^a-zA-Z0-9\-]", "", string)


def sanitize_string(string):
def sanitize_text(string):
"""Remove special characters from string."""
pattern = re.compile(r"[^\w\s]+")
sanitized_text = pattern.sub("", string())
Expand All @@ -69,7 +65,7 @@ def get_orgs():
for value in pe_orgs:
value[0] = sanitize_uid(value[0]) # org_uid
value[1] = value[1]
value[2] = sanitize_string(value[2]) # cyhy_db_name
value[2] = sanitize_text(value[2]) # cyhy_db_name

pe_orgs = [dict(zip(keys, values)) for values in pe_orgs]
cur.close()
Expand Down Expand Up @@ -277,7 +273,7 @@ def get_breaches():
pe_orgs = cur.fetchall()
cur.close()
for breach in pe_orgs:
breach[0] = sanitize_string([0])
breach[0] = sanitize_text([0])
breach[1] = sanitize_uid(breach[1])
return pe_orgs
except (Exception, psycopg2.DatabaseError) as error:
Expand Down Expand Up @@ -471,7 +467,7 @@ def get_intelx_breaches(source_uid):
cur.execute(sql, [source_uid])
all_breaches = cur.fetchall()
for breach in all_breaches:
breach[0] = sanitize_string([0])
breach[0] = sanitize_text([0])
breach[1] = sanitize_uid(breach[1])
cur.close()
return all_breaches
Expand Down

0 comments on commit f2aedef

Please sign in to comment.