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
9 "name": (str, 'Settings Name'),
10 "default": (bool, 'Default Settings'),
11 "type": (str, 'Type of Settings'),
12 "value": (bool, 'Settings Value')
16 @APIRouter('/settings', Scope
.CONFIG_OPT
)
17 @APIDoc("Settings Management API", "Settings")
18 class Settings(RESTController
):
20 Enables to manage the settings of the dashboard (not the Ceph cluster).
22 @EndpointDoc("Display Settings Information",
24 'names': (str, 'Name of Settings'),
26 responses
={200: SETTINGS_SCHEMA
})
27 def list(self
, names
=None):
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``.
33 :return: A list of available options.
37 name
for name
in Options
.__dict
__
38 if name
.isupper() and not name
.startswith('_')
41 names
= names
.split(',')
42 option_names
= list(set(option_names
) & set(names
))
43 return [self
._get
(name
) for name
in option_names
]
46 with SettingsService
.attribute_handler(name
) as sname
:
47 setting
= getattr(Options
, sname
)
50 'default': setting
.default_value
,
51 'type': setting
.types_as_str(),
52 'value': getattr(SettingsModule
, sname
)
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.
63 return self
._get
(name
)
65 def set(self
, name
, value
):
66 with SettingsService
.attribute_handler(name
) as sname
:
67 setattr(SettingsModule
, _to_native(sname
), value
)
69 def delete(self
, name
):
70 with SettingsService
.attribute_handler(name
) as sname
:
71 delattr(SettingsModule
, _to_native(sname
))
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
)
79 @UIRouter('/standard_settings')
80 class StandardSettings(RESTController
):
83 Get various Dashboard related settings.
84 :return: Returns a dictionary containing various Dashboard
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
,
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