~ubuntu-branches/ubuntu/utopic/gitolite3/utopic-proposed

« back to all changes in this revision

Viewing changes to src/commands/access

  • Committer: Package Import Robot
  • Author(s): David Bremner
  • Date: 2013-05-18 17:59:21 UTC
  • Revision ID: package-import@ubuntu.com-20130518175921-ac4xe6vd0jtxvjot
Tags: upstream-3.5.1+4
ImportĀ upstreamĀ versionĀ 3.5.1+4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
use strict;
 
3
use warnings;
 
4
 
 
5
use lib $ENV{GL_LIBDIR};
 
6
use Gitolite::Rc;
 
7
use Gitolite::Common;
 
8
use Gitolite::Conf::Load;
 
9
 
 
10
=for usage
 
11
Usage:  gitolite access [-q] <repo> <user> <perm> <ref>
 
12
 
 
13
Print access rights for arguments given.  The string printed has the word
 
14
DENIED in it if access was denied.  With '-q', returns only an exit code
 
15
(shell truth, not perl truth -- 0 is success).
 
16
 
 
17
  - repo: mandatory
 
18
  - user: mandatory
 
19
  - perm: defauts to '+'.  Valid values: R, W, +, C, D, M
 
20
  - ref:  defauts to 'any'.  See notes below
 
21
 
 
22
Notes:
 
23
  - ref: Any fully qualified ref ('refs/heads/master', not 'master') is fine.
 
24
    The 'any' ref is special -- it ignores deny rules (see docs for what this
 
25
    means and exceptions).
 
26
 
 
27
Batch mode: see src/triggers/post-compile/update-git-daemon-access-list for a
 
28
good example that shows how to test several repos in one invocation.  This is
 
29
orders of magnitude faster than running the command multiple times; you'll
 
30
notice if you have more than a hundred or so repos.
 
31
=cut
 
32
 
 
33
usage() if not @ARGV or $ARGV[0] eq '-h';
 
34
my $quiet = 0;
 
35
if ( $ARGV[0] eq '-q' ) { $quiet = 1; shift @ARGV; }
 
36
 
 
37
my ( $repo, $user, $aa, $ref ) = @ARGV;
 
38
$aa  ||= '+';
 
39
$ref ||= 'any';
 
40
_die "invalid perm" if not( $aa and $aa =~ /^(R|W|\+|C|D|M|\^C)$/ );
 
41
_die "invalid ref name" if not( $ref and $ref =~ $REPONAME_PATT );
 
42
 
 
43
my $ret = '';
 
44
 
 
45
if ( $repo ne '%' and $user ne '%' ) {
 
46
    # single repo, single user; no STDIN
 
47
    $ret = access( $repo, $user, $aa, $ref );
 
48
 
 
49
    if ( $ret =~ /DENIED/ ) {
 
50
        print "$ret\n" unless $quiet;
 
51
        exit 1;
 
52
    }
 
53
 
 
54
    print "$ret\n" unless $quiet;
 
55
    exit 0;
 
56
}
 
57
 
 
58
$repo = '' if $repo eq '%';
 
59
$user = '' if $user eq '%';
 
60
 
 
61
_die "'-q' doesn't go with using a pipe" if $quiet;
 
62
@ARGV = ();
 
63
while (<>) {
 
64
    my @in = split;
 
65
    my $r  = $repo || shift @in;
 
66
    my $u  = $user || shift @in;
 
67
    $ret = access( $r, $u, $aa, $ref );
 
68
    print "$r\t$u\t$ret\n";
 
69
}