]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei convert: auth directly from worker process
authorEric Wong <e@80x24.org>
Mon, 22 Feb 2021 11:22:53 +0000 (08:22 -0300)
committerEric Wong <e@80x24.org>
Mon, 22 Feb 2021 22:14:19 +0000 (18:14 -0400)
Since this only has one worker, we can auth directly in the
worker since the convert worker now has access to the script/lei
{sock} for running "git credential".

lib/PublicInbox/LeiConvert.pm
lib/PublicInbox/NetReader.pm
lib/PublicInbox/NetWriter.pm

index ba375772369065d725c08ec3d0cc845a68225b18..3a714502bb71988b4f1c42f13fb65cabd50517d2 100644 (file)
@@ -32,6 +32,10 @@ sub do_convert { # via wq_do
        my ($self) = @_;
        my $lei = $self->{lei};
        my $in_fmt = $lei->{opt}->{'in-format'};
+       my $mics;
+       if (my $nrd = $lei->{nrd}) { # may prompt user once
+               $nrd->{mics_cached} = $nrd->imap_common_init($lei);
+       }
        if (my $stdin = delete $self->{0}) {
                PublicInbox::MboxReader->$in_fmt($stdin, \&mbox_cb, $self);
        }
@@ -120,16 +124,14 @@ sub call { # the main "lei convert" method
                require PublicInbox::MdirReader;
        }
        $self->{inputs} = \@inputs;
-       return convert_start($lei) if !$nrd;
-
-       if (my $err = $nrd->errors) {
-               return $lei->fail($err);
+       if ($nrd) {
+               if (my $err = $nrd->errors) {
+                       return $lei->fail($err);
+               }
+               $nrd->{quiet} = $opt->{quiet};
+               $lei->{nrd} = $nrd;
        }
-       $nrd->{quiet} = $opt->{quiet};
-       $lei->{nrd} = $nrd;
-       require PublicInbox::LeiAuth;
-       my $auth = $lei->{auth} = PublicInbox::LeiAuth->new($nrd);
-       $auth->auth_start($lei, \&convert_start, $lei);
+       convert_start($lei);
 }
 
 sub ipc_atfork_child {
index 0956d5dad6517509194e093fcc4db9efd74e9f64..c29e09c190a6159c9c1a442e110ee5c4ffe018ff 100644 (file)
@@ -423,14 +423,16 @@ sub _imap_fetch_all ($$$) {
 
 # uses cached auth info prepared by mic_for
 sub mic_get {
-       my ($self, $sec) = @_;
-       my $mic_arg = $self->{mic_arg}->{$sec};
-       unless ($mic_arg) {
-               my $uri = ref $sec ? $sec : PublicInbox::URIimap->new($sec);
-               $sec = uri_section($uri);
-               $mic_arg = $self->{mic_arg}->{$sec} or
-                       die "BUG: no Mail::IMAPClient->new arg for $sec";
+       my ($self, $uri) = @_;
+       my $sec = uri_section($uri);
+       # see if caller saved result of imap_common_init
+       if (my $cached = $self->{mics_cached}) {
+               my $mic = $cached->{$sec};
+               return $mic if $mic && $mic->IsConnected;
+               delete $cached->{$sec};
        }
+       my $mic_arg = $self->{mic_arg}->{$sec} or
+                       die "BUG: no Mail::IMAPClient->new arg for $sec";
        if (defined(my $cb_name = $mic_arg->{Authcallback})) {
                if (ref($cb_name) ne 'CODE') {
                        $mic_arg->{Authcallback} = $self->can($cb_name);
index 89f8662efa647009ce68778e94c95c2d94a1e7ff..c68b0669e2f67435d54369883c31de3251d7f321 100644 (file)
@@ -28,7 +28,7 @@ sub imap_delete_all {
        my $uri = PublicInbox::URIimap->new($url);
        my $sec = $self->can('uri_section')->($uri);
        local $0 = $uri->mailbox." $sec";
-       my $mic = $self->mic_get($sec) or die "E: not connected: $@";
+       my $mic = $self->mic_get($uri) or die "E: not connected: $@";
        $mic->select($uri->mailbox) or return; # non-existent
        if ($mic->delete_message('1:*')) {
                $mic->expunge;