App-GitHooks-Plugin-PgBouncerAuthSyntax
view release on metacpan or search on metacpan
lib/App/GitHooks/Plugin/PgBouncerAuthSyntax.pm view on Meta::CPAN
=head1 DESCRIPTION
This plugin verifies that staged PgBouncer authentication files have a proper
syntax before allowing the commit to be completed.
See http://pgbouncer.projects.pgfoundry.org/doc/config.html, under the
"Authentication File Format" section, for more information about the required
syntax.
=head1 VERSION
Version 1.1.0
=cut
our $VERSION = '1.1.0';
=head1 CONFIGURATION OPTIONS
This plugin supports the following options in the C<[PgBouncerAuthSyntax]>
section of your C<.githooksrc> file.
[PgBouncerAuthSyntax]
file_pattern = /^configs\/pgbouncer\/userlist.txt$/
comments_setting = disallow
=head2 file_pattern
A regular expression that will be checked against the path of files that are
committed and that indicates a PgBouncer auth file to analyze when it matches.
file_pattern = /^configs\/pgbouncer\/userlist.txt$/
=head2 comments_setting
As of version 1.5.4, PgBouncer does not allow comments. This will however
change in the next release, thanks to
L<this patch|https://github.com/markokr/pgbouncer-dev/commit/995acda16ce30cde67ab1839387138b7545ff786>.
Configure this setting accordingly based on your PgBouncer version:
=over 4
=item * I<allow_anywhere>
Allow comments anywhere. Use with PgBouncer versions above 1.5.4 (not
included).
comments_setting = allow_anywhere
=item * I<allow_end_only>
Allow comments at the end of the file only. PgBouncer will stop parsing the
auth file as soon as it encounters an incorrectly formatted line, so you can
technically add comments at the end of the file. This setting will prevent you
from accidentally adding anything but comments once the first comment is seen,
to catch errors that are otherwise tricky to debug.
comments_setting = allow_end_only
=item * I<disallow>
Don't allow comments at all. The safest setting for PgBouncer versions up to
1.5.4 (included).
comments_setting = disallow
=back
=head1 METHODS
=head2 get_file_pattern()
Return a pattern to filter the files this plugin should analyze.
my $file_pattern = App::GitHooks::Plugin::PgBouncerAuthSyntax->get_file_pattern(
app => $app,
);
=cut
sub get_file_pattern
{
my ( $class, %args ) = @_;
my $app = delete( $args{'app'} );
my $config = $app->get_config();
# Retrieve the config value.
my $regex = $config->get_regex( 'PgBouncerAuthSyntax', 'file_pattern' );
croak "'file_pattern' is not defined in the [PgBouncerAuthSyntax] section of your config file"
if !defined $regex;
return qr/$regex/;
}
=head2 get_file_check_description()
Return a description of the check performed on files by the plugin and that
will be displayed to the user, if applicable, along with an indication of the
success or failure of the plugin.
my $description = App::GitHooks::Plugin::PgBouncerAuthSyntax->get_file_check_description();
=cut
sub get_file_check_description
{
return 'The PgBouncer syntax is correct';
}
=head2 run_pre_commit_file()
Code to execute for each file as part of the pre-commit hook.
( run in 0.836 second using v1.01-cache-2.11-cpan-39bf76dae61 )