From: Eric Wong <e@80x24.org> To: meta@public-inbox.org Subject: [PATCH 04/10] lei convert: auth directly from worker process Date: Mon, 22 Feb 2021 08:22:53 -0300 Message-ID: <20210222112259.32402-4-e@80x24.org> (raw) In-Reply-To: <20210222112259.32402-1-e@80x24.org> 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 | 20 +++++++++++--------- lib/PublicInbox/NetReader.pm | 16 +++++++++------- lib/PublicInbox/NetWriter.pm | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/PublicInbox/LeiConvert.pm b/lib/PublicInbox/LeiConvert.pm index ba375772..3a714502 100644 --- a/lib/PublicInbox/LeiConvert.pm +++ b/lib/PublicInbox/LeiConvert.pm @@ -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 { diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm index 0956d5da..c29e09c1 100644 --- a/lib/PublicInbox/NetReader.pm +++ b/lib/PublicInbox/NetReader.pm @@ -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); diff --git a/lib/PublicInbox/NetWriter.pm b/lib/PublicInbox/NetWriter.pm index 89f8662e..c68b0669 100644 --- a/lib/PublicInbox/NetWriter.pm +++ b/lib/PublicInbox/NetWriter.pm @@ -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;
next prev parent reply other threads:[~2021-02-22 11:22 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-02-22 11:21 [PATCH 00/10] lei: avoid wasting IMAP connections Eric Wong 2021-02-22 11:22 ` [PATCH 01/10] lei_auth: rename {nrd} field to {net} for clarity Eric Wong 2021-02-22 11:22 ` [PATCH 02/10] lei: keep client {sock} in short-lived workers Eric Wong 2021-02-22 11:22 ` [PATCH 03/10] lei: _lei_cfg: return empty hashref if unconfigured Eric Wong 2021-02-22 11:22 ` Eric Wong [this message] 2021-02-22 11:22 ` [PATCH 05/10] lei import: no separate auth worker Eric Wong 2021-02-22 11:22 ` [PATCH 06/10] lei_auth: migrate common auth code from lei_import Eric Wong 2021-02-22 11:22 ` [PATCH 07/10] lei q: reduce wasted IMAP connection for auth Eric Wong 2021-02-22 11:22 ` [PATCH 08/10] net_reader: mic_get: reuse connections if cache enabled Eric Wong 2021-02-22 11:22 ` [PATCH 09/10] lei convert: inline convert_start Eric Wong 2021-02-22 11:22 ` [PATCH 10/10] lei_auth: trim and remove leftover worker code Eric Wong
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: https://public-inbox.org/README * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210222112259.32402-4-e@80x24.org \ --to=e@80x24.org \ --cc=meta@public-inbox.org \ --subject='Re: [PATCH 04/10] lei convert: auth directly from worker process' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
user/dev discussion of public-inbox itself This inbox may be cloned and mirrored by anyone: git clone --mirror https://public-inbox.org/meta git clone --mirror http://czquwvybam4bgbro.onion/meta git clone --mirror http://hjrcffqmbrq6wope.onion/meta git clone --mirror http://ou63pmih66umazou.onion/meta # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \ meta@public-inbox.org public-inbox-index meta Example config snippet for mirrors. Newsgroups are available over NNTP: nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta nntp://news.gmane.io/gmane.mail.public-inbox.general note: .onion URLs require Tor: https://www.torproject.org/ code repositories for project(s) associated with this inbox: https://80x24.org/public-inbox.git AGPL code for this site: git clone https://public-inbox.org/public-inbox.git