Commit Graph

64 Commits

Author SHA1 Message Date
Carlo Costino
99edc88197 Localize notification_utils to the API
This changeset pulls in all of the notification_utils code directly into the API and removes it as an external dependency.  We are doing this to cut down on operational maintenance of the project and will begin removing parts of it no longer needed for the API.

Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
2024-05-16 10:17:45 -04:00
Cliff Hill
985ad27b3e Getting imports right to use app.enums
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
2024-02-28 12:43:32 -05:00
Cliff Hill
43f18eed6a More changes for enums.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
2024-02-28 12:41:57 -05:00
Cliff Hill
820ee5a942 Cleaning up a lot of things, getting Enums used everywhere.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
2024-02-28 12:40:52 -05:00
Kenneth Kehl
6af998a080 notify-api-521 code review feedback and fix code coverage 2023-10-03 07:31:24 -07:00
Kenneth Kehl
1ecb747c6d reformat 2023-08-29 14:54:30 -07:00
Kenneth Kehl
1765dba476 fix references to gds 2023-08-17 09:01:53 -07:00
Ryan Ahearn
828671ecfc Remove obsolete strip_leading_plus_one method 2023-01-06 11:14:45 -05:00
Ryan Ahearn
6a04be0370 Remove firetext and mmg from inbound SMS options 2022-12-22 09:31:12 -05:00
stvnrlly
8e2b8dd7c4 keep on flakin the flake world 2022-10-21 13:29:52 +00:00
stvnrlly
e9fdfd59f4 clean flake8 except provider code 2022-10-19 16:16:26 +00:00
jimmoffet
863dfe39ba config flag for turning off inbound SMS replies 2022-10-07 17:25:31 -07:00
jimmoffet
4feaa06f5d fix migrations 2022-10-04 17:42:04 -07:00
jimmoffet
fc9e4107c1 all tests passing 2022-10-03 20:07:42 -07:00
jimmoffet
c04d1df6b3 fixing tests 2022-10-03 17:16:59 -07:00
jimmoffet
8cb6f60f04 modify inbound notif processing 2022-10-03 09:05:34 -07:00
Ben Thorner
3d30965193 Downgrade log about orphaned inbound SMS
We can't control who might be sending messages on inbound numbers
that we own i.e. this log isn't an actionable error. Looks like it
used to represent something that _was_ an error [1], but that's not
the case anymore, so it seems reasonable to downgrade it.

[1]: d99ab329eb (diff-80d123d9abb40f80a221979940657a2751cc7cb33f255aa8f352a8324023e022L125)
2021-12-21 12:49:00 +00:00
Ben Thorner
86b6217cf3 Log service ID for invalid inbound SMS
This could help identify issues with inbound SMS for a service.
2021-03-31 10:22:34 +01:00
Ben Thorner
a91fde2fda Run auto-correct on app/ and tests/ 2021-03-12 11:45:45 +00:00
David McDonald
1e253b2257 Add prometheus client metric for number of inbound text messages
As we gradually move from statsd to prometheus, we change the metric to
be a prometheus metric rather than statsd.

The change worth pointing out is that we have dropped the 'successful'
and 'failed' statuses from the metrics. I don't think it's useful to
have these statuses. It's very rare for an inbound message to fail when
we receive it and when it does, we raise an error and see it in our
logs. We aren't going to be looking at a graph of it as it's a rare
event, not typical behaviour that we want to monitor with a graph.
2020-06-30 10:13:55 +01:00
Rebecca Law
aecf17fef1 This morning we raise a ParseError for a bad date format for the DateReceived attribute on the /notifications/receive/mmg request.
This PR tries to parse the date, if that throws an error return now as the datereceived. This will at least allow the message to be persisted. Typically the DateReceived, provider_date, and the created_at date in the inbound_sms table are within a second of each other.
2020-05-13 10:37:41 +01:00
Rebecca Law
b8283c31d4 When we get an inbound message from MMG, the function format_mmg_datetime was converting the date to UTC, however, the provider date is already in UTC format. 2020-04-30 14:19:08 +01:00
Rebecca Law
c98faa929a Revert the log message that was added to test inbound numbers 2019-05-22 13:21:19 +01:00
Rebecca Law
0e6ef9fa57 This is probably a temporary log message, to make sure our new inbound numbers are working. 2019-05-21 16:39:45 +01:00
Katie Smith
ff06d120e8 Bump notifications-utils to 3.7.0
Bumped notifications-utils to 3.7.0. Version 3.7.0 includes the
`convert_utc_to_bst` and `convert_bst_to_utc` functions and the
`LETTER_PROCESSING_DEADLINE` constant, so these have been removed from
this repo and anywhere using these has now been updated to get these
from `notifications-utils`.

