file_advanced_samples_4.py 786 B

12345678910111213141516171819202122
  1. def set_cors_rules(self, service):
  2. print('1. Get Cors Rules')
  3. original_cors_rules = service.get_service_properties()['cors']
  4. print('2. Overwrite Cors Rules')
  5. cors_rule = CorsRule(
  6. allowed_origins=['*'],
  7. allowed_methods=['POST', 'GET'],
  8. allowed_headers=['*'],
  9. exposed_headers=['*'],
  10. max_age_in_seconds=3600)
  11. try:
  12. service.set_service_properties(cors=[cors_rule])
  13. except Exception as e:
  14. print(e)
  15. finally:
  16. #reverting cors rules back to the original ones
  17. print('3. Revert Cors Rules back the original ones')
  18. service.set_service_properties(cors=original_cors_rules)
  19. print("CORS sample completed")