diff --git a/Pipfile.lock b/Pipfile.lock index 5c149fcb..7cbd7c80 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -166,6 +166,7 @@ "sha256:b1260ed381b10a11753c73444408e19869f3241fc45c985cd55a30177c789d13" ], "index": "pypi", + "markers": "python_version >= '3.8'", "version": "==4.2.10" }, "django-audit-log-middleware": { @@ -173,14 +174,16 @@ "sha256:e92b1b594db68720ac35edfecc21daaf8d1c446af00622ade4de14bcbc43329b" ], "index": "pypi", + "markers": "python_version >= '3.6'", "version": "==0.0.4" }, "django-chunk-upload-handlers": { "hashes": [ - "sha256:9959a4e8211ec7afee266f02034441898f31540e84b558d6ec6509c408af211c" + "sha256:4a8c7113f1fea9f307b4caa79995dc5824c7f5bc70bdc486cb93b5091d782854" ], "index": "pypi", - "version": "==0.0.13" + "markers": "python_version >= '3.8'", + "version": "==0.0.14" }, "django-countries": { "hashes": [ @@ -196,6 +199,7 @@ "sha256:d592044771412ae1bd539cc377203aa61d4eebe77fcbc07fbc8f12d3746d4f6b" ], "index": "pypi", + "markers": "python_version >= '3.8'", "version": "==2.1" }, "django-environ": { @@ -204,6 +208,7 @@ "sha256:f32a87aa0899894c27d4e1776fa6b477e8164ed7f6b3e410a62a6d72caaf64be" ], "index": "pypi", + "markers": "python_version >= '3.6' and python_version < '4'", "version": "==0.11.2" }, "django-formtools": { @@ -212,6 +217,7 @@ "sha256:bce9b64eda52cc1eef6961cc649cf75aacd1a707c2fff08d6c3efcbc8e7e761a" ], "index": "pypi", + "markers": "python_version >= '3.8'", "version": "==2.5.1" }, "django-ipware": { @@ -228,6 +234,7 @@ "sha256:992dcca3cddc0b67b470fc91f77292e2d2a6010d37c9eac3536e9d80e8754032" ], "index": "pypi", + "markers": "python_version >= '3.8'", "version": "==3.4.0" }, "django-storages": { @@ -236,6 +243,7 @@ "sha256:51b36af28cc5813b98d5f3dfe7459af638d84428c8df4a03990c7d74d1bea4e5" ], "index": "pypi", + "markers": "python_version >= '3.7'", "version": "==1.14.2" }, "docopt": { @@ -369,6 +377,7 @@ "sha256:88ec8bff1d634f98e61b9f65bc4bf3cd918a90806c6f5c48bc5603849ec81033" ], "index": "pypi", + "markers": "python_version >= '3.5'", "version": "==21.2.0" }, "idna": { @@ -400,6 +409,7 @@ "sha256:664a5b5da2aa1a00efa8106bfa4855db04da95d79586e5edfb0411637d20d2d9" ], "index": "pypi", + "markers": "python_version >= '3.7'", "version": "==9.0.0" }, "packaging": { @@ -416,6 +426,7 @@ "sha256:4d5a0a5a8590906daa58ebd5f3cfc34091377354a1acced269dd10faf55da60e" ], "index": "pypi", + "markers": "python_version >= '3.7'", "version": "==3.1.18" }, "pycodestyle": { @@ -448,6 +459,7 @@ "sha256:86ea5559263c098e1aa4f866776aa2cf45362fd91a576b9fd8fbbbb55db12c4e" ], "index": "pypi", + "markers": "python_full_version >= '3.8.1'", "version": "==6.1.0" }, "python-dateutil": { @@ -528,6 +540,7 @@ "sha256:b1f9db9bf67dc183484d760b99f4080185633136a273a03f6436034a41064146" ], "index": "pypi", + "markers": "python_version >= '3.8'", "version": "==6.6.0" }, "zope.event": { @@ -624,6 +637,7 @@ "sha256:e0aaf6041986767a5e0ce663c7a2f0e9eaf21e6ff87a5f95cbf3675bfd4c41d2" ], "index": "pypi", + "markers": "python_version >= '3.8'", "version": "==23.12.1" }, "boto3": { @@ -740,6 +754,7 @@ "sha256:b1260ed381b10a11753c73444408e19869f3241fc45c985cd55a30177c789d13" ], "index": "pypi", + "markers": "python_version >= '3.8'", "version": "==4.2.10" }, "django-formtools": { @@ -748,6 +763,7 @@ "sha256:bce9b64eda52cc1eef6961cc649cf75aacd1a707c2fff08d6c3efcbc8e7e761a" ], "index": "pypi", + "markers": "python_version >= '3.8'", "version": "==2.5.1" }, "djhtml": { @@ -775,11 +791,11 @@ }, "identify": { "hashes": [ - "sha256:a4316013779e433d08b96e5eabb7f641e6c7942e4ab5d4c509ebd2e7a8994aed", - "sha256:ee17bc9d499899bc9eaec1ac7bf2dc9eedd480db9d88b96d123d3b64a9d34f5d" + "sha256:10a7ca245cfcd756a554a7288159f72ff105ad233c7c4b9c6f0f4d108f5f6791", + "sha256:c4de0081837b211594f8e877a6b4fad7ca32bbfc1a9307fdd61c28bfe923f13e" ], "markers": "python_version >= '3.8'", - "version": "==2.5.34" + "version": "==2.5.35" }, "iniconfig": { "hashes": [ @@ -795,6 +811,7 @@ "sha256:ee6cbb101af1a859c7fe84f2a264c059020b0cb7fe3535f9424300ab568f6bd5" ], "index": "pypi", + "markers": "python_version >= '3.6'", "version": "==2.2.0" }, "isort": { @@ -871,8 +888,8 @@ }, "pre-commit": { "hashes": [ - "sha256:9fe989afcf095d2c4796ce7c553cf28d4d4a9b9346de3cda079bcf40748454a4", - "sha256:c90961d8aa706f75d60935aba09469a6b0bcb8345f127c3fbee4bdc5f114cf4b" + "sha256:ba637c2d7a670c10daedc059f5c49b5bd0aadbccfcd7ec15592cf9665117532c", + "sha256:c3ef34f463045c88658c5b99f38c1e297abdcc0ff13f98d3370055fbbfabc67e" ], "index": "pypi", "version": "==3.6.1" @@ -899,6 +916,7 @@ "sha256:7a1585285aefc5165db81083c3e06363a27448f6b467b3b0f30dbd0ac1f73810" ], "index": "pypi", + "markers": "python_full_version >= '3.8.0'", "version": "==3.0.3" }, "pyproject-flake8": { @@ -907,15 +925,16 @@ "sha256:86ea5559263c098e1aa4f866776aa2cf45362fd91a576b9fd8fbbbb55db12c4e" ], "index": "pypi", + "markers": "python_full_version >= '3.8.1'", "version": "==6.1.0" }, "pytest": { "hashes": [ - "sha256:249b1b0864530ba251b7438274c4d251c58d868edaaec8762893ad4a0d71c36c", - "sha256:50fb9cbe836c3f20f0dfa99c565201fb75dc54c8d76373cd1bde06b06657bdb6" + "sha256:267f6563751877d772019b13aacbe4e860d73fe8f651f28112e9ac37de7513ae", + "sha256:3e4f16fe1c0a9dc9d9389161c127c3edc5d810c38d6793042fb81d9f48a59fca" ], "markers": "python_version >= '3.8'", - "version": "==8.0.0" + "version": "==8.0.1" }, "pytest-cov": { "hashes": [ @@ -923,6 +942,7 @@ "sha256:6ba70b9e97e69fcc3fb45bfeab2d0a138fb65c4d0d6a41ef33983ad114be8c3a" ], "index": "pypi", + "markers": "python_version >= '3.7'", "version": "==4.1.0" }, "python-dateutil": { diff --git a/config/settings/base.py b/config/settings/base.py index 90987c2b..045ef197 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -188,6 +188,9 @@ DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" +# Companies House API +COMPANIES_HOUSE_API_KEY = env.str("COMPANIES_HOUSE_API_KEY", default="") + # GOV NOTIFY GOV_NOTIFY_API_KEY = env.str("GOV_NOTIFY_API_KEY") EMAIL_VERIFY_CODE_TEMPLATE_ID = env.str("GOVUK_NOTIFY_TEMPLATE_EMAIL_VERIFICATION") diff --git a/local.env.example b/local.env.example index fa502b3b..d7cd88de 100644 --- a/local.env.example +++ b/local.env.example @@ -16,3 +16,5 @@ AWS_REGION=Ask a Colleague CLAM_AV_USERNAME=Ask a Colleague CLAM_AV_PASSWORD=Ask a Colleague CLAM_AV_DOMAIN=Ask a Colleague + +COMPANIES_HOUSE_API_KEY=ask team members diff --git a/report_a_breach/core/services/ch_proxy.py b/report_a_breach/core/services/ch_proxy.py new file mode 100644 index 00000000..e5a6918a --- /dev/null +++ b/report_a_breach/core/services/ch_proxy.py @@ -0,0 +1,32 @@ +import base64 + +import requests +from django.conf import settings +from exceptions import CompaniesHouseException + +COMPANIES_HOUSE_BASIC_AUTH = base64.b64encode( # /PS-IGNORE + bytes(f"{settings.COMPANIES_HOUSE_API_KEY}:", "utf-8") +).decode("utf-8") +COMPANIES_HOUSE_BASE_DOMAIN = "https://api.companieshouse.gov.uk" + + +def get_details_from_companies_house(self, registration_number): + """ + Retrieves and returns details of a company from Companies House + using registration number that is passed in. + """ + + if registration_number: + headers_get_company = {"Authorization": f"Basic {COMPANIES_HOUSE_BASIC_AUTH}"} + response = requests.get( + f"{COMPANIES_HOUSE_BASE_DOMAIN}/company/{registration_number}", + headers=headers_get_company, + ) + if response.status_code == 200: + return response.json() + else: + raise CompaniesHouseException( + f"Companies House API request failed: {response.status_code}" + ) + else: + raise CompaniesHouseException("No registration number provided for Companies House API") diff --git a/report_a_breach/exceptions.py b/report_a_breach/exceptions.py new file mode 100644 index 00000000..f200b330 --- /dev/null +++ b/report_a_breach/exceptions.py @@ -0,0 +1,4 @@ +class CompaniesHouseException(Exception): + """Exception raised when issue encountered with Companies House API""" + + pass