mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-21 06:49:26 -04:00
Compare commits
108 Commits
4-24-2025
...
05-22-2025
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa24bde454 | ||
|
|
beda5a409d | ||
|
|
3ef32e6a05 | ||
|
|
bfd3342006 | ||
|
|
76014891ac | ||
|
|
2739ff644c | ||
|
|
f37641990b | ||
|
|
bf87076d01 | ||
|
|
30cb114e3c | ||
|
|
860d4c73e3 | ||
|
|
f62e3269f0 | ||
|
|
87c7c8da1d | ||
|
|
ca2a1012db | ||
|
|
fc75c16a76 | ||
|
|
60c760442d | ||
|
|
17e93b2323 | ||
|
|
63ef551d4d | ||
|
|
00f11b2ac8 | ||
|
|
7370b7e9b0 | ||
|
|
e369ce413b | ||
|
|
0d5cd99f34 | ||
|
|
4c970f25aa | ||
|
|
b45b9cbdbe | ||
|
|
0b0c0bdcd5 | ||
|
|
68b4cd30f5 | ||
|
|
835de96793 | ||
|
|
fe2f14c6e6 | ||
|
|
135e2af559 | ||
|
|
e2ce37ae61 | ||
|
|
cfc108baa3 | ||
|
|
b09fede328 | ||
|
|
9a8591bf91 | ||
|
|
c44ba77313 | ||
|
|
b339bbd78c | ||
|
|
02b50fd871 | ||
|
|
ecbdf83cf6 | ||
|
|
d2b0207333 | ||
|
|
515bff8b62 | ||
|
|
da5b35c402 | ||
|
|
388728e69d | ||
|
|
62cda290db | ||
|
|
9b44f806ee | ||
|
|
8ef8791f70 | ||
|
|
6f945ea0ab | ||
|
|
af107ccd27 | ||
|
|
9c93e81f66 | ||
|
|
572f5020fa | ||
|
|
546c4f724c | ||
|
|
026bf55912 | ||
|
|
575f1b4c6b | ||
|
|
d8962a59ff | ||
|
|
f90a1197f4 | ||
|
|
355890e459 | ||
|
|
33051ada65 | ||
|
|
6aa6feed72 | ||
|
|
cd71432126 | ||
|
|
3961e72d32 | ||
|
|
9cbf0df32b | ||
|
|
d38ada100f | ||
|
|
798a3ff723 | ||
|
|
c515efc7da | ||
|
|
fd974e1b79 | ||
|
|
ca2c0afa5d | ||
|
|
891fbe2dee | ||
|
|
fe049326ac | ||
|
|
83050ccc55 | ||
|
|
ec81a057fe | ||
|
|
a9c23db227 | ||
|
|
cd1ddd794f | ||
|
|
a5b3ccc170 | ||
|
|
4a5f67122c | ||
|
|
dcd9bec087 | ||
|
|
dde6c2f574 | ||
|
|
f8b29fb461 | ||
|
|
3c608b4538 | ||
|
|
92b35ed6be | ||
|
|
bfcf81d91d | ||
|
|
029e40766c | ||
|
|
cacaedac0c | ||
|
|
106d938d4f | ||
|
|
812ffd7b53 | ||
|
|
4bdcf2c53e | ||
|
|
96fb2dead9 | ||
|
|
333631aee2 | ||
|
|
be2e3252b1 | ||
|
|
2d42f26839 | ||
|
|
b4a82785c3 | ||
|
|
00451bb56c | ||
|
|
26a7f541a5 | ||
|
|
2bcf90584c | ||
|
|
d1c105447a | ||
|
|
cba7a712db | ||
|
|
739a08e203 | ||
|
|
eb76f2cee8 | ||
|
|
9113062d98 | ||
|
|
6ef23b70a6 | ||
|
|
0ce6c6b263 | ||
|
|
f1df78b4ba | ||
|
|
debb14d216 | ||
|
|
01b9ea451a | ||
|
|
1242c524a5 | ||
|
|
4c91629ee8 | ||
|
|
a74e5d15a4 | ||
|
|
6689214317 | ||
|
|
6824c45909 | ||
|
|
e8214e4a01 | ||
|
|
1302c15275 | ||
|
|
71bbd6a375 |
256
.ds.baseline
256
.ds.baseline
@@ -127,262 +127,16 @@
|
||||
}
|
||||
],
|
||||
"results": {
|
||||
".github/workflows/checks.yml": [
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": ".github/workflows/checks.yml",
|
||||
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
|
||||
"is_verified": false,
|
||||
"line_number": 28,
|
||||
"is_secret": false
|
||||
},
|
||||
{
|
||||
"type": "Basic Auth Credentials",
|
||||
"filename": ".github/workflows/checks.yml",
|
||||
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
|
||||
"is_verified": false,
|
||||
"line_number": 45,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
".github/workflows/daily_checks.yml": [
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": ".github/workflows/daily_checks.yml",
|
||||
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
|
||||
"is_verified": false,
|
||||
"line_number": 61,
|
||||
"is_secret": false
|
||||
},
|
||||
{
|
||||
"type": "Basic Auth Credentials",
|
||||
"filename": ".github/workflows/daily_checks.yml",
|
||||
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
|
||||
"is_verified": false,
|
||||
"line_number": 77,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"app/enums.py": [
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": "app/enums.py",
|
||||
"hashed_secret": "12322e07b94ee3c7cd65a2952ece441538b53eb3",
|
||||
"is_verified": false,
|
||||
"line_number": 123,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"app/notifications/receive_notifications.py": [
|
||||
{
|
||||
"type": "Base64 High Entropy String",
|
||||
"filename": "app/notifications/receive_notifications.py",
|
||||
"hashed_secret": "d70eab08607a4d05faa2d0d6647206599e9abc65",
|
||||
"is_verified": false,
|
||||
"line_number": 29,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"deploy-config/sandbox.yml": [
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": "deploy-config/sandbox.yml",
|
||||
"hashed_secret": "113151dd10316fcb0d5507b6215d78e2f3fe9e54",
|
||||
"is_verified": false,
|
||||
"line_number": 11,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"sample.env": [
|
||||
{
|
||||
"type": "Basic Auth Credentials",
|
||||
"filename": "sample.env",
|
||||
"hashed_secret": "5b98cf4c3d794c8af1fcd7991e89cd4e52fb42a4",
|
||||
"is_verified": false,
|
||||
"line_number": 16,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"tests/app/aws/test_s3.py": [
|
||||
".github/actions/deploy-proxy/action.yml": [
|
||||
{
|
||||
"type": "Hex High Entropy String",
|
||||
"filename": "tests/app/aws/test_s3.py",
|
||||
"hashed_secret": "67a74306b06d0c01624fe0d0249a570f4d093747",
|
||||
"filename": ".github/actions/deploy-proxy/action.yml",
|
||||
"hashed_secret": "a6c13f5da3788e8d654cd24001dc79a238723248",
|
||||
"is_verified": false,
|
||||
"line_number": 42,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"tests/app/clients/test_document_download.py": [
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": "tests/app/clients/test_document_download.py",
|
||||
"hashed_secret": "3acfb2c2b433c0ea7ff107e33df91b18e52f960f",
|
||||
"is_verified": false,
|
||||
"line_number": 14,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"tests/app/clients/test_performance_platform.py": [
|
||||
{
|
||||
"type": "Base64 High Entropy String",
|
||||
"filename": "tests/app/clients/test_performance_platform.py",
|
||||
"hashed_secret": "76bb66c38ac4046bf73cd4a2c35a2b0af94aeb61",
|
||||
"is_verified": false,
|
||||
"line_number": 84,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"tests/app/dao/test_services_dao.py": [
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": "tests/app/dao/test_services_dao.py",
|
||||
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
|
||||
"is_verified": false,
|
||||
"line_number": 289,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"tests/app/dao/test_users_dao.py": [
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": "tests/app/dao/test_users_dao.py",
|
||||
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
|
||||
"is_verified": false,
|
||||
"line_number": 69,
|
||||
"is_secret": false
|
||||
},
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": "tests/app/dao/test_users_dao.py",
|
||||
"hashed_secret": "f2c57870308dc87f432e5912d4de6f8e322721ba",
|
||||
"is_verified": false,
|
||||
"line_number": 199,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"tests/app/db.py": [
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": "tests/app/db.py",
|
||||
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
|
||||
"is_verified": false,
|
||||
"line_number": 90,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"tests/app/notifications/test_receive_notification.py": [
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": "tests/app/notifications/test_receive_notification.py",
|
||||
"hashed_secret": "913a73b565c8e2c8ed94497580f619397709b8b6",
|
||||
"is_verified": false,
|
||||
"line_number": 27,
|
||||
"is_secret": false
|
||||
},
|
||||
{
|
||||
"type": "Base64 High Entropy String",
|
||||
"filename": "tests/app/notifications/test_receive_notification.py",
|
||||
"hashed_secret": "d70eab08607a4d05faa2d0d6647206599e9abc65",
|
||||
"is_verified": false,
|
||||
"line_number": 57,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"tests/app/notifications/test_validators.py": [
|
||||
{
|
||||
"type": "Base64 High Entropy String",
|
||||
"filename": "tests/app/notifications/test_validators.py",
|
||||
"hashed_secret": "6c1a8443963d02d13ffe575a71abe19ea731fb66",
|
||||
"is_verified": false,
|
||||
"line_number": 672,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"tests/app/service/test_rest.py": [
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": "tests/app/service/test_rest.py",
|
||||
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
|
||||
"is_verified": false,
|
||||
"line_number": 1285,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"tests/app/test_cloudfoundry_config.py": [
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": "tests/app/test_cloudfoundry_config.py",
|
||||
"hashed_secret": "e5e178db7317356946d13e5d2da037d39ac61c71",
|
||||
"is_verified": false,
|
||||
"line_number": 12,
|
||||
"is_secret": false
|
||||
},
|
||||
{
|
||||
"type": "Basic Auth Credentials",
|
||||
"filename": "tests/app/test_cloudfoundry_config.py",
|
||||
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
|
||||
"is_verified": false,
|
||||
"line_number": 14,
|
||||
"is_secret": false
|
||||
},
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": "tests/app/test_cloudfoundry_config.py",
|
||||
"hashed_secret": "cfd48edeb81ba7d48cbddcf1eeede25ba67057e8",
|
||||
"is_verified": false,
|
||||
"line_number": 33,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"tests/app/user/test_rest.py": [
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": "tests/app/user/test_rest.py",
|
||||
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
|
||||
"is_verified": false,
|
||||
"line_number": 110,
|
||||
"is_secret": false
|
||||
},
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": "tests/app/user/test_rest.py",
|
||||
"hashed_secret": "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33",
|
||||
"is_verified": false,
|
||||
"line_number": 864,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"tests/notifications_utils/clients/antivirus/test_antivirus_client.py": [
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": "tests/notifications_utils/clients/antivirus/test_antivirus_client.py",
|
||||
"hashed_secret": "932b25270abe1301c22c709a19082dff07d469ff",
|
||||
"is_verified": false,
|
||||
"line_number": 16,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"tests/notifications_utils/clients/encryption/test_encryption_client.py": [
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": "tests/notifications_utils/clients/encryption/test_encryption_client.py",
|
||||
"hashed_secret": "f1e923a9667de11be6a210849a8651c1bfd81605",
|
||||
"is_verified": false,
|
||||
"line_number": 13,
|
||||
"is_secret": false
|
||||
}
|
||||
],
|
||||
"tests/notifications_utils/clients/zendesk/test_zendesk_client.py": [
|
||||
{
|
||||
"type": "Secret Keyword",
|
||||
"filename": "tests/notifications_utils/clients/zendesk/test_zendesk_client.py",
|
||||
"hashed_secret": "913a73b565c8e2c8ed94497580f619397709b8b6",
|
||||
"is_verified": false,
|
||||
"line_number": 16,
|
||||
"line_number": 18,
|
||||
"is_secret": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"generated_at": "2025-02-27T21:09:45Z"
|
||||
"generated_at": "2025-05-12T16:45:34Z"
|
||||
}
|
||||
|
||||
2
.github/actions/deploy-proxy/action.yml
vendored
2
.github/actions/deploy-proxy/action.yml
vendored
@@ -15,7 +15,7 @@ inputs:
|
||||
default: https://github.com/GSA-TTS/cg-egress-proxy.git
|
||||
proxy_version:
|
||||
description: git ref to be deployed
|
||||
default: main
|
||||
default: 1500c67157c1a7a6fbbda7a2de172b3d0a67e703
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
|
||||
3
.github/actions/setup-project/action.yml
vendored
3
.github/actions/setup-project/action.yml
vendored
@@ -16,3 +16,6 @@ runs:
|
||||
- name: Install poetry
|
||||
shell: bash
|
||||
run: pip install poetry==1.8.5
|
||||
- name: Downgrade virtualenv to compatible version
|
||||
shell: bash
|
||||
run: pip install "virtualenv<20.30"
|
||||
|
||||
4
.github/dependabot.yml
vendored
4
.github/dependabot.yml
vendored
@@ -11,3 +11,7 @@ updates:
|
||||
interval: "daily"
|
||||
labels:
|
||||
- "dependabot" # Custom label to identify Dependabot PRs
|
||||
assignees:
|
||||
- "alexjanousekGSA"
|
||||
reviewers:
|
||||
- "alexjanousekGSA"
|
||||
|
||||
2
.profile
2
.profile
@@ -6,4 +6,4 @@
|
||||
export http_proxy=$egress_proxy
|
||||
export https_proxy=$egress_proxy
|
||||
export NEW_RELIC_PROXY_HOST=$egress_proxy
|
||||
export no_proxy="apps.internal"
|
||||
export no_proxy="apps.internal,s3-fips.us-gov-west-1.amazonaws.com"
|
||||
|
||||
2
Makefile
2
Makefile
@@ -16,7 +16,6 @@ GIT_HOOKS_PATH ?= $(shell git config --global core.hooksPath || echo "")
|
||||
.PHONY: bootstrap
|
||||
bootstrap: ## Set up everything to run the app
|
||||
make generate-version-file
|
||||
poetry self add poetry-dotenv-plugin
|
||||
poetry lock --no-update
|
||||
poetry install --sync --no-root
|
||||
poetry run pre-commit install
|
||||
@@ -27,7 +26,6 @@ bootstrap: ## Set up everything to run the app
|
||||
.PHONY: bootstrap-with-git-hooks
|
||||
bootstrap-with-git-hooks: ## Sets everything up and accounts for pre-existing git hooks
|
||||
make generate-version-file
|
||||
poetry self add poetry-dotenv-plugin
|
||||
poetry lock --no-update
|
||||
poetry install --sync --no-root
|
||||
git config --global --unset-all core.hooksPath
|
||||
|
||||
@@ -221,7 +221,7 @@ If you don't have a line for your `$PATH` environment variable, add it in like
|
||||
this, which will include the PostgreSQL binaries:
|
||||
|
||||
```
|
||||
export PATH="/opt/homebrew/opt/postgresql@15/bin:$PATH
|
||||
export PATH="/opt/homebrew/opt/postgresql@15/bin:$PATH"
|
||||
```
|
||||
|
||||
_NOTE: You don't want to overwrite your existing `$PATH` environment variable! Hence the reason why it is included on the end like this; paths are separated by a colon._
|
||||
@@ -507,8 +507,10 @@ instructions above for more details.
|
||||
- [Deploying to Production](./docs/all.md#-deploying-to-production)
|
||||
- [Smoke-testing the App](./docs/all.md#-smoke-testing-the-app)
|
||||
- [Configuration Management](./docs/all.md#-configuration-management)
|
||||
- [DNS Changes](./docs/all.md#-dns-changes)
|
||||
- [Exporting test results for compliance monitoring](./docs/all.md#exporting-test-results-for-compliance-monitoring)
|
||||
- [DNS and Domain Changes](./docs/all.md#-dns-and-domain-changes)
|
||||
- [Exporting daily scan results for compliance monitoring](./docs/all.md#exporting-daily-scan-results-for-compliance-monitoring)
|
||||
- [Reviewing daily scan results for compliance](./docs/all.md#reviewing-daily-scan-results-for-compliance)
|
||||
- [Rotating environment variable secrets](./docs/all.md#rotating-environment-variable-secrets)
|
||||
- [Known Gotchas](./docs/all.md#-known-gotchas)
|
||||
- [User Account Management](./docs/all.md#-user-account-management)
|
||||
- [SMS Phone Number Management](./docs/all.md#-sms-phone-number-management)
|
||||
|
||||
@@ -2,10 +2,10 @@ import csv
|
||||
import datetime
|
||||
import re
|
||||
import time
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from io import StringIO
|
||||
|
||||
import botocore
|
||||
import eventlet
|
||||
from boto3 import Session
|
||||
from flask import current_app
|
||||
|
||||
@@ -24,8 +24,15 @@ s3_client = None
|
||||
s3_resource = None
|
||||
|
||||
|
||||
def get_service_id_from_key(key):
|
||||
key = key.replace("service-", "")
|
||||
key = key.split("/")
|
||||
key = key[0].replace("-notify", "")
|
||||
return key
|
||||
|
||||
|
||||
def set_job_cache(key, value):
|
||||
current_app.logger.debug(f"Setting {key} in the job_cache.")
|
||||
current_app.logger.debug(f"Setting {key} in the job_cache to {value}.")
|
||||
job_cache = current_app.config["job_cache"]
|
||||
job_cache[key] = (value, time.time() + 8 * 24 * 60 * 60)
|
||||
|
||||
@@ -36,7 +43,7 @@ def get_job_cache(key):
|
||||
if ret is None:
|
||||
current_app.logger.warning(f"Could not find {key} in the job_cache.")
|
||||
else:
|
||||
current_app.logger.debug(f"Got {key} from job_cache.")
|
||||
current_app.logger.debug(f"Got {key} from job_cache with value {ret}.")
|
||||
return ret
|
||||
|
||||
|
||||
@@ -73,7 +80,7 @@ def get_s3_client():
|
||||
aws_secret_access_key=secret_key,
|
||||
region_name=region,
|
||||
)
|
||||
s3_client = session.client("s3")
|
||||
s3_client = session.client("s3", config=AWS_CLIENT_CONFIG)
|
||||
return s3_client
|
||||
|
||||
|
||||
@@ -116,9 +123,9 @@ def list_s3_objects():
|
||||
)
|
||||
else:
|
||||
break
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
current_app.logger.exception(
|
||||
"An error occurred while regenerating cache #notify-debug-admin-1200",
|
||||
f"An error occurred while regenerating cache #notify-debug-admin-1200: {str(e)}",
|
||||
)
|
||||
|
||||
|
||||
@@ -184,18 +191,20 @@ def read_s3_file(bucket_name, object_key, s3res):
|
||||
"""
|
||||
try:
|
||||
job_id = get_job_id_from_s3_object_key(object_key)
|
||||
service_id = get_service_id_from_key(object_key)
|
||||
|
||||
if get_job_cache(job_id) is None:
|
||||
object = (
|
||||
job = (
|
||||
s3res.Object(bucket_name, object_key)
|
||||
.get()["Body"]
|
||||
.read()
|
||||
.decode("utf-8")
|
||||
)
|
||||
set_job_cache(job_id, object)
|
||||
set_job_cache(f"{job_id}_phones", extract_phones(object))
|
||||
set_job_cache(job_id, job)
|
||||
set_job_cache(f"{job_id}_phones", extract_phones(job, service_id, job_id))
|
||||
set_job_cache(
|
||||
f"{job_id}_personalisation",
|
||||
extract_personalisation(object),
|
||||
extract_personalisation(job),
|
||||
)
|
||||
|
||||
except LookupError:
|
||||
@@ -215,11 +224,21 @@ def get_s3_files():
|
||||
current_app.logger.info(
|
||||
f"job_cache length before regen: {len_job_cache()} #notify-debug-admin-1200"
|
||||
)
|
||||
count = 0
|
||||
try:
|
||||
with ThreadPoolExecutor() as executor:
|
||||
executor.map(lambda key: read_s3_file(bucket_name, key, s3res), object_keys)
|
||||
for object_key in object_keys:
|
||||
read_s3_file(bucket_name, object_key, s3res)
|
||||
count = count + 1
|
||||
eventlet.sleep(0.2)
|
||||
except Exception:
|
||||
current_app.logger.exception("Connection pool issue")
|
||||
current_app.logger.exception(
|
||||
f"Trouble reading {object_key} which is # {count} during cache regeneration"
|
||||
)
|
||||
except OSError as e:
|
||||
current_app.logger.exception(
|
||||
f"Egress proxy issue reading {object_key} which is # {count}"
|
||||
)
|
||||
raise e
|
||||
|
||||
current_app.logger.info(
|
||||
f"job_cache length after regen: {len_job_cache()} #notify-debug-admin-1200"
|
||||
@@ -375,7 +394,7 @@ def get_job_from_s3(service_id, job_id):
|
||||
)
|
||||
retries += 1
|
||||
sleep_time = backoff_factor * (2**retries) # Exponential backoff
|
||||
time.sleep(sleep_time)
|
||||
eventlet.sleep(sleep_time)
|
||||
continue
|
||||
else:
|
||||
# Typically this is "NoSuchKey"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import json
|
||||
from time import sleep
|
||||
|
||||
import eventlet
|
||||
from celery.signals import task_postrun
|
||||
from flask import current_app
|
||||
from requests import HTTPError, RequestException, request
|
||||
@@ -83,7 +83,7 @@ def process_job(job_id, sender_id=None):
|
||||
process_row(row, template, job, service, sender_id=sender_id)
|
||||
count = count + 1
|
||||
if count % 3 == 0:
|
||||
sleep(1)
|
||||
eventlet.sleep(1)
|
||||
|
||||
# End point/Exit point for message send flow.
|
||||
job_complete(job, start=start)
|
||||
|
||||
@@ -151,7 +151,7 @@ class AwsCloudwatchClient(Client):
|
||||
# result = temp_client.get_query_results(queryId=query_id)
|
||||
# if result['status'] == 'Complete':
|
||||
# break
|
||||
# time.sleep(1)
|
||||
# eventlet.sleep(1)
|
||||
|
||||
# delivery_receipts = []
|
||||
# for log in result['results']:
|
||||
|
||||
181
docs/all.md
181
docs/all.md
@@ -53,8 +53,10 @@
|
||||
- [Smoke-testing the App](#-smoke-testing-the-app)
|
||||
- [Simulated bulk send testing](#-simulated-bulk-send-testing)
|
||||
- [Configuration Management](#-configuration-management)
|
||||
- [DNS Changes](#-dns-changes)
|
||||
- [Exporting test results for compliance monitoring](#exporting-test-results-for-compliance-monitoring)
|
||||
- [DNS and Domain Changes](#-dns-and-domain-changes)
|
||||
- [Exporting daily scan results for compliance monitoring](#exporting-daily-scan-results-for-compliance-monitoring)
|
||||
- [Reviewing daily scan results for compliance](#reviewing-daily-scan-results-for-compliance)
|
||||
- [Rotating environment variable secrets](#rotating-environment-variable-secrets)
|
||||
- [Known Gotchas](#-known-gotchas)
|
||||
- [User Account Management](#-user-account-management)
|
||||
- [SMS Phone Number Management](#-sms-phone-number-management)
|
||||
@@ -1068,7 +1070,7 @@ that the security of the system is maintained.
|
||||
1. [Smoke-testing the App](#smoke-testing)
|
||||
1. [Simulated bulk send testing](#simulated-bulk-send-testing)
|
||||
1. [Configuration Management](#cm)
|
||||
1. [DNS Changes](#dns)
|
||||
1. [DNS and Domain Changes](#dns)
|
||||
1. [Known Gotchas](#gotcha)
|
||||
1. [User Account Management](#ac)
|
||||
1. [SMS Phone Number Management](#phone-numbers)
|
||||
@@ -1239,17 +1241,43 @@ US_Notify Administrators are responsible for ensuring that remediations for vuln
|
||||
- Low - 180 days
|
||||
- Informational - 365 days (depending on the analysis of the issue)
|
||||
|
||||
## <a name="dns"></a> DNS Changes
|
||||
## <a name="dns"></a> DNS and Domain Changes
|
||||
|
||||
Notify.gov DNS records are maintained within [the 18f/dns repository](https://github.com/18F/dns/blob/main/terraform/notify.gov.tf). To create new DNS records for notify.gov or any subdomains:
|
||||
Notify.gov DNS records are maintained within [the GSA-TTS/dns repository](https://github.com/GSA-TTS/dns/blob/main/terraform/notify.gov.tf), and the domains and routes are managed directly in our Cloud.gov production space.
|
||||
|
||||
1. Update the `notify.gov.tf` terraform to update oƒr create the new records within Route53 and push the branch to the 18f/dns repository.
|
||||
1. Open a PR.
|
||||
1. Verify that the plan output within circleci creates the records that you expect.
|
||||
1. Request a PR review from the 18F/tts-tech-portfolio team
|
||||
1. Once the PR is approved and merged, verify that the apply step happened correctly within [CircleCI](https://app.circleci.com/pipelines/github/18F/dns)
|
||||
**Step 1: Make changes to the DNS records**
|
||||
|
||||
## Exporting test results for compliance monitoring
|
||||
1. If you haven't already, clone a local copy of [the GSA-TTS/dns repository](https://github.com/GSA-TTS/dns).
|
||||
1. Create a new branch and update the [`notify.gov.tf`]((https://github.com/GSA-TTS/dns/blob/main/terraform/notify.gov.tf)) Terraform file to update, create, or remove DNS records within AWS Route 53.
|
||||
1. Open a PR in the repository and verify that the plan output within CircleCI makes the changes that you expect.
|
||||
1. Request a PR review from the `@tts-tech-operations` team within the GSA-TTS GitHub org.
|
||||
1. Once the PR is approved and merged, verify that the apply step happened correctly within [CircleCI](https://app.circleci.com/pipelines/github/GSA-TTS/dns).
|
||||
|
||||
**Step 2: Make changes to the domains and routes in Cloud.gov**
|
||||
|
||||
The domains and routes are managed via the [external domain service](https://www.cloud.gov/docs/services/external-domain-service/) within Cloud.gov.
|
||||
|
||||
If you're creating new domains:
|
||||
|
||||
1. Sign in to the `cf` CLI in your terminal and target the `notify-production` space.
|
||||
1. Create the new domain(s) with [`cf create-private-domain`](https://docs.cloudfoundry.org/devguide/deploy-apps/routes-domains.html#private-domains).
|
||||
1. Map the routes needed to the new domain(s) with [`cf map-route`](https://docs.cloudfoundry.org/devguide/deploy-apps/routes-domains.html#map-route).
|
||||
1. Update the service to account for the new domain(s): `cf update-service notify-admin-domain-production -c '{"domains": "example.gov,www.example.gov,..."}'` (make sure to list *all* domains that need to be accounted for, including any existing ones that you want to keep!).
|
||||
|
||||
If you're removing existing domains:
|
||||
|
||||
1. Sign in to the `cf` CLI in your terminal and target the `notify-production` space.
|
||||
1. Unmap the routes to the existing domain(s) with [`cf unmap-route`](https://docs.cloudfoundry.org/devguide/deploy-apps/routes-domains.html#unmap-route).
|
||||
1. Delete the existing domain(s) with [`cf delete-private-domain`](https://docs.cloudfoundry.org/devguide/deploy-apps/routes-domains.html#private-domains).
|
||||
1. Update the service to account for the deleted domain(s): `cf update-service notify-admin-domain-production -c '{"domains": "example.gov,www.example.gov,..."}'` (make sure to list *all* domains that need to be accounted for, including any existing ones that you want to keep!).
|
||||
|
||||
**Step 3: Redeploy or restage the Admin app:**
|
||||
|
||||
Restage or redeploy the `notify-admin-production` app. To restage, you can trigger the action in GitHub or run the command directly: `cf restage notify-admin-production --strategy rolling`.
|
||||
|
||||
Test that the changes took effect properly by going to the domain(s) that were adjusted and seeing if they resolve correctly and/or no longer resolve as expected. Note that this may take up to 72 hours, depending on how long it takes for the DNS changes to propogate.
|
||||
|
||||
## Exporting daily scan results for compliance monitoring
|
||||
|
||||
- Head to https://github.com/GSA/notifications-api/actions/workflows/daily_checks.yml
|
||||
- Open the most recent scan (it should be today's)
|
||||
@@ -1261,16 +1289,115 @@ Notify.gov DNS records are maintained within [the 18f/dns repository](https://gi
|
||||
- Rename to `api_static_scan_DATE.zip` and add it to 🔒 https://drive.google.com/drive/folders/1dSe9H7Ag_hLfi5hmQDB2ktWaDwWSf4_R
|
||||
- Repeat for https://github.com/GSA/notifications-admin/actions/workflows/daily_checks.yml
|
||||
|
||||
## Rotating the DANGEROUS_SALT
|
||||
## Reviewing daily scan results for compliance
|
||||
|
||||
1. Start API locally `make run-procfile`
|
||||
2. In a separate terminal tab, navigate to the API project and run `poetry run flask command generate-salt`
|
||||
3. A random secret will appear in the tab
|
||||
4. Go to github->settings->secrets and variables->actions in the admin project and find the DANGEROUS_SALT secret for the admin project for staging. Open it and paste the result of #3 into the secret and save. Repeat for the API project, for staging.
|
||||
5. Repeat #3 and #4 but do it for demo
|
||||
6. Repeat #3 and #4 but do it for production
|
||||
To review the daily scan results and check for any new reported findings that need to be remediated, perform the following steps.
|
||||
|
||||
**For the API**
|
||||
|
||||
1. Go to the daily scan page: https://github.com/GSA/notifications-api/actions/workflows/daily_checks.yml
|
||||
1. Click on the latest scan (it should have run on the current day and be at the time)
|
||||
1. Scroll to the bottom and download the two artifacts: `bandit-report` and `zap_scan` - these are zip files that contain the full scan reports
|
||||
1. Click on the `pip-audit` job in the menu on the left of the screen
|
||||
1. Click on the `Run pypa/gh-action-pip-audit` step (the version number may change over time as it gets updated)
|
||||
1. Check that the output of the step doesn't show any new audit findings (the step and job will have failed if it did)
|
||||
1. Click on the `static-scan` job in the menu on the left of the screen
|
||||
1. Click on the `Run scan` step
|
||||
1. Check that the output of the step doesn't show any new scan findings (note: the step and job may still show as successful even if something was found)
|
||||
1. Click on the `dynamic-scan` job in the menu on the left of the screen
|
||||
1. Click on the `Run OWASP API Scan` step
|
||||
1. Check that the output of the step doesn't show any new scan findings (note: the step and job may still show as successful even if something was found)
|
||||
|
||||
Once you're done performing the steps above to gather all of the information, make a note of any new findings that need to be accounted for and remediated and create issues to track the work.
|
||||
|
||||
**For the Admin**
|
||||
|
||||
1. Go to the daily scan page: https://github.com/GSA/notifications-admin/actions/workflows/daily_checks.yml
|
||||
1. Click on the latest scan (it should have run on the current day and be at the time)
|
||||
1. Scroll to the bottom and download the artifact: `zap_scan` - this is a zip file that contains the full scan reports
|
||||
1. Click on the `dependency-audits` job in the menu on the left of the screen
|
||||
1. Click on the `Run pypa/gh-action-pip-audit` step (the version number may change over time as it gets updated)
|
||||
1. Check that the output of the step doesn't show any new audit findings (the step and job will have failed if it did)
|
||||
1. Click on the `Run npm audit` step
|
||||
1. Check that the output of the step doesn't show any new audit findings (the step and job will have failed if it did)
|
||||
1. Click on the `static-scan` job in the menu on the left of the screen
|
||||
1. Click on the `Run scan` step
|
||||
1. Check that the output of the step doesn't show any new scan findings (note: the step and job may still show as successful even if something was found)
|
||||
1. Click on the `dynamic-scan` job in the menu on the left of the screen
|
||||
1. Click on the `Run OWASP Full Scan` step
|
||||
1. Check that the output of the step doesn't show any new scan findings (note: the step and job may still show as successful even if something was found)
|
||||
|
||||
Once you're done performing the steps above to gather all of the information, make a note of any new findings that need to be accounted for and remediated and create issues to track the work.
|
||||
|
||||
|
||||
## Rotating environment variable secrets
|
||||
|
||||
There are a few different ways to handle rotating environment variable secrets, depending on what the secret is.
|
||||
|
||||
### Secret environment variables (set directly)
|
||||
|
||||
The `ADMIN_CLIENT_SECRET`, `DANGEROUS_SALT`, and `SECRET_KEY` environment variables are all generated random strings of characters. To make a new value for any of these environment variables, perform the following steps:
|
||||
|
||||
1. Start the API locally with the command `make run-procfile`
|
||||
1. In a separate terminal tab, navigate to the API project and run `poetry run flask command generate-salt` (this command is found in the [`app/commands.py` file](https://github.com/GSA/notifications-api/blob/main/app/commands.py#L1030-L1037))
|
||||
1. A random secret will appear in the tab, which you will use to update the value(s) in GitHub
|
||||
|
||||
Next, you'll need to go into GitHub for either the [API repo environment settings](https://github.com/GSA/notifications-api/settings/environments) or [Admin repo environment settings](https://github.com/GSA/notifications-admin/settings/environments). Once there you'll see a list of all of the environments; click into the one that you're looking to update and then find the corresponding environment that you need to update. Click on the pencil icon to the right of the environment variable name to edit the value, then paste in the value you generated with the previous steps.
|
||||
|
||||
**NOTE:** These values must match between the API and Admin environment variables per environment (meaning, if you change the Admin repo value for any of these values in any environment, the same variable for the API in the same environment must be changed to match it!).
|
||||
|
||||
The important thing is to use the same secret for Admin and API on each tier -- i.e. you only generate three secrets per environment.
|
||||
|
||||
**NOTE:** You may also have to update these values for Dependabot as well! To do this, go into GitHub and the navigate through `Settings -> Secrets and variables -> Dependabot`, which will take you to a special page to manage environment variables specifically for Dependabot. This is more necessary in the Admin repo because of the E2E tests.
|
||||
|
||||
### E2E environment variables (set directly)
|
||||
|
||||
See the [end-to-end testing section](#end-to-end-testing).
|
||||
|
||||
### Service bindings for Cloud.gov-managed services
|
||||
|
||||
For any Cloud.gov service instance that you need to rotate credentials for, you need to run the following commands:
|
||||
|
||||
1. `cf unbind-service <APP NAME> <SERVICE NAME>`
|
||||
1. `cf bind-service <APP NAME> <SERVICE NAME>`
|
||||
|
||||
Once you are done unbinding and re-binding all services you're looking to rotate credentials for, you need to restage or redeploy the application(s) for the changes to take effect. You can restage directly in the command line: `cf restage <APP NAME> --strategy rolling`
|
||||
|
||||
### Rotating New Relic API keys and licenses
|
||||
|
||||
To rotate New Relic API key, license key, and other credentials, you need access to New Relic. If you have access, sign in and then click on your name in the lower left. Click on `API keys` and you'll be taken to the management screen for all of the API keys. From there, perform these steps:
|
||||
|
||||
1. Create new versions of whichever key(s) you would like to rotate
|
||||
1. Update the corresponding environment variable(s) in GitHub for both the [API repo environment settings](https://github.com/GSA/notifications-api/settings/environments) and the [Admin repo environment settings](https://github.com/GSA/notifications-admin/settings/environments)
|
||||
1. Restage or redeploy the applications
|
||||
1. Once you confirm the new key(s) in New Relic are working, delete the old keys on the API Key management screen
|
||||
|
||||
### Terraform state bucket key rotation
|
||||
|
||||
To rotate the Terraform state bucket key, run these commands in the `api/terraform/bootstrap` directory of the API repo:
|
||||
|
||||
```sh
|
||||
# comment out prevent_destroy in terraform/bootstrap/main.tf
|
||||
# update username to create in run.sh and teardown-creds.sh
|
||||
$ ./run.sh plan -replace=cloudfoundry_service_key.bucket_creds
|
||||
$ ./run.sh apply -replace=cloudfoundry_service_key.bucket_creds
|
||||
```
|
||||
|
||||
Once that's done, copy the key generating to the staging, demo, and production environments of both the API and the Admin.
|
||||
|
||||
### Refreshing/rotating the Login.gov certificate
|
||||
|
||||
1. generate certificate: `openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.crt -nodes`
|
||||
1. update the github secrets for staging, demo, production (contents of key.pem go in LOGIN_PEM and contents of cert.crt in LOGIN_PUB). **DO NOT RESTAGE YET**.
|
||||
1. use the same certificate for staging, demo, and production
|
||||
1. login to the login.gov partner app (https://portal.int.identitysandbox.gov)
|
||||
1. add the new certificate to the production version of Notify in the partner app (our partner app account has sandbox and production)
|
||||
1. Make a Zendesk support request for login.gov to push the new version of Notify (https://zendesk.login.gov)
|
||||
1. Do not delete the old certificate, because you need things to keep working until you complete the transition.
|
||||
1. When you receive an email from login.gov that the app has been pushed successfully, restage notify on the staging tier
|
||||
1. If staging works, you can restage demo and production
|
||||
1. Delete the old certificate in the partner app, send another zendesk request to push again. This is best practice but a lower priority, because certificates eventually expire anyway and we have changed the certificate in github secrets, so the old cert is no longer relevant.
|
||||
|
||||
The important thing is to use the same secret for Admin and API on each tier--i.e. you only generate three secrets.
|
||||
|
||||
## <a name="gotcha"></a> Known Gotchas
|
||||
|
||||
@@ -1507,19 +1634,3 @@ Note: better to search on space 'notify-production' rather than specifically for
|
||||
#notify-admin-1505 (general login issues)
|
||||
#notify-admin-1701 (wrong sender phone number)
|
||||
#notify-admin-1859 (job is created with created_at being the wrong time)
|
||||
|
||||
### refreshing the login.gov certificate
|
||||
|
||||
1. generate certificate: `openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.crt -nodes`
|
||||
2. update the github secrets for staging, demo, production (contents of key.pem go in LOGIN_PEM and contents of cert.crt in LOGIN_PUB).
|
||||
DO NOT RESTAGE YET.
|
||||
3. use the same certificate for staging, demo, and production
|
||||
4. login to the login.gov partner app (https://portal.int.identitysandbox.gov)
|
||||
5. add the new certificate to the production version of Notify in the partner app (our partner app account has sandbox and production)
|
||||
6. Make a Zendesk support request for login.gov to push the new version of Notify (https://zendesk.login.gov)
|
||||
7. Do not delete the old certificate, because you need things to keep working until you complete the transition.
|
||||
8. When you receive an email from login.gov that the app has been pushed successfully, restage notify on the staging tier
|
||||
9. If staging works, you can restage demo and production
|
||||
10. Delete the old certificate in the partner app, send another zendesk request to push again. This is best practice but a lower
|
||||
priority, because certificates eventually expire anyway and we have changed the certificate in github secrets, so the old cert is
|
||||
no longer relevant.
|
||||
|
||||
2076
poetry.lock
generated
2076
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -8,25 +8,25 @@ readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.12.2"
|
||||
alembic = "==1.13.2"
|
||||
alembic = "==1.16.1"
|
||||
amqp = "==5.3.1"
|
||||
beautifulsoup4 = "==4.12.3"
|
||||
beautifulsoup4 = "==4.13.4"
|
||||
boto3 = "^1.34.150"
|
||||
botocore = "^1.34.159"
|
||||
cachetools = "==5.4.0"
|
||||
celery = {version = "==5.4.0", extras = ["redis"]}
|
||||
celery = {version = "==5.5.2", extras = ["redis"]}
|
||||
certifi = ">=2022.12.7"
|
||||
cffi = "==1.17.1"
|
||||
charset-normalizer = "^3.4.1"
|
||||
click = "==8.1.8"
|
||||
charset-normalizer = "^3.4.2"
|
||||
click = "==8.2.1"
|
||||
click-datetime = "==0.4.0"
|
||||
click-didyoumean = "==0.3.1"
|
||||
click-plugins = "==1.1.1"
|
||||
click-repl = "==0.3.0"
|
||||
deprecated = "==1.2.14"
|
||||
eventlet = "==0.39.1"
|
||||
eventlet = "==0.36.1"
|
||||
expiringdict = "==1.2.2"
|
||||
flask = "~=3.0"
|
||||
flask = "~=3.1"
|
||||
flask-bcrypt = "==1.0.1"
|
||||
flask-marshmallow = "==1.2.1"
|
||||
flask-migrate = "==4.1.0"
|
||||
@@ -35,36 +35,36 @@ flask-sqlalchemy = "==3.1.1"
|
||||
gunicorn = {version = "==23.0.0", extras = ["eventlet"]}
|
||||
iso8601 = "==2.1.0"
|
||||
jsonschema = {version = "==4.23.0", extras = ["format"]}
|
||||
lxml = "==5.3.1"
|
||||
lxml = "==5.4.0"
|
||||
marshmallow = "==3.26.1"
|
||||
marshmallow-sqlalchemy = "==1.0.0"
|
||||
newrelic = "*"
|
||||
notifications-python-client = "==10.0.0"
|
||||
notifications-python-client = "==10.0.1"
|
||||
oscrypto = { git = "https://github.com/wbond/oscrypto.git", rev = "1547f53" }
|
||||
packaging = "==25.0"
|
||||
poetry-dotenv-plugin = "==0.2.0"
|
||||
psycopg2-binary = "==2.9.9"
|
||||
pyjwt = "==2.10.1"
|
||||
python-dotenv = "==1.0.1"
|
||||
sqlalchemy = "==2.0.31"
|
||||
python-dotenv = "==1.1.0"
|
||||
sqlalchemy = "==2.0.41"
|
||||
werkzeug = "^3.0.6"
|
||||
faker = "^26.0.0"
|
||||
faker = "^37.3.0"
|
||||
async-timeout = "^5.0.1"
|
||||
bleach = "^6.1.0"
|
||||
geojson = "^3.2.0"
|
||||
numpy = "^2.2.5"
|
||||
numpy = "^2.2.6"
|
||||
ordered-set = "^4.1.0"
|
||||
phonenumbers = "^8.13.42"
|
||||
phonenumbers = "^9.0.5"
|
||||
python-json-logger = "^3.3.0"
|
||||
regex = "^2024.11.6"
|
||||
shapely = "^2.0.5"
|
||||
shapely = "^2.1.1"
|
||||
smartypants = "^2.0.1"
|
||||
mistune = "^3.1.3"
|
||||
blinker = "^1.9.0"
|
||||
cryptography = "^44.0.1"
|
||||
cryptography = "^45.0.2"
|
||||
idna = "^3.7"
|
||||
jmespath = "^1.0.1"
|
||||
markupsafe = "^2.1.5"
|
||||
markupsafe = "^3.0.2"
|
||||
pycparser = "^2.22"
|
||||
python-dateutil = "^2.9.0.post0"
|
||||
pyyaml = "^6.0.2"
|
||||
@@ -77,6 +77,7 @@ jinja2 = "^3.1.6"
|
||||
redis = "^5.0.8"
|
||||
requests = "^2.32.3"
|
||||
flask-socketio = "^5.5.1"
|
||||
virtualenv = "<20.30"
|
||||
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
@@ -84,12 +85,12 @@ awscli = "^1.33.32"
|
||||
bandit = "*"
|
||||
black = "^25.1.0"
|
||||
cloudfoundry-client = "*"
|
||||
exceptiongroup = "==1.2.2"
|
||||
exceptiongroup = "==1.3.0"
|
||||
flake8 = "^7.2.0"
|
||||
flake8-bugbear = "^24.12.12"
|
||||
freezegun = "^1.5.1"
|
||||
honcho = "*"
|
||||
isort = "^5.13.2"
|
||||
isort = "^6.0.1"
|
||||
jinja2-cli = {version = "==0.8.2", extras = ["yaml"]}
|
||||
moto = "==5.1.4"
|
||||
pip-audit = "*"
|
||||
@@ -101,12 +102,16 @@ pytest-cov = "^6.1.1"
|
||||
pytest-xdist = "^3.5.0"
|
||||
radon = "^6.0.1"
|
||||
requests-mock = "^1.11.0"
|
||||
setuptools = "^75.8.0"
|
||||
setuptools = "^80.8.0"
|
||||
sqlalchemy-utils = "^0.41.2"
|
||||
vulture = "^2.10"
|
||||
detect-secrets = "^1.5.0"
|
||||
poetry-dotenv-plugin = "^0.2.0"
|
||||
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.poetry.plugins."poetry.application.plugin"]
|
||||
dotenv = "poetry_dotenv_plugin.plugin:PoetryDotenvPlugin"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
from datetime import timedelta
|
||||
from os import getenv
|
||||
from unittest.mock import MagicMock, Mock, call, patch
|
||||
from unittest.mock import ANY, MagicMock, Mock, call, patch
|
||||
|
||||
import botocore
|
||||
import pytest
|
||||
@@ -39,7 +39,7 @@ default_region = getenv("CSV_AWS_REGION")
|
||||
|
||||
def single_s3_object_stub(key="foo", last_modified=None):
|
||||
return {
|
||||
"ETag": '"d41d8cd98f00b204e9800998ecf8427e"',
|
||||
"ETag": '"d"',
|
||||
"Key": key,
|
||||
"LastModified": last_modified or utc_now(),
|
||||
}
|
||||
@@ -420,29 +420,17 @@ def test_get_s3_files_success(client, mocker):
|
||||
"CSV_UPLOAD_BUCKET": {"bucket": "test-bucket"},
|
||||
"job_cache": {},
|
||||
}
|
||||
mock_thread_pool_executor = mocker.patch("app.aws.s3.ThreadPoolExecutor")
|
||||
mock_read_s3_file = mocker.patch("app.aws.s3.read_s3_file")
|
||||
mock_list_s3_objects = mocker.patch("app.aws.s3.list_s3_objects")
|
||||
mock_get_s3_resource = mocker.patch("app.aws.s3.get_s3_resource")
|
||||
mock_list_s3_objects.return_value = ["file1.csv", "file2.csv"]
|
||||
mock_s3_resource = MagicMock()
|
||||
mock_get_s3_resource.return_value = mock_s3_resource
|
||||
mock_executor = MagicMock()
|
||||
|
||||
def mock_map(func, iterable):
|
||||
for item in iterable:
|
||||
func(item)
|
||||
|
||||
mock_executor.map.side_effect = mock_map
|
||||
mock_thread_pool_executor.return_value.__enter__.return_value = mock_executor
|
||||
|
||||
get_s3_files()
|
||||
|
||||
# mock_current_app.config.__getitem__.assert_called_once_with("CSV_UPLOAD_BUCKET")
|
||||
mock_list_s3_objects.assert_called_once()
|
||||
mock_thread_pool_executor.assert_called_once()
|
||||
|
||||
mock_executor.map.assert_called_once()
|
||||
|
||||
calls = [
|
||||
(("test-bucket", "file1.csv", mock_s3_resource),),
|
||||
@@ -473,7 +461,7 @@ def test_get_s3_client(mocker):
|
||||
mock_session.return_value.client.return_value = mock_s3_client
|
||||
result = get_s3_client()
|
||||
|
||||
mock_session.return_value.client.assert_called_once_with("s3")
|
||||
mock_session.return_value.client.assert_called_once_with("s3", config=ANY)
|
||||
assert result == mock_s3_client
|
||||
|
||||
|
||||
@@ -615,15 +603,6 @@ def test_get_s3_files_handles_exception(mocker):
|
||||
mock_read_s3_file = mocker.patch(
|
||||
"app.aws.s3.read_s3_file", side_effect=[None, Exception("exception here")]
|
||||
)
|
||||
|
||||
mock_thread_pool_executor = mocker.patch("app.aws.s3.ThreadPoolExecutor")
|
||||
mock_executor = mock_thread_pool_executor.return_value.__enter__.return_value
|
||||
|
||||
def mock_map(func, iterable):
|
||||
for item in iterable:
|
||||
func(item)
|
||||
|
||||
mock_executor.map.side_effect = mock_map
|
||||
get_s3_files()
|
||||
|
||||
calls = [
|
||||
@@ -632,4 +611,6 @@ def test_get_s3_files_handles_exception(mocker):
|
||||
]
|
||||
mock_read_s3_file.assert_has_calls(calls, any_order=True)
|
||||
|
||||
mock_current_app.logger.exception.assert_called_with("Connection pool issue")
|
||||
mock_current_app.logger.exception.assert_called_with(
|
||||
"Trouble reading file2.csv which is # 1 during cache regeneration"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user