Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DST-224: Companies house integration #19

Merged
merged 7 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions local.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 32 additions & 0 deletions report_a_breach/core/services/ch_proxy.py
Original file line number Diff line number Diff line change
@@ -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")
4 changes: 4 additions & 0 deletions report_a_breach/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class CompaniesHouseException(Exception):
"""Exception raised when issue encountered with Companies House API"""

pass