Also bumped pytest by a patch version to bring in a bug fix.
2018-11-26 12:53:39 +00:00
Rebecca Law
dce79832ff As Notify matures we probably need less logging, especially to report happy path events.
This PR is a proposal to reduce the average messages we see for a single notification from about 7 messages to 2.

Messaging would change to something like this:
February 2nd 2018, 15:39:05.885	Full delivery response from Firetext for notification: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
{'status': ['0'], 'reference': ['8eda51d5-cd82-4569-bfc9-d5570cdf2126'], 'time': ['2018-02-02 15:39:01'], 'code': ['000']}
February 2nd 2018, 15:39:05.885	Firetext callback return status of 0 for reference: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
February 2nd 2018, 15:38:57.727	SMS 8eda51d5-cd82-4569-bfc9-d5570cdf2126 sent to provider firetext at 2018-02-02 15:38:56.716814
February 2nd 2018, 15:38:56.727	Starting sending SMS 8eda51d5-cd82-4569-bfc9-d5570cdf2126 to provider at 2018-02-02 15:38:56.408181
February 2nd 2018, 15:38:56.727	Firetext request for 8eda51d5-cd82-4569-bfc9-d5570cdf2126 finished in 0.30376038211397827
February 2nd 2018, 15:38:49.449	sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 created at 2018-02-02 15:38:48.439113
February 2nd 2018, 15:38:49.449	sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 sent to the priority-tasks queue for delivery

To somthing like this:
February 2nd 2018, 15:39:05.885	Firetext callback return status of 0 for reference: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
February 2nd 2018, 15:38:49.449	sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 created at 2018-02-02 15:38:48.439113
2018-02-02 15:55:25 +00:00
venusbb
a35b04f5e7 Enable MMG inbound blocking 2017-12-19 15:00:51 +00:00
venusbb
ab66f5c0ac Change MMG username to look at env variable 2017-12-15 12:19:58 +00:00
Katie Smith
a8d3b0952f Add MMG_INBOUND_SMS_AUTH config variable and auth check
Checks authentication header value on inbound SMS requests from
MMG  against a list of allowed API keys set in the application
config.

At the moment, we're only logging the attempts without aborting the
requests. Once this is rolled out to production and we've checked
the logs we'll switch on the aborts and add the tests for 401 and 403
responses.

This work has already been done for Firetext in a previous PR:
https://github.com/alphagov/notifications-api/pull/1409
2017-12-14 13:37:50 +00:00
Leo Hemsted
28d5f9b87f flake8 - remove unused imports and ensure they're always at the top of the file 2017-11-28 14:28:01 +00:00
Alexey Bezhan
1971d7d4b3 Merge pull request #1425 from alphagov/enable-firetext-inbound-sms-auth
Abort unauthenticated requests for Firetext inbound SMS
2017-11-27 10:45:34 +00:00
Alexey Bezhan
4d48421767 Abort unauthenticated requests for Firetext inbound SMS
Switches on authentication checks for Firetext inbound SMS callbacks.

