From dd9b0d8fd947b1bd75db0e296b54a8545906575d Mon Sep 17 00:00:00 2001 From: PCoder Date: Mon, 8 Jan 2018 19:50:42 +0100 Subject: [PATCH] Refactor dcl's ssh key name prefix to DCL_SSH_KEY_NAME_PREFIX --- dynamicweb/settings/base.py | 2 ++ hosting/forms.py | 6 +++++- hosting/views.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index d66093ed..47534585 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -540,6 +540,8 @@ ONEADMIN_USER_SSH_PUBLIC_KEY = env('ONEADMIN_USER_SSH_PUBLIC_KEY') DCL_TEXT = env('DCL_TEXT') DCL_SUPPORT_FROM_ADDRESS = env('DCL_SUPPORT_FROM_ADDRESS') +DCL_SSH_KEY_NAME_PREFIX = 'dcl-gen-key-' + # Settings for Google analytics GOOGLE_ANALYTICS_PROPERTY_IDS = { 'ungleich.ch': 'UA-62285904-1', diff --git a/hosting/forms.py b/hosting/forms.py index dbb18730..7beab60f 100644 --- a/hosting/forms.py +++ b/hosting/forms.py @@ -4,6 +4,7 @@ import subprocess import tempfile from django import forms +from django.conf import settings from django.contrib.auth import authenticate from django.utils.translation import ugettext_lazy as _ @@ -15,7 +16,10 @@ logger = logging.getLogger(__name__) def generate_ssh_key_name(): - return 'dcl-gen-key-' + datetime.datetime.now().strftime('%m%d%y%H%M%S') + return '{prefix}{date_time_str}'.format( + prefix=settings.DCL_SSH_KEY_NAME_PREFIX, + date_time_str=datetime.datetime.now().strftime('%m%d%y%H%M%S') + ) class HostingUserLoginForm(forms.Form): diff --git a/hosting/views.py b/hosting/views.py index 8f9f7c31..38b92d0a 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -487,7 +487,7 @@ class SSHKeyCreateView(LoginRequiredMixin, FormView): def form_valid(self, form): form.save() - if 'dcl-gen-key-' in form.instance.name: + if settings.DCL_SSH_KEY_NAME_PREFIX in form.instance.name: content = ContentFile(form.cleaned_data.get('private_key')) filename = form.cleaned_data.get( 'name') + '_' + str(uuid.uuid4())[:8] + '_private.pem'