Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JSON Web Signature and Encryption (JWS & JWE) between webvirtcloud and gstfsd #111

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions computes/forms.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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']
Expand Down Expand Up @@ -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')},
Expand All @@ -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']
Expand Down Expand Up @@ -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')},
Expand All @@ -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']
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
19 changes: 19 additions & 0 deletions computes/migrations/0002_compute_gstfsd_key.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
1 change: 1 addition & 0 deletions computes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions computes/templates/computes.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ <h4 class="modal-title">{% trans "Edit connection" %}</h4>
<input type="password" name="password" class="form-control" value="{{ compute.password }}">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">{% trans "Gstfsd key" %}</label>
<div class="col-sm-6">
<input type="text" name="gstfsd_key" class="form-control" value="{{ compute.gstfsd_key }}" maxlength="256">
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="pull-left btn btn-danger" name="host_del">
Expand Down Expand Up @@ -121,6 +127,12 @@ <h4 class="modal-title">{% trans "Edit connection" %}</h4>
<input type="text" name="login" class="form-control" value="{{ compute.login }}">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">{% trans "Gstfsd key" %}</label>
<div class="col-sm-6">
<input type="text" name="gstfsd_key" class="form-control" value="{{ compute.gstfsd_key }}" maxlength="256">
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="pull-left btn btn-danger" name="host_del">
Expand Down Expand Up @@ -163,6 +175,12 @@ <h4 class="modal-title">{% trans "Edit connection" %}</h4>
<input type="password" name="password" class="form-control" value="{{ compute.password }}">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">{% trans "Gstfsd key" %}</label>
<div class="col-sm-6">
<input type="text" name="gstfsd_key" class="form-control" value="{{ compute.gstfsd_key }}" maxlength="256">
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="pull-left btn btn-danger" name="host_del">
Expand All @@ -187,6 +205,12 @@ <h4 class="modal-title">{% trans "Edit connection" %}</h4>
<input type="text" name="name" class="form-control" value="{{ compute.name }}" maxlength="20" required pattern="[a-z0-9\.\-_]+">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">{% trans "Gstfsd key" %}</label>
<div class="col-sm-6">
<input type="text" name="gstfsd_key" class="form-control" value="{{ compute.gstfsd_key }}" maxlength="256">
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="pull-left btn btn-danger" name="host_del">
Expand Down
24 changes: 24 additions & 0 deletions computes/templates/create_comp_block.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ <h4 class="modal-title">{% trans "Add Connection" %}</h4>
<input type="password" name="password" class="form-control" placeholder="{% trans "Password" %}">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">{% trans "Gstfsd key" %}</label>
<div class="col-sm-6">
<input type="text" name="gstfsd_key" placeholder="Gstfsd JSON Web Key" class="form-control" value="{{ compute.gstfsd_key }}" maxlength="256">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
Expand Down Expand Up @@ -83,6 +89,12 @@ <h4 class="modal-title">{% trans "Add Connection" %}</h4>
<input type="text" name="login" class="form-control" placeholder="{% trans "Username" %}">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">{% trans "Gstfsd key" %}</label>
<div class="col-sm-6">
<input type="text" name="gstfsd_key" placeholder="Gstfsd JSON Web Key" class="form-control" value="{{ compute.gstfsd_key }}" maxlength="256">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
Expand Down Expand Up @@ -121,6 +133,12 @@ <h4 class="modal-title">{% trans "Add Connection" %}</h4>
<input type="password" name="password" class="form-control" placeholder="{% trans "Password" %}">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">{% trans "Gstfsd key" %}</label>
<div class="col-sm-6">
<input type="text" name="gstfsd_key" placeholder="Gstfsd JSON Web Key" class="form-control" value="{{ compute.gstfsd_key }}" maxlength="256">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
Expand All @@ -141,6 +159,12 @@ <h4 class="modal-title">{% trans "Add Connection" %}</h4>
<input type="text" name="name" class="form-control" placeholder="Label Name" maxlength="20" required pattern="[a-z0-9\.\-_]+">
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">{% trans "Gstfsd key" %}</label>
<div class="col-sm-6">
<input type="text" name="gstfsd_key" placeholder="Gstfsd JSON Web Key" class="form-control" value="{{ compute.gstfsd_key }}" maxlength="256">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
Expand Down
16 changes: 11 additions & 5 deletions computes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def get_hosts_status(computes):
'status': connection_manager.host_is_up(compute.type, compute.hostname),
'type': compute.type,
'login': compute.login,
'password': compute.password
'password': compute.password,
'gstfsd_key': compute.gstfsd_key
})
return compute_data

Expand Down Expand Up @@ -66,7 +67,8 @@ def get_hosts_status(computes):
hostname=data['hostname'],
type=CONN_TCP,
login=data['login'],
password=data['password'])
password=data['password'],
gstfsd_key=data['gstfsd_key'])
new_tcp_host.save()
return HttpResponseRedirect(request.get_full_path())
else:
Expand All @@ -79,7 +81,8 @@ def get_hosts_status(computes):
new_ssh_host = Compute(name=data['name'],
hostname=data['hostname'],
type=CONN_SSH,
login=data['login'])
login=data['login'],
gstfsd_key=data['gstfsd_key'])
new_ssh_host.save()
return HttpResponseRedirect(request.get_full_path())
else:
Expand All @@ -93,7 +96,8 @@ def get_hosts_status(computes):
hostname=data['hostname'],
type=CONN_TLS,
login=data['login'],
password=data['password'])
password=data['password'],
gstfsd_key=data['gstfsd_key'])
new_tls_host.save()
return HttpResponseRedirect(request.get_full_path())
else:
Expand All @@ -107,7 +111,8 @@ def get_hosts_status(computes):
hostname='localhost',
type=CONN_SOCKET,
login='',
password='')
password='',
gstfsd_key=data['gstfsd_key'])
new_socket_host.save()
return HttpResponseRedirect(request.get_full_path())
else:
Expand All @@ -122,6 +127,7 @@ def get_hosts_status(computes):
compute_edit.hostname = data['hostname']
compute_edit.login = data['login']
compute_edit.password = data['password']
compute_edit.gstfsd_key = data['gstfsd_key']
compute_edit.save()
return HttpResponseRedirect(request.get_full_path())
else:
Expand Down
Loading