Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. import re
  2.  
  3. service = {
  4. "service_id": "sps:service:template-test",
  5. "service_name": "template-test",
  6. "urn": "{}/template.format(version_slug)",
  7. "actions": [
  8. {
  9. "action": "render-jinja2",
  10. "params": [
  11. {"name": "source", "type": "string", "required": "True"},
  12. {"name": "variables", "type": "dict", "required": "True"}
  13. ]
  14. },
  15. {
  16. "action": "render-jinja2",
  17. "params": [
  18. {"name": "source", "type": "string", "required": "True"},
  19. {"name": "variables", "type": "dict", "required": "True"}
  20. ]
  21. },
  22.  
  23. ]
  24. }
  25.  
  26. service_id = service['service_id']
  27. service_name = service['service_name']
  28. service_url = service['urn']
  29. actions = service['actions']
  30.  
  31. if service_id is None or service_name is None or service_url is None:
  32. # log().error("event does not contain neccessary params")
  33. # raise BadRequestException, "Missing params"
  34. print ('there are missing params in service')
  35.  
  36. if re.match("^[a-zA-Z0-9_:-]*$", service_id) is None:
  37. print ('service_id has wrong format')
  38.  
  39. if re.match("^[a-zA-Z0-9_:-]*$", service_name) is None:
  40. print ('service_name has wrong format')
  41.  
  42. for index in range(0, len(actions)):
  43. if re.match("^[a-zA-Z0-9_:-]*$", actions[index]['action']) is None:
  44. print ('action_name {} has wrong format'.format(actions[index]['action']))
  45.  
  46. params = actions[index]['params']
  47. for param_index in range(0, len(params)):
  48. params_keys = params[param_index].keys()
  49. if 'required' not in params_keys or 'name' not in params_keys:
  50. print ("action params don't contain all neccesary attributes")
  51.  
  52. if params[param_index]['required'] not in ('True', 'False'):
  53. print ("value of 'required' param attribute can be True or False only")
  54.  
  55. if re.match("^[a-zA-Z0-9_:-]*$", params[param_index]['name']) is None:
  56. print "value of 'name' param attribute contains illegal characters"
  57.  
  58. print ('done')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement