proxy_app.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #
  2. # Copyright 2019 The FATE Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from flask import request
  17. from flask.json import jsonify
  18. from fate_arch.common import FederatedMode
  19. from fate_flow.utils.api_utils import federated_api, forward_api, proxy_api
  20. page_name = 'forward'
  21. @manager.route('/<role>', methods=['POST'])
  22. def start_proxy(role):
  23. _job_id = f'{role}_forward'
  24. request_config = request.json or request.form.to_dict()
  25. if request_config.get('header') and request_config.get('body'):
  26. request_config['header'] = {
  27. **request.headers,
  28. **{
  29. k.replace('_', '-').upper(): v
  30. for k, v in request_config['header'].items()
  31. },
  32. }
  33. else:
  34. request_config = {
  35. 'header': request.headers,
  36. 'body': request_config,
  37. }
  38. response = (
  39. proxy_api(role, _job_id, request_config) if role == 'marketplace'
  40. else federated_api(
  41. _job_id, 'POST', f'/forward/{role}/do',
  42. request_config['header'].get('SRC-PARTY-ID'),
  43. request_config['header'].get('DEST-PARTY-ID'),
  44. '', request_config, FederatedMode.MULTIPLE,
  45. )
  46. )
  47. return jsonify(response)
  48. @manager.route('/<role>/do', methods=['POST'])
  49. def start_forward(role):
  50. request_config = request.json or request.form.to_dict()
  51. return jsonify(forward_api(role, request_config))