CLASS METHODS

get_default_path

Determine the path for the default backend_config.ini file. A list of values and locations are checked and the first match is returned. If all places are checked and no file is found, an exception is thrown.

This procedure is idempotent - i.e. if you call this procedure multiple times the same value is returned no matter if environment variables or the file system have changed.

The following checks are made in order:

$ZONEMASTER_BACKEND_CONFIG_FILE

If this environment variable is set ot a truthy value, that path is returned.

/etc/zonemaster/backend_config.ini

If a file exists at this path, it is returned.

/usr/local/etc/zonemaster/backend_config.ini

If a file exists at such a path, it is returned.

DIST_DIR/backend_config.ini

If a file exists at this path, it is returned. DIST_DIR is wherever File::ShareDir installs the Zonemaster-Backend dist.

load_profiles

Loads and returns a set of named profiles.

my %all_profiles = (
    $config->PUBLIC_PROFILES,
    $config->PRIVATE_PROFILES,
);
my %profiles = %{ Zonemaster::Backend::Config->load_profiles( %all_profiles ) };

Takes a hash mapping profile names to profile paths. An `undef` path value means the default profile.

Returns a hashref mapping profile names to profile objects.

The returned profiles have omitted values filled in with defaults from the default profile.

Dies if any of the given paths cannot be read or their contents cannot be parsed as JSON.

CONSTRUCTORS

load_config

A wrapper around parse that also determines where the config file is located in the file system and reads it.

Throws an exception if the determined configuration file cannot be read. See parse for details on additional parsing-related error modes.

parse

Construct a new Zonemaster::Backend::Config based on a given configuration.

my $config = Zonemaster::Backend::Config->parse(
    q{
        [DB]
        engine = SQLite

        [SQLITE]
        database_file = /var/db/zonemaster.sqlite
    }
);

The configuration is interpreted according to the configuration format specification.

Returns a new Zonemaster::Backend::Config instance with its properties set to normalized and untainted values according to the given configuration with defaults according to the configuration format.

Emits a log warning with a deprecation message for each deprecated property that is present.

Throws an exception if the given configuration contains errors.

In a valid config file:

  • all required properties are present, and

  • all sections and properties are recognized.

METHODS

check_db

Returns a normalized string based on the supported databases.

EXCEPTION

Dies if the value is not one of SQLite, PostgreSQL or MySQL.

DB_engine

Get the value of DB.engine.

Returns one of "SQLite", "PostgreSQL" or "MySQL".

DB_polling_interval

Get the value of DB.polling_interval.

Returns a number.

MYSQL_database

Get the value of MYSQL.database.

Returns a string.

MYSQL_host

Get the value of MYSQL.host.

Returns a string.

MYSQL_port

Returns the MYSQL.port property from the loaded config.

Returns a number.

MYSQL_password

Get the value of MYSQL.password.

Returns a string.

MYSQL_user

Get the value of MYSQL.user.

Returns a string.

POSTGRESQL_database

Get the value of POSTGRESQL.database.

Returns a string.

POSTGRESQL_host

Get the value of POSTGRESQL.host.

Returns a string.

POSTGRESQL_port

Returns the POSTGRESQL.port property from the loaded config.

Returns a number.

POSTGRESQL_password

Get the value of POSTGRESQL.password.

Returns a string.

POSTGRESQL_user

Get the value of POSTGRESQL.user.

Returns a string.

SQLITE_database_file

Get the value of SQLITE.database_file.

Returns a string.

LANGUAGE_locale

Get the value of LANGUAGE.locale.

Returns a mapping from two-letter locale tag prefixes to full locale tags. This is represented by a hash mapping prefix to full locale tag.

E.g.:

(
    en => "en_US",
    sv => "sv_SE",
)

PUBLIC_PROFILES

Get the set of PUBLIC PROFILES.

Returns a hash mapping profile names to profile paths. The profile names are normalized to lowercase. Profile paths are either strings or undef. undef means that the Zonemaster Engine default profile should be used.

PRIVATE_PROFILES

Get the set of PRIVATE PROFILES.

Returns a hash mapping profile names to profile paths. The profile names are normalized to lowercase. Profile paths are always strings (contrast with PUBLIC_PROFILES).

ZONEMASTER_max_zonemaster_execution_time

Get the value of ZONEMASTER.max_zonemaster_execution_time.

Returns a number.

ZONEMASTER_number_of_processes_for_frontend_testing

Get the value of ZONEMASTER.number_of_processes_for_frontend_testing.

Returns a number.

ZONEMASTER_number_of_processes_for_batch_testing

Get the value of ZONEMASTER.number_of_processes_for_batch_testing.

Returns a number.

ZONEMASTER_lock_on_queue

Get the value of ZONEMASTER.lock_on_queue.

Returns a number.

ZONEMASTER_age_reuse_previous_test

Get the value of ZONEMASTER.age_reuse_previous_test.

Returns a number.

METRICS_statsd_host

Get the value of METRICS.statsd_host.

Returns a string.

METRICS_statsd_port

Get the value of METRICS.statsd_host.

Returns a number.

RPCAPI_enable_user_create

Experimental. Get the value of RPCAPI.enable_user_create.

Return 0 or 1

RPCAPI_enable_batch_create

Experimental. Get the value of RPCAPI.enable_batch_create.

Return 0 or 1

RPCAPI_enable_add_api_user

Get the value of RPCAPI.enable_add_api_user.

Return 0 or 1

RPCAPI_enable_add_batch_job

Get the value of RPCAPI.enable_add_batch_job.

Return 0 or 1

new_DB

Create a new database adapter object according to configuration.

The adapter connects to the database before it is returned.

INPUT

The database adapter class is selected based on the return value of DB_engine. The database adapter class constructor is called without arguments and is expected to configure itself according to available global configuration.

RETURNS

A configured Zonemaster::Backend::DB object.

EXCEPTIONS

Dies if no adapter for the configured database engine can be loaded.
Dies if the adapter is unable to connect to the database.

new_PM

Create a new processing manager object according to configuration.

INPUT

The values of the following attributes affect the construction of the returned object:

ZONEMASTER_max_zonemaster_execution_time
ZONEMASTER_number_of_processes_for_batch_testing
ZONEMASTER_number_of_processes_for_frontend_testing

RETURNS

A configured Parallel::ForkManager object.