"""Interface to the ows-contracts microservice.""" from oto import response from owsrequest import request from ows_product_physical.constant import error from ows_product_physical.constant import service_name def is_mech_admin(account_type, account_id): """Check whether user with provided Grass credentials is mechadmin. ows-contracts returns 200 if user is mechadmin, 204 if not. Args: account_type (str): Grass-Account-Type header account_id (str): Grass-Account-Id header Returns: oto.response.Response """ mech_admin_url = '/{0}/{1}/mechadmin_for_account'.format( account_type, account_id) contracts_response = request.get( service_name.OWS_CONTRACTS, mech_admin_url) if contracts_response.status_code != 200: try: errors_data = contracts_response.json() except Exception: errors_data = { 'code': error.OWS_CONTRACTS_ERROR_CODE, 'message': contracts_response.content.decode() } return response.create_error_response( status=contracts_response.status_code, **errors_data) return response.Response(message=contracts_response.json())