This should only be released once Firetext callback URLs have been
updated with authentication details.
2017-11-23 17:17:37 +00:00
Leo Hemsted
f3d129b0d8 fix 500s when inbound msgs sent from alphanumerics rather than normal phone numbers 2017-11-23 15:22:18 +00:00
Alexey Bezhan
5e53d781e0 Add FIRETEXT_INBOUND_SMS_AUTH config variable and auth check
Checks authentication header value on inbound SMS requests from
Firetext against a list of allowed API keys set in the application
config.

At the moment, we're only logging the attempts without aborting the
requests. Once this is rolled out to production and we've checked
the logs we'll switch on the aborts and add the tests for 401 and 403
responses.
2017-11-22 09:54:42 +00:00
venusbb
d70fdbb5c2 no auth check 2017-11-17 15:57:41 +00:00
venusbb
12a99f9a7f Verify authorisation header being send 2017-11-17 14:36:28 +00:00
Chris Hill-Scott
4761d852e9 Fix escaping in inbound text messages from MMG
One of our providers gives us messages with special characters escaped,
ie a newline comes through as `\n`, not a literal newline. We shouldn’t
be showing these backslashes to any of our users. We also have examples
of real inbound messages containing `👍` and `’`, so we should continue
to display these properly.

It’s a bit tricky, because the strings we get from this provider are a
mixture of escape sequences (eg `\n`) and unicode characters (eg `😨`).
So we have to first convert the unicode character `😨` into an escape
sequence, `\U0001f628` in this example. We do this by encoding with
the `raw_unicode_escape` codec:

> Latin-1 encoding with \uXXXX and \UXXXXXXXX for other code points.
> Existing backslashes are not escaped in any way. It is used in the
> Python pickle protocol.

– https://docs.python.org/3/library/codecs.html#text-encodings

Then we turn this back into a string using the `unicode_escape` codec,
which transforms all escape sequences into their literal representations
(eg `\U0001f628` becomes `😨` and `\n` becomes a newline).
2017-11-08 13:32:30 +00:00
Ken Tsang
d99ab329eb Refactored code to use inbound_number.number
- Removed filter on sms_sender for `dao_fetch_services_by_inbound_number`
2017-08-23 14:14:32 +01:00
Ken Tsang
667ee57a35 Refactor code to use inbound_numbers if set 2017-08-16 12:50:44 +01:00
Leo Hemsted
6c61a3fc2a Revert celery4
Revert the following three pull requests:
https://github.com/alphagov/notifications-api/pull/1085
https://github.com/alphagov/notifications-api/pull/1086
https://github.com/alphagov/notifications-api/pull/1088

celery 4.0.2 looked promising, however, on staging under mild load
(5/sec api calls) the performance was actually worse than 3.1.25
2017-07-19 15:17:19 +01:00
Leo Hemsted
1a03248317 temp fix to sort out circular imports 2017-07-12 13:02:19 +01:00
Ken Tsang
8b04039a5a Refactor to abstract inbound_sms perms check 2017-07-06 12:31:02 +01:00
Ken Tsang
e96a67c59b Firetext tests 2017-07-06 12:31:01 +01:00
Ken Tsang
5a82fe0a70 Add inbound sms permission check 2017-07-06 12:31:01 +01:00
venusbb
2d8048654c deleted last check 2017-06-29 11:11:08 +01:00
venusbb
16571c5b3c IP restriction for inbound sms test 2 2017-06-29 10:47:27 +01:00
venusbb
c5cb70210e add logs to see the IP address of the inbound sms 2017-06-26 16:15:58 +01:00
Rebecca Law
6559da3239 Updates as per review comments 2017-06-21 15:29:55 +01:00
Rebecca Law
c608f5997b New task to send the inbound sms to the service.
If the service has not set the url then nothing happens.
If the request to the service url returns with 500 or greater the task is retries.
The task is created when the SMS provider post the inbound SMS.
2017-06-20 17:13:40 +01:00
Martyn Inglis
29455b6d3b Strip leading 44 from inbound SMS numbers to normalise to how we store things. 2017-06-06 11:50:30 +01:00