File Coverage

blib/lib/Mojo/Darkpan.pm
Criterion Covered Total %
statement 14 27 51.8
branch n/a
condition n/a
subroutine 5 6 83.3
pod 1 1 100.0
total 20 34 58.8


line stmt bran cond sub pod time code
1             package Mojo::Darkpan;
2 1     1   997 use v5.20;
  1         4  
3 1     1   650 use Data::Dumper;
  1         7863  
  1         93  
4 1     1   658 use FindBin;
  1         1221  
  1         61  
5 1     1   1191 use Mojo::Base 'Mojolicious', -signatures;
  1         235780  
  1         13  
6 1     1   454466 use Mojo::Darkpan::Config;
  1         4  
  1         283  
7              
8 0     0 1   sub startup($self) {
  0            
  0            
9             # https://metacpan.org/pod/Mojolicious::Plugin::BasicAuthPlus
10 0           $self->plugin('basic_auth_plus');
11 0           $self->plugin('DirectoryHandler',
12             delivery_path => Mojo::Darkpan::Config->new->path);
13              
14             #----------
15             # Router
16             #----------
17 0           my $r = $self->routes;
18 0           my $index = $r->any('/');
19 0           $index->get('/list')->to(controller => 'index', action => 'list');
20 0           $index->get('/reindex')->to(controller => 'index', action => 'reindex');
21              
22 0           my $uploader = $r->any('/publish');
23 0           $uploader->post('/')->to(controller => 'publish', action => 'upload');
24              
25             # goes to the same place as publish, used for compatibility
26 0           my $authenquery = $r->any('/authenquery');
27 0           $authenquery->post('/')->to(controller => 'publish', action => 'upload');
28              
29             }
30              
31             our $VERSION = "0.06";
32              
33             1;
34             __END__
35              
36             =encoding utf-8
37              
38             =head1 NAME
39              
40             Mojo::Darkpan - A Mojolicious web service frontend leveraging OrePAN2
41              
42             =head1 DESCRIPTION
43              
44             Mojo::Darkpan is a webservice build on Mojolicious to frontend L<OrePAN2|https://metacpan.org/pod/OrePAN2>. This module was inspired
45             by L<OrePAN2::Server|https://metacpan.org/pod/OrePAN2::Server'> but built on
46             Mojolicious to take advantage of it's robust framework of tools. A good bit of the documentation
47             was also taken from OrePAN2::Server as the functionality is similar if not identical.
48              
49             =head1 SYNOPSIS
50              
51             =head2 Running the server
52              
53             # start a server with default configurations on port 8080
54             darkpan --port 8080
55            
56             # start a server with AD backed basic auth
57             # config.json
58             {
59             "basic_auth": {
60             "Realm Name": {
61             "host": "ldaps://my.ldap.server.org",
62             "port": 636,
63             "basedn": "DC=my,DC=compoany,DC=org",
64             "binddn": "bind_name",
65             "bindpw": "bond_pw",
66             "filter": "(&(objectCategory=*)(sAMAccountName=%s)(|(objectClass=user)(objectClass=group)))"
67             }
68             }
69             }
70            
71             darkpan --config ./config.json
72              
73             =head4 Options:
74              
75             =over 2
76              
77             =item B<-c,--config> I<default: undef>:
78             JSON configuration file location
79              
80             =item B<-p,--port> I<default: 3000>:
81             Web application port
82              
83             =back
84              
85             =head4 Paths:
86              
87             =over 2
88              
89             =item B</publish> or B</authenquery>:
90             POST path(s) for releasing packages, set as the upload_uri in your .pause file
91              
92             =item B</list>:
93             JSON list of packages and info about them
94            
95             =item B</reindex>:
96             Force OrePAN2 to do a index all modules and recreate the 02packages.details file.
97            
98             =item B</darkpan> I<(may differ if you set a custom path)>:
99             Directory listing of the repository. This is the path to reference as your mirror or
100             set the PERL_CARTON_MIRROR env var
101              
102             =back
103              
104             =head2 Configuring the server
105              
106             Configurations can be done using environment variables or by creating a json config file.
107              
108             =head3 environment variables
109              
110             Environment variables are at a higher order than values set in the json configuration
111             file and will take precedence if set. The B<DARKPAN_CONFIG_FILE> env variable can be
112             set instead of using the command line option to denote the path of the config file.
113              
114             =over 2
115              
116             =item B<DARKPAN_CONFIG_FILE>:
117             Location of a json configuration file, same as passing the --config option
118              
119             =item B<DARKPAN_DIRECTORY>:
120             Directory where uploads will be stored.
121              
122             =item B<DARKPAN_PATH>:
123             URL path to function as cpan repository resolver/mirror endpoint.
124            
125             =item B<DARKPAN_COMPRESS_INDEX>:
126             Setting whether to compress (gzip) the 02packages.details.txt file.
127              
128             =item B<DARKPAN_AUTH_REALM>:
129             Basic auth realm name. This variable needs to be set to enable parsing of additional
130             auth settings using the following the format DARKPAN_AUTH_[setting].
131            
132             =item B<DARKPAN_AUTH_[setting]>:
133             Additional basic auth settings can be passed using this format. The settings
134             will be parsed and applied to your basic auth configurations. See
135             L<Mojolicious::Plugin::BasicAuthPlus|https://metacpan.org/pod/Mojolicious::Plugin::BasicAuthPlus>
136             for additional details on configurations.
137              
138             =back
139              
140             =head3 config.json
141              
142             The config.json file contains customizations for the darkpan web application. It can be
143             referenced by absolute path or relative to where the application is run from.
144              
145             {
146             "directory": "darkpan",
147             "compress_index": true,
148             "path": "darkpan,
149             "basic_auth": {
150             "Realm Name": {
151             "host": "ldaps://my.ldap.server.org",
152             "port": 636,
153             "basedn": "DC=my,DC=compoany,DC=org",
154             "binddn": "bind_name",
155             "bindpw": "bond_pw",
156             "filter": "(&(objectCategory=*)(sAMAccountName=%s)(|(objectClass=user)(objectClass=group)))"
157             }
158             }
159             }
160              
161             =head4 config.json options
162              
163             =over 2
164              
165             =item B<directory> I<default: darkpan>:
166             Directory where uploads will be stored.
167              
168             =item B<path> I<default: darkpan>:
169             URL path to function as cpan repository resolver/mirror endpoint.
170              
171             =item B<compress_index> I<default: true>:
172             Setting whether to compress (gzip) the 02packages.details.txt file.
173              
174             =item B<basic_auth> I<default: undef>:
175             Basic authentication settings, see configurations for L<Mojolicious::Plugin::BasicAuthPlus|https://metacpan.org/pod/Mojolicious::Plugin::BasicAuthPlus>. When not provided
176             no authentication is necessary to post modules to the service.
177              
178             =back
179              
180             =head3 Authentication
181              
182             Authentication is handled by L<Mojolicious::Plugin::BasicAuthPlus|https://metacpan.org/pod/Mojolicious::Plugin::BasicAuthPlus>.
183             To configure basic auth, see the configuration options for L<Mojolicious::Plugin::BasicAuthPlus|https://metacpan.org/pod/Mojolicious::Plugin::BasicAuthPlus>
184             and add your settings to the basic auth section of the config.json file.
185              
186             =head2 How to Deploy
187              
188             =head3 Deploying with POST
189              
190             Publishing to darkpan can be done using a post request and a URL to git or bitbucket repo.
191            
192             #upload git managed module to my darkpan by curl
193             curl --data-urlencode 'module=git+ssh://git@mygit/home/git/repos/MyModule.git' --data-urlencode 'author=reshingleton' http://localhost:3000/publish
194             curl --data-urlencode 'module=git+file:///home/rshingleton/project/MyModule.git' --data-urlencode 'author=reshingleton' http://localhost:3000/publish
195             curl --data-urlencode 'module=git@github.com:rshingleton/perl-module-test.git' --data-urlencode 'author=reshingleton' http://localhost:3000/publish
196              
197             The module parameter can also be an HTTP url. see L<OrePAN2::Injector|https://metacpan.org/pod/OrePAN2::Injector> for
198             additional details.
199              
200             curl --data-urlencode 'module=https://cpan.metacpan.org/authors/id/O/OA/OALDERS/OrePAN2-0.48.tar.gz' --data-urlencode 'author=OALDERS' http://localhost:3000/publish
201            
202             =head3 Deploying with L<Minilla|https://metacpan.org/pod/Minilla>
203              
204             Minilla is a cpan authoring tool, see L<Minilla|https://metacpan.org/pod/Minilla> for more details.
205              
206             =head4 minil.toml
207              
208             Add a reference to a pause configruation file in your minil.toml that points to your darkpan instance.
209             The configuration can reference a relative path as follows:
210            
211             [release]
212             pause_config=".pause"
213              
214             =head4 .pause file
215              
216             The .pause file is a configuration file for uploading modules to CPAN or your own Darkpan Repository.
217             See L<CPAN::Uploader|https://metacpan.org/pod/CPAN::Uploader> for more detail.
218              
219             upload_uri http://my-darkpan.server/publish
220             user myUsername
221             password myPassword
222            
223             I<** if you don't set the upload_uri, you will upload to CPAN>
224              
225             If basic auth is enabled, the username and password set in the .pause file will be
226             used as basic auth credentials.
227              
228             =head2 How to install from your Darkpan
229              
230             =head3 cpanm
231              
232             See L<cpanm|https://metacpan.org/pod/cpanm> for additional details.
233              
234             # check CPAN and your Darkpan server
235             cpanm --mirror http://my-darkpan.server/darkpan
236            
237             # check for packages from only your Darkpan server
238             cpanm --mirror-only http://my-darkpan.server/darkpan
239             cpanm --from http://my-darkpan.server/darkpan
240              
241             =head3 cpm
242              
243             See L<cpm|https://metacpan.org/dist/App-cpm/view/script/cpm> for additional details.
244              
245             # resolve distribution names from DARKPAN/modules/02packages.details.txt.gz
246             # and fetch distibutions from DARKPAN/authors/id/...
247             > cpm install --resolver 02packages,http://example.com/darkpan Your::Module
248            
249             # use darkpan first, and if it fails, use metadb and normal CPAN
250             > cpm install --resolver 02packages,http://my-darkpan.server/darkpan --resolver metadb Your::Module
251              
252             =head3 carton
253              
254             See L<carton|https://metacpan.org/pod/Carton> for additional details.
255            
256             # in the cpanfile
257             # local mirror (darkpan)
258            
259             requires 'Plack', '== 0.9981',
260             dist => 'MYCOMPANY/Plack-0.9981-p1.tar.gz',
261             mirror => 'http://my-darkpan.server/darkpan';
262              
263             Carton also uses an (L<undocumented|https://domm.plix.at/perl/2017_07_carton_darkpan.html>) environment variable PERL_CARTON_MIRROR that will enable you
264             to add your Darkpan server to its list of resolvers. Carton will install from
265             your Darkpan and from the default CPAN mirror.
266              
267             PERL_CARTON_MIRROR=http://my-darkpan.server/darkpan carton install
268              
269             =head1 SEE ALSO
270              
271             L<OrePAN2|https://metacpan.org/pod/OrePAN2>
272              
273             L<OrePAN2::Server|https://metacpan.org/pod/OrePAN2::Server>
274              
275            
276             =head1 LICENSE
277              
278             Copyright (C) rshingleton.
279              
280             This library is free software; you can redistribute it and/or modify
281             it under the same terms as Perl itself.
282              
283             =head1 AUTHOR
284              
285             rshingleton E<lt>reshingleton@gmail.comE<gt>
286              
287             =cut
288