add a secret key to services (#5026)
This commit is contained in:
parent
11c04b868f
commit
a845ff0da3
|
@ -1,17 +1,23 @@
|
|||
from django import forms
|
||||
from django.template.defaultfilters import slugify
|
||||
from django.utils.crypto import get_random_string
|
||||
|
||||
from .models import Authentic, Wcs
|
||||
|
||||
SECRET_CHARS = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
|
||||
|
||||
class AuthenticForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Authentic
|
||||
exclude = ('slug', 'last_operational_check_timestamp',
|
||||
'last_operational_success_timestamp')
|
||||
'last_operational_success_timestamp',
|
||||
'secret_key')
|
||||
|
||||
def save(self, commit=True):
|
||||
if not self.instance.slug:
|
||||
self.instance.slug = slugify(self.instance.title)
|
||||
if not self.instance.secret_key:
|
||||
self.instance.secret_key = get_random_string(50, SECRET_CHARS)
|
||||
return super(AuthenticForm, self).save(commit=commit)
|
||||
|
||||
|
||||
|
@ -19,9 +25,12 @@ class WcsForm(forms.ModelForm):
|
|||
class Meta:
|
||||
model = Wcs
|
||||
exclude = ('slug', 'last_operational_check_timestamp',
|
||||
'last_operational_success_timestamp')
|
||||
'last_operational_success_timestamp',
|
||||
'secret_key')
|
||||
|
||||
def save(self, commit=True):
|
||||
if not self.instance.slug:
|
||||
self.instance.slug = slugify(self.instance.title)
|
||||
if not self.instance.secret_key:
|
||||
self.instance.secret_key = get_random_string(50, SECRET_CHARS)
|
||||
return super(WcsForm, self).save(commit=commit)
|
||||
|
|
|
@ -15,6 +15,7 @@ class ServiceBase(models.Model):
|
|||
title = models.CharField(_('Title'), max_length=50)
|
||||
slug = models.SlugField()
|
||||
base_url = models.CharField(_('Base URL'), max_length=200)
|
||||
secret_key = models.CharField(_('Secret Key'), max_length=60)
|
||||
|
||||
last_operational_check_timestamp = models.DateTimeField(null=True)
|
||||
last_operational_success_timestamp = models.DateTimeField(null=True)
|
||||
|
|
Loading…
Reference in New Issue