Skip to content

Commit

Permalink
validate config ingredients can be xmlrpc marshaled
Browse files Browse the repository at this point in the history
  • Loading branch information
btubbs committed Nov 19, 2014
1 parent 8dd3a8e commit e180a57
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions server/vr/server/forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import xmlrpclib

from django import forms
from django.conf import settings
from django.contrib.auth import authenticate
Expand All @@ -21,18 +23,29 @@ def clean_config_yaml(self):
config_yaml = self.cleaned_data.get('config_yaml', None)
if config_yaml:
try:
yaml.safe_load(config_yaml)
data = yaml.safe_load(config_yaml)
except:
raise forms.ValidationError("Invalid YAML")

try:
xmlrpclib.dumps((data,), allow_none=True)
except Exception as e:
raise forms.ValidationError("Cannot be marshalled to XMLRPC: %s" % e)
return config_yaml

def clean_env_yaml(self):
env_yaml = self.cleaned_data.get('env_yaml', None)
if env_yaml:
try:
yaml.safe_load(env_yaml)
data = yaml.safe_load(env_yaml)
except:
raise forms.ValidationError("Invalid YAML")

try:
xmlrpclib.dumps((data,), allow_none=True)
except Exception as e:
raise forms.ValidationError("Cannot be marshalled to XMLRPC: %s" % e)

return env_yaml


Expand Down

0 comments on commit e180a57

Please sign in to comment.