git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] add git credential login to remote mediawiki 
@ 2012-06-11 18:54 Javier.Roucher-Iglesias
  2012-06-11 19:13 ` Matthieu Moy
  2012-06-12  8:44 ` Simon Perrat
  0 siblings, 2 replies; 4+ messages in thread
From: Javier.Roucher-Iglesias @ 2012-06-11 18:54 UTC (permalink / raw)
  To: git
  Cc: Javier Roucher, Pavel Volek, NGUYEN Kim Thuat,
	ROUCHER IGLESIAS Javier, Matthieu Moy

From: Javier Roucher <jroucher@gmail.com>

This path uses git credential to store the login/password of the mediawiki.

Changes in the version2 vs version1:
· Correction of the name of the PATCH v2 vs PATCH_v1
· Code style correction
. Code correction, now is user who defines the helper how wants to use


If i miss some correction, please remember me. Thanks.

Adding to the next patch, version3:
· Tests files

Signed-off-by: Pavel Volek <Pavel.Volek@ensimag.imag.fr>
Signed-off-by: NGUYEN Kim Thuat <Kim-Thuat.Nguyen@ensimag.imag.fr>
Signed-off-by: ROUCHER IGLESIAS Javier <roucherj@ensimag.imag.fr>
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>

---
 contrib/mw-to-git/git-remote-mediawiki | 103 +++++++++++++++++++++++++++++----
 1 file changed, 92 insertions(+), 11 deletions(-)

diff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki
index c18bfa1..09ec0f0 100755
--- a/contrib/mw-to-git/git-remote-mediawiki
+++ b/contrib/mw-to-git/git-remote-mediawiki
@@ -154,26 +154,107 @@ while (<STDIN>) {
 # MediaWiki API instance, created lazily.
 my $mediawiki;
 
+sub run_credential {
+	my $cre_protocol = "";
+	my $cre_host = "";
+	my $cre_path = "";
+	my $msg = "";
+	my $result = "";
+	my $op = $_[0];
+
+	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";
+
+	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$_";
+		}
+	}
+}
+
+my $mediawiki;
+
+sub ask_login {
+	run_credential("fill");
+
+	if (!$mediawiki->login( {
+		lgname => $wiki_login,
+		lgpassword => $wiki_passwd,
+		lgdomain => $wiki_domain,
+		} )) {
+			print STDERR "Failed to log in mediawiki user \"$wiki_login\" on $url\n";
+			print STDERR "URL:$wiki_domain $url\n";
+			print STDERR "(error " .
+			    $mediawiki->{error}->{code} . ': ' .
+			    $mediawiki->{error}->{details} . ")\n";
+			run_credential("reject");
+			exit 1;
+	} else {
+		print STDERR "Logged in with user \"$wiki_login\".\n";
+		run_credential("approve");
+	}
+}
+
 sub mw_connect_maybe {
+
 	if ($mediawiki) {
 	    return;
 	}
 	$mediawiki = MediaWiki::API->new;
 	$mediawiki->{config}->{api_url} = "$url/api.php";
 	if ($wiki_login) {
-		if (!$mediawiki->login({
-			lgname => $wiki_login,
-			lgpassword => $wiki_passwd,
-			lgdomain => $wiki_domain,
-		})) {
-			print STDERR "Failed to log in mediawiki user \"$wiki_login\" on $url\n";
-			print STDERR "(error " .
-			    $mediawiki->{error}->{code} . ': ' .
-			    $mediawiki->{error}->{details} . ")\n";
-			exit 1;
+		if (!$wiki_passwd) {
+			#user knows, password not.
+			ask_login();
 		} else {
-			print STDERR "Logged in with user \"$wiki_login\".\n";
+			#user and password knows.
+			ask_login();
 		}
+	} else 	{
+		#user or password not knows
+		ask_login();
 	}
 }
 
-- 
1.7.11.rc2.4.gfbe8a84.dirty

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] add git credential login to remote mediawiki
  2012-06-11 18:54 [PATCH v2] add git credential login to remote mediawiki Javier.Roucher-Iglesias
@ 2012-06-11 19:13 ` Matthieu Moy
  2012-06-12  8:44 ` Simon Perrat
  1 sibling, 0 replies; 4+ messages in thread
From: Matthieu Moy @ 2012-06-11 19:13 UTC (permalink / raw)
  To: Javier.Roucher-Iglesias
  Cc: git, Javier Roucher, Pavel Volek, NGUYEN Kim Thuat,
	ROUCHER IGLESIAS Javier

Javier.Roucher-Iglesias@ensimag.imag.fr writes:

