]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/controllers/settings.py
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / pybind / mgr / dashboard / controllers / settings.py
1 # -*- coding: utf-8 -*-
2 from ..security import Scope
3 from ..services.settings import SettingsService, _to_native
4 from ..settings import Options
5 from ..settings import Settings as SettingsModule
6 from . import APIDoc, APIRouter, EndpointDoc, RESTController, UIRouter
7
8 SETTINGS_SCHEMA = [{
9 "name": (str, 'Settings Name'),
10 "default": (bool, 'Default Settings'),
11 "type": (str, 'Type of Settings'),
12 "value": (bool, 'Settings Value')
13 }]
14
15
16 @APIRouter('/settings', Scope.CONFIG_OPT)
17 @APIDoc("Settings Management API", "Settings")
18 class Settings(RESTController):
19 """
20 Enables to manage the settings of the dashboard (not the Ceph cluster).
21 """
22 @EndpointDoc("Display Settings Information",
23 parameters={
24 'names': (str, 'Name of Settings'),
25 },
26 responses={200: SETTINGS_SCHEMA})
27 def list(self, names=None):
28 """
29 Get the list of available options.
30 :param names: A comma separated list of option names that should
31 be processed. Defaults to ``None``.
32 :type names: None|str
33 :return: A list of available options.
34 :rtype: list[dict]
35 """
36 option_names = [
37 name for name in Options.__dict__
38 if name.isupper() and not name.startswith('_')
39 ]
40 if names:
41 names = names.split(',')
42 option_names = list(set(option_names) & set(names))
43 return [self._get(name) for name in option_names]
44
45 def _get(self, name):
46 with SettingsService.attribute_handler(name) as sname:
47 setting = getattr(Options, sname)
48 return {
49 'name': sname,
50 'default': setting.default_value,
51 'type': setting.types_as_str(),
52 'value': getattr(SettingsModule, sname)
53 }
54
55 def get(self, name):
56 """
57 Get the given option.
58 :param name: The name of the option.
59 :return: Returns a dict containing the name, type,
60 default value and current value of the given option.
61 :rtype: dict
62 """
63 return self._get(name)
64
65 def set(self, name, value):
66 with SettingsService.attribute_handler(name) as sname:
67 setattr(SettingsModule, _to_native(sname), value)
68
69 def delete(self, name):
70 with SettingsService.attribute_handler(name) as sname:
71 delattr(SettingsModule, _to_native(sname))
72
73 def bulk_set(self, **kwargs):
74 with SettingsService.attribute_handler(kwargs) as data:
75 for name, value in data.items():
76 setattr(SettingsModule, _to_native(name), value)
77
78
79 @UIRouter('/standard_settings')
80 class StandardSettings(RESTController):
81 def list(self):
82 """
83 Get various Dashboard related settings.
84 :return: Returns a dictionary containing various Dashboard
85 settings.
86 :rtype: dict
87 """
88 return { # pragma: no cover - no complexity there
89 'user_pwd_expiration_span':
90 SettingsModule.USER_PWD_EXPIRATION_SPAN,
91 'user_pwd_expiration_warning_1':
92 SettingsModule.USER_PWD_EXPIRATION_WARNING_1,
93 'user_pwd_expiration_warning_2':
94 SettingsModule.USER_PWD_EXPIRATION_WARNING_2,
95 'pwd_policy_enabled':
96 SettingsModule.PWD_POLICY_ENABLED,
97 'pwd_policy_min_length':
98 SettingsModule.PWD_POLICY_MIN_LENGTH,
99 'pwd_policy_check_length_enabled':
100 SettingsModule.PWD_POLICY_CHECK_LENGTH_ENABLED,
101 'pwd_policy_check_oldpwd_enabled':
102 SettingsModule.PWD_POLICY_CHECK_OLDPWD_ENABLED,
103 'pwd_policy_check_username_enabled':
104 SettingsModule.PWD_POLICY_CHECK_USERNAME_ENABLED,
105 'pwd_policy_check_exclusion_list_enabled':
106 SettingsModule.PWD_POLICY_CHECK_EXCLUSION_LIST_ENABLED,
107 'pwd_policy_check_repetitive_chars_enabled':
108 SettingsModule.PWD_POLICY_CHECK_REPETITIVE_CHARS_ENABLED,
109 'pwd_policy_check_sequential_chars_enabled':
110 SettingsModule.PWD_POLICY_CHECK_SEQUENTIAL_CHARS_ENABLED,
111 'pwd_policy_check_complexity_enabled':
112 SettingsModule.PWD_POLICY_CHECK_COMPLEXITY_ENABLED
113 }