From 2465843690c36cfc1179c10d2f4c879c8a964a73 Mon Sep 17 00:00:00 2001 From: nikunj2512 Date: Wed, 21 Jan 2015 22:53:51 +0530 Subject: [PATCH] Adds config to disable the password in stack Currently a password is needed when doing a stack creation using Horizon. This patch adds a configurable setting in local_settings.py file, so that it can be disabled from the stack creation form. Change-Id: I82783b73940e39d961ac70a5ce86abdaca02eba7 Closes-bug: #1290344 Co-Authored-By: Richard Jones Co-Authored-By: Jesse Keating --- doc/source/topics/settings.rst | 15 +++++++++++ .../dashboards/project/stacks/forms.py | 27 ++++++++++++------- .../local/local_settings.py.example | 6 +++++ 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/doc/source/topics/settings.rst b/doc/source/topics/settings.rst index 5a69a19629..78544e5497 100755 --- a/doc/source/topics/settings.rst +++ b/doc/source/topics/settings.rst @@ -819,6 +819,21 @@ A dictionary of settings which can be used to enable optional services provided by cinder. Currently only the backup service is available. +``OPENSTACK_HEAT_STACK`` +----------------------------- + +.. versionadded:: 9.0.0(Mitaka) + +Default: ``{'enable_user_pass': True}`` + +A dictionary of settings to use with heat stacks. Currently, the only setting +available is "enable_user_pass", which can be used to disable the password +field while launching the stack. Currently HEAT API needs user password to +perform all the heat operations because in HEAT API trusts is not enabled by +default. So, this setting can be set as "False" in-case HEAT uses trusts by +default otherwise it needs to be set as "True". + + ``OPENSTACK_NEUTRON_NETWORK`` ----------------------------- diff --git a/openstack_dashboard/dashboards/project/stacks/forms.py b/openstack_dashboard/dashboards/project/stacks/forms.py index 431b6c2595..a4da2068ec 100644 --- a/openstack_dashboard/dashboards/project/stacks/forms.py +++ b/openstack_dashboard/dashboards/project/stacks/forms.py @@ -13,6 +13,7 @@ import json import logging +from django.conf import settings from django.utils import html from django.utils.translation import ugettext_lazy as _ from django.views.decorators.debug import sensitive_variables # noqa @@ -281,18 +282,24 @@ class CreateStackForm(forms.SelfHandlingForm): def __init__(self, *args, **kwargs): parameters = kwargs.pop('parameters') # special case: load template data from API, not passed in params - if(kwargs.get('validate_me')): + if kwargs.get('validate_me'): parameters = kwargs.pop('validate_me') super(CreateStackForm, self).__init__(*args, **kwargs) + + if self._stack_password_enabled(): + self.fields['password'] = forms.CharField( + label=_('Password for user "%s"') % self.request.user.username, + help_text=_('This is required for operations to be performed ' + 'throughout the lifecycle of the stack'), + widget=forms.PasswordInput()) + self._build_parameter_fields(parameters) - def _build_parameter_fields(self, template_validate): - self.fields['password'] = forms.CharField( - label=_('Password for user "%s"') % self.request.user.username, - help_text=_('This is required for operations to be performed ' - 'throughout the lifecycle of the stack'), - widget=forms.PasswordInput()) + def _stack_password_enabled(self): + stack_settings = getattr(settings, 'OPENSTACK_HEAT_STACK', {}) + return stack_settings.get('enable_user_pass', True) + def _build_parameter_fields(self, template_validate): self.help_text = template_validate['Description'] params = template_validate.get('Parameters', {}) @@ -368,8 +375,9 @@ class CreateStackForm(forms.SelfHandlingForm): 'timeout_mins': data.get('timeout_mins'), 'disable_rollback': not(data.get('enable_rollback')), 'parameters': dict(params_list), - 'password': data.get('password') } + if data.get('password'): + fields['password'] = data.get('password') if data.get('template_data'): fields['template'] = data.get('template_data') @@ -422,8 +430,9 @@ class EditStackForm(CreateStackForm): 'timeout_mins': data.get('timeout_mins'), 'disable_rollback': not(data.get('enable_rollback')), 'parameters': dict(params_list), - 'password': data.get('password') } + if data.get('password'): + fields['password'] = data.get('password') # if the user went directly to this form, resubmit the existing # template data. otherwise, submit what they had from the first form diff --git a/openstack_dashboard/local/local_settings.py.example b/openstack_dashboard/local/local_settings.py.example index 3e34e39929..f28cc676e7 100644 --- a/openstack_dashboard/local/local_settings.py.example +++ b/openstack_dashboard/local/local_settings.py.example @@ -275,6 +275,12 @@ OPENSTACK_NEUTRON_NETWORK = { 'supported_vnic_types': ['*'] } +# The OPENSTACK_HEAT_STACK settings can be used to disable password +# field required while launching the stack. +OPENSTACK_HEAT_STACK = { + 'enable_user_pass': True, +} + # The OPENSTACK_IMAGE_BACKEND settings can be used to customize features # in the OpenStack Dashboard related to the Image service, such as the list # of supported image formats.