Merge pull request #562 from pcoder/task/3670/shorten_ssh_key_name

Task/3670/shorten ssh key name
This commit is contained in:
Pcoder 2018-01-23 22:01:51 +01:00 committed by GitHub
commit 5595bf9b9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

View file

@ -540,6 +540,8 @@ ONEADMIN_USER_SSH_PUBLIC_KEY = env('ONEADMIN_USER_SSH_PUBLIC_KEY')
DCL_TEXT = env('DCL_TEXT') DCL_TEXT = env('DCL_TEXT')
DCL_SUPPORT_FROM_ADDRESS = env('DCL_SUPPORT_FROM_ADDRESS') DCL_SUPPORT_FROM_ADDRESS = env('DCL_SUPPORT_FROM_ADDRESS')
DCL_SSH_KEY_NAME_PREFIX = 'dcl-gen-key-'
# Settings for Google analytics # Settings for Google analytics
GOOGLE_ANALYTICS_PROPERTY_IDS = { GOOGLE_ANALYTICS_PROPERTY_IDS = {
'ungleich.ch': 'UA-62285904-1', 'ungleich.ch': 'UA-62285904-1',

View file

@ -4,6 +4,7 @@ import subprocess
import tempfile import tempfile
from django import forms from django import forms
from django.conf import settings
from django.contrib.auth import authenticate from django.contrib.auth import authenticate
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -15,8 +16,10 @@ logger = logging.getLogger(__name__)
def generate_ssh_key_name(): def generate_ssh_key_name():
return 'dcl-generated-key-' + datetime.datetime.now().strftime( return '{prefix}{date_time_str}'.format(
'%m%d%y%H%M') prefix=settings.DCL_SSH_KEY_NAME_PREFIX,
date_time_str=datetime.datetime.now().strftime('%m%d%y%H%M%S')
)
class HostingUserLoginForm(forms.Form): class HostingUserLoginForm(forms.Form):

View file

@ -487,7 +487,7 @@ class SSHKeyCreateView(LoginRequiredMixin, FormView):
def form_valid(self, form): def form_valid(self, form):
form.save() form.save()
if 'dcl-generated-key-' in form.instance.name: if settings.DCL_SSH_KEY_NAME_PREFIX in form.instance.name:
content = ContentFile(form.cleaned_data.get('private_key')) content = ContentFile(form.cleaned_data.get('private_key'))
filename = form.cleaned_data.get( filename = form.cleaned_data.get(
'name') + '_' + str(uuid.uuid4())[:8] + '_private.pem' 'name') + '_' + str(uuid.uuid4())[:8] + '_private.pem'