Skip to content

Commit

Permalink
Merge pull request #1755 from metacpan/leo/fastly_datacenters
Browse files Browse the repository at this point in the history
Add datacenters end point to sort out mirrors.cpan.org
  • Loading branch information
oalders committed Jul 27, 2016
2 parents 83a3c30 + ae6573d commit e8254d8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
9 changes: 6 additions & 3 deletions .perlcriticrc
Expand Up @@ -16,9 +16,6 @@ theme = core
[CodeLayout::RequireTrailingCommas]
severity = 4

[TestingAndDebugging::RequireUseStrict]
equivalent_modules = Test::Routine

[ValuesAndExpressions::ProhibitEmptyQuotes]
severity = 4

Expand All @@ -29,3 +26,9 @@ severity = 4

[ValuesAndExpressions::ProhibitNoisyQuotes]
severity = 4

[TestingAndDebugging::RequireUseStrict]
equivalent_modules = MetaCPAN::Moose Moose

[TestingAndDebugging::RequireUseWarnings]
equivalent_modules = MetaCPAN::Moose Moose
27 changes: 27 additions & 0 deletions lib/MetaCPAN/Web/Controller/SysAdmin/DataCenters.pm
@@ -0,0 +1,27 @@
package MetaCPAN::Web::Controller::SysAdmin::DataCenters;

use MetaCPAN::Moose;

BEGIN { extends 'MetaCPAN::Web::Controller' }

# This is used by http://mirrors.cpan.org/ fetch our
# datacenters and update the official CPAN list

sub list_datacenters : Path('list') : Args(0) GET {
my ( $self, $c ) = @_;

# Fetch the data center info from fastly
# XXX: will not work unless you have the credentials
my $datacenters = $c->datacenters;

$c->add_surrogate_key('datacenters');
$c->cdn_cache_ttl( $c->cdn_times->{one_day} );
$c->res->header(
'Cache-Control' => 'max-age=' . $c->cdn_times->{one_day} );
$c->stash( { success => $datacenters } );
$c->detach( $c->view('JSON') );
}

__PACKAGE__->meta->make_immutable;

1;
11 changes: 11 additions & 0 deletions lib/MetaCPAN/Web/Role/Fastly.pm
Expand Up @@ -86,6 +86,17 @@ has 'cdn_times' => (
lazy_build => 1,
);

sub datacenters {
my ($c) = @_;
my $net_fastly = $c->_net_fastly();
return unless $net_fastly;

# Uses the private interface as fastly client doesn't
# have this end point yet
my $datacenters = $net_fastly->client->_get('/datacenters');
return $datacenters;
}

sub _build_cdn_times {
return {
one_hour => 3600,
Expand Down

0 comments on commit e8254d8

Please sign in to comment.