App-Spoor
view release on metacpan or search on metacpan
lib/App/Spoor/Config.pm view on Meta::CPAN
package App::Spoor::Config;
use v5.10;
use strict;
use warnings;
use YAML::Tiny qw(Load);
use Path::Tiny qw(path);
=head1 NAME
App::Spoor::Config
=head1 VERSION
Version 0.01
=cut
our $VERSION = '0.01';
=head1 SYNOPSIS
Allows access to the spoor config file located at /etc/spoor/spoor.yml which currently has the following format;
---
application:
ignored_entries_path: //var/lib/spoor/ignored
parsed_entries_path: //var/lib/spoor/parsed
transmitted_entries_path: //var/lib/spoor/transmitted
followers:
access:
debug: 1
maxinterval: 10
name: /usr/local/cpanel/logs/access_log
transformer: bin/login_log_transformer.pl
error:
debug: 1
maxinterval: 10
name: /usr/local/cpanel/logs/error_log
transformer: bin/login_log_transformer.pl
login:
debug: 1
maxinterval: 10
name: /usr/local/cpanel/logs/login_log
transformer: bin/login_log_transformer.pl
transmission:
credentials:
api_identifier: api_identifier_goes_here
api_secret: api_secret_goes_here
endpoints:
report: /api/reports
host: https://spoor.capefox.co
=head1 SUBROUTINES/METHODS
=head2 get_follower_config
Gets the config related to a specific type of follower (access, error, login).
$reference_to_access_config_hash = App::Spoor::Config::get_follower_config('access');
# Optionally, you can pass in an alternative to the root path '/' which is used when building the path
# to the config file. In the code snipper below, the method will look for the config file in /tmp/etc/spoor
# rather than /etc/spoor. This is primarily used to support testing.
$reference_to_access_config_hash = App::Spoor::Config::get_follower_config('access', '/tmp');
=cut
sub get_follower_config {
my $follower_type = shift @_;
my $root_path = shift @_ // '/';
my $config_file_path = "$root_path/etc/spoor/spoor.yml";
my $file_contents = path($config_file_path)->slurp_utf8;
Load($file_contents)->{'followers'}{$follower_type};
}
=head2 get_application_config
Returns application config. This is *not* actually read from the config file but it is, for now, hard coded data.
Should the contents of the application config ever become more dynamic this will change.
$reference_to_application_config_hash = App::Spoor::Config::get_application_config();
# Optionally, you can pass in an alternative to the root path '/' which is used when building the path
# to the config file. In the code snipper below, the method will look for the config file in /tmp/etc/spoor
# rather than /etc/spoor. This is primarily used to support testing.
$reference_to_application_config_hash = App::Spoor::Config::get_application_config('/tmp');
=cut
sub get_application_config {
# YAGNI - Hard code application config - cleaner and more reliable than trying to sanitise the paths
{
parsed_entries_path => '/var/lib/spoor/parsed',
transmitted_entries_path => '/var/lib/spoor/transmitted',
transmission_failed_entries_path => '/var/lib/spoor/transmission_failed',
};
}
=head2 get_transmission_config
Returns the config from the `transmission` section of the config file.
$reference_to_transmission_config_hash = App::Spoor::Config::get_transmission_config('access');
( run in 0.695 second using v1.01-cache-2.11-cpan-5837b0d9d2c )