Adding verifications for fields.
Change-Id: If949f362d8752d29d4efe926c9e3614d2168ec57
This commit is contained in:
parent
b1a6015274
commit
e83eb0c099
|
@ -13,58 +13,43 @@
|
|||
# under the License.
|
||||
|
||||
import logging
|
||||
import string
|
||||
|
||||
from django import forms
|
||||
from django.core.validators import RegexValidator
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
import re
|
||||
from muranodashboard.panel import api
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
name_re = re.compile(r'^[-\w]+$')
|
||||
validate_name = RegexValidator(name_re, _(u'Enter a valid name consisting '
|
||||
u'of letters, numbers, \
|
||||
underscores or hyphens.'), 'invalid')
|
||||
|
||||
|
||||
class PasswordField(forms.CharField):
|
||||
# Setup the Field
|
||||
special_characters = '!@#$%^&*()_+|\/.,~?><:{}'
|
||||
password_re = re.compile('^.*(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[%s]).*$'
|
||||
% special_characters)
|
||||
validate_password = RegexValidator(password_re, _('Your password must \
|
||||
include at least one letter, \
|
||||
at least one number and at least \
|
||||
one special character'), 'invalid')
|
||||
|
||||
def __init__(self, label, *args, **kwargs):
|
||||
super(PasswordField, self).__init__(min_length=7, required=True,
|
||||
super(PasswordField, self).__init__(min_length=7, max_length=255,
|
||||
required=True, validators=
|
||||
[self.validate_password],
|
||||
label=label,
|
||||
error_messages={'invalid':
|
||||
self.validate_password.message,
|
||||
'required':
|
||||
'Password is required'},
|
||||
widget=forms.PasswordInput(
|
||||
render_value=False),
|
||||
render_value=False),
|
||||
*args, **kwargs)
|
||||
|
||||
def clean(self, value):
|
||||
|
||||
# Setup Our Lists of Characters and Numbers
|
||||
characters = list(string.letters)
|
||||
special_characters = '!@#$%^&*()_+|\/.,~?><:{}'
|
||||
numbers = [str(i) for i in range(10)]
|
||||
|
||||
# Assume False until Proven Otherwise
|
||||
numCheck = False
|
||||
charCheck = False
|
||||
specCharCheck = False
|
||||
|
||||
# Loop until we Match
|
||||
for char in value:
|
||||
if not charCheck:
|
||||
if char in characters:
|
||||
charCheck = True
|
||||
if not specCharCheck:
|
||||
if char in special_characters:
|
||||
specCharCheck = True
|
||||
if not numCheck:
|
||||
if char in numbers:
|
||||
numCheck = True
|
||||
if numCheck and charCheck and specCharCheck:
|
||||
break
|
||||
|
||||
if not numCheck or not charCheck or not specCharCheck:
|
||||
raise forms.ValidationError(u'Your password must include at least \
|
||||
one letter, at least one number and \
|
||||
at least one special character.')
|
||||
|
||||
return super(PasswordField, self).clean(value)
|
||||
|
||||
|
||||
class WizardFormServiceType(forms.Form):
|
||||
ad_service = ('Active Directory', 'Active Directory')
|
||||
|
@ -96,7 +81,12 @@ class CommonPropertiesExtension(object):
|
|||
|
||||
class WizardFormADConfiguration(forms.Form, CommonPropertiesExtension):
|
||||
dc_name = forms.CharField(label=_('Domain Name'),
|
||||
required=True)
|
||||
min_length=2,
|
||||
max_length=64,
|
||||
required=True,
|
||||
validators=[validate_name], error_messages=
|
||||
{'invalid': validate_name.message},
|
||||
)
|
||||
|
||||
dc_count = forms.IntegerField(label=_('Instance Count'),
|
||||
required=True,
|
||||
|
@ -115,7 +105,9 @@ class WizardFormADConfiguration(forms.Form, CommonPropertiesExtension):
|
|||
|
||||
class WizardFormIISConfiguration(forms.Form, CommonPropertiesExtension):
|
||||
iis_name = forms.CharField(label=_('Service Name'),
|
||||
required=True)
|
||||
required=True, validators=[validate_name],
|
||||
error_messages=
|
||||
{'invalid': validate_name.message})
|
||||
|
||||
adm_password = PasswordField(_('Administrator password'))
|
||||
|
||||
|
@ -153,8 +145,18 @@ class WebFarmExtension(forms.Form):
|
|||
class WizardFormAspNetAppConfiguration(WizardFormIISConfiguration,
|
||||
WebFarmExtension,
|
||||
CommonPropertiesExtension):
|
||||
|
||||
git_repo_re = re.compile(r'(\w+://)(.+@)*([\w\d\.]+)(:[\d]+)?/*(.*)',
|
||||
re.IGNORECASE)
|
||||
validate_git = RegexValidator(git_repo_re,
|
||||
_('Input correct git repository url'),
|
||||
'invalid')
|
||||
|
||||
repository = forms.CharField(label=_('Git repository'),
|
||||
required=True)
|
||||
required=True,
|
||||
validators=[validate_git],
|
||||
error_messages=
|
||||
{'invalid': validate_git.message})
|
||||
|
||||
|
||||
class WizardFormIISFarmConfiguration(WizardFormIISConfiguration,
|
||||
|
|
|
@ -1,209 +1,209 @@
|
|||
# Copyright (c) 2013 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.urlresolvers import reverse
|
||||
from horizon import exceptions
|
||||
|
||||
from horizon import tables
|
||||
from muranodashboard.panel import api
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
STATUS_ID_READY = 'ready'
|
||||
STATUS_ID_PENDING = 'pending'
|
||||
STATUS_ID_DEPLOYING = 'deploying'
|
||||
|
||||
STATUS_CHOICES = (
|
||||
(None, True),
|
||||
('Ready to configure', True),
|
||||
('Ready', True),
|
||||
('Configuring', False),
|
||||
|
||||
)
|
||||
|
||||
STATUS_DISPLAY_CHOICES = (
|
||||
(STATUS_ID_READY, 'Ready'),
|
||||
(STATUS_ID_DEPLOYING, 'Deploy in progress'),
|
||||
(STATUS_ID_PENDING, 'Configuring'),
|
||||
('', 'Ready to configure'),
|
||||
)
|
||||
|
||||
|
||||
class CreateService(tables.LinkAction):
|
||||
name = 'CreateService'
|
||||
verbose_name = _('Create Service')
|
||||
url = 'horizon:project:murano:create'
|
||||
classes = ('btn-launch', 'ajax-modal')
|
||||
|
||||
def allowed(self, request, environment):
|
||||
status = getattr(environment, 'status', None)
|
||||
if status not in [STATUS_ID_DEPLOYING]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def action(self, request, service):
|
||||
try:
|
||||
api.service_create(request, service)
|
||||
except:
|
||||
msg = _('Sorry, you can\'t create service right now')
|
||||
redirect = reverse("horizon:project:murano:index")
|
||||
exceptions.handle(request, msg, redirect=redirect)
|
||||
|
||||
|
||||
class CreateEnvironment(tables.LinkAction):
|
||||
name = 'CreateEnvironment'
|
||||
verbose_name = _('Create Environment')
|
||||
url = 'horizon:project:murano:create_environment'
|
||||
classes = ('btn-launch', 'ajax-modal')
|
||||
|
||||
def allowed(self, request, datum):
|
||||
return True
|
||||
|
||||
def action(self, request, environment):
|
||||
api.environment_create(request, environment)
|
||||
|
||||
|
||||
class DeleteEnvironment(tables.DeleteAction):
|
||||
data_type_singular = _("Environment")
|
||||
data_type_plural = _("Environments")
|
||||
|
||||
def allowed(self, request, environment):
|
||||
status = getattr(environment, 'status', None)
|
||||
if status not in [STATUS_ID_DEPLOYING]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def action(self, request, environment_id):
|
||||
try:
|
||||
api.environment_delete(request, environment_id)
|
||||
except:
|
||||
msg = _('Sorry, you can\'t delete this environment right now')
|
||||
exceptions.handle(request, msg)
|
||||
|
||||
|
||||
class DeleteService(tables.DeleteAction):
|
||||
data_type_singular = _('Service')
|
||||
data_type_plural = _('Services')
|
||||
|
||||
def allowed(self, request, environment):
|
||||
status = getattr(environment, 'status', None)
|
||||
if status not in [STATUS_ID_DEPLOYING]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def action(self, request, service_id):
|
||||
try:
|
||||
api.service_delete(request, service_id)
|
||||
except:
|
||||
msg = _('Sorry, you can\'t delete service right now')
|
||||
redirect = reverse("horizon:project:murano:index")
|
||||
exceptions.handle(request, msg, redirect=redirect)
|
||||
|
||||
|
||||
class DeployEnvironment(tables.BatchAction):
|
||||
name = 'deploy'
|
||||
action_present = _('Deploy')
|
||||
action_past = _('Deployed')
|
||||
data_type_singular = _('Environment')
|
||||
data_type_plural = _('Environments')
|
||||
classes = 'btn-launch'
|
||||
|
||||
def allowed(self, request, environment):
|
||||
status = getattr(environment, 'status', None)
|
||||
services = api.services_list(request, environment.id)
|
||||
|
||||
if status not in [STATUS_ID_DEPLOYING, None] and services:
|
||||
return True
|
||||
return False
|
||||
|
||||
def action(self, request, environment_id):
|
||||
try:
|
||||
api.environment_deploy(request, environment_id)
|
||||
except:
|
||||
msg = _('Unable to deploy. Maybe this environment \
|
||||
is already deploying by someone else. Try again later')
|
||||
redirect = reverse("horizon:project:murano:index")
|
||||
exceptions.handle(request, msg, redirect=redirect)
|
||||
|
||||
|
||||
class ShowEnvironmentServices(tables.LinkAction):
|
||||
name = 'edit'
|
||||
verbose_name = _('Services')
|
||||
url = 'horizon:project:murano:services'
|
||||
|
||||
def allowed(self, request, environment):
|
||||
status = getattr(environment, 'status', None)
|
||||
if status not in [STATUS_ID_DEPLOYING]:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
class UpdateEnvironmentRow(tables.Row):
|
||||
ajax = True
|
||||
|
||||
def get_data(self, request, environment_id):
|
||||
return api.environment_get(request, environment_id)
|
||||
|
||||
|
||||
class UpdateServiceRow(tables.Row):
|
||||
ajax = True
|
||||
|
||||
def get_data(self, request, service_id):
|
||||
return api.service_get(request, service_id)
|
||||
|
||||
|
||||
class EnvironmentsTable(tables.DataTable):
|
||||
name = tables.Column('name',
|
||||
link='horizon:project:murano:services',
|
||||
verbose_name=_('Name'))
|
||||
|
||||
status = tables.Column('status', verbose_name=_('Status'),
|
||||
status=True,
|
||||
status_choices=STATUS_CHOICES,
|
||||
display_choices=STATUS_DISPLAY_CHOICES)
|
||||
|
||||
class Meta:
|
||||
name = 'murano'
|
||||
verbose_name = _('Environments')
|
||||
row_class = UpdateEnvironmentRow
|
||||
status_columns = ['status']
|
||||
table_actions = (CreateEnvironment, DeleteEnvironment)
|
||||
row_actions = (ShowEnvironmentServices, DeployEnvironment,
|
||||
DeleteEnvironment)
|
||||
|
||||
|
||||
class ServicesTable(tables.DataTable):
|
||||
name = tables.Column('name', verbose_name=_('Name'),
|
||||
link=('horizon:project:murano:service_details'))
|
||||
|
||||
_type = tables.Column('service_type', verbose_name=_('Type'))
|
||||
|
||||
status = tables.Column('status', verbose_name=_('Status'),
|
||||
status=True,
|
||||
status_choices=STATUS_CHOICES,
|
||||
display_choices=STATUS_DISPLAY_CHOICES)
|
||||
|
||||
operation = tables.Column('operation', verbose_name=_('Operation'))
|
||||
|
||||
class Meta:
|
||||
name = 'services'
|
||||
verbose_name = _('Services')
|
||||
row_class = UpdateServiceRow
|
||||
status_columns = ['status']
|
||||
table_actions = (CreateService, DeleteService)
|
||||
row_actions = (DeleteService,)
|
||||
# Copyright (c) 2013 Mirantis, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.urlresolvers import reverse
|
||||
from horizon import exceptions
|
||||
|
||||
from horizon import tables
|
||||
from muranodashboard.panel import api
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
STATUS_ID_READY = 'ready'
|
||||
STATUS_ID_PENDING = 'pending'
|
||||
STATUS_ID_DEPLOYING = 'deploying'
|
||||
|
||||
STATUS_CHOICES = (
|
||||
(None, True),
|
||||
('Ready to configure', True),
|
||||
('Ready', True),
|
||||
('Configuring', False),
|
||||
|
||||
)
|
||||
|
||||
STATUS_DISPLAY_CHOICES = (
|
||||
(STATUS_ID_READY, 'Ready'),
|
||||
(STATUS_ID_DEPLOYING, 'Deploy in progress'),
|
||||
(STATUS_ID_PENDING, 'Configuring'),
|
||||
('', 'Ready to configure'),
|
||||
)
|
||||
|
||||
|
||||
class CreateService(tables.LinkAction):
|
||||
name = 'CreateService'
|
||||
verbose_name = _('Create Service')
|
||||
url = 'horizon:project:murano:create'
|
||||
classes = ('btn-launch', 'ajax-modal')
|
||||
|
||||
def allowed(self, request, environment):
|
||||
status = getattr(environment, 'status', None)
|
||||
if status not in [STATUS_ID_DEPLOYING]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def action(self, request, service):
|
||||
try:
|
||||
api.service_create(request, service)
|
||||
except:
|
||||
msg = _('Sorry, you can\'t create service right now')
|
||||
redirect = reverse("horizon:project:murano:index")
|
||||
exceptions.handle(request, msg, redirect=redirect)
|
||||
|
||||
|
||||
class CreateEnvironment(tables.LinkAction):
|
||||
name = 'CreateEnvironment'
|
||||
verbose_name = _('Create Environment')
|
||||
url = 'horizon:project:murano:create_environment'
|
||||
classes = ('btn-launch', 'ajax-modal')
|
||||
|
||||
def allowed(self, request, datum):
|
||||
return True
|
||||
|
||||
def action(self, request, environment):
|
||||
api.environment_create(request, environment)
|
||||
|
||||
|
||||
class DeleteEnvironment(tables.DeleteAction):
|
||||
data_type_singular = _("Environment")
|
||||
data_type_plural = _("Environments")
|
||||
|
||||
def allowed(self, request, environment):
|
||||
status = getattr(environment, 'status', None)
|
||||
if status not in [STATUS_ID_DEPLOYING]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def action(self, request, environment_id):
|
||||
try:
|
||||
api.environment_delete(request, environment_id)
|
||||
except:
|
||||
msg = _('Sorry, you can\'t delete this environment right now')
|
||||
exceptions.handle(request, msg)
|
||||
|
||||
|
||||
class DeleteService(tables.DeleteAction):
|
||||
data_type_singular = _('Service')
|
||||
data_type_plural = _('Services')
|
||||
|
||||
def allowed(self, request, environment):
|
||||
status = getattr(environment, 'status', None)
|
||||
if status not in [STATUS_ID_DEPLOYING]:
|
||||
return True
|
||||
return False
|
||||
|
||||
def action(self, request, service_id):
|
||||
try:
|
||||
api.service_delete(request, service_id)
|
||||
except:
|
||||
msg = _('Sorry, you can\'t delete service right now')
|
||||
redirect = reverse("horizon:project:murano:index")
|
||||
exceptions.handle(request, msg, redirect=redirect)
|
||||
|
||||
|
||||
class DeployEnvironment(tables.BatchAction):
|
||||
name = 'deploy'
|
||||
action_present = _('Deploy')
|
||||
action_past = _('Deployed')
|
||||
data_type_singular = _('Environment')
|
||||
data_type_plural = _('Environments')
|
||||
classes = 'btn-launch'
|
||||
|
||||
def allowed(self, request, environment):
|
||||
status = getattr(environment, 'status', None)
|
||||
services = api.services_list(request, environment.id)
|
||||
|
||||
if status not in [STATUS_ID_DEPLOYING, None] and services:
|
||||
return True
|
||||
return False
|
||||
|
||||
def action(self, request, environment_id):
|
||||
try:
|
||||
api.environment_deploy(request, environment_id)
|
||||
except:
|
||||
msg = _('Unable to deploy. Maybe this environment \
|
||||
is already deploying by someone else. Try again later')
|
||||
redirect = reverse("horizon:project:murano:index")
|
||||
exceptions.handle(request, msg, redirect=redirect)
|
||||
|
||||
|
||||
class ShowEnvironmentServices(tables.LinkAction):
|
||||
name = 'edit'
|
||||
verbose_name = _('Services')
|
||||
url = 'horizon:project:murano:services'
|
||||
|
||||
def allowed(self, request, environment):
|
||||
status = getattr(environment, 'status', None)
|
||||
if status not in [STATUS_ID_DEPLOYING]:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
class UpdateEnvironmentRow(tables.Row):
|
||||
ajax = True
|
||||
|
||||
def get_data(self, request, environment_id):
|
||||
return api.environment_get(request, environment_id)
|
||||
|
||||
|
||||
class UpdateServiceRow(tables.Row):
|
||||
ajax = True
|
||||
|
||||
def get_data(self, request, service_id):
|
||||
return api.service_get(request, service_id)
|
||||
|
||||
|
||||
class EnvironmentsTable(tables.DataTable):
|
||||
name = tables.Column('name',
|
||||
link='horizon:project:murano:services',
|
||||
verbose_name=_('Name'))
|
||||
|
||||
status = tables.Column('status', verbose_name=_('Status'),
|
||||
status=True,
|
||||
status_choices=STATUS_CHOICES,
|
||||
display_choices=STATUS_DISPLAY_CHOICES)
|
||||
|
||||
class Meta:
|
||||
name = 'murano'
|
||||
verbose_name = _('Environments')
|
||||
row_class = UpdateEnvironmentRow
|
||||
status_columns = ['status']
|
||||
table_actions = (CreateEnvironment, DeleteEnvironment)
|
||||
row_actions = (ShowEnvironmentServices, DeployEnvironment,
|
||||
DeleteEnvironment)
|
||||
|
||||
|
||||
class ServicesTable(tables.DataTable):
|
||||
name = tables.Column('name', verbose_name=_('Name'),
|
||||
link='horizon:project:murano:service_details')
|
||||
|
||||
_type = tables.Column('service_type', verbose_name=_('Type'))
|
||||
|
||||
status = tables.Column('status', verbose_name=_('Status'),
|
||||
status=True,
|
||||
status_choices=STATUS_CHOICES,
|
||||
display_choices=STATUS_DISPLAY_CHOICES)
|
||||
|
||||
operation = tables.Column('operation', verbose_name=_('Operation'))
|
||||
|
||||
class Meta:
|
||||
name = 'services'
|
||||
verbose_name = _('Services')
|
||||
row_class = UpdateServiceRow
|
||||
status_columns = ['status']
|
||||
table_actions = (CreateService, DeleteService)
|
||||
row_actions = (DeleteService,)
|
||||
|
|
Loading…
Reference in New Issue