Commit Graph

35 Commits

Author SHA1 Message Date
Chris Hill-Scott
5ba8387c6d Bump utils to 44.5.0
Brings in a new `intersects_with()` method of `Polygons` which will come
in handy.
2021-08-23 16:57:15 +01:00
Ben Thorner
63926235cc Bump Python client version to 6.2.1
This is a prerequisite for [1]. I'd like to deploy it as a separate
change so it's easy to roll back if we need to.

[1]: https://github.com/alphagov/notifications-admin/pull/3970
2021-07-19 10:19:43 +01:00
Pea Tyczynska
7f08ae7c29 Bump utils to revert a bug to conditional multiline placeholders 2021-07-09 13:51:39 +01:00
Chris Hill-Scott
e4ca78634d Bump utils to bring in new polygon simplification
We’ve changed our simplification a bit so:
- polygons have slightly more points (see https://github.com/alphagov/notifications-utils/pull/873)
- the individual points have less precision (see https://github.com/alphagov/notifications-utils/pull/872)

Overall this reduces the size of the data we’re storing from 74MB to
63MB, and should make any pages where we are rendering lots of
coordinates load a bit quicker.
2021-07-06 17:00:50 +01:00
Chris Hill-Scott
7832c862a1 Pin Flask to less than version 2
Flask 2.0 requires Jinja 3.0

govuk_frontend_jinja is not compatible with Jinja 3.0 yet
2021-06-02 16:15:34 +01:00
pyup-bot
164a44e41b Pin cryptography to latest version 3.4.7 2021-06-02 15:28:29 +01:00
pyup-bot
afcc1a90ed Update itsdangerous from 1.1.0 to 2.0.1 2021-06-02 15:28:29 +01:00
pyup-bot
e7893001f3 Update notifications-python-client from 6.0.2 to 6.1.0 2021-06-02 15:28:29 +01:00
pyup-bot
0345c95179 Update flask-wtf from 0.14.3 to 0.15.1 2021-06-02 15:28:29 +01:00
pyup-bot
5d209a4ad9 Update flask from 1.1.2 to 2.0.1 2021-06-02 15:28:29 +01:00
pyup-bot
e26922e82a Update humanize from 3.4.0 to 3.6.0 2021-06-02 15:28:29 +01:00
Rebecca Law
9a4b6de37d Bump utils version for new invalid address character 2021-05-27 13:04:46 +01:00
Ben Thorner
a7d7cb3421 Merge pull request #3878 from alphagov/register-security-key
Allow registering WebAuthn authenticators in memory
2021-05-13 12:43:16 +01:00
Ben Thorner
e2cf3e2c70 Support registering a new authenticator
This adds Yubico's FIDO2 library and two APIs for working with the
"navigator.credentials.create()" function in JavaScript. The GET
API uses the library to generate options for the "create()" function,
and the POST API decodes and verifies the resulting credential. While
the options and response are dict-like, CBOR is necessary to encode
some of the byte-level values, which can't be represented in JSON.

Much of the code here is based on the Yubico library example [1][2].

Implementation notes:

- There are definitely better ways to alert the user about failure, but
window.alert() will do for the time being. Using location.reload() is
also a bit jarring if the page scrolls, but not a major issue.

- Ideally we would use window.fetch() to do AJAX calls, but we don't
have a polyfill for this, and we use $.ajax() elsewhere [3]. We need
to do a few weird tricks [6] to stop jQuery trashing the data.

- The FIDO2 server doesn't serve web requests; it's just a "server" in
the sense of WebAuthn terminology. It lives in its own module, since it
needs to be initialised with the app / config.

- $.ajax returns a promise-like object. Although we've used ".fail()"
elsewhere [3], I couldn't find a stub object that supports it, so I've
gone for ".catch()", and used a Promise stub object in tests.

- WebAuthn only works over HTTPS, but there's an exception for "localhost"
[4].  However, the library is a bit too strict [5], so we have to disable
origin verification to avoid needing HTTPS for dev work.

[1]: c42d9628a4/examples/server/server.py
[2]: c42d9628a4/examples/server/static/register.html
[3]: 91453d3639/app/assets/javascripts/updateContent.js (L33)
[4]: https://stackoverflow.com/questions/55971593/navigator-credentials-is-null-on-local-server
[5]: c42d9628a4/fido2/rpid.py (L69)
[6]: https://stackoverflow.com/questions/12394622/does-jquery-ajax-or-load-allow-for-responsetype-arraybuffer
2021-05-13 10:22:23 +01:00
Chris Hill-Scott
98847742d3 Stop pyup complaining
The apps won’t start with Eventlet 0.31.0

But Pyup complains when we try to downgrade
2021-05-10 17:06:10 +01:00
Chris Hill-Scott
9566bae96a Revert "Bump eventlet from 0.30.2 to 0.31.0" 2021-05-10 16:45:51 +01:00
dependabot[bot]
3ad9e1ac6a Bump eventlet from 0.30.2 to 0.31.0
Bumps [eventlet](https://github.com/eventlet/eventlet) from 0.30.2 to 0.31.0.
- [Release notes](https://github.com/eventlet/eventlet/releases)
- [Changelog](https://github.com/eventlet/eventlet/blob/master/NEWS)
- [Commits](https://github.com/eventlet/eventlet/compare/v0.30.2...v0.31.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-08 16:57:07 +00:00
pyup-bot
dea6a4dbe9 Update humanize from 3.3.0 to 3.4.0 2021-04-14 17:24:20 +01:00
Chris Hill-Scott
e7aad61220 Use pure Python Rtree library
The Python rtree library we are using to build RTrees has a dependency
on the C package libspatialindex. This package is not installed on PaaS,
so it’s hard for us to use it.

This commit changes the code to use a library called rtreelib instead.

rtreelib doesn’t have a built in way to serialise the index it builds,
so I’ve had to implement that using pickle.
2021-04-13 12:43:28 +01:00
Chris Hill-Scott
83c521915c Estimate number of phones in an arbitrary polygon
We want to know how many phones are in a user-supplied polygon, so we
can show the impact of a broadcast, in the same way that we do when
users pick areas from our library.

We already know how many phones are in each electoral ward. But there
are challenges with an arbitrary polygon:
- where it does overlap a ward, the overlap could be partial
- it could overlap more than one ward
- finding out which wards it overlaps by brute force (looping through
  all the wards and seeing which ones intersect with our polygon) would
  be way to slow to do in real time

Instead we can use a data structure called an R-tree[1] to build an
index which provides a much, much faster way of looking up which
polygons overlap another. We can build this tree in advance and save it
somewhere, which means there’s a lot of computation we don’t need to do
in real time.

The R-tree returns a set of objects (ward IDs) which we can go and look
up in our library of electoral wards. These wards will be the ones that
might have some overlap with our custom polygon.

Once we have this small set of wards which might overlap our ward, we
can look at the size of the area of overlap (relative to the size of the
whole ward) and multiply that by the known count of phones in that ward
to get an approximation of the count of phones in the overlap area.
Summing these approximations give an estimate for the whole area of the
custom polygon.

1. https://en.wikipedia.org/wiki/R-tree
2021-04-12 15:45:48 +01:00
Leo Hemsted
8954dc2fae skip prometheus-client 0.10.0
we saw exceptions on prod that I think might have caused a worker that
is being terminated to die ungracefully. While I'm not sure if this is
an actual problem that changed behaviour (app instances crashing and
restarting), at the very least it definitely polluted the logs and
obscured any actual issues we were having.

https://github.com/prometheus/client_python/releases/tag/v0.10.0

see the pending fix for this problem here:
https://github.com/prometheus/client_python/pull/644
2021-04-08 11:09:45 +01:00
pyup-bot
f136731442 Update prometheus-client from 0.9.0 to 0.10.0 2021-04-05 14:55:04 +01:00
pyup-bot
415e570666 Update gunicorn from 20.0.4 to 20.1.0 2021-04-05 14:55:03 +01:00
pyup-bot
3f29d2bb0d Update humanize from 3.2.0 to 3.3.0 2021-04-05 14:55:03 +01:00
Pea Tyczynska
a631942d55 Bump utils to allow double hyphens in email address domain
It was requested by our user and it is an allowed domain format
with Amazon SES, so we started allowing it in our validation.
2021-03-29 17:38:37 +01:00
Chris Hill-Scott
738ac1d818 Vary bleed amount based on population density
There are basically two kinds of 4G masts:

Frequency | Range       | Bandwidth
----------|-------------|----------------------------------
800MHz    | Long (500m) | Low (can handle a bit of traffic)
1800Mhz   | Short (5km) | High (can handle lots of traffic)

The 1800Mhz masts are better in terms of how much traffic they can
handle and how fast a connection they provide. But because they have
quite short range, it’s only economical to install them in very built up
areas†.

In more rural areas the 800MHz masts are better because they cover a
wider area, and have enough bandwidth for the lower population density.

The net effect of this is that cell broadcasts in rural areas are likely
to bleed further, because the masts they are being broadcast from are
less precise.

We can use population density as a proxy for how likely it is to be
covered by 1800Mhz masts, and therefore how much bleed we should expect.
So this commit varies the amount of bleed shown based on the population
density.

I came up with the formula based on 3 fixed points:
- The most remote areas (for example the Scottish Highlands) should have
  the highest average bleed, estimated at 5km
- An town, like Crewe, should have about the same bleed as we were
  estimating before (1.5km) – Pete D thinks this is about right based on
  his knowledge of the area around his office in Crewe
- The most built up areas, like London boroughs, could have as little as
  500m of bleed

Based on these three figures I came up with the following formula, which
roughly gives the right bleed distance (`b`) for each of their population
densities (`d`):
```
b = 5900 - (log10(d) × 1_250)
```

Plotted on a curve it looks like this:

This is based on averages – remember that the UI shows where is _likely_
to receive the alert, based on bleed, not where it’s _possible_ to
receive the alert.

Here’s what it looks like on the map:

---

†There are some additional subtleties which make this not strictly true:
- The 800Mhz masts are also used in built up areas to fill in the gaps
  between the areas covered by the 1800Mhz masts
- Switching between masts is inefficient, so if you’re moving fast
  through a built up area (for example on a train) your phone will only
  use the 800MHz masts so that you have to handoff from one mast to
  another less often
2021-03-18 09:37:23 +00:00
pyup-bot
cea19e657c Update eventlet from 0.30.1 to 0.30.2 2021-03-08 18:48:33 +00:00
Ben Thorner
14ef2b95cd Revert "Revert "Scheduled weekly dependency update for week 07""
This reverts commit e23daa205c.
2021-02-16 16:16:17 +00:00
Ben Thorner
e23daa205c Revert "Scheduled weekly dependency update for week 07" 2021-02-16 14:25:43 +00:00
pyup-bot
d70e5bb104 Update notifications-python-client from 5.7.1 to 6.0.2 2021-02-15 13:55:09 +00:00
pyup-bot
e017aa6c9a Update eventlet from 0.30.0 to 0.30.1 2021-02-15 13:55:08 +00:00
pyup-bot
aa0394f2d1 Update pytz from 2020.5 to 2021.1 2021-02-15 13:55:07 +00:00
Rebecca Law
f0ce2c6f5b Update utils to version 43.8.
Invalid characters for the first line of a postal address now include < >
2021-02-09 14:07:01 +00:00
Pea Tyczynska
77008fe3cc Update requirements - install patch for jinja2 vulnerability 2021-02-02 17:13:18 +00:00
Chris Hill-Scott
6786b892fd Copy requirements files to .in
We’re going to move to using pip-tools for freezing requirements.

pip-tools uses `.in` files for the un-frozen list of requirements, and
then generates `.txt` equivalents.

This commit just copies our existing `.txt` files, keeping the same name
but giving them a `.in` extension ready for pip-tools to use.
2021-01-08 17:02:39 +00:00