Showing 3 changed files with 30 additions and 14 deletions
+1 -1
lib/Gitprep.pm
... ...
@@ -72,7 +72,7 @@ sub startup {
72 72
   my $authorized_keys_file = $self->config('authorized_keys_file');
73 73
   unless (defined $authorized_keys_file) {
74 74
     if (defined $ENV{HOME}) {
75
-      $authorized_keys_file = "$ENV{HOME}/.ssh/authorized_keys_file";
75
+      $authorized_keys_file = "$ENV{HOME}/.ssh/authorized_keys";
76 76
     }
77 77
   }
78 78
   if (defined $authorized_keys_file) {
+24 -11
lib/Gitprep/Manager.pm
... ...
@@ -460,7 +460,7 @@ sub update_authorized_keys_file {
460 460
   if (defined $authorized_keys_file) {
461 461
     
462 462
     # Lock file
463
-    my $lock_file = $self->app->rel_file('lock/authorized_keys');
463
+    my $lock_file = $self->app->home->rel_file('lock/authorized_keys');
464 464
     open my $lock_fh, $lock_file
465 465
       or croak "Can't open lock file $lock_file";
466 466
     flock $lock_fh, LOCK_EX
... ...
@@ -473,8 +473,12 @@ sub update_authorized_keys_file {
473 473
     }
474 474
     
475 475
     # Parse file
476
-    my ($before_part, $gitprep_part, $after_part)
477
-      = $self->_parse_authorized_keys_file($authorized_keys_file);
476
+    my $result = $self->_parse_authorized_keys_file($authorized_keys_file);
477
+    my $before_part = $result->{before_part};
478
+    my $gitprep_part = $result->{gitprep_part};
479
+    my $after_part = $result->{after_part};
480
+    my $start_symbol = $result->{start_symbol};
481
+    my $end_symbol = $result->{end_symbol};
478 482
     
479 483
     # Backup at first time
480 484
     if ($gitprep_part eq '') {
... ...
@@ -485,25 +489,25 @@ sub update_authorized_keys_file {
485 489
           or croak "Can't copy $authorized_keys_file to $to";
486 490
       }
487 491
     }
488
-    
492
+
489 493
     # Create public keys
490
-    my $ssh_public_keys = $self->app->dbi->mode('ssh_public_key')->select->all;
494
+    my $ssh_public_keys = $self->app->dbi->model('ssh_public_key')->select->all;
491 495
     my $ssh_public_keys_str = '';
492 496
     for my $key (@$ssh_public_keys) {
493 497
       my $ssh_public_key_str = $self->app->home->rel_file('script/gitprep-shell')
494 498
         . " $key->{user_id},no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty $key->{key}";
495
-      $ssh_public_keys_str .= "$ssh_public_key_str\n\n";
499
+      $ssh_public_keys_str .= "$ssh_public_key_str $key->{user_id}\n\n";
496 500
     }
497 501
     
498 502
     # Output tmp file
499
-    my $output = "$before_part\n\n$ssh_public_keys_str\n\n$after_part";
503
+    my $output = "$before_part\n\n$start_symbol\n\n$ssh_public_keys_str$end_symbol\n\n$after_part";
500 504
     my $output_file = "$authorized_keys_file.gitprep.tmp";
501 505
     open my $out_fh, '>', $output_file
502 506
       or croak "Can't create authorized_keys tmp file $output_file";
503 507
     print $out_fh $output;
504 508
     close $out_fh
505 509
       or croak "Can't close authorized_keys tmp file $output_file";
506
-    
510
+
507 511
     # Replace
508 512
     move $output_file, $authorized_keys_file
509 513
       or croak "Can't replace $authorized_keys_file by $output_file";
... ...
@@ -518,14 +522,14 @@ sub update_authorized_keys_file {
518 522
 }
519 523
 
520 524
 sub _parse_authorized_keys_file {
521
-  my ($self, $file) = shift;
525
+  my ($self, $file) = @_;
522 526
   
523 527
   my $start_symbol = "# gitprep start";
524 528
   my $end_symbol = "# gitprep end";
525 529
   
526 530
   # Parse
527 531
   open my $fh, '<', $file
528
-    or croak "Can't open $file";
532
+    or croak "Can't open authorized_key file $file";
529 533
   my $start_symbol_count = 0;
530 534
   my $end_symbol_count = 0;
531 535
   my $before_part = '';
... ...
@@ -564,7 +568,16 @@ sub _parse_authorized_keys_file {
564 568
       $after_part .= $line;
565 569
     }
566 570
   }
567
-  return ($before_part, $gitprep_part, $after_part);
571
+  
572
+  my $result = {
573
+    start_symbol => $start_symbol,
574
+    end_symbol => $end_symbol,
575
+    before_part => $before_part,
576
+    gitprep_part => $gitprep_part,
577
+    after_part => $after_part
578
+  };
579
+  
580
+  return $result;
568 581
 }
569 582
 
570 583
 sub _create_project {
+5 -2
templates/user-settings/ssh.html.ep
... ...
@@ -87,7 +87,7 @@
87 87
         eval {
88 88
           app->dbi->connector->txn(sub {
89 89
             app->dbi->model('ssh_public_key')->insert($p);
90
-            # $self->manager->update_authorized_keys_file;
90
+            $self->app->manager->update_authorized_keys_file;
91 91
           });
92 92
         };
93 93
         
... ...
@@ -109,7 +109,10 @@
109 109
     elsif ($op eq 'delete') {
110 110
       my $row_id = param('row-id');
111 111
       eval {
112
-        app->dbi->model('ssh_public_key')->delete(where => {row_id => $row_id});
112
+        app->dbi->connector->txn(sub {
113
+          app->dbi->model('ssh_public_key')->delete(where => {row_id => $row_id});
114
+          $self->app->manager->update_authorized_keys_file;
115
+        });
113 116
       };
114 117
       
115 118
       if (my $e = $@) {