From bd7b6fc4011825c2e54fb2e7691fd87dc5f91969 Mon Sep 17 00:00:00 2001 From: Rob Vermaas Date: Fri, 10 Jan 2014 11:04:28 +0100 Subject: [PATCH] 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. --- src/lib/Hydra/Controller/Root.pm | 15 +++++++++++++++ src/root/topbar.tt | 12 ++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index e60420b0..eeb46452 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -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"} || ""; $c->stash->{nixVersion} = $ENV{"NIX_RELEASE"} || ""; @@ -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(); diff --git a/src/root/topbar.tt b/src/root/topbar.tt index 82af9088..09c0b8b1 100644 --- a/src/root/topbar.tt +++ b/src/root/topbar.tt @@ -6,7 +6,9 @@ [% END %] +[% showPrivate = (isPrivateHydra && c.user_exists) || ! isPrivateHydra %] +[% IF showPrivate %] +[% END %]