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:
Rob Vermaas 2014-01-10 11:04:28 +01:00
parent 3e1a98668f
commit bd7b6fc401
2 changed files with 23 additions and 4 deletions

View file

@ -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();

View file

@ -6,7 +6,9 @@
</ul>
</li>
[% END %]
[% showPrivate = (isPrivateHydra && c.user_exists) || ! isPrivateHydra %]
[% IF showPrivate %]
<ul class="nav pull-left">
[% IF c.user_exists %]
@ -110,13 +112,15 @@
[% END %]
</ul>
[% END %]
<ul class="nav pull-right">
[% IF showPrivate %]
<form class="navbar-search" action="[% c.uri_for('/search') %]">
<input name="query" type="text" class="search-query span2" placeholder="Search" [% HTML.attributes(value => c.req.params.query) %]/>
</form>
[% END %]
[% IF c.user_exists %]
[% INCLUDE menuItem uri = c.uri_for(c.controller('User').action_for('edit'), [c.user.username]) title = "Preferences" %]
<li>