Skip to content
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

Comma escape #1191

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
18 changes: 16 additions & 2 deletions app/aws/s3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import re
import csv

from app.utils import hilite
import botocore
from boto3 import Session
from expiringdict import ExpiringDict
Expand Down Expand Up @@ -124,17 +126,28 @@ def extract_phones(job):


def extract_personalisation(job):
print(hilite(f"job type: {type(job)}"))
print(hilite(f"Job? {job}"))

job = job.split("\r\n")
print(hilite(f"job after first split: {job}"))
first_row = job[0]
print(hilite(f"first_row: {first_row}"))
job.pop(0)
first_row = first_row.split(",")
print(hilite(f"first_row again: {first_row}"))
personalisation = {}
job_row = 0
for row in job:
row = row.split(",")
row_csv_module = csv.reader(job)

for row in row_csv_module:
print(hilite(f"row: {row}"))
temp = dict(zip(first_row, row))
print(hilite(f"temp: {temp}"))
personalisation[job_row] = temp
job_row = job_row + 1
print(hilite(f"job_row: {job_row}"))
print(hilite(f"personalisation: {personalisation}"))
return personalisation


Expand Down Expand Up @@ -190,6 +203,7 @@ def get_personalisation_from_s3(service_id, job_id, job_row_number):
job = JOBS.get(job_id)
if job is None:
job = get_job_from_s3(service_id, job_id)
print(hilite(f"job at the beginning: {job}"))
JOBS[job_id] = job
incr_jobs_cache_misses()
else:
Expand Down
4 changes: 2 additions & 2 deletions app/celery/provider_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from app.delivery import send_to_providers
from app.enums import NotificationStatus
from app.exceptions import NotificationTechnicalFailureException
from app.utils import utc_now
from app.utils import hilite, utc_now

# This is the amount of time to wait after sending an sms message before we check the aws logs and look for delivery
# receipts
Expand Down Expand Up @@ -100,7 +100,7 @@ def deliver_sms(self, notification_id):
notification = notifications_dao.get_notification_by_id(notification_id)
ansi_green = "\033[32m"
ansi_reset = "\033[0m"

print(hilite(f"notification inside of deliver_sms: {notification}"))
if not notification:
raise NoResultFound()
if (
Expand Down
1 change: 1 addition & 0 deletions app/celery/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def __total_sending_limits_for_job_exceeded(service, job, job_id):
def save_sms(self, service_id, notification_id, encrypted_notification, sender_id=None):
"""Persist notification to db and place notification in queue to send to sns."""
notification = encryption.decrypt(encrypted_notification)
print(hilite(f"notification at the top of save_sms: {notification}"))
# SerialisedService and SerialisedTemplate classes are
# used here to grab the same service and template from the cache
# to improve performance.
Expand Down
3 changes: 2 additions & 1 deletion app/clients/sms/aws_sns.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
from time import monotonic

from app.utils import hilite
import botocore
import phonenumbers
from boto3 import client
Expand Down Expand Up @@ -54,7 +55,7 @@ def send_sms(self, to, content, reference, sender=None, international=False):
to = phonenumbers.format_number(
match.number, phonenumbers.PhoneNumberFormat.E164
)

print(hilite(f"to in send_sms: {to}"))
# See documentation
# https://docs.aws.amazon.com/sns/latest/dg/sms_publish-to-phone.html#sms_publish_sdk
attributes = {
Expand Down
2 changes: 2 additions & 0 deletions app/delivery/send_to_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
notification.job_id,
notification.job_row_number,
)
print(hilite(f"recipient: {recipient}"))

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (private)
as clear text.
except Exception:
# It is our 2facode, maybe
key = f"2facode-{notification.id}".replace(" ", "")
Expand All @@ -108,6 +109,7 @@
"sender": notification.reply_to_text,
"international": notification.international,
}
print(hilite(f"send_sms_kwargs: {send_sms_kwargs}"))

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

This expression logs
sensitive data (private)
as clear text.
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this is okay to keep here for the moment for debugging purposes.

db.session.close() # no commit needed as no changes to objects have been made above

message_id = provider.send_sms(**send_sms_kwargs)
Expand Down
3 changes: 2 additions & 1 deletion app/job/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
notifications_filter_schema,
unarchived_template_schema,
)
from app.utils import midnight_n_days_ago, pagination_links
from app.utils import hilite, midnight_n_days_ago, pagination_links

job_blueprint = Blueprint("job", __name__, url_prefix="/service/<uuid:service_id>/job")

Expand Down Expand Up @@ -172,6 +172,7 @@ def create_job(service_id):
raise InvalidRequest("Create job is not allowed: service is inactive ", 403)

data = request.get_json()
print(hilite(f"data at the top of create_job: {data}"))
original_file_name = data.get("original_file_name")
data.update({"service": service_id})
try:
Expand Down
5 changes: 4 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading