1 | # ------------------------------------------------------------------------------ |
---|
2 | # Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
---|
3 | # |
---|
4 | # This file is part of FCM, tools for managing and building source code. |
---|
5 | # |
---|
6 | # FCM is free software: you can redistribute it and/or modify |
---|
7 | # it under the terms of the GNU General Public License as published by |
---|
8 | # the Free Software Foundation, either version 3 of the License, or |
---|
9 | # (at your option) any later version. |
---|
10 | # |
---|
11 | # FCM is distributed in the hope that it will be useful, |
---|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | # GNU General Public License for more details. |
---|
15 | # |
---|
16 | # You should have received a copy of the GNU General Public License |
---|
17 | # along with FCM. If not, see <http://www.gnu.org/licenses/>. |
---|
18 | # ------------------------------------------------------------------------------ |
---|
19 | |
---|
20 | use strict; |
---|
21 | use warnings; |
---|
22 | |
---|
23 | package FCM::Admin::Config; |
---|
24 | use base qw{FCM::Class::HASH}; |
---|
25 | |
---|
26 | use FCM::Context::Locator; |
---|
27 | use FCM::Util; |
---|
28 | use File::Basename qw{dirname}; |
---|
29 | use File::Spec::Functions qw{catfile}; |
---|
30 | use FindBin; |
---|
31 | |
---|
32 | our $UTIL = FCM::Util->new(); |
---|
33 | |
---|
34 | my $TRAC_LIVE_URL_TMPL = 'https://{host}/trac/{project}'; |
---|
35 | my $USER_ID = (getpwuid($<))[0]; |
---|
36 | |
---|
37 | __PACKAGE__->class({ |
---|
38 | # Emails |
---|
39 | admin_email => {isa => '$', default => $USER_ID}, |
---|
40 | notification_from => {isa => '$'}, |
---|
41 | |
---|
42 | # Location for log files |
---|
43 | log_dir => {isa => '$', default => '/var/log/fcm'}, |
---|
44 | |
---|
45 | # FCM installation locations |
---|
46 | fcm_home => {isa => '$', default => dirname($FindBin::Bin)}, |
---|
47 | fcm_site_home => {isa => '$', default => q{}}, |
---|
48 | |
---|
49 | # FCM installation mirror locations |
---|
50 | mirror_dests => {isa => '$', default => q{}}, |
---|
51 | mirror_keys => {isa => '$', default => q{}}, |
---|
52 | |
---|
53 | # Subversion repositories settings |
---|
54 | svn_backup_dir => {isa => '$', default => '/var/svn/backups'}, |
---|
55 | svn_dump_dir => {isa => '$', default => '/var/svn/dumps'}, |
---|
56 | svn_group => {isa => '$', default => q{}}, |
---|
57 | svn_hook_path_env => {isa => '$', default => q{}}, |
---|
58 | svn_live_dir => {isa => '$', default => '/srv/svn'}, |
---|
59 | svn_passwd_file => {isa => '$', default => q{}}, |
---|
60 | svn_project_suffix => {isa => '$', default => q{}}, |
---|
61 | |
---|
62 | # Trac environments settings |
---|
63 | trac_admin_users => {isa => '$', default => q{}}, |
---|
64 | trac_backup_dir => {isa => '$', default => '/var/trac/backups'}, |
---|
65 | trac_group => {isa => '$', default => q{}}, |
---|
66 | trac_host_name => {isa => '$', default => 'localhost'}, |
---|
67 | trac_ini_file => {isa => '$', default => 'trac.ini'}, |
---|
68 | trac_live_dir => {isa => '$', default => '/srv/trac'}, |
---|
69 | trac_live_url_tmpl => {isa => '$', default => $TRAC_LIVE_URL_TMPL}, |
---|
70 | trac_passwd_file => {isa => '$', default => q{}}, |
---|
71 | |
---|
72 | # User information tool settings |
---|
73 | user_info_tool => {isa => '$', default => 'passwd'}, |
---|
74 | |
---|
75 | # User information tool, LDAP settings |
---|
76 | ldappw => {isa => '$', default => '~/.ldappw'}, |
---|
77 | ldap_uri => {isa => '$', default => q{}}, |
---|
78 | ldap_binddn => {isa => '$', default => q{}}, |
---|
79 | ldap_basedn => {isa => '$', default => q{}}, |
---|
80 | ldap_attrs => {isa => '$', default => q{uid cn mail}}, |
---|
81 | ldap_filter_more => {isa => '$', default => q{}}, |
---|
82 | |
---|
83 | # User information tool, passwd settings |
---|
84 | passwd_email_domain => {isa => '$', default => q{}}, |
---|
85 | passwd_gid_max => {isa => '$'}, |
---|
86 | passwd_uid_max => {isa => '$'}, |
---|
87 | passwd_gid_min => {isa => '$', default => 1000}, |
---|
88 | passwd_uid_min => {isa => '$', default => 1000}, |
---|
89 | }); |
---|
90 | |
---|
91 | |
---|
92 | # Returns a unique instance of this class. |
---|
93 | my $INSTANCE; |
---|
94 | sub instance { |
---|
95 | my ($class) = @_; |
---|
96 | if (!defined($INSTANCE)) { |
---|
97 | $INSTANCE = $class->new(); |
---|
98 | # Load $FCM_HOME/etc/fcm/admin.cfg and $HOME/.metomi/fcm/admin.cfg |
---|
99 | $UTIL->cfg_init( |
---|
100 | 'admin.cfg', |
---|
101 | sub { |
---|
102 | my $config_reader = shift(); |
---|
103 | while (defined(my $entry = $config_reader->())) { |
---|
104 | my $label = $entry->get_label(); |
---|
105 | if (exists($INSTANCE->{$label})) { |
---|
106 | $INSTANCE->{$label} = $entry->get_value(); |
---|
107 | } |
---|
108 | } |
---|
109 | }, |
---|
110 | ); |
---|
111 | } |
---|
112 | return $INSTANCE; |
---|
113 | } |
---|
114 | |
---|
115 | 1; |
---|
116 | __END__ |
---|
117 | |
---|
118 | =head1 NAME |
---|
119 | |
---|
120 | FCM::Admin::Config |
---|
121 | |
---|
122 | =head1 SYNOPSIS |
---|
123 | |
---|
124 | $config = FCM::Admin::Config->instance(); |
---|
125 | $dir = $config->get_svn_backup_dir(); |
---|
126 | # ... |
---|
127 | |
---|
128 | =head1 DESCRIPTION |
---|
129 | |
---|
130 | This class is used to retrieve/store configurations required by FCM |
---|
131 | admininstration scripts. |
---|
132 | |
---|
133 | It is a sub-class of L<FCM::Class::HASH|FCM::Class::HASH>. |
---|
134 | |
---|
135 | =head1 METHODS |
---|
136 | |
---|
137 | =over 4 |
---|
138 | |
---|
139 | =item FCM::Admin::Config->instance() |
---|
140 | |
---|
141 | Returns a unique instance of this class. On first call, creates the instance |
---|
142 | with the configurations set to their default values; and loads from the |
---|
143 | site/user configuration at $FCM_HOME/etc/fcm/admin.cfg and |
---|
144 | $HOME/.metomi/fcm/admin.cfg. |
---|
145 | |
---|
146 | =back |
---|
147 | |
---|
148 | =head1 ATTRIBUTES |
---|
149 | |
---|
150 | Email addresses. |
---|
151 | |
---|
152 | =over 4 |
---|
153 | |
---|
154 | =item admin_email |
---|
155 | |
---|
156 | The e-mail address of the FCM administrator. |
---|
157 | |
---|
158 | =item notification_from |
---|
159 | |
---|
160 | Notification email address (for the "From:" field in notification emails). |
---|
161 | |
---|
162 | =back |
---|
163 | |
---|
164 | Location for log files. |
---|
165 | |
---|
166 | =over 4 |
---|
167 | |
---|
168 | =item log_dir |
---|
169 | |
---|
170 | The location for log files. |
---|
171 | |
---|
172 | =back |
---|
173 | |
---|
174 | Locations of FCM installation. |
---|
175 | |
---|
176 | =over 4 |
---|
177 | |
---|
178 | =item fcm_home |
---|
179 | |
---|
180 | The source path of the default FCM distribution. |
---|
181 | |
---|
182 | =item fcm_site_home |
---|
183 | |
---|
184 | The source path of the default FCM site distribution. |
---|
185 | |
---|
186 | =back |
---|
187 | |
---|
188 | Settings on how to mirror FCM installation. |
---|
189 | |
---|
190 | =over 4 |
---|
191 | |
---|
192 | =item mirror_dests |
---|
193 | |
---|
194 | A space-delimited list of destinations to mirror FCM installation. |
---|
195 | |
---|
196 | =item mirror_keys |
---|
197 | |
---|
198 | A string containing a list of source keys. Each source key should point |
---|
199 | to a source location in this $config. The source locations will be distributed |
---|
200 | to the list of destinations in C<mirror_dests>. |
---|
201 | |
---|
202 | =back |
---|
203 | |
---|
204 | Subversion repositories settings. |
---|
205 | |
---|
206 | =over 4 |
---|
207 | |
---|
208 | =item svn_backup_dir |
---|
209 | |
---|
210 | The path to a directory containing the backups of SVN repositories. |
---|
211 | |
---|
212 | =item svn_dump_dir |
---|
213 | |
---|
214 | The path to a directory containing the revision dumps of SVN |
---|
215 | repositories. |
---|
216 | |
---|
217 | =item svn_group |
---|
218 | |
---|
219 | The group name in which Subversion repositories should be created in. |
---|
220 | |
---|
221 | =item svn_hook_dir |
---|
222 | |
---|
223 | The path to a directory containing source files of SVN hook scripts. |
---|
224 | |
---|
225 | =item svn_hook_path_env |
---|
226 | |
---|
227 | The value of the PATH environment variable, in which SVN hook scripts |
---|
228 | should run with. |
---|
229 | |
---|
230 | =item svn_live_dir |
---|
231 | |
---|
232 | The path to a directory containing the live SVN repositories. |
---|
233 | |
---|
234 | =item svn_passwd_file |
---|
235 | |
---|
236 | The base name of the SVN password file. |
---|
237 | |
---|
238 | =item svn_project_suffix |
---|
239 | |
---|
240 | The suffix added to the name of each SVN repository. |
---|
241 | |
---|
242 | =back |
---|
243 | |
---|
244 | Trac environment settings. |
---|
245 | |
---|
246 | =over 4 |
---|
247 | |
---|
248 | =item trac_admin_users |
---|
249 | |
---|
250 | A space-delimited list of admin users for all Trac environments. |
---|
251 | |
---|
252 | =item trac_backup_dir |
---|
253 | |
---|
254 | The path to a directory containing the backups of Trac environments. |
---|
255 | |
---|
256 | =item trac_group |
---|
257 | |
---|
258 | The group name in which Trac environment files should be created in. |
---|
259 | |
---|
260 | =item trac_host_name |
---|
261 | |
---|
262 | The host name of the Trac server, from the user's perspective. |
---|
263 | |
---|
264 | =item trac_ini_file |
---|
265 | |
---|
266 | The base name of the Trac INI file. |
---|
267 | |
---|
268 | =item trac_live_dir |
---|
269 | |
---|
270 | The path to a directory containing the live Trac environments. |
---|
271 | |
---|
272 | =item trac_live_url_tmpl |
---|
273 | |
---|
274 | The template string for determining the URL of the Trac environment of a |
---|
275 | project. |
---|
276 | |
---|
277 | =item trac_passwd_file |
---|
278 | |
---|
279 | The base name of the Trac password file. |
---|
280 | |
---|
281 | =back |
---|
282 | |
---|
283 | =over 4 |
---|
284 | |
---|
285 | User information tool settings. |
---|
286 | |
---|
287 | =item user_info_tool |
---|
288 | |
---|
289 | The name of the tool for obtaining user information. |
---|
290 | |
---|
291 | =back |
---|
292 | |
---|
293 | LDAP settings, only relevant if C<user_info_tool = ldap> |
---|
294 | |
---|
295 | =over 4 |
---|
296 | |
---|
297 | =item ldappw |
---|
298 | |
---|
299 | File containing the password to the LDAP server, if required. |
---|
300 | |
---|
301 | =item ldap_uri |
---|
302 | |
---|
303 | The URI of the LDAP server. |
---|
304 | |
---|
305 | =item ldap_binddn |
---|
306 | |
---|
307 | The DN in the LDAP server to bind with to search the directory. |
---|
308 | |
---|
309 | =item ldap_basedn |
---|
310 | |
---|
311 | The DN in the LDAP server that is the base for a search. |
---|
312 | |
---|
313 | =item ldap_attrs |
---|
314 | |
---|
315 | The attributes for UID, common name and email in the LDAP directory. |
---|
316 | |
---|
317 | =item ldap_filter_more |
---|
318 | |
---|
319 | If specified, use the value as extra (AND) filters to an LDAP search. |
---|
320 | |
---|
321 | =back |
---|
322 | |
---|
323 | PASSWD settings, only relevant if user_info_tool = passwd |
---|
324 | |
---|
325 | =over 4 |
---|
326 | |
---|
327 | =item passwd_email_domain |
---|
328 | |
---|
329 | Domain name to suffix user IDs to create an email address. |
---|
330 | |
---|
331 | =item passwd_gid_max |
---|
332 | |
---|
333 | Maximum GID considered to be a normal user group. |
---|
334 | |
---|
335 | =item passwd_uid_max |
---|
336 | |
---|
337 | Maximum UID considered to be a normal user. |
---|
338 | |
---|
339 | =item passwd_gid_min |
---|
340 | |
---|
341 | Minimum GID considered to be a normal user group. (default=1000) |
---|
342 | |
---|
343 | =item passwd_uid_min |
---|
344 | |
---|
345 | Minimum UID considered to be a normal user. (default=1000) |
---|
346 | |
---|
347 | =back |
---|
348 | |
---|
349 | =head1 COPYRIGHT |
---|
350 | |
---|
351 | Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
---|
352 | |
---|
353 | =cut |
---|