Commit Graph

94 Commits

Author SHA1 Message Date
Chris Hill-Scott
13b63e1a24 Remove reference to styleguide from config
The styleguide no longer exists, so this variable isn’t referred to from
anywhere.
2020-10-16 10:29:26 +01:00
Leo Hemsted
626b1c4211 enable broadcast org in all environments
This organisation is defined in the config file. It's hard coded to a
UUID as defined in the api db migration 0331_add_broadcast_org.
2020-09-25 13:42:13 +01:00
Leo Hemsted
c7ef7d5083 Merge pull request #3643 from alphagov/broadcast-org
move service to broadcast org when broadcasting is enabled
2020-09-24 13:13:34 +01:00
Chris Hill-Scott
6f389d044e Don’t use $yellow to indicate local environment
It clashes with the new `$govuk-focus-colour` now. This commit changes
it to half way between `govuk-colour("dark-grey")` (`#505a5f`) and
`govuk-colour("mid-grey")` (`#b1b4b6`) from the Design System. Dark was
too dark and mid was too light.

It also adds a line of JS to let us easily switch the header to blue by
clicking on it, which is useful for taking screenshots etc.
2020-09-23 11:02:21 +01:00
Leo Hemsted
93d1137474 move service to broadcast org when broadcasting is enabled
we want to keep track of all broadcast services across govt easily. As
such, when broadcasting is enabled for a service, we've decided we're
going to add the service to a special broadcasting organisation.

This organisation is defined in the config file. It's hard coded for
production, if you want to test locally, you should set
BROADCAST_ORGANISATION_ID in your local environment.
2020-09-22 18:18:00 +01:00
David McDonald
2aaca11f8b Turn redis back on 2020-08-11 14:26:12 +01:00
David McDonald
30ed483b7a Turn off redis in all environments for rotation
This is a very short term turn off for while we rotate creds. It will
then be followed immediately by a PR to turn it back on.
2020-08-10 10:25:08 +01:00
David McDonald
d4ed909d0f Revert "Revert "Statsd to prometheus"" 2020-07-01 13:27:12 +01:00
David McDonald
5fb58260e2 Revert "Statsd to prometheus" 2020-07-01 10:00:39 +01:00
David McDonald
6958c0d677 Remove statsd
We don't expose these metrics anywhere anyway and we want to move to
prometheus too (which will be done in the next commit)
2020-06-30 11:08:11 +01:00
Chris Hill-Scott
585fdd9076 Use the correct name for the contact list bucket
Everything else is production. The bucket is currently called
production. The fact that the CSV bucket is called `live-` is a legacy
thing that’s hard to change.
2020-03-16 17:56:55 +00:00
Chris Hill-Scott
03f2368deb Use the correct bucket for storing contact lists
We don’t want to muddy them up with the normal CSV uploads.

I’ve tried to reuse the existing S3 code where possible because it’s
well tested.

Buckets have already been created.
2020-03-16 13:07:39 +00:00
David McDonald
5f548a395a Remove unused environment variable
We no longer use this.

See f56795655e
for further details.
2020-03-06 13:25:53 +00:00
Leo Hemsted
e5b2d81d22 increase reply to address validation timeout on preview
Celery/SQS underperforms in low-traffic environments. Tasks will sit on
celery queues for several seconds before getting picked up if they're
the only thing on the queue. This is observable in our test environments
like preview and staging, but we've got enough load on production that
this isn't an issue.

