From: Jeff King <peff@peff.net>
To: Javier.Roucher-Iglesias@ensimag.imag.fr
Cc: git@vger.kernel.org, Javier Roucher <jroucher@gmail.com>,
Pavel Volek <Pavel.Volek@ensimag.imag.fr>,
NGUYEN Kim Thuat <Kim-Thuat.Nguyen@ensimag.imag.fr>,
ROUCHER IGLESIAS Javier <roucherj@ensimag.imag.fr>,
Matthieu Moy <Matthieu.Moy@imag.fr>
Subject: Re: [PATCH_v1] add git credential login to remote mediawiki
Date: Sun, 10 Jun 2012 08:18:28 -0400 [thread overview]
Message-ID: <20120610121827.GB6453@sigill.intra.peff.net> (raw)
In-Reply-To: <1339268028-13991-1-git-send-email-Javier.Roucher-Iglesias@ensimag.imag.fr>
On Sat, Jun 09, 2012 at 08:53:48PM +0200, Javier.Roucher-Iglesias@ensimag.imag.fr wrote:
> diff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki
> index c18bfa1..4b14d78 100755
> --- a/contrib/mw-to-git/git-remote-mediawiki
> +++ b/contrib/mw-to-git/git-remote-mediawiki
> @@ -152,28 +152,111 @@ while (<STDIN>) {
> ########################## Functions ##############################
>
> # MediaWiki API instance, created lazily.
> +sub run_credential {
Is there any reason not to add this to perl/Git.pm? I suspect that other
scripts will want to use it, too (for example, send-email could probably
use it for SMTP credentials).
> + if (scalar(@_) == 2) {
> + if ($_[1] eq ("store" || "cache")) {
> + run_git("config credential.helper \'$_[1]\'");
> + } else {
> + print STDERR "ERROR: run_credential (fill|approve|reject) [store|cache]\n";
> + exit 1;
> + }
> + }
This hunk looks wrong. You should never be setting the credential.helper
config; that is the responsibility of the user to set, as they want to
select whatever helper is appropriate. Nor do you need to care about
which helpers are in use; the point of git-credential is that it will do
that for you.
> + my $parsed = URI->new($url);
> + $cre_protocol = $parsed->scheme;
> + $cre_host = $parsed->host;
> + $cre_path = $parsed->path;
> +
> + if ($wiki_login ne "") {
> + $msg .= "username=$wiki_login\n";
> + }
> + if ($wiki_passwd ne "") {
> + $msg .= "password=$wiki_passwd\n";
> + }
> + if ($cre_protocol ne "") {
> + $msg .= "protocol=$cre_protocol\n";
> + }
> + if ($cre_host ne "") {
> + $msg .= "host=$cre_host\n";
> + }
> + if ($cre_path ne "") {
> + $msg .= "path=$cre_path\n";
> + }
> +
> + $msg .= "\n";
All of this could just go away for the "fill" case if we allow URLs on
the command line (see my previous email if you haven't already). And for
the "approve" and "reject" cases, we could just save the result from
"fill" and feed it back verbatim, as I described in the earlier email.
Then it would be as simple as:
sub fill_credential {
my $quoted_url = quotemeta(shift);
my $verbatim = `git credential fill $quoted_url`;
$? and die "git-credential failed";
$verbatim =~ /^username=(.*)$/m
or die "git-credential did not give us a username";
my $username = $1;
$verbatim =~ /^password=(.*)$/m
or die "git-credential did not give us a password";
return ($username, $password, $verbatim);
}
sub report_credential {
my ($type, $verbatim) = @_;
open(my $fh, '|-', "git credential $type");
print $fh $verbatim;
}
> + my $key;
> + my $value;
> + my $Prog = "git credential $op";
> + open2(*Reader, *Writer, $Prog);
> + print Writer $msg;
> + close (Writer);
> +
> + if ($op eq "fill") {
> + while (<Reader>) {
> + my ($key, $value) = /([^=]*)=(.*)/;
> + # error if key undef
> + if (not defined $key) {
> + print STDERR "ERROR reciving reponse git credential fill\n";
> + exit 1;
> + }
> + if ($key eq "username") {
> + $wiki_login = $value;
> + }
> + if ($key eq "password") {
> + $wiki_passwd = $value;
> + }
> + }
> + } else {
> + while (<Reader>) {
> + print STDERR "\nERROR while running git credential $op:\n$_";
> + }
> + }
> +}
This isn't a good way to check for errors. The non-fill actions will
never produce output on stdout, and you are not intercepting their
stderr. Besides which, checking for errors by reading stderr is not a
good practice; you should check the return value of the command in $?
after it finishes.
-Peff
next prev parent reply other threads:[~2012-06-10 12:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-09 18:53 [PATCH_v1] add git credential login to remote mediawiki Javier.Roucher-Iglesias
2012-06-10 6:54 ` Junio C Hamano
2012-06-10 12:18 ` Jeff King [this message]
2012-06-10 13:37 ` Matthieu Moy
2012-06-10 17:36 ` roucherj
2012-06-10 18:39 ` Jeff King
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120610121827.GB6453@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=Javier.Roucher-Iglesias@ensimag.imag.fr \
--cc=Kim-Thuat.Nguyen@ensimag.imag.fr \
--cc=Matthieu.Moy@imag.fr \
--cc=Pavel.Volek@ensimag.imag.fr \
--cc=git@vger.kernel.org \
--cc=jroucher@gmail.com \
--cc=roucherj@ensimag.imag.fr \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).