aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Ruppert <idl0r@gentoo.org>2012-02-17 23:33:48 +0100
committerChristian Ruppert <idl0r@gentoo.org>2012-02-18 18:33:55 +0100
commit52ab8376f43676e40d87ad8481194bd99b5329ec (patch)
treeae23424ca20ebf170c2602c7e2e78b03a1574520
parentParse and export metadata (diff)
downloadgitolite-gentoo-52ab8376f43676e40d87ad8481194bd99b5329ec.tar.gz
gitolite-gentoo-52ab8376f43676e40d87ad8481194bd99b5329ec.tar.bz2
gitolite-gentoo-52ab8376f43676e40d87ad8481194bd99b5329ec.zip
Add export_key_metadata() function
-rw-r--r--src/gitolite.pm68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/gitolite.pm b/src/gitolite.pm
index 1b9a1ce..ca66107 100644
--- a/src/gitolite.pm
+++ b/src/gitolite.pm
@@ -36,6 +36,7 @@ use Exporter 'import';
mirror_redirectOK
get_repo_umask
+ export_key_metadata
);
@EXPORT_OK = qw(
%repos
@@ -1345,6 +1346,73 @@ sub get_repo_umask {
return $repos{$repo}{"umask"} ? $repos{$repo}{"umask"} : $REPO_UMASK;
}
+# Find pubkeys recursive
+sub find_pubkeys {
+ my $dir = shift;
+ my $name = shift;
+ my @files = ();
+ my @tmp = ();
+
+ opendir(my $dir_fh, $dir) or do { print STDERR "Error opendir(): $! '$dir'\n"; return @files; };
+ foreach my $entry (readdir($dir_fh)) {
+ next if $entry =~ /^\.\.?$/; # Skip . and .. entries.
+ $entry = join("/", $dir, $entry);
+
+ if(-f $entry and $entry =~ /\.pub$/) {
+ if(defined($name) && length($name) > 0) {
+ my $cmp = $entry;
+ $cmp =~ s(.*/)();
+ $cmp =~ s/\.pub$//;
+ if($cmp eq $name) {
+ push(@files, $entry);
+ next;
+ }
+ }
+ else {
+ push(@files, $entry);
+ next;
+ }
+ }
+ if(-d $entry) {
+ @tmp = find_pubkeys($entry, $name);
+ @files = (@files, @tmp);
+ next;
+ }
+ }
+
+ closedir($dir_fh);
+
+ return sort(@files);
+}
+
+sub export_key_metadata {
+ my $user = shift;
+
+ my @tmp = find_pubkeys($GL_KEYDIR, $user);
+ return if $#tmp ne 0; # one pubkey only!
+
+ my $pubkey = $tmp[0];
+
+ return if ! -f $pubkey;
+
+ open(PUBKEY, '<', $pubkey);
+ while(defined(my $line = <PUBKEY>)) {
+ chomp($line);
+ next if $line !~ m/^\s*#/;
+ $line =~ s/^\s*#\s*//;
+
+ my ($variable, $value) = split(/:\s*/, $line, 2);
+
+ if(grep(/^\Q${variable}\E$/, @GL_METADATA)) {
+ if(length($value) > 0) {
+ $variable =~ s/-/_/g;
+ $ENV{$variable} = $value;
+ }
+ }
+ }
+ close(PUBKEY);
+}
+
# ------------------------------------------------------------------------------
# per perl rules, this should be the last line in such a file:
1;