When we validate reply to email addresses, we expect a delivery receipt
to have been processed within 45 seconds of the button being pressed. On
preview, we often observe times over that, possibly due to the several
queues involved in sending an email and processing its receipt. So, to
ensure that functional tests can pass (when we don't really care how
fast things are, just that the flow doesn't break), bump this timeout up
to 120 seconds on preview. The functional tests were waiting for 120
seconds for the reply to address to be validated anyway.
2020-01-07 12:03:32 +00:00
David McDonald
022c10c20c Merge pull request #3218 from alphagov/dev-antivirus-setting
Antivirus off for development by default
2019-12-06 11:49:48 +00:00
David McDonald
ff9f12c4a7 Antivirus off for development by default
I have copied the approach we use in the API for this
2019-12-05 11:18:48 +00:00
Leo Hemsted
72acc4ebdc add no_cookie blueprint
we have a hunch that some session related issues that we've seen over
the last few weeks might be related to weird race conditions where
cookies set by subresources (image previews of letters on the send flow)
arrive just as the img request is cancelled because the user has clicked
on a button to navigate to a new page, but still manage to set the
cookie? We're not entirely sure what's going on, but we've got a hunch
that not setting cookies on image fetches sounds sensible. Images are
always loaded as a subresource (ie: through a `src` tag in an html
element), so they should never need to change the cookies, so this seems
sensible. We've done this by creating a new blueprint that doesn't set
session.permanent, and doesn't call `save_serivce_or_org_after_request`
either.

cookies are sent back to the browser if:
`sesion.modified or (session.permanent and 'REFRESH_EVERY_REQUEST')`
(where the latter is a config setting).

Turning off REFRESH_EVERY_REQUEST (which is True by default) means that
we will only update the sesion if it's been modified. In practice,
literally every request is modified in the after_request handler
`save_service_or_org_after_request`. This is accidentally convenient,
as it guarantees that we'll still send back the cookie normally even
though refresh_every_request is disabled. Sending back the cookie
updates the expiry time (20 hours), so we need to keep doing this to
preserve existing session timeout behaviour.
2019-12-03 17:06:14 +00:00
Katie Smith
8a322b844b Sanitise uploaded letters and store in S3
This sanitises uploaded letters and stores the sanitised result in S3
with if it passes validation or the original PDF in S3 if validation
fails. A metadata value of 'status' is set to either 'valid' or
'invalid'.
2019-09-12 09:54:36 +01:00
Chris Hill-Scott
13a98a73c1 Set free allowance for GP surgeries
This also tests that a user from an unknown organisation can pick any
of the available options and get the right allowance.
2019-08-29 17:47:14 +01:00
Andy Paine
5242f67d97 REP-340: Use PaaS hosted stats exporter
- We are running the statsd exporter on PaaS now and we can route to it
  on apps.internal
- Send metrics there instead so they end up in Prometheus
2019-08-05 13:47:53 +01:00
Pea Tyczynska
c8bad44db4 Delete references to NHS generic organisation type 2019-07-22 15:59:31 +01:00
Pea Tyczynska
77d281f44f Introduce new org types 2019-07-16 17:00:26 +01:00
Pea Tyczynska
45ac0d7812 Waiting page shows correct messages 2019-05-23 15:34:23 +01:00
Leo Hemsted
f6513613d3 bump utils to bring in redis changes
also set redis url locally to be localhost. redis is disabled by
default so this won't do anything unless you set REDIS_ENABLED=1 as an
environment variable
2019-02-15 11:44:08 +00:00
Chris Hill-Scott
dd711f51b3 Fix asset path in asset fingeprinter
The asset fingerprinter was hard coded to always point to `/static`.

It needs to change depending on which environment the app is running
in.
2018-11-29 13:14:52 +00:00
Chris Hill-Scott
fe6610c221 Fix content security policy for the CDN
The CDN URLs aren’t in included in the content security policy. So
browsers will refuse to load them.

This commit:
- adds each of the CDN URLs to the
- only prepend URLs in CSS files with `/static/` if we’re running
  locally (because the CDN URLs are like `static.example.com` not
  `example.com/static`)
2018-11-29 11:29:52 +00:00
Chris Hill-Scott
b1c0778bde Since moving to putting the admin app on Cloudfront anything on the
`www.notifications.service.gov.uk` domain is:
- not gzipped

The PaaS proxy used to GZip and set headers for anything served from a
path starting with `/static/`:
76dd511a8a/ansible/roles/paas-proxy/templates/admin.conf.j2 (L53-L64)

Anything served from `static.notifications.service.gov.uk` is:
- GZipped
- and as a bonus, cached by Cloudfront where possible (meaning the
requests won’t ever hit our app)

This commit moves to serving static asset from `/static/` to
`static.notifications.service.gov.uk`, to get the above listed benefits.

***

We could do even better by setting long cache expiry headers on the static subdomain (currently they’re only set to cache for 60 seconds). But that’s out of scope for this commit.
2018-11-28 15:50:21 +00:00
Alexey Bezhan
2f0abb9c7d Rename staging CSV uploads bucket to match other environments 2018-11-20 16:46:38 +00:00
Pea Tyczynska
e6e363ba3f Add antivirus scan to letter validation preview view 2018-10-05 16:27:57 +01:00
Chris Hill-Scott
f387f1e6ba Merge pull request #2268 from alphagov/request-to-go-live-better-data
Make the data we get from the go live requests more useful
2018-09-04 16:25:59 +01:00
Athanasios Voutsadakis
c64433b3e7 Disable paas-proxy header check on staging
See: alphagov/notifications-api#2052
2018-09-03 11:10:58 +01:00
Chris Hill-Scott
3c563ddca6 Use commas not tabs to delimit service info
Zendesk strips out the tabs. Commas are the next best thing because
Excel will automatically use them if you select ‘Split text into
columns’.
2018-08-30 15:31:46 +01:00
Athanasios Voutsadakis
c7cce495bd Disable paas-proxy header check on preview
See: https://github.com/alphagov/notifications-api/pull/2052
2018-08-28 13:58:31 +01:00
Katie Smith
1b6c357dea Use new value of SMS_CHAR_COUNT_LIMIT from utils
Admin, API and utils were all defining a value for SMS_CHAR_COUNT_LIMIT.
This value has been updated in notifications-utils to allow text
messages to be 4 fragments long and notifications-admin now gets the value of
SMS_CHAR_COUNT_LIMIT from notifications-utils instead of defining it in
config.
2018-08-16 16:56:32 +01:00
Leo Hemsted
d675ceb5c2 send zendesk rather than deskpro tickets 2018-04-24 17:37:15 +01:00
Chris Hill-Scott
24dbe7b7b1 Add Redis cache between admin and API
Most of the time spent by the admin app to generate a page is spent
waiting for the API. This is slow for three reasons:

1. Talking to the API means going out to the internet, then through
   nginx, the Flask app, SQLAlchemy, down to the database, and then
   serialising the result to JSON and making it into a HTTP response
2. Each call to the API is synchronous, therefore if a page needs 3 API
   calls to render then the second API call won’t be made until the
   first has finished, and the third won’t start until the second has
   finished
3. Every request for a service page in the admin app makes a minimum
   of two requests to the API (`GET /service/…` and `GET /user/…`)

Hitting the database will always be the slowest part of an app like
Notify. But this slowness is exacerbated by 2. and 3. Conversely every
speedup made to 1. is multiplied by 2. and 3.

So this pull request aims to make 1. a _lot_ faster by taking nginx,
Flask, SQLAlchemy and the database out of the equation. It replaces them
with Redis, which as an in-memory key/value store is a lot faster than
Postgres. There is still the overhead of going across the network to
talk to Redis, but the net improvement is vast.

This commit only caches the `GET /service` response, but is written in
such a way that we can easily expand to caching other responses down the
line.

The tradeoff here is that our code is more complex, and we risk
introducing edge cases where a cache becomes stale. The mitigations
against this are:
- invalidating all caches after 24h so a stale cache doesn’t remain
  around indefinitely
- being careful when we add new stuff to the service response

---

Some indicative numbers, based on:
- `GET http://localhost:6012/services/<service_id>/template/<template_id>`
- with the admin app running locally
- talking to Redis running locally
- also talking to the API running locally, itself talking to a local
  Postgres instance
- times measured with Chrome web inspector, average of 10 requests

╲ | No cache | Cache service | Cache service and user | Cache service, user and template
-- | -- | -- | -- | --
**Request time** | 136ms | 97ms | 73ms | 37ms
**Improvement** | 0% | 41% | 88% | 265%

---

Estimates of how much storage this requires:

- Services: 1,942 on production × 2kb = 4Mb
- Users: 4,534 on production × 2kb = 9Mb
- Templates: 7,079 on production × 4kb = 28Mb
2018-04-10 12:58:35 +01:00
Chris Hill-Scott
68292d2299 Add endpoints to serve the agreement
Rather than making users contact us to get the agreement, we should just
let them download it, when we know which version to send them.

This commit adds two endpoints:
- one to serve a page which links to the agreement
- one to serve the agreement itself

These pages are not linked to anywhere because the underlying files
don’t exist yet. So I haven’t bothered putting real content on the page
yet either. I imagine the deploy sequence will be:

1. Upload the files to the buckets in each environment
2. Deploy this code through each enviroment, checking the links work
3. Make another PR to start linking to the endpoints added by this
   commit
2018-03-27 11:35:17 +01:00
Leo Hemsted
8ecbb37f71 raise 503 if you dont mock api properly in your tests
otherwise they'll return unexpected things (eg 404) if you have api
running locally (as you often do in dev)
2018-03-14 15:39:55 +00:00
Chris Hill-Scott
91a7858c45 Merge pull request #1910 from alphagov/env-sh-fix
hardcode some development values
2018-03-01 11:21:00 +00:00
Chris Hill-Scott
f3a0c505bd Enforce order and style of imports
Done using isort[1], with the following command:
```
isort -rc ./app ./tests
```

Adds linting to the `run_tests.sh` script to stop badly-sorted imports
getting re-introduced.

Chosen style is ‘Vertical Hanging Indent’ with trailing commas, because
I think it gives the cleanest diffs, eg:
```
from third_party import (
    lib1,
    lib2,
    lib3,
    lib4,
)
```

1. https://pypi.python.org/pypi/isort
2018-02-27 16:35:13 +00:00
Leo Hemsted
11a4a08ccb hardcode some development values
this'll ensure that you won't get your dev secret keys out of sync
between api and admin
2018-02-27 15:55:20 +00:00
Chris Hill-Scott
3e79ae1bfe Encapsulate domain list in class
Code shouldn’t be accessing this list directly; the class should provide
a sensible interface to the data.
2018-02-26 08:53:46 +00:00
Pete Herlihy
892aac44b2 Adding Highways England to the whitelist of domains 2018-01-30 11:20:52 +00:00
Leo Hemsted
c780c94fb6 derry strabane council email whitelist 2018-01-10 10:47:40 +00:00
Alexey Bezhan
0088d588e1 Use VCAP_APPLICATION to detect CloudFoundry environment
VCAP_SERVICES is not set on PaaS if no services are bound to the
application, so we need to check for VCAP_APPLICATION to parse the
application name and environment.
2018-01-09 14:50:41 +00:00
Chris Hill-Scott
1e7b330bd9 Add British Museum to whitelist
> BM is an executive non-departmental public body, sponsored by the
> Department for Digital, Culture, Media & Sport.
>
> British Museum has a separate website (http://www.britishmuseum.org)

– https://www.gov.uk/government/organisations/british-museum
2018-01-04 15:36:22 +00:00
Chris Hill-Scott
08c007d998 Add Marine Management Organisation as email domain
Seems like sometimes they use a Defra email address, sometimes their
own .org.uk one.
2017-12-18 11:52:56 +00:00
Pete Herlihy
33dc83083e Added big lottery fund to approved domains 2017-11-21 13:57:11 +00:00
Athanasios Voutsadakis
0e9291c9d8 Add CHECK_PROXY_HEADER flag and bump utils 2017-11-16 16:33:21 +00:00
Athanasios Voutsadakis
36663bd9ac Load route_secret config 2017-11-15 12:05:05 +00:00