diff --git a/computes/forms.py b/computes/forms.py index a626106c..8feaa0e8 100644 --- a/computes/forms.py +++ b/computes/forms.py @@ -1,4 +1,5 @@ import re +import json from django import forms from django.utils.translation import ugettext_lazy as _ from computes.models import Compute @@ -13,6 +14,8 @@ class ComputeAddTcpForm(forms.Form): max_length=100) password = forms.CharField(error_messages={'required': _('No password has been entered')}, max_length=100) + gstfsd_key = forms.CharField(max_length=256, required=False) + def clean_name(self): name = self.cleaned_data['name'] @@ -41,6 +44,20 @@ def clean_hostname(self): return hostname raise forms.ValidationError(_('This host is already connected')) + def clean_gstfsd_key(self): + gstfsd_key = self.cleaned_data['gstfsd_key'] + try: + data = json.loads(gstfsd_key) + if not isinstance(data, dict): + raise forms.ValidationError(_('Gstfsd key must be a json object')) + if not 'k' in data: + raise forms.ValidationError(_('Gstfsd key must have a "k" field')) + if not 'kty' in data: + raise forms.ValidationError(_('Gstfsd key must have a "kty" field')) + except ValueError: + raise forms.ValidationError(_('Gstfsd key must be a valid json')) + return gstfsd_key + class ComputeAddSshForm(forms.Form): name = forms.CharField(error_messages={'required': _('No hostname has been entered')}, @@ -49,6 +66,8 @@ class ComputeAddSshForm(forms.Form): max_length=100) login = forms.CharField(error_messages={'required': _('No login has been entered')}, max_length=20) + gstfsd_key = forms.CharField(max_length=256, required=False) + def clean_name(self): name = self.cleaned_data['name'] @@ -77,6 +96,20 @@ def clean_hostname(self): return hostname raise forms.ValidationError(_('This host is already connected')) + def clean_gstfsd_key(self): + gstfsd_key = self.cleaned_data['gstfsd_key'] + try: + data = json.loads(gstfsd_key) + if not isinstance(data, dict): + raise forms.ValidationError(_('Gstfsd key must be a json object')) + if not 'k' in data: + raise forms.ValidationError(_('Gstfsd key must have a "k" field')) + if not 'kty' in data: + raise forms.ValidationError(_('Gstfsd key must have a "kty" field')) + except ValueError: + raise forms.ValidationError(_('Gstfsd key must be a valid json')) + return gstfsd_key + class ComputeAddTlsForm(forms.Form): name = forms.CharField(error_messages={'required': _('No hostname has been entered')}, @@ -87,6 +120,8 @@ class ComputeAddTlsForm(forms.Form): max_length=100) password = forms.CharField(error_messages={'required': _('No password has been entered')}, max_length=100) + gstfsd_key = forms.CharField(max_length=256, required=False) + def clean_name(self): name = self.cleaned_data['name'] @@ -115,6 +150,20 @@ def clean_hostname(self): return hostname raise forms.ValidationError(_('This host is already connected')) + def clean_gstfsd_key(self): + gstfsd_key = self.cleaned_data['gstfsd_key'] + try: + data = json.loads(gstfsd_key) + if not isinstance(data, dict): + raise forms.ValidationError(_('Gstfsd key must be a json object')) + if not 'k' in data: + raise forms.ValidationError(_('Gstfsd key must have a "k" field')) + if not 'kty' in data: + raise forms.ValidationError(_('Gstfsd key must have a "kty" field')) + except ValueError: + raise forms.ValidationError(_('Gstfsd key must be a valid json')) + return gstfsd_key + class ComputeEditHostForm(forms.Form): host_id = forms.CharField() @@ -126,6 +175,8 @@ class ComputeEditHostForm(forms.Form): max_length=100) password = forms.CharField(max_length=100) + gstfsd_key = forms.CharField(max_length=256, required=False) + def clean_name(self): name = self.cleaned_data['name'] have_symbol = re.match('[^a-zA-Z0-9._-]+', name) @@ -145,11 +196,28 @@ def clean_hostname(self): raise forms.ValidationError(_('Wrong IP address')) return hostname + def clean_gstfsd_key(self): + gstfsd_key = self.cleaned_data['gstfsd_key'] + try: + data = json.loads(gstfsd_key) + if not isinstance(data, dict): + raise forms.ValidationError(_('Gstfsd key must be a json object')) + if not 'k' in data: + raise forms.ValidationError(_('Gstfsd key must have a "k" field')) + if not 'kty' in data: + raise forms.ValidationError(_('Gstfsd key must have a "kty" field')) + except ValueError: + raise forms.ValidationError(_('Gstfsd key must be a valid json')) + return gstfsd_key + class ComputeAddSocketForm(forms.Form): name = forms.CharField(error_messages={'required': _('No hostname has been entered')}, max_length=20) + gstfsd_key = forms.CharField(max_length=256, required=False) + + def clean_name(self): name = self.cleaned_data['name'] have_symbol = re.match('[^a-zA-Z0-9._-]+', name) @@ -162,3 +230,17 @@ def clean_name(self): except Compute.DoesNotExist: return name raise forms.ValidationError(_('This host is already connected')) + + def clean_gstfsd_key(self): + gstfsd_key = self.cleaned_data['gstfsd_key'] + try: + data = json.loads(gstfsd_key) + if not isinstance(data, dict): + raise forms.ValidationError(_('Gstfsd key must be a json object')) + if not 'k' in data: + raise forms.ValidationError(_('Gstfsd key must have a "k" field')) + if not 'kty' in data: + raise forms.ValidationError(_('Gstfsd key must have a "kty" field')) + except ValueError: + raise forms.ValidationError(_('Gstfsd key must be a valid json')) + return gstfsd_key diff --git a/computes/migrations/0002_compute_gstfsd_key.py b/computes/migrations/0002_compute_gstfsd_key.py new file mode 100644 index 00000000..f1c4debe --- /dev/null +++ b/computes/migrations/0002_compute_gstfsd_key.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('computes', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='compute', + name='gstfsd_key', + field=models.CharField(max_length=256, null=True, blank=True), + ), + ] diff --git a/computes/models.py b/computes/models.py index 6ee7de8a..553f0370 100644 --- a/computes/models.py +++ b/computes/models.py @@ -7,6 +7,7 @@ class Compute(models.Model): login = models.CharField(max_length=20) password = models.CharField(max_length=14, blank=True, null=True) type = models.IntegerField() + gstfsd_key = models.CharField(max_length=256, blank=True, null=True) def __unicode__(self): return self.hostname diff --git a/computes/templates/computes.html b/computes/templates/computes.html index 7c1c28f5..70fec700 100644 --- a/computes/templates/computes.html +++ b/computes/templates/computes.html @@ -84,6 +84,12 @@
{% trans "You need shut down your instance and enter a new root password." %}
- +{% trans "An empty password disable the root password." %}