Skip to content

Commit

Permalink
FEEDER: add token inside party colin calls too (#1420)
Browse files Browse the repository at this point in the history
Signed-off-by: Kial Jinnah <[email protected]>
  • Loading branch information
kialj876 authored Sep 19, 2023
1 parent 67153b7 commit 068d6b6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
13 changes: 9 additions & 4 deletions solr-feeder/solr_feeder/services/colin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,21 @@ def get_business_info(legal_type: str, identifier: str, token: str) -> tuple[dic
return None, {'message': 'COLIN service error.', 'status_code': HTTPStatus.INTERNAL_SERVER_ERROR}


def get_owners(legal_type: str, identifier: str) -> tuple[list[dict], dict]:
def get_owners(legal_type: str, identifier: str, token: str) -> tuple[list[dict], dict]:
"""Return the firm owners of the business."""
try:
owners = []
if legal_type not in FIRM_LEGAL_TYPES:
return [], None

parties_url = f'{current_app.config["COLIN_API_URL"]}/businesses/{legal_type}/{identifier}/parties'
headers = {'Authorization': 'Bearer ' + token}
# get owners
fio_res = requests.get(f'{parties_url}?partyType=Firm Individual Owner',
headers=headers,
timeout=current_app.config['COLIN_API_TIMEOUT'])
fbo_res = requests.get(f'{parties_url}?partyType=Firm Business Owner',
headers=headers,
timeout=current_app.config['COLIN_API_TIMEOUT'])
if fio_res.status_code not in [HTTPStatus.OK, HTTPStatus.NOT_FOUND]:
return None, {'message': fio_res.json(), 'status_code': fio_res.status_code}
Expand All @@ -122,14 +125,16 @@ def get_owners(legal_type: str, identifier: str) -> tuple[list[dict], dict]:
return None, {'message': 'COLIN service error.', 'status_code': HTTPStatus.INTERNAL_SERVER_ERROR}


def get_parties(legal_type: str, identifier: str) -> tuple[list[dict], dict]:
def get_parties(legal_type: str, identifier: str, token: str) -> tuple[list[dict], dict]:
"""Return the parties of the business."""
try:
parties = []
parties_url = f'{current_app.config["COLIN_API_URL"]}/businesses/{legal_type}/{identifier}/parties/all'

headers = {'Authorization': 'Bearer ' + token}
# get all parties
all_parties = requests.get(f'{parties_url}', timeout=current_app.config['COLIN_API_TIMEOUT'])
all_parties = requests.get(f'{parties_url}',
headers=headers,
timeout=current_app.config['COLIN_API_TIMEOUT'])
if all_parties.status_code not in [HTTPStatus.OK, HTTPStatus.NOT_FOUND]:
return None, {'message': all_parties.json(), 'status_code': all_parties.status_code}

Expand Down
4 changes: 2 additions & 2 deletions solr-feeder/solr_feeder/services/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def update_search_cores(identifier: str, legal_type: str):
error_messages = []
# send data to bor search core via bor-api
if bor_url := current_app.config['BOR_API_URL']:
parties, error = get_parties(legal_type, identifier)
parties, error = get_parties(legal_type, identifier, token)
if error:
logging.error('Error getting COLIN party data: %s', error)
return {'message': error['message']}, HTTPStatus.INTERNAL_SERVER_ERROR
Expand All @@ -82,7 +82,7 @@ def update_search_cores(identifier: str, legal_type: str):
logging.debug('BOR core updated (%s).', identifier)

# for business search only include owners
owners, error = get_owners(legal_type, identifier)
owners, error = get_owners(legal_type, identifier, token)
if error:
logging.error('Error getting COLIN owner data: %s', error)
return {'message': error['message']}, HTTPStatus.INTERNAL_SERVER_ERROR
Expand Down
2 changes: 1 addition & 1 deletion solr-feeder/solr_feeder/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
Development release segment: .devN
"""

__version__ = '2.0.5' # pylint: disable=invalid-name
__version__ = '2.0.6' # pylint: disable=invalid-name

0 comments on commit 068d6b6

Please sign in to comment.