Commit 1719eee2 authored by ibuler's avatar ibuler

[Bugfix] 修复py3 bytes bug

parent 41633be1
......@@ -21,5 +21,6 @@ migrations/
host_rsa_key
*.bat
tags
tmp/*
jumpserver.iml
.python-version
tmp/*
......@@ -179,14 +179,6 @@ class IDCForm(forms.ModelForm):
class AdminUserForm(forms.ModelForm):
# Admin user assets define, let user select, save it in form not in view
assets = forms.ModelMultipleChoiceField(
queryset=Asset.objects.all(),
label=_('Asset'),
required=False,
widget=forms.SelectMultiple(
attrs={'class': 'select2', 'data-placeholder': _('Select assets')})
)
# Form field name can not start with `_`, so redefine it,
password = forms.CharField(
widget=forms.PasswordInput, max_length=100,
......@@ -196,20 +188,6 @@ class AdminUserForm(forms.ModelForm):
# Need use upload private key file except paste private key content
private_key_file = forms.FileField(required=False)
def __init__(self, *args, **kwargs):
# When update a admin user instance, initial it
if kwargs.get('instance'):
initial = kwargs.get('initial', {})
initial['assets'] = kwargs['instance'].assets.all()
super(AdminUserForm, self).__init__(*args, **kwargs)
def _save_m2m(self):
# Save assets relation with admin user
super(AdminUserForm, self)._save_m2m()
assets = self.cleaned_data['assets']
self.instance.assets.clear()
self.instance.assets.add(*tuple(assets))
def save(self, commit=True):
# Because we define custom field, so we need rewrite :method: `save`
admin_user = super(AdminUserForm, self).save(commit=commit)
......
......@@ -38,7 +38,6 @@
{% bootstrap_field form.username layout="horizontal" %}
{% bootstrap_field form.password layout="horizontal" %}
{% bootstrap_field form.private_key_file layout="horizontal" %}
{% bootstrap_field form.assets layout="horizontal" %}
{% bootstrap_field form.comment layout="horizontal" %}
<div class="form-group">
......
# -*- coding: utf-8 -*-
#
from __future__ import unicode_literals
from collections import OrderedDict
from six import string_types
......@@ -55,6 +54,8 @@ class Signer(object):
self.secret_key = secret_key
def sign(self, value):
if isinstance(value, bytes):
value = value.decode("utf-8")
s = JSONWebSignatureSerializer(self.secret_key)
return s.dumps(value)
......@@ -194,9 +195,10 @@ def ssh_key_string_to_obj(text):
def ssh_pubkey_gen(private_key=None, username='jumpserver', hostname='localhost'):
if isinstance(private_key, bytes):
private_key = private_key.decode("utf-8")
if isinstance(private_key, string_types):
private_key = ssh_key_string_to_obj(private_key)
if not isinstance(private_key, (paramiko.RSAKey, paramiko.DSSKey)):
raise IOError('Invalid private key')
......@@ -237,6 +239,8 @@ def ssh_key_gen(length=2048, type='rsa', password=None, username='jumpserver', h
def validate_ssh_private_key(text):
if isinstance(text, bytes):
text = text.decode("utf-8")
key = ssh_key_string_to_obj(text)
if key is None:
return False
......
......@@ -36,7 +36,7 @@
<li id="applications">
<a>
<i class="fa fa-coffee"></i> <span class="nav-label">{% trans 'Applications' %}</span><span class="fa arrow"></span>
<i class="fa fa-rocket"></i> <span class="nav-label">{% trans 'Applications' %}</span><span class="fa arrow"></span>
</a>
<ul class="nav nav-second-level">
<li id="terminal"><a href="{% url 'applications:terminal-list' %}">{% trans 'Terminal' %}</a></li>
......
Because ansible connect remote host using key file path except key string, so I create this dir for keep them.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment