From: Tatjana Dehler Date: Wed, 6 Feb 2019 15:32:23 +0000 (+0100) Subject: mgr/dashboard: disallow editing read-only config options X-Git-Tag: v14.1.0~109^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F26297%2Fhead;p=ceph.git mgr/dashboard: disallow editing read-only config options Fixes: https://tracker.ceph.com/issues/34528 Signed-off-by: Tatjana Dehler --- diff --git a/src/pybind/mgr/dashboard/controllers/cluster_configuration.py b/src/pybind/mgr/dashboard/controllers/cluster_configuration.py index 2d93b51ea4f..d6314024444 100644 --- a/src/pybind/mgr/dashboard/controllers/cluster_configuration.py +++ b/src/pybind/mgr/dashboard/controllers/cluster_configuration.py @@ -7,6 +7,7 @@ from . import ApiController, RESTController from .. import mgr from ..security import Scope from ..services.ceph_service import CephService +from ..exceptions import DashboardException @ApiController('/cluster_conf', Scope.CONFIG_OPT) @@ -31,17 +32,22 @@ class ClusterConfiguration(RESTController): return options def list(self): - options = mgr.get("config_options")['options'] + options = mgr.get('config_options')['options'] return self._append_config_option_values(options) def get(self, name): - for option in mgr.get('config_options')['options']: - if option['name'] == name: - return self._append_config_option_values([option])[0] - - raise cherrypy.HTTPError(404) + return self._get_config_option(name) def create(self, name, value): + # Check if config option is updateable at runtime + config_option = self._get_config_option(name) + if not config_option['can_update_at_runtime']: + raise DashboardException( + msg='Config option {} is not updatable at runtime'.format(name), + code='config_option_not_updatable_at_runtime', + component='cluster_configuration') + + # Update config option availSections = ['global', 'mon', 'mgr', 'osd', 'mds', 'client'] for section in availSections: @@ -60,3 +66,10 @@ class ClusterConfiguration(RESTController): for name, value in options.items(): CephService.send_command('mon', 'config set', who=value['section'], name=name, value=str(value['value'])) + + def _get_config_option(self, name): + for option in mgr.get('config_options')['options']: + if option['name'] == name: + return self._append_config_option_values([option])[0] + + raise cherrypy.HTTPError(404) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration-details/configuration-details.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration-details/configuration-details.component.html index 35e47e0d610..b8d6037ca00 100755 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration-details/configuration-details.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration-details/configuration-details.component.html @@ -84,7 +84,7 @@ Can be updated at runtime + class="bold col-sm-1">Can be updated at runtime (editable) {{ selectedItem.can_update_at_runtime }} diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration.component.ts index 9c056bcb602..f7b7787a29b 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration.component.ts @@ -3,6 +3,7 @@ import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core'; import { I18n } from '@ngx-translate/i18n-polyfill'; import { ConfigurationService } from '../../../shared/api/configuration.service'; +import { CellTemplate } from '../../../shared/enum/cell-template.enum'; import { CdTableAction } from '../../../shared/models/cd-table-action'; import { CdTableColumn } from '../../../shared/models/cd-table-column'; import { CdTableFetchDataContext } from '../../../shared/models/cd-table-fetch-data-context'; @@ -91,7 +92,8 @@ export class ConfigurationComponent implements OnInit { permission: 'update', icon: 'fa-pencil', routerLink: () => `/configuration/edit/${getConfigOptUri()}`, - name: this.i18n('Edit') + name: this.i18n('Edit'), + disable: () => !this.isEditable(this.selection) }; this.tableActions = [editAction]; } @@ -106,7 +108,14 @@ export class ConfigurationComponent implements OnInit { cellClass: 'wrap', cellTemplate: this.confValTpl }, - { prop: 'default', name: this.i18n('Default'), cellClass: 'wrap' } + { prop: 'default', name: this.i18n('Default'), cellClass: 'wrap' }, + { + prop: 'can_update_at_runtime', + name: this.i18n('Editable'), + cellTransformation: CellTemplate.checkIcon, + flexGrow: 0.4, + cellClass: 'text-center' + } ]; } @@ -135,4 +144,12 @@ export class ConfigurationComponent implements OnInit { }); this.data = [...this.data]; } + + isEditable(selection: CdTableSelection): boolean { + if (selection.selected.length !== 1) { + return false; + } + + return selection.selected[0].can_update_at_runtime; + } } diff --git a/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf b/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf index c3c1ad3115d..d0d30e70494 100644 --- a/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf +++ b/src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf @@ -2983,8 +2983,8 @@ app/ceph/cluster/configuration/configuration-details/configuration-details.component.html 82 - - Can be updated at runtime + + Can be updated at runtime (editable) app/ceph/cluster/configuration/configuration-details/configuration-details.component.html 87 @@ -4130,6 +4130,13 @@ 1 + + Editable + + src/app/ceph/cluster/configuration/configuration.component.ts + 1 + + Public Address