| 1 | package App::Spoor::Config; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use v5.10; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 2 | ▶ | use YAML::Tiny qw(Load); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 2 | ▶ | use Path::Tiny qw(path); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | =head1 NAME | ||||||||||||
| 11 | |||||||||||||
| 12 | App::Spoor::Config | ||||||||||||
| 13 | |||||||||||||
| 14 | =head1 VERSION | ||||||||||||
| 15 | |||||||||||||
| 16 | Version 0.01 | ||||||||||||
| 17 | |||||||||||||
| 18 | =cut | ||||||||||||
| 19 | |||||||||||||
| 20 | 2 | our $VERSION = '0.01'; | |||||||||||
| 21 | |||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||
| 23 | |||||||||||||
| 24 | Allows access to the spoor config file located at /etc/spoor/spoor.yml which currently has the following format; | ||||||||||||
| 25 | |||||||||||||
| 26 | --- | ||||||||||||
| 27 | application: | ||||||||||||
| 28 | ignored_entries_path: //var/lib/spoor/ignored | ||||||||||||
| 29 | parsed_entries_path: //var/lib/spoor/parsed | ||||||||||||
| 30 | transmitted_entries_path: //var/lib/spoor/transmitted | ||||||||||||
| 31 | followers: | ||||||||||||
| 32 | access: | ||||||||||||
| 33 | debug: 1 | ||||||||||||
| 34 | maxinterval: 10 | ||||||||||||
| 35 | name: /usr/local/cpanel/logs/access_log | ||||||||||||
| 36 | transformer: bin/login_log_transformer.pl | ||||||||||||
| 37 | error: | ||||||||||||
| 38 | debug: 1 | ||||||||||||
| 39 | maxinterval: 10 | ||||||||||||
| 40 | name: /usr/local/cpanel/logs/error_log | ||||||||||||
| 41 | transformer: bin/login_log_transformer.pl | ||||||||||||
| 42 | login: | ||||||||||||
| 43 | debug: 1 | ||||||||||||
| 44 | maxinterval: 10 | ||||||||||||
| 45 | name: /usr/local/cpanel/logs/login_log | ||||||||||||
| 46 | transformer: bin/login_log_transformer.pl | ||||||||||||
| 47 | transmission: | ||||||||||||
| 48 | credentials: | ||||||||||||
| 49 | api_identifier: api_identifier_goes_here | ||||||||||||
| 50 | api_secret: api_secret_goes_here | ||||||||||||
| 51 | endpoints: | ||||||||||||
| 52 | report: /api/reports | ||||||||||||
| 53 | host: https://spoor.capefox.co | ||||||||||||
| 54 | |||||||||||||
| 55 | =head1 SUBROUTINES/METHODS | ||||||||||||
| 56 | |||||||||||||
| 57 | =head2 get_follower_config | ||||||||||||
| 58 | |||||||||||||
| 59 | Gets the config related to a specific type of follower (access, error, login). | ||||||||||||
| 60 | |||||||||||||
| 61 | $reference_to_access_config_hash = App::Spoor::Config::get_follower_config('access'); | ||||||||||||
| 62 | |||||||||||||
| 63 | # Optionally, you can pass in an alternative to the root path '/' which is used when building the path | ||||||||||||
| 64 | # to the config file. In the code snipper below, the method will look for the config file in /tmp/etc/spoor | ||||||||||||
| 65 | # rather than /etc/spoor. This is primarily used to support testing. | ||||||||||||
| 66 | |||||||||||||
| 67 | $reference_to_access_config_hash = App::Spoor::Config::get_follower_config('access', '/tmp'); | ||||||||||||
| 68 | |||||||||||||
| 69 | =cut | ||||||||||||
| 70 | |||||||||||||
| 71 | 1 | ▶ | sub get_follower_config { | ||||||||||
|
Subroutine
get_follower_config: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 72 | 1 | my $follower_type = shift @_; | |||||||||||
| 73 | 1 | ▶ | my $root_path = shift @_ // '/'; | ||||||||||
|
Condition50%1/2
shift @_ // "/"
MC/DC0%0/1
shift @_ // "/"
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||
| 74 | 1 | my $config_file_path = "$root_path/etc/spoor/spoor.yml"; | |||||||||||
| 75 | 1 | my $file_contents = path($config_file_path)->slurp_utf8; | |||||||||||
| 76 | |||||||||||||
| 77 | 1 | Load($file_contents)->{'followers'}{$follower_type}; | |||||||||||
| 78 | } | ||||||||||||
| 79 | |||||||||||||
| 80 | =head2 get_application_config | ||||||||||||
| 81 | |||||||||||||
| 82 | Returns application config. This is *not* actually read from the config file but it is, for now, hard coded data. | ||||||||||||
| 83 | Should the contents of the application config ever become more dynamic this will change. | ||||||||||||
| 84 | |||||||||||||
| 85 | $reference_to_application_config_hash = App::Spoor::Config::get_application_config(); | ||||||||||||
| 86 | |||||||||||||
| 87 | # Optionally, you can pass in an alternative to the root path '/' which is used when building the path | ||||||||||||
| 88 | # to the config file. In the code snipper below, the method will look for the config file in /tmp/etc/spoor | ||||||||||||
| 89 | # rather than /etc/spoor. This is primarily used to support testing. | ||||||||||||
| 90 | |||||||||||||
| 91 | $reference_to_application_config_hash = App::Spoor::Config::get_application_config('/tmp'); | ||||||||||||
| 92 | |||||||||||||
| 93 | =cut | ||||||||||||
| 94 | |||||||||||||
| 95 | 1 | ▶ | sub get_application_config { | ||||||||||
|
Subroutine
get_application_config: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 96 | # YAGNI - Hard code application config - cleaner and more reliable than trying to sanitise the paths | ||||||||||||
| 97 | { | ||||||||||||
| 98 | 1 | parsed_entries_path => '/var/lib/spoor/parsed', | |||||||||||
| 99 | transmitted_entries_path => '/var/lib/spoor/transmitted', | ||||||||||||
| 100 | transmission_failed_entries_path => '/var/lib/spoor/transmission_failed', | ||||||||||||
| 101 | }; | ||||||||||||
| 102 | } | ||||||||||||
| 103 | |||||||||||||
| 104 | =head2 get_transmission_config | ||||||||||||
| 105 | |||||||||||||
| 106 | Returns the config from the `transmission` section of the config file. | ||||||||||||
| 107 | |||||||||||||
| 108 | $reference_to_transmission_config_hash = App::Spoor::Config::get_transmission_config('access'); | ||||||||||||
| 109 | |||||||||||||
| 110 | # Optionally, you can pass in an alternative to the root path '/' which is used when building the path | ||||||||||||
| 111 | # to the config file. In the code snipper below, the method will look for the config file in /tmp/etc/spoor | ||||||||||||
| 112 | # rather than /etc/spoor. This is primarily used to support testing. | ||||||||||||
| 113 | |||||||||||||
| 114 | $reference_to_transmission_config_hash = App::Spoor::Config::get_transmission_config('/tmp'); | ||||||||||||
| 115 | |||||||||||||
| 116 | =cut | ||||||||||||
| 117 | |||||||||||||
| 118 | 1 | ▶ | sub get_transmission_config { | ||||||||||
|
Subroutine
get_transmission_config: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 119 | 1 | ▶ | my $root_path = shift @_ // '/'; | ||||||||||
|
Condition50%1/2
shift @_ // "/"
MC/DC0%0/1
shift @_ // "/"
shift @_
Truth table50%1/2
A
A= shift @_
| |||||||||||||
| 120 | 1 | my $config_file_path = "$root_path/etc/spoor/spoor.yml"; | |||||||||||
| 121 | 1 | my $file_contents = path($config_file_path)->slurp_utf8; | |||||||||||
| 122 | |||||||||||||
| 123 | 1 | Load($file_contents)->{'transmission'}; | |||||||||||
| 124 | } | ||||||||||||
| 125 | |||||||||||||
| 126 | =head1 AUTHOR | ||||||||||||
| 127 | |||||||||||||
| 128 | Rory McKinley, C<< <rorymckinley at capefox.co> >> | ||||||||||||
| 129 | |||||||||||||
| 130 | =head1 BUGS | ||||||||||||
| 131 | |||||||||||||
| 132 | Please report any bugs or feature requests to C<bug-. at rt.cpan.org>, or through | ||||||||||||
| 133 | the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=.>. I will be notified, and then you'll | ||||||||||||
| 134 | automatically be notified of progress on your bug as I make changes. | ||||||||||||
| 135 | |||||||||||||
| 136 | =head1 SUPPORT | ||||||||||||
| 137 | |||||||||||||
| 138 | You can find documentation for this module with the perldoc command. | ||||||||||||
| 139 | |||||||||||||
| 140 | perldoc App::Spoor::Config | ||||||||||||
| 141 | |||||||||||||
| 142 | |||||||||||||
| 143 | You can also look for information at: | ||||||||||||
| 144 | |||||||||||||
| 145 | =over 4 | ||||||||||||
| 146 | |||||||||||||
| 147 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||
| 148 | |||||||||||||
| 149 | L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=.> | ||||||||||||
| 150 | |||||||||||||
| 151 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||
| 152 | |||||||||||||
| 153 | L<http://annocpan.org/dist/.> | ||||||||||||
| 154 | |||||||||||||
| 155 | =item * CPAN Ratings | ||||||||||||
| 156 | |||||||||||||
| 157 | L<https://cpanratings.perl.org/d/.> | ||||||||||||
| 158 | |||||||||||||
| 159 | =item * Search CPAN | ||||||||||||
| 160 | |||||||||||||
| 161 | L<https://metacpan.org/release/.> | ||||||||||||
| 162 | |||||||||||||
| 163 | =back | ||||||||||||
| 164 | |||||||||||||
| 165 | =head1 LICENSE AND COPYRIGHT | ||||||||||||
| 166 | |||||||||||||
| 167 | Copyright 2019 Rory McKinley. | ||||||||||||
| 168 | |||||||||||||
| 169 | This program is free software; you can redistribute it and/or modify it | ||||||||||||
| 170 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||||
| 171 | copy of the full license at: | ||||||||||||
| 172 | |||||||||||||
| 173 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||
| 174 | |||||||||||||
| 175 | Any use, modification, and distribution of the Standard or Modified | ||||||||||||
| 176 | Versions is governed by this Artistic License. By using, modifying or | ||||||||||||
| 177 | distributing the Package, you accept this license. Do not use, modify, | ||||||||||||
| 178 | or distribute the Package, if you do not accept this license. | ||||||||||||
| 179 | |||||||||||||
| 180 | If your Modified Version has been derived from a Modified Version made | ||||||||||||
| 181 | by someone other than you, you are nevertheless required to ensure that | ||||||||||||
| 182 | your Modified Version complies with the requirements of this license. | ||||||||||||
| 183 | |||||||||||||
| 184 | This license does not grant you the right to use any trademark, service | ||||||||||||
| 185 | mark, tradename, or logo of the Copyright Holder. | ||||||||||||
| 186 | |||||||||||||
| 187 | This license includes the non-exclusive, worldwide, free-of-charge | ||||||||||||
| 188 | patent license to make, have made, use, offer to sell, sell, import and | ||||||||||||
| 189 | otherwise transfer the Package with respect to any patent claims | ||||||||||||
| 190 | licensable by the Copyright Holder that are necessarily infringed by the | ||||||||||||
| 191 | Package. If you institute patent litigation (including a cross-claim or | ||||||||||||
| 192 | counterclaim) against any party alleging that the Package constitutes | ||||||||||||
| 193 | direct or contributory patent infringement, then this Artistic License | ||||||||||||
| 194 | to you shall terminate on the date that such litigation is filed. | ||||||||||||
| 195 | |||||||||||||
| 196 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||||||||||||
| 197 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||||||||||||
| 198 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||||||||||||
| 199 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||||||||||||
| 200 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||||||||||||
| 201 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||||||||||||
| 202 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||||||||||||
| 203 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||||
| 204 | |||||||||||||
| 205 | |||||||||||||
| 206 | =cut | ||||||||||||
| 207 | |||||||||||||
| 208 | 2 | 1; # End of App::Spoor::Config | |||||||||||