Skip to content

Commit 5f127f2

Browse files
committed
Get elasticsearch servers from config
1 parent 4c81a88 commit 5f127f2

File tree

7 files changed

+26
-11
lines changed

7 files changed

+26
-11
lines changed

lib/Catalyst/Plugin/Session/Store/ElasticSearch.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ use Moose;
66
extends 'Catalyst::Plugin::Session::Store';
77
use MooseX::Types::ElasticSearch qw(:all);
88

9+
use MetaCPAN::Config ();
10+
911
has _session_es => (
1012
required => 1,
1113
is => 'ro',
1214
coerce => 1,
1315
isa => ES,
14-
default => sub { shift->_session_plugin_config->{servers} || ':9200' }
16+
default => sub { MetaCPAN::Config::config()->{elasticsearch_servers} },
1517
);
1618
has _session_es_index => (
1719
required => 1,

lib/MetaCPAN/Script/Snapshot.pm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use DateTime::Format::ISO8601 ();
99
use DDP;
1010
use HTTP::Tiny ();
1111
use Log::Contextual qw( :log );
12+
use MetaCPAN::Config ();
1213
use MetaCPAN::Types::TypeTiny qw( ArrayRef Bool Str );
1314
use Moose;
1415
use Sys::Hostname qw( hostname );
@@ -80,9 +81,9 @@ has snap_name => (
8081
);
8182

8283
has host => (
83-
is => 'ro',
84-
isa => Str,
85-
default => 'http://localhost:9200',
84+
is => 'ro',
85+
isa => Str,
86+
default => sub { MetaCPAN::Config::config()->{elasticsearch_servers} },
8687
documentation => 'ES host, defaults to: http://localhost:9200',
8788
);
8889

lib/MetaCPAN/Server/Model/CPAN.pm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package MetaCPAN::Server::Model::CPAN;
22

3-
use strict;
4-
use warnings;
5-
6-
use MetaCPAN::Model ();
73
use Moose;
84

5+
use MetaCPAN::Config ();
6+
use MetaCPAN::Model ();
7+
98
extends 'Catalyst::Model';
109

1110
has esx_model => (
@@ -22,7 +21,9 @@ has index => (
2221

2322
has servers => (
2423
is => 'ro',
25-
default => ':9200',
24+
default => sub {
25+
return MetaCPAN::Config::config()->{elasticsearch_servers};
26+
},
2627
);
2728

2829
sub _build_esx_model {

metacpan_server.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
git /usr/bin/git
22

3+
elasticsearch_servers = :9200
34
minion_dsn = postgresql:///minion_queue
45

56
<controller User::Turing>

metacpan_server_testing.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
cpan var/t/tmp/fakecpan
22
source_base var/t/tmp/source
33

4+
elasticsearch_servers = http://elasticsearch_test:9200
5+
46
<model CPAN>
57
servers __ENV(ES)__
68
</model CPAN>

t/lib/MetaCPAN/Server/Test.pm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use strict;
44
use warnings;
55

66
use HTTP::Request::Common qw(POST GET DELETE);
7+
use MetaCPAN::Config ();
78
use MetaCPAN::Server ();
89
use Plack::Test;
910
use Test::More;
@@ -40,7 +41,12 @@ sub app {
4041
require MetaCPAN::Model;
4142

4243
sub model {
43-
MetaCPAN::Model->new( es => ( $ENV{ES_TEST} ||= 'localhost:9200' ) );
44+
MetaCPAN::Model->new(
45+
es => (
46+
$ENV{ES_TEST}
47+
||= MetaCPAN::Config::config()->{elasticsearch_servers}
48+
)
49+
);
4450
}
4551

4652
1;

t/lib/MetaCPAN/TestServer.pm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package MetaCPAN::TestServer;
22

33
use MetaCPAN::Moose;
44

5+
use MetaCPAN::Config ();
56
use MetaCPAN::DarkPAN ();
67
use MetaCPAN::Script::Author ();
78
use MetaCPAN::Script::Cover ();
@@ -82,7 +83,8 @@ sub _build_config {
8283
sub _build_es_home {
8384
my $self = shift;
8485

85-
my $es_home = $ENV{ES_TEST};
86+
my $es_home = $ENV{ES_TEST}
87+
|| MetaCPAN::Config::config()->{elasticsearch_servers};
8688

8789
if ( !$es_home ) {
8890
my $es_home = $ENV{ES_HOME} or die <<'USAGE';

0 commit comments

Comments
 (0)