/usr/lib/python2.7/dist-packages/barman/config.py is in barman 2.3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 | # Copyright (C) 2011-2017 2ndQuadrant Limited
#
# This file is part of Barman.
#
# Barman is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Barman is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Barman. If not, see <http://www.gnu.org/licenses/>.
"""
This module is responsible for all the things related to
Barman configuration, such as parsing configuration file.
"""
import collections
import datetime
import inspect
import logging.handlers
import os
import re
import sys
from glob import iglob
from barman import output
try:
from ConfigParser import ConfigParser, NoOptionError
except ImportError:
from configparser import ConfigParser, NoOptionError
# create a namedtuple object called PathConflict with 'label' and 'server'
PathConflict = collections.namedtuple('PathConflict', 'label server')
_logger = logging.getLogger(__name__)
FORBIDDEN_SERVER_NAMES = ['all']
DEFAULT_USER = 'barman'
DEFAULT_LOG_LEVEL = logging.INFO
DEFAULT_LOG_FORMAT = "%(asctime)s [%(process)s] %(name)s " \
"%(levelname)s: %(message)s"
_TRUE_RE = re.compile(r"""^(true|t|yes|1|on)$""", re.IGNORECASE)
_FALSE_RE = re.compile(r"""^(false|f|no|0|off)$""", re.IGNORECASE)
_TIME_INTERVAL_RE = re.compile(r"""
^\s*
(\d+)\s+(day|month|week)s? # N (day|month|week) with optional 's'
\s*$
""", re.IGNORECASE | re.VERBOSE)
REUSE_BACKUP_VALUES = ('copy', 'link', 'off')
# Possible copy methods for backups (must be all lowercase)
BACKUP_METHOD_VALUES = ['rsync', 'postgres']
class CsvOption(set):
"""
Base class for CSV options.
Given a comma delimited string, this class is a list containing the
submitted options.
Internally, it uses a set in order to avoid option replication.
Allowed values for the CSV option are contained in the 'value_list'
attribute.
The 'conflicts' attribute specifies for any value, the list of
values that are prohibited (and thus generate a conflict).
If a conflict is found, raises a ValueError exception.
"""
value_list = []
conflicts = {}
def __init__(self, value, key, source):
# Invoke parent class init and initialize an empty set
super(CsvOption, self).__init__()
# Parse not None values
if value is not None:
self.parse(value, key, source)
# Validates the object structure before returning the new instance
self.validate(key, source)
def parse(self, value, key, source):
"""
Parses a list of values and correctly assign the set of values
(removing duplication) and checking for conflicts.
"""
if not value:
return
values_list = value.split(',')
for val in sorted(values_list):
val = val.strip().lower()
if val in self.value_list:
# check for conflicting values. if a conflict is
# found the option is not valid then, raise exception.
if val in self.conflicts and self.conflicts[val] in self:
raise ValueError("Invalid configuration value '%s' for "
"key %s in %s: cannot contain both "
"'%s' and '%s'."
"Configuration directive ignored." %
(val, key, source, val,
self.conflicts[val]))
else:
# otherwise use parsed value
self.add(val)
else:
# not allowed value, reject the configuration
raise ValueError("Invalid configuration value '%s' for "
"key %s in %s: Unknown option" %
(val, key, source))
def validate(self, key, source):
"""
Override this method for special validation needs
"""
def to_json(self):
"""
Output representation of the obj for JSON serialization
The result is a string which can be parsed by the same class
"""
return ",".join(self)
class BackupOptions(CsvOption):
"""
Extends CsvOption class providing all the details for the backup_options
field
"""
# constants containing labels for allowed values
EXCLUSIVE_BACKUP = 'exclusive_backup'
CONCURRENT_BACKUP = 'concurrent_backup'
EXTERNAL_CONFIGURATION = 'external_configuration'
# list holding all the allowed values for the BackupOption class
value_list = [EXCLUSIVE_BACKUP, CONCURRENT_BACKUP, EXTERNAL_CONFIGURATION]
# map holding all the possible conflicts between the allowed values
conflicts = {
EXCLUSIVE_BACKUP: CONCURRENT_BACKUP,
CONCURRENT_BACKUP: EXCLUSIVE_BACKUP, }
class RecoveryOptions(CsvOption):
"""
Extends CsvOption class providing all the details for the recovery_options
field
"""
# constants containing labels for allowed values
GET_WAL = 'get-wal'
# list holding all the allowed values for the RecoveryOptions class
value_list = [GET_WAL]
def parse_boolean(value):
"""
Parse a string to a boolean value
:param str value: string representing a boolean
:raises ValueError: if the string is an invalid boolean representation
"""
if _TRUE_RE.match(value):
return True
if _FALSE_RE.match(value):
return False
raise ValueError("Invalid boolean representation (use 'true' or 'false')")
def parse_time_interval(value):
"""
Parse a string, transforming it in a time interval.
Accepted format: N (day|month|week)s
:param str value: the string to evaluate
"""
# if empty string or none return none
if value is None or value == '':
return None
result = _TIME_INTERVAL_RE.match(value)
# if the string doesn't match, the option is invalid
if not result:
raise ValueError("Invalid value for a time interval %s" %
value)
# if the int conversion
value = int(result.groups()[0])
unit = result.groups()[1][0].lower()
# Calculates the time delta
if unit == 'd':
time_delta = datetime.timedelta(days=value)
elif unit == 'w':
time_delta = datetime.timedelta(weeks=value)
elif unit == 'm':
time_delta = datetime.timedelta(days=(31 * value))
else:
# This should never happen
raise ValueError("Invalid unit time %s" % unit)
return time_delta
def parse_reuse_backup(value):
"""
Parse a string to a valid reuse_backup value.
Valid values are "copy", "link" and "off"
:param str value: reuse_backup value
:raises ValueError: if the value is invalid
"""
if value is None:
return None
if value.lower() in REUSE_BACKUP_VALUES:
return value.lower()
raise ValueError(
"Invalid value (use '%s' or '%s')" % (
"', '".join(REUSE_BACKUP_VALUES[:-1]), REUSE_BACKUP_VALUES[-1]))
def parse_backup_method(value):
"""
Parse a string to a valid backup_method value.
Valid values are contained in BACKUP_METHOD_VALUES list
:param str value: backup_method value
:raises ValueError: if the value is invalid
"""
if value is None:
return None
if value.lower() in BACKUP_METHOD_VALUES:
return value.lower()
raise ValueError(
"Invalid value (must be one in: '%s')" % (
"', '".join(BACKUP_METHOD_VALUES)))
class ServerConfig(object):
"""
This class represents the configuration for a specific Server instance.
"""
KEYS = [
'active',
'archiver',
'archiver_batch_size',
'backup_directory',
'backup_method',
'backup_options',
'bandwidth_limit',
'basebackup_retry_sleep',
'basebackup_retry_times',
'basebackups_directory',
'check_timeout',
'compression',
'conninfo',
'custom_compression_filter',
'custom_decompression_filter',
'description',
'disabled',
'errors_directory',
'immediate_checkpoint',
'incoming_wals_directory',
'last_backup_maximum_age',
'max_incoming_wals_queue',
'minimum_redundancy',
'network_compression',
'parallel_jobs',
'path_prefix',
'post_archive_retry_script',
'post_archive_script',
'post_backup_retry_script',
'post_backup_script',
'pre_archive_retry_script',
'pre_archive_script',
'pre_backup_retry_script',
'pre_backup_script',
'recovery_options',
'retention_policy',
'retention_policy_mode',
'reuse_backup',
'slot_name',
'ssh_command',
'streaming_archiver',
'streaming_archiver_batch_size',
'streaming_archiver_name',
'streaming_backup_name',
'streaming_conninfo',
'streaming_wals_directory',
'tablespace_bandwidth_limit',
'wal_retention_policy',
'wals_directory'
]
BARMAN_KEYS = [
'archiver',
'archiver_batch_size',
'backup_method',
'backup_options',
'bandwidth_limit',
'basebackup_retry_sleep',
'basebackup_retry_times',
'check_timeout',
'compression',
'configuration_files_directory',
'custom_compression_filter',
'custom_decompression_filter',
'immediate_checkpoint',
'last_backup_maximum_age',
'max_incoming_wals_queue',
'minimum_redundancy',
'network_compression',
'parallel_jobs',
'path_prefix',
'post_archive_retry_script',
'post_archive_script',
'post_backup_retry_script',
'post_backup_script',
'pre_archive_retry_script',
'pre_archive_script',
'pre_backup_retry_script',
'pre_backup_script',
'recovery_options',
'retention_policy',
'retention_policy_mode',
'reuse_backup',
'slot_name',
'streaming_archiver',
'streaming_archiver_batch_size',
'streaming_archiver_name',
'streaming_backup_name',
'tablespace_bandwidth_limit',
'wal_retention_policy'
]
DEFAULTS = {
'active': 'true',
'archiver': 'off',
'archiver_batch_size': '0',
'backup_directory': '%(barman_home)s/%(name)s',
'backup_method': 'rsync',
'backup_options': '',
'basebackup_retry_sleep': '30',
'basebackup_retry_times': '0',
'basebackups_directory': '%(backup_directory)s/base',
'check_timeout': '30',
'disabled': 'false',
'errors_directory': '%(backup_directory)s/errors',
'immediate_checkpoint': 'false',
'incoming_wals_directory': '%(backup_directory)s/incoming',
'minimum_redundancy': '0',
'network_compression': 'false',
'parallel_jobs': '1',
'recovery_options': '',
'retention_policy_mode': 'auto',
'streaming_archiver': 'off',
'streaming_archiver_batch_size': '0',
'streaming_archiver_name': 'barman_receive_wal',
'streaming_backup_name': 'barman_streaming_backup',
'streaming_conninfo': '%(conninfo)s',
'streaming_wals_directory': '%(backup_directory)s/streaming',
'wal_retention_policy': 'main',
'wals_directory': '%(backup_directory)s/wals'
}
FIXED = [
'disabled',
]
PARSERS = {
'active': parse_boolean,
'archiver': parse_boolean,
'archiver_batch_size': int,
'backup_method': parse_backup_method,
'backup_options': BackupOptions,
'basebackup_retry_sleep': int,
'basebackup_retry_times': int,
'check_timeout': int,
'disabled': parse_boolean,
'immediate_checkpoint': parse_boolean,
'last_backup_maximum_age': parse_time_interval,
'max_incoming_wals_queue': int,
'network_compression': parse_boolean,
'parallel_jobs': int,
'recovery_options': RecoveryOptions,
'reuse_backup': parse_reuse_backup,
'streaming_archiver': parse_boolean,
'streaming_archiver_batch_size': int,
}
def invoke_parser(self, key, source, value, new_value):
"""
Function used for parsing configuration values.
If needed, it uses special parsers from the PARSERS map,
and handles parsing exceptions.
Uses two values (value and new_value) to manage
configuration hierarchy (server config overwrites global config).
:param str key: the name of the configuration option
:param str source: the section that contains the configuration option
:param value: the old value of the option if present.
:param str new_value: the new value that needs to be parsed
:return: the parsed value of a configuration option
"""
# If the new value is None, returns the old value
if new_value is None:
return value
# If we have a parser for the current key, use it to obtain the
# actual value. If an exception is thrown, print a warning and
# ignore the value.
# noinspection PyBroadException
if key in self.PARSERS:
parser = self.PARSERS[key]
try:
# If the parser is a subclass of the CsvOption class
# we need a different invocation, which passes not only
# the value to the parser, but also the key name
# and the section that contains the configuration
if inspect.isclass(parser) \
and issubclass(parser, CsvOption):
value = parser(new_value, key, source)
else:
value = parser(new_value)
except Exception as e:
output.warning("Ignoring invalid configuration value '%s' "
"for key %s in %s: %s",
new_value, key, source, e)
else:
value = new_value
return value
def __init__(self, config, name):
self.msg_list = []
self.config = config
self.name = name
self.barman_home = config.barman_home
self.barman_lock_directory = config.barman_lock_directory
config.validate_server_config(self.name)
for key in ServerConfig.KEYS:
value = None
# Skip parameters that cannot be configured by users
if key not in ServerConfig.FIXED:
# Get the setting from the [name] section of config file
# A literal None value is converted to an empty string
new_value = config.get(name, key, self.__dict__, none_value='')
source = '[%s] section' % name
value = self.invoke_parser(key, source, value, new_value)
# If the setting isn't present in [name] section of config file
# check if it has to be inherited from the [barman] section
if value is None and key in ServerConfig.BARMAN_KEYS:
new_value = config.get('barman',
key,
self.__dict__,
none_value='')
source = '[barman] section'
value = self.invoke_parser(key, source, value, new_value)
# If the setting isn't present in [name] section of config file
# and is not inherited from global section use its default
# (if present)
if value is None and key in ServerConfig.DEFAULTS:
new_value = ServerConfig.DEFAULTS[key] % self.__dict__
source = 'DEFAULTS'
value = self.invoke_parser(key, source, value, new_value)
# An empty string is a None value (bypassing inheritance
# from global configuration)
if value is not None and value == '' or value == 'None':
value = None
setattr(self, key, value)
def to_json(self):
"""
Return an equivalent dictionary that can be encoded in json
"""
json_dict = dict(vars(self))
# remove the reference to main Config object
del json_dict['config']
return json_dict
def get_bwlimit(self, tablespace=None):
"""
Return the configured bandwidth limit for the provided tablespace
If tablespace is None, it returns the global bandwidth limit
:param barman.infofile.Tablespace tablespace: the tablespace to copy
:rtype: str
"""
# Default to global bandwidth limit
bwlimit = self.bandwidth_limit
if tablespace:
# A tablespace can be copied using a per-tablespace bwlimit
tablespaces_bw_limit = self.tablespace_bandwidth_limit
if (tablespaces_bw_limit and
tablespace.name in tablespaces_bw_limit):
bwlimit = tablespaces_bw_limit[tablespace.name]
return bwlimit
class Config(object):
"""This class represents the barman configuration.
Default configuration files are /etc/barman.conf,
/etc/barman/barman.conf
and ~/.barman.conf for a per-user configuration
"""
CONFIG_FILES = [
'~/.barman.conf',
'/etc/barman.conf',
'/etc/barman/barman.conf',
]
_QUOTE_RE = re.compile(r"""^(["'])(.*)\1$""")
def __init__(self, filename=None):
self._config = ConfigParser()
if filename:
if hasattr(filename, 'read'):
self._config.readfp(filename)
else:
# check for the existence of the user defined file
if not os.path.exists(filename):
sys.exit("Configuration file '%s' does not exist" %
filename)
self._config.read(os.path.expanduser(filename))
else:
# Check for the presence of configuration files
# inside default directories
for path in self.CONFIG_FILES:
full_path = os.path.expanduser(path)
if os.path.exists(full_path) \
and full_path in self._config.read(full_path):
filename = full_path
break
else:
sys.exit("Could not find any configuration file at "
"default locations.\n"
"Check Barman's documentation for more help.")
self.config_file = filename
self._servers = None
self.servers_msg_list = []
self._parse_global_config()
def get(self, section, option, defaults=None, none_value=None):
"""Method to get the value from a given section from
Barman configuration
"""
if not self._config.has_section(section):
return None
try:
value = self._config.get(section, option, raw=False, vars=defaults)
if value.lower() == 'none':
value = none_value
if value is not None:
value = self._QUOTE_RE.sub(lambda m: m.group(2), value)
return value
except NoOptionError:
return None
def _parse_global_config(self):
"""
This method parses the global [barman] section
"""
self.barman_home = self.get('barman', 'barman_home')
self.barman_lock_directory = self.get(
'barman', 'barman_lock_directory') or self.barman_home
self.user = self.get('barman', 'barman_user') or DEFAULT_USER
self.log_file = self.get('barman', 'log_file')
self.log_format = self.get(
'barman', 'log_format') or DEFAULT_LOG_FORMAT
self.log_level = self.get('barman', 'log_level') or DEFAULT_LOG_LEVEL
# save the raw barman section to be compared later in
# _is_global_config_changed() method
self._global_config = set(self._config.items('barman'))
def _is_global_config_changed(self):
"""Return true if something has changed in global configuration"""
return self._global_config != set(self._config.items('barman'))
def load_configuration_files_directory(self):
"""
Read the "configuration_files_directory" option and load all the
configuration files with the .conf suffix that lie in that folder
"""
config_files_directory = self.get('barman',
'configuration_files_directory')
if not config_files_directory:
return
if not os.path.isdir(os.path.expanduser(config_files_directory)):
_logger.warn(
'Ignoring the "configuration_files_directory" option as "%s" '
'is not a directory',
config_files_directory)
return
for cfile in sorted(iglob(
os.path.join(os.path.expanduser(config_files_directory),
'*.conf'))):
filename = os.path.basename(cfile)
if os.path.isfile(cfile):
# Load a file
_logger.debug('Including configuration file: %s', filename)
self._config.read(cfile)
if self._is_global_config_changed():
msg = "the configuration file %s contains a not empty [" \
"barman] section" % filename
_logger.fatal(msg)
raise SystemExit("FATAL: %s" % msg)
else:
# Add an info that a file has been discarded
_logger.warn('Discarding configuration file: %s (not a file)',
filename)
def _populate_servers(self):
"""
Populate server list from configuration file
Also check for paths errors in configuration.
If two or more paths overlap in
a single server, that server is disabled.
If two or more directory paths overlap between
different servers an error is raised.
"""
# Populate servers
if self._servers is not None:
return
self._servers = {}
# Cycle all the available configurations sections
for section in self._config.sections():
if section == 'barman':
# skip global settings
continue
# Exit if the section has a reserved name
if section in FORBIDDEN_SERVER_NAMES:
msg = "the reserved word '%s' is not allowed as server name." \
"Please rename it." % section
_logger.fatal(msg)
raise SystemExit("FATAL: %s" % msg)
# Create a ServerConfig object
self._servers[section] = ServerConfig(self, section)
# Check for conflicting paths in Barman configuration
self._check_conflicting_paths()
def _check_conflicting_paths(self):
"""
Look for conflicting paths intra-server and inter-server
"""
# All paths in configuration
servers_paths = {}
# Global errors list
self.servers_msg_list = []
# Cycle all the available configurations sections
for section in sorted(self._config.sections()):
if section == 'barman':
# skip global settings
continue
# Paths map
section_conf = self._servers[section]
config_paths = {
'backup_directory':
section_conf.backup_directory,
'basebackups_directory':
section_conf.basebackups_directory,
'errors_directory':
section_conf.errors_directory,
'incoming_wals_directory':
section_conf.incoming_wals_directory,
'streaming_wals_directory':
section_conf.streaming_wals_directory,
'wals_directory':
section_conf.wals_directory,
}
# Check for path errors
for label, path in sorted(config_paths.items()):
# If the path does not conflict with the others, add it to the
# paths map
real_path = os.path.realpath(path)
if real_path not in servers_paths:
servers_paths[real_path] = PathConflict(label, section)
else:
if section == servers_paths[real_path].server:
# Internal path error.
# Insert the error message into the server.msg_list
if real_path == path:
self._servers[section].msg_list.append(
"Conflicting path: %s=%s conflicts with "
"'%s' for server '%s'" % (
label, path,
servers_paths[real_path].label,
servers_paths[real_path].server))
else:
# Symbolic link
self._servers[section].msg_list.append(
"Conflicting path: %s=%s (symlink to: %s) "
"conflicts with '%s' for server '%s'" % (
label, path, real_path,
servers_paths[real_path].label,
servers_paths[real_path].server))
# Disable the server
self._servers[section].disabled = True
else:
# Global path error.
# Insert the error message into the global msg_list
if real_path == path:
self.servers_msg_list.append(
"Conflicting path: "
"%s=%s for server '%s' conflicts with "
"'%s' for server '%s'" % (
label, path, section,
servers_paths[real_path].label,
servers_paths[real_path].server))
else:
# Symbolic link
self.servers_msg_list.append(
"Conflicting path: "
"%s=%s (symlink to: %s) for server '%s' "
"conflicts with '%s' for server '%s'" % (
label, path, real_path, section,
servers_paths[real_path].label,
servers_paths[real_path].server))
def server_names(self):
"""This method returns a list of server names"""
self._populate_servers()
return self._servers.keys()
def servers(self):
"""This method returns a list of server parameters"""
self._populate_servers()
return self._servers.values()
def get_server(self, name):
"""
Get the configuration of the specified server
:param str name: the server name
"""
self._populate_servers()
return self._servers.get(name, None)
def validate_global_config(self):
"""
Validate global configuration parameters
"""
# Check for the existence of unexpected parameters in the
# global section of the configuration file
keys = ['barman_home',
'barman_lock_directory',
'barman_user',
'log_file',
'log_level',
'configuration_files_directory']
keys.extend(ServerConfig.KEYS)
self._validate_with_keys(self._global_config,
keys, 'barman')
def validate_server_config(self, server):
"""
Validate configuration parameters for a specified server
:param str server: the server name
"""
# Check for the existence of unexpected parameters in the
# server section of the configuration file
self._validate_with_keys(self._config.items(server),
ServerConfig.KEYS, server)
@staticmethod
def _validate_with_keys(config_items, allowed_keys, section):
"""
Check every config parameter against a list of allowed keys
:param config_items: list of tuples containing provided parameters
along with their values
:param allowed_keys: list of allowed keys
:param section: source section (for error reporting)
"""
for parameter in config_items:
# if the parameter name is not in the list of allowed values,
# then output a warning
name = parameter[0]
if name not in allowed_keys:
output.warning('Invalid configuration option "%s" in [%s] '
'section.', name, section)
# easy raw config diagnostic with python -m
# noinspection PyProtectedMember
def _main():
print("Active configuration settings:")
r = Config()
r.load_configuration_files_directory()
for section in r._config.sections():
print("Section: %s" % section)
for option in r._config.options(section):
print("\t%s = %s " % (option, r.get(section, option)))
if __name__ == "__main__":
_main()
|