diff options
-rw-r--r-- | usr/src/libpiny/debian/changelog | 6 | ||||
-rw-r--r-- | usr/src/libpiny/lib/Piny/Repo.pm | 22 | ||||
-rw-r--r-- | usr/src/libpiny/lib/Piny/User.pm | 26 | ||||
-rwxr-xr-x | usr/src/pinyadmin/bin/lsaccess | 30 | ||||
-rwxr-xr-x | usr/src/pinyadmin/bin/lsrepo | 12 | ||||
-rw-r--r-- | usr/src/pinyadmin/debian/changelog | 6 | ||||
-rw-r--r-- | usr/src/pinyadmin/debian/control | 2 |
7 files changed, 103 insertions, 1 deletions
diff --git a/usr/src/libpiny/debian/changelog b/usr/src/libpiny/debian/changelog index 891d7f4..79952b6 100644 --- a/usr/src/libpiny/debian/changelog +++ b/usr/src/libpiny/debian/changelog @@ -1,3 +1,9 @@ +libpiny-perl (0.5) unstable; urgency=low + + * Allow listing repos and querying access rights. + + -- Julian Blake Kongslie <jblake@omgwallhack.org> Tue, 29 Jun 2010 22:28:59 -0700 + libpiny-perl (0.4) unstable; urgency=low * Switch to native packaging. diff --git a/usr/src/libpiny/lib/Piny/Repo.pm b/usr/src/libpiny/lib/Piny/Repo.pm index 6dcabca..26d936a 100644 --- a/usr/src/libpiny/lib/Piny/Repo.pm +++ b/usr/src/libpiny/lib/Piny/Repo.pm @@ -99,6 +99,12 @@ sub remove_access { $s->group( )->remove_member( @users ); }; +sub has_access { + my ( $s, $user ) = @_; + + return $s->owner( )->uid( ) == $user->uid( ) or $user->has_group( $s->group( ) ); +}; + # Triggers sub _rename_repo { @@ -132,6 +138,22 @@ sub _change_owner { find( { wanted => sub { chown( $new_owner->uid( ), -1, $_ ) or die "Couldn't chown $_: $!"; }, no_chdir => 1 }, $s->path( ) ); }; +# Class methods + +sub all_repos { + my ( $class, $dir ) = @_; + + $dir = "/srv/git" unless defined $dir; + + my @ret; + + find( { wanted => sub { print "$_\n"; if ( /^[^.].*\.git$/ ) { $File::Find::prune = 1; push( @ret, $File::Find::name ); }; } }, $dir ); + + @ret = map { print "$_ "; s/^\Q$dir\E\/?//; s/\.git$//; print "$_\n"; $class->new( name => $_ ); } @ret; + + return @ret; +}; + # Builder methods # If constructed with just one argument, then treat it as a repo name. diff --git a/usr/src/libpiny/lib/Piny/User.pm b/usr/src/libpiny/lib/Piny/User.pm index e0687a3..f9a5f0d 100644 --- a/usr/src/libpiny/lib/Piny/User.pm +++ b/usr/src/libpiny/lib/Piny/User.pm @@ -77,6 +77,32 @@ sub remove_group { }; }; +sub has_group { + my ( $s, $group ) = @_; + + foreach my $owngroup ( $s->groups( ) ) { + return if $owngroup->gid( ) == $group->gid( ); + }; + + return; +}; + +# Class methods + +sub all_users { + my ( $class ) = @_; + + endpwent( ); + + my @ret; + + while ( my @info = getpwent( ) ) { + push( @ret, $class->new( uid => $info[2] ) ); + }; + + return @ret; +}; + # Builder methods # If constructed with just one argument, then diff --git a/usr/src/pinyadmin/bin/lsaccess b/usr/src/pinyadmin/bin/lsaccess new file mode 100755 index 0000000..eb7b6bc --- /dev/null +++ b/usr/src/pinyadmin/bin/lsaccess @@ -0,0 +1,30 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Piny; + +my $env = Piny::Environment->new( ); + +my ( $reponame ) = @ARGV; + +if ( defined $reponame ) { + + my $repo = Piny::Repo->new( $repo ); + + foreach my $user ( Piny::User->all_users( ) ) { + if ( $repo->has_access( $user ) ) { + print $user->name . "\n"; + }; + }; + +} else { + + foreach my $repo ( Piny::Repo->all_repos( ) ) { + if ( $repo->has_access( $env->user ) ) { + print $repo->name . "\n"; + }; + }; + +}; diff --git a/usr/src/pinyadmin/bin/lsrepo b/usr/src/pinyadmin/bin/lsrepo new file mode 100755 index 0000000..1587654 --- /dev/null +++ b/usr/src/pinyadmin/bin/lsrepo @@ -0,0 +1,12 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Piny; + +my $env = Piny::Environment->new( ); + +foreach my $repo ( Piny::Repo->all_repos( ) ) { + print $repo->name . "\n"; +}; diff --git a/usr/src/pinyadmin/debian/changelog b/usr/src/pinyadmin/debian/changelog index 98f4e2c..4f0a8eb 100644 --- a/usr/src/pinyadmin/debian/changelog +++ b/usr/src/pinyadmin/debian/changelog @@ -1,3 +1,9 @@ +pinyadmin (0.5) unstable; urgency=low + + * Listing repos and repo access rights. + + -- Julian Blake Kongslie <jblake@omgwallhack.org> Tue, 29 Jun 2010 22:32:30 -0700 + pinyadmin (0.4) unstable; urgency=low * Minor typo in manpage. diff --git a/usr/src/pinyadmin/debian/control b/usr/src/pinyadmin/debian/control index b6c3c9e..25df07d 100644 --- a/usr/src/pinyadmin/debian/control +++ b/usr/src/pinyadmin/debian/control @@ -7,7 +7,7 @@ Standards-version: 3.8.4 Package: pinyadmin Architecture: all -Depends: ${perl:Depends}, ${misc:Depends}, libpiny-perl +Depends: ${perl:Depends}, ${misc:Depends}, libpiny-perl (>= 0.5) Description: Administrative programs for piny The command-line programs for day-to-day administrative tasks in the Piny infrastructure. |