"""Various utility functions for handlers.""" from flask import request from oto import response from owsrequest import flask_request from masters_registry.constant import error from masters_registry.constant import field_const def get_grass_account(): """Get grass account info from headers or request params. Returns: reponse.Response: response object, containing (grass_account_id, grass_account_type) or error """ account_type, account_id = flask_request.get_grass_headers(request) alt_account_type = request.args.get(field_const.ACCOUNT_TYPE) alt_account_id = request.args.get(field_const.ACCOUNT_ID) # If no account data from headers, check query parameters if not account_type and not account_id: account_type = alt_account_type account_id = alt_account_id elif alt_account_type or alt_account_id: # More than one method was used to pass in account data return response.create_error_response( code=error.ERROR_ACCOUNT_DATA_CODE, message=error.ERROR_ACCOUNT_DATA_REQUIRED_MSG) # Could not find complete account data if not account_type or not account_id: return response.create_error_response( code=error.ERROR_ACCOUNT_DATA_CODE, message=error.ERROR_ACCOUNT_DATA_REQUIRED_MSG) return response.Response(message=(account_type, account_id))