Allow Hydra to run as a private instance by requiring a login.
Use the following in your hydra.conf to make your instance a private Hydra instance (public is the default): private 1 Currently, this will not allow you to use the API, channels and the binary cache when running in private mode. We will add solutions for these functionalities later.
This commit is contained in:
@ -13,9 +13,18 @@ use Encode;
|
||||
# Put this controller at top-level.
|
||||
__PACKAGE__->config->{namespace} = '';
|
||||
|
||||
sub noLoginNeeded {
|
||||
my ($c) = @_;
|
||||
|
||||
return $c->request->path eq "persona-login" ||
|
||||
$c->request->path eq "login" ||
|
||||
$c->request->path eq "logo" ||
|
||||
$c->request->path =~ /^static\//;
|
||||
}
|
||||
|
||||
sub begin :Private {
|
||||
my ($self, $c, @args) = @_;
|
||||
|
||||
$c->stash->{curUri} = $c->request->uri;
|
||||
$c->stash->{version} = $ENV{"HYDRA_RELEASE"} || "<devel>";
|
||||
$c->stash->{nixVersion} = $ENV{"NIX_RELEASE"} || "<devel>";
|
||||
@ -26,6 +35,12 @@ sub begin :Private {
|
||||
$c->stash->{successMsg} = $c->flash->{successMsg};
|
||||
$c->stash->{personaEnabled} = $c->config->{enable_persona} // "0" eq "1";
|
||||
|
||||
$c->stash->{isPrivateHydra} = $c->config->{private} // "0" ne "0";
|
||||
|
||||
if ($c->stash->{isPrivateHydra} && ! noLoginNeeded($c)) {
|
||||
requireUser($c);
|
||||
}
|
||||
|
||||
if (scalar(@args) == 0 || $args[0] ne "static") {
|
||||
$c->stash->{nrRunningBuilds} = $c->model('DB::Builds')->search({ finished => 0, busy => 1 }, {})->count();
|
||||
$c->stash->{nrQueuedBuilds} = $c->model('DB::Builds')->search({ finished => 0 })->count();
|
||||
|
Reference in New Issue
Block a user