> --- a/contrib/mw-to-git/git-remote-mediawiki
> +++ b/contrib/mw-to-git/git-remote-mediawiki
> @@ -154,26 +154,107 @@ while (<STDIN>) {
>  # MediaWiki API instance, created lazily.
>  my $mediawiki;
>  
[...]
> +my $mediawiki;

You're adding a second declaration of $mediawiki. Cut-and-paste issue?

Plus, didn't I already mention that this "my $mediawiki;" was meant to
be right above mw_connect_maybe?

> +        if ($wiki_login ne "") {
> +                $msg .= "username=$wiki_login\n";
> +        }

Indentation with space.

> +	my $key;
> +	my $value;
> +	my $Prog = "git credential $op";
> +	open2(*Reader, *Writer, $Prog);
> +	print Writer $msg;
> +	close (Writer);

No space before "(" (already mentionned off-list).

> +			# error if key undef
> +			if (not defined $key) {

The comment is useless and therefore counter-productive. Remove it.

> +				print STDERR "ERROR reciving reponse git credential fill\n";

You can add $_ to the message. If this ever happens, the user will
appreciate to see what's going on.

>  sub mw_connect_maybe {
> +
>  	if ($mediawiki) {

Don't add useless newlines.

> +		if (!$wiki_passwd) {
> +			#user knows, password not.
> +			ask_login();
>  		} else {
> -			print STDERR "Logged in with user \"$wiki_login\".\n";
> +			#user and password knows.
> +			ask_login();
>  		}

What is this? You have an "if" with both branches identical.

If the user didn't specify any login name, then you should try to
connect to the wiki anonymously, which works in many wikis.

(BTW, doesn't "ask_login" ask for a password more than a login? If so,
please rename the function).

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] add git credential login to remote mediawiki
  2012-06-11 18:54 [PATCH v2] add git credential login to remote mediawiki Javier.Roucher-Iglesias
  2012-06-11 19:13 ` Matthieu Moy
@ 2012-06-12  8:44 ` Simon Perrat
  2012-06-12 12:20   ` roucherj
  1 sibling, 1 reply; 4+ messages in thread
From: Simon Perrat @ 2012-06-12  8:44 UTC (permalink / raw)
  To: Javier.Roucher-Iglesias
  Cc: git, Javier Roucher, Pavel Volek, NGUYEN Kim Thuat,
	ROUCHER IGLESIAS Javier, Matthieu Moy

2012/6/11 <Javier.Roucher-Iglesias@ensimag.imag.fr>

> +       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";

rec*eiving re*sponse


> +sub ask_login {
> +       run_credential("fill");
> +
> +       if (!$mediawiki->login( {
> +               lgname => $wiki_login,
> +               lgpassword => $wiki_passwd,
> +               lgdomain => $wiki_domain,
> +               } )) {
> +                       print STDERR "Failed to log in mediawiki user
> \"$wiki_login\" on $url\n";

Is there a reason for escaping $wiki_login alone ?

> +                       print STDERR "URL:$wiki_domain $url\n";

Space after :

> +                       print STDERR "(error " .
> +                           $mediawiki->{error}->{code} . ': ' .
> +                           $mediawiki->{error}->{details} . ")\n";

Broken indentation

> +               if (!$wiki_passwd) {
> +                       #user knows, password not.
> +                       ask_login();

know*n (other instances below)
and don't forget space after # ;)


Best regards.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] add git credential login to remote mediawiki
  2012-06-12  8:44 ` Simon Perrat
@ 2012-06-12 12:20   ` roucherj
  0 siblings, 0 replies; 4+ messages in thread
From: roucherj @ 2012-06-12 12:20 UTC (permalink / raw)
  To: Simon Perrat
  Cc: Javier.Roucher-Iglesias, git, Javier Roucher, Pavel Volek,
	NGUYEN Kim Thuat, ROUCHER IGLESIAS Javier, Matthieu Moy

On Tue, 12 Jun 2012 10:44:40 +0200, Simon Perrat wrote:
> 2012/6/11 <Javier.Roucher-Iglesias@ensimag.imag.fr>
>
>> +       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";
>
> rec*eiving re*sponse
>
>

Changed it

>> +sub ask_login {
>> +       run_credential("fill");
>> +
>> +       if (!$mediawiki->login( {
>> +               lgname => $wiki_login,
>> +               lgpassword => $wiki_passwd,
>> +               lgdomain => $wiki_domain,
>> +               } )) {
>> +                       print STDERR "Failed to log in mediawiki 
>> user
>> \"$wiki_login\" on $url\n";
>
> Is there a reason for escaping $wiki_login alone ?
>

Ok, i have changed the message now there is no quotes

>> +                       print STDERR "URL:$wiki_domain $url\n";
>
> Space after :
>

Space added

>> +                       print STDERR "(error " .
>> +                           $mediawiki->{error}->{code} . ': ' .
>> +                           $mediawiki->{error}->{details} . ")\n";
>
> Broken indentation
>

indentation changed

>> +               if (!$wiki_passwd) {
>> +                       #user knows, password not.
>> +                       ask_login();
>
> know*n (other instances below)
> and don't forget space after # ;)
>
>
> Best regards.

Space added


Thanks

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-06-12 12:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-11 18:54 [PATCH v2] add git credential login to remote mediawiki Javier.Roucher-Iglesias
2012-06-11 19:13 ` Matthieu Moy
2012-06-12  8:44 ` Simon Perrat
2012-06-12 12:20   ` roucherj

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).