Mercurial > kallithea
annotate rhodecode/model/settings.py @ 1290:74685a31cc43 beta
Enable start_tls connection encryption.
author | "Lorenzo M. Catucci" <lorenzo@sancho.ccd.uniroma2.it> |
---|---|
date | Tue, 26 Apr 2011 19:17:06 +0200 |
parents | a671db5bdd58 |
children |
rev | line source |
---|---|
1012
551c7d5ae89d
#56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents:
991
diff
changeset
|
1 # -*- coding: utf-8 -*- |
551c7d5ae89d
#56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents:
991
diff
changeset
|
2 """ |
551c7d5ae89d
#56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents:
991
diff
changeset
|
3 rhodecode.model.settings |
551c7d5ae89d
#56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents:
991
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~ |
551c7d5ae89d
#56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents:
991
diff
changeset
|
5 |
551c7d5ae89d
#56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents:
991
diff
changeset
|
6 Settings model for RhodeCode |
551c7d5ae89d
#56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents:
991
diff
changeset
|
7 |
551c7d5ae89d
#56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents:
991
diff
changeset
|
8 :created on Nov 17, 2010 |
551c7d5ae89d
#56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents:
991
diff
changeset
|
9 :author: marcink |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> |
1012
551c7d5ae89d
#56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents:
991
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
551c7d5ae89d
#56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents:
991
diff
changeset
|
12 """ |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
13 # This program is free software: you can redistribute it and/or modify |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
14 # it under the terms of the GNU General Public License as published by |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
15 # the Free Software Foundation, either version 3 of the License, or |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
16 # (at your option) any later version. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
17 # |
704
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # This program is distributed in the hope that it will be useful, |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # GNU General Public License for more details. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
22 # |
704
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # You should have received a copy of the GNU General Public License |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
752
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
705
diff
changeset
|
25 |
1012
551c7d5ae89d
#56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents:
991
diff
changeset
|
26 import logging |
551c7d5ae89d
#56 added users/groups autocomplete for repository editing.
Marcin Kuzminski <marcin@python-works.com>
parents:
991
diff
changeset
|
27 |
752
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
705
diff
changeset
|
28 from rhodecode.model import BaseModel |
704
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 from rhodecode.model.caching_query import FromCache |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 from rhodecode.model.db import RhodeCodeSettings |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 log = logging.getLogger(__name__) |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 |
752
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
705
diff
changeset
|
34 class SettingsModel(BaseModel): |
704
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 """ |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 Settings model |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 """ |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 def get(self, settings_key, cache=False): |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 r = self.sa.query(RhodeCodeSettings)\ |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 .filter(RhodeCodeSettings.app_settings_name == settings_key).scalar() |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 if cache: |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 r = r.options(FromCache("sql_cache_short", |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 "get_setting_%s" % settings_key)) |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 return r |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 |
892
9adc0c1d9a87
Added optional cache into get_application settings
Marcin Kuzminski <marcin@python-works.com>
parents:
890
diff
changeset
|
47 def get_app_settings(self, cache=False): |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
48 """Get's config from database, each config key is prefixed with |
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
49 'rhodecode_' prefix, than global pylons config is updated with such |
890
042d38683d42
implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents:
756
diff
changeset
|
50 keys |
042d38683d42
implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents:
756
diff
changeset
|
51 """ |
042d38683d42
implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents:
756
diff
changeset
|
52 |
892
9adc0c1d9a87
Added optional cache into get_application settings
Marcin Kuzminski <marcin@python-works.com>
parents:
890
diff
changeset
|
53 ret = self.sa.query(RhodeCodeSettings) |
9adc0c1d9a87
Added optional cache into get_application settings
Marcin Kuzminski <marcin@python-works.com>
parents:
890
diff
changeset
|
54 |
9adc0c1d9a87
Added optional cache into get_application settings
Marcin Kuzminski <marcin@python-works.com>
parents:
890
diff
changeset
|
55 if cache: |
9adc0c1d9a87
Added optional cache into get_application settings
Marcin Kuzminski <marcin@python-works.com>
parents:
890
diff
changeset
|
56 ret = ret.options(FromCache("sql_cache_short", "get_hg_settings")) |
756
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
57 |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
58 if not ret: |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
59 raise Exception('Could not get application settings !') |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
60 settings = {} |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
61 for each in ret: |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
62 settings['rhodecode_' + each.app_settings_name] = each.app_settings_value |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
63 |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
64 return settings |
704
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 def get_ldap_settings(self): |
705
9e9f1b919c0c
implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents:
704
diff
changeset
|
67 """ |
9e9f1b919c0c
implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents:
704
diff
changeset
|
68 Returns ldap settings from database |
9e9f1b919c0c
implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents:
704
diff
changeset
|
69 :returns: |
9e9f1b919c0c
implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents:
704
diff
changeset
|
70 ldap_active |
9e9f1b919c0c
implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents:
704
diff
changeset
|
71 ldap_host |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
72 ldap_port |
1290
74685a31cc43
Enable start_tls connection encryption.
"Lorenzo M. Catucci" <lorenzo@sancho.ccd.uniroma2.it>
parents:
1206
diff
changeset
|
73 ldap_tls_kind |
991
b232a36cc51f
Improve LDAP authentication
Thayne Harbaugh <thayne@fusionio.com>
parents:
902
diff
changeset
|
74 ldap_tls_reqcert |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
75 ldap_dn_user |
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1135
diff
changeset
|
76 ldap_dn_pass |
705
9e9f1b919c0c
implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents:
704
diff
changeset
|
77 ldap_base_dn |
991
b232a36cc51f
Improve LDAP authentication
Thayne Harbaugh <thayne@fusionio.com>
parents:
902
diff
changeset
|
78 ldap_filter |
b232a36cc51f
Improve LDAP authentication
Thayne Harbaugh <thayne@fusionio.com>
parents:
902
diff
changeset
|
79 ldap_search_scope |
b232a36cc51f
Improve LDAP authentication
Thayne Harbaugh <thayne@fusionio.com>
parents:
902
diff
changeset
|
80 ldap_attr_login |
b232a36cc51f
Improve LDAP authentication
Thayne Harbaugh <thayne@fusionio.com>
parents:
902
diff
changeset
|
81 ldap_attr_firstname |
b232a36cc51f
Improve LDAP authentication
Thayne Harbaugh <thayne@fusionio.com>
parents:
902
diff
changeset
|
82 ldap_attr_lastname |
b232a36cc51f
Improve LDAP authentication
Thayne Harbaugh <thayne@fusionio.com>
parents:
902
diff
changeset
|
83 ldap_attr_email |
705
9e9f1b919c0c
implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents:
704
diff
changeset
|
84 """ |
991
b232a36cc51f
Improve LDAP authentication
Thayne Harbaugh <thayne@fusionio.com>
parents:
902
diff
changeset
|
85 # ldap_search_scope |
704
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
87 r = self.sa.query(RhodeCodeSettings)\ |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
88 .filter(RhodeCodeSettings.app_settings_name\ |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 .startswith('ldap_'))\ |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 .all() |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
92 fd = {} |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
94 for row in r: |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
95 v = row.app_settings_value |
1135
1aa1655bf019
fixed some config bool converter problems with ldap
Marcin Kuzminski <marcin@python-works.com>
parents:
1012
diff
changeset
|
96 if v in ['true', 'yes', 'on', 'y', 't', '1']: |
1aa1655bf019
fixed some config bool converter problems with ldap
Marcin Kuzminski <marcin@python-works.com>
parents:
1012
diff
changeset
|
97 v = True |
1aa1655bf019
fixed some config bool converter problems with ldap
Marcin Kuzminski <marcin@python-works.com>
parents:
1012
diff
changeset
|
98 elif v in ['false', 'no', 'off', 'n', 'f', '0']: |
1aa1655bf019
fixed some config bool converter problems with ldap
Marcin Kuzminski <marcin@python-works.com>
parents:
1012
diff
changeset
|
99 v = False |
1aa1655bf019
fixed some config bool converter problems with ldap
Marcin Kuzminski <marcin@python-works.com>
parents:
1012
diff
changeset
|
100 |
704
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
101 fd.update({row.app_settings_name:v}) |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 |
26237de9b613
Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 return fd |