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