{"thread":{"id":"30769","subject":"[PATCH v2] add git credential login to remote mediawiki","startedAt":"2012-06-11T18:54:53Z","lastAt":"2012-06-12T12:20:00Z","messageCount":4,"participants":["javier.roucher-iglesias@ensimag.imag.fr","Matthieu Moy","Simon Perrat","roucherj"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"193350","messageId":"1339440893-8522-1-git-send-email-Javier.Roucher-Iglesias@enismag.imag.fr","threadId":"30769","inReplyTo":null,"subject":"[PATCH v2] add git credential login to remote mediawiki","fromName":"","fromEmail":"javier.roucher-iglesias@ensimag.imag.fr","sentAt":"2012-06-11T18:54:53Z","receivedAt":"2012-06-11T18:54:53Z","isPatch":true,"sender":{"key":"javier.roucher-iglesias@ensimag.imag.fr","avatar":null},"body":"From: Javier Roucher <jroucher@gmail.com>\n\nThis path uses git credential to store the login/password of the mediawiki.\n\nChanges in the version2 vs version1:\n· Correction of the name of the PATCH v2 vs PATCH_v1\n· Code style correction\n. Code correction, now is user who defines the helper how wants to use\n\n\nIf i miss some correction, please remember me. Thanks.\n\nAdding to the next patch, version3:\n· Tests files\n\nSigned-off-by: Pavel Volek <Pavel.Volek@ensimag.imag.fr>\nSigned-off-by: NGUYEN Kim Thuat <Kim-Thuat.Nguyen@ensimag.imag.fr>\nSigned-off-by: ROUCHER IGLESIAS Javier <roucherj@ensimag.imag.fr>\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n\n---\n contrib/mw-to-git/git-remote-mediawiki | 103 +++++++++++++++++++++++++++++----\n 1 file changed, 92 insertions(+), 11 deletions(-)\n\ndiff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki\nindex c18bfa1..09ec0f0 100755\n--- a/contrib/mw-to-git/git-remote-mediawiki\n+++ b/contrib/mw-to-git/git-remote-mediawiki\n@@ -154,26 +154,107 @@ while (<STDIN>) {\n # MediaWiki API instance, created lazily.\n my $mediawiki;\n \n+sub run_credential {\n+\tmy $cre_protocol = \"\";\n+\tmy $cre_host = \"\";\n+\tmy $cre_path = \"\";\n+\tmy $msg = \"\";\n+\tmy $result = \"\";\n+\tmy $op = $_[0];\n+\n+\tmy $parsed = URI->new($url);\n+\t$cre_protocol = $parsed->scheme;\n+\t$cre_host = $parsed->host;\n+\t$cre_path = $parsed->path;\n+\n+        if ($wiki_login ne \"\") {\n+                $msg .= \"username=$wiki_login\\n\";\n+        }\n+        if ($wiki_passwd ne \"\") {\n+                $msg .= \"password=$wiki_passwd\\n\";\n+        }\n+        if ($cre_protocol ne \"\") {\n+                $msg .= \"protocol=$cre_protocol\\n\";\n+        }\n+        if ($cre_host ne \"\") {\n+                $msg .= \"host=$cre_host\\n\";\n+        }\n+        if ($cre_path ne \"\") {\n+                $msg .= \"path=$cre_path\\n\";\n+        }\n+\n+        $msg .= \"\\n\";\n+\n+\tmy $key;\n+\tmy $value;\n+\tmy $Prog = \"git credential $op\";\n+\topen2(*Reader, *Writer, $Prog);\n+\tprint Writer $msg;\n+\tclose (Writer);\n+\n+\tif ($op eq \"fill\") {\n+\t\twhile (<Reader>) {\n+\t\t\tmy ($key, $value) = /([^=]*)=(.*)/;\n+\t\t\t# error if key undef\n+\t\t\tif (not defined $key) {\n+\t\t\t\tprint STDERR \"ERROR reciving reponse git credential fill\\n\";\n+\t\t\t\texit 1;\n+\t\t\t}\n+\t\t\tif ($key eq \"username\") {\n+\t\t\t\t$wiki_login = $value;\n+\t\t\t}\n+\t\t\tif ($key eq \"password\") {\n+\t\t\t\t$wiki_passwd = $value;\n+\t\t\t}\n+\t\t}\n+\t} else {\n+\t\twhile (<Reader>) {\n+\t\t\tprint STDERR \"\\nERROR while running git credential $op:\\n$_\";\n+\t\t}\n+\t}\n+}\n+\n+my $mediawiki;\n+\n+sub ask_login {\n+\trun_credential(\"fill\");\n+\n+\tif (!$mediawiki->login( {\n+\t\tlgname => $wiki_login,\n+\t\tlgpassword => $wiki_passwd,\n+\t\tlgdomain => $wiki_domain,\n+\t\t} )) {\n+\t\t\tprint STDERR \"Failed to log in mediawiki user \\\"$wiki_login\\\" on $url\\n\";\n+\t\t\tprint STDERR \"URL:$wiki_domain $url\\n\";\n+\t\t\tprint STDERR \"(error \" .\n+\t\t\t    $mediawiki->{error}->{code} . ': ' .\n+\t\t\t    $mediawiki->{error}->{details} . \")\\n\";\n+\t\t\trun_credential(\"reject\");\n+\t\t\texit 1;\n+\t} else {\n+\t\tprint STDERR \"Logged in with user \\\"$wiki_login\\\".\\n\";\n+\t\trun_credential(\"approve\");\n+\t}\n+}\n+\n sub mw_connect_maybe {\n+\n \tif ($mediawiki) {\n \t    return;\n \t}\n \t$mediawiki = MediaWiki::API->new;\n \t$mediawiki->{config}->{api_url} = \"$url/api.php\";\n \tif ($wiki_login) {\n-\t\tif (!$mediawiki->login({\n-\t\t\tlgname => $wiki_login,\n-\t\t\tlgpassword => $wiki_passwd,\n-\t\t\tlgdomain => $wiki_domain,\n-\t\t})) {\n-\t\t\tprint STDERR \"Failed to log in mediawiki user \\\"$wiki_login\\\" on $url\\n\";\n-\t\t\tprint STDERR \"(error \" .\n-\t\t\t    $mediawiki->{error}->{code} . ': ' .\n-\t\t\t    $mediawiki->{error}->{details} . \")\\n\";\n-\t\t\texit 1;\n+\t\tif (!$wiki_passwd) {\n+\t\t\t#user knows, password not.\n+\t\t\task_login();\n \t\t} else {\n-\t\t\tprint STDERR \"Logged in with user \\\"$wiki_login\\\".\\n\";\n+\t\t\t#user and password knows.\n+\t\t\task_login();\n \t\t}\n+\t} else \t{\n+\t\t#user or password not knows\n+\t\task_login();\n \t}\n }\n \n-- \n1.7.11.rc2.4.gfbe8a84.dirty\n"},{"id":"193360","messageId":"vpqaa094q6q.fsf@bauges.imag.fr","threadId":"30769","inReplyTo":"1339440893-8522-1-git-send-email-Javier.Roucher-Iglesias@enismag.imag.fr","subject":"Re: [PATCH v2] add git credential login to remote mediawiki","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2012-06-11T19:13:49Z","receivedAt":"2012-06-11T19:13:49Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Javier.Roucher-Iglesias@ensimag.imag.fr writes:\n\n> --- a/contrib/mw-to-git/git-remote-mediawiki\n> +++ b/contrib/mw-to-git/git-remote-mediawiki\n> @@ -154,26 +154,107 @@ while (<STDIN>) {\n>  # MediaWiki API instance, created lazily.\n>  my $mediawiki;\n>  \n[...]\n> +my $mediawiki;\n\nYou're adding a second declaration of $mediawiki. Cut-and-paste issue?\n\nPlus, didn't I already mention that this \"my $mediawiki;\" was meant to\nbe right above mw_connect_maybe?\n\n> +        if ($wiki_login ne \"\") {\n> +                $msg .= \"username=$wiki_login\\n\";\n> +        }\n\nIndentation with space.\n\n> +\tmy $key;\n> +\tmy $value;\n> +\tmy $Prog = \"git credential $op\";\n> +\topen2(*Reader, *Writer, $Prog);\n> +\tprint Writer $msg;\n> +\tclose (Writer);\n\nNo space before \"(\" (already mentionned off-list).\n\n> +\t\t\t# error if key undef\n> +\t\t\tif (not defined $key) {\n\nThe comment is useless and therefore counter-productive. Remove it.\n\n> +\t\t\t\tprint STDERR \"ERROR reciving reponse git credential fill\\n\";\n\nYou can add $_ to the message. If this ever happens, the user will\nappreciate to see what's going on.\n\n>  sub mw_connect_maybe {\n> +\n>  \tif ($mediawiki) {\n\nDon't add useless newlines.\n\n> +\t\tif (!$wiki_passwd) {\n> +\t\t\t#user knows, password not.\n> +\t\t\task_login();\n>  \t\t} else {\n> -\t\t\tprint STDERR \"Logged in with user \\\"$wiki_login\\\".\\n\";\n> +\t\t\t#user and password knows.\n> +\t\t\task_login();\n>  \t\t}\n\nWhat is this? You have an \"if\" with both branches identical.\n\nIf the user didn't specify any login name, then you should try to\nconnect to the wiki anonymously, which works in many wikis.\n\n(BTW, doesn't \"ask_login\" ask for a password more than a login? If so,\nplease rename the function).\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"193422","messageId":"CA+hdvHjnVc50rOsxeKUHrwBxRHi4FjcG5sSnnKYWejwXLesKNg@mail.gmail.com","threadId":"30769","inReplyTo":"1339440893-8522-1-git-send-email-Javier.Roucher-Iglesias@enismag.imag.fr","subject":"Re: [PATCH v2] add git credential login to remote mediawiki","fromName":"Simon Perrat","fromEmail":"simon.perrat@gmail.com","sentAt":"2012-06-12T08:44:40Z","receivedAt":"2012-06-12T08:44:40Z","isPatch":true,"sender":{"key":"simon.perrat@gmail.com","avatar":null},"body":"2012/6/11 <Javier.Roucher-Iglesias@ensimag.imag.fr>\n\n> +       if ($op eq \"fill\") {\n> +               while (<Reader>) {\n> +                       my ($key, $value) = /([^=]*)=(.*)/;\n> +                       # error if key undef\n> +                       if (not defined $key) {\n> +                               print STDERR \"ERROR reciving reponse git\n> credential fill\\n\";\n\nrec*eiving re*sponse\n\n\n> +sub ask_login {\n> +       run_credential(\"fill\");\n> +\n> +       if (!$mediawiki->login( {\n> +               lgname => $wiki_login,\n> +               lgpassword => $wiki_passwd,\n> +               lgdomain => $wiki_domain,\n> +               } )) {\n> +                       print STDERR \"Failed to log in mediawiki user\n> \\\"$wiki_login\\\" on $url\\n\";\n\nIs there a reason for escaping $wiki_login alone ?\n\n> +                       print STDERR \"URL:$wiki_domain $url\\n\";\n\nSpace after :\n\n> +                       print STDERR \"(error \" .\n> +                           $mediawiki->{error}->{code} . ': ' .\n> +                           $mediawiki->{error}->{details} . \")\\n\";\n\nBroken indentation\n\n> +               if (!$wiki_passwd) {\n> +                       #user knows, password not.\n> +                       ask_login();\n\nknow*n (other instances below)\nand don't forget space after # ;)\n\n\nBest regards.\n"},{"id":"193430","messageId":"964d34b0b5dcdb2e26cac78096629d44@telesun.imag.fr","threadId":"30769","inReplyTo":"CA+hdvHjnVc50rOsxeKUHrwBxRHi4FjcG5sSnnKYWejwXLesKNg@mail.gmail.com","subject":"Re: [PATCH v2] add git credential login to remote mediawiki","fromName":"roucherj","fromEmail":"roucherj@telesun.imag.fr","sentAt":"2012-06-12T12:20:00Z","receivedAt":"2012-06-12T12:20:00Z","isPatch":true,"sender":{"key":"roucherj@telesun.imag.fr","avatar":null},"body":"On Tue, 12 Jun 2012 10:44:40 +0200, Simon Perrat wrote:\n> 2012/6/11 <Javier.Roucher-Iglesias@ensimag.imag.fr>\n>\n>> +       if ($op eq \"fill\") {\n>> +               while (<Reader>) {\n>> +                       my ($key, $value) = /([^=]*)=(.*)/;\n>> +                       # error if key undef\n>> +                       if (not defined $key) {\n>> +                               print STDERR \"ERROR reciving reponse \n>> git\n>> credential fill\\n\";\n>\n> rec*eiving re*sponse\n>\n>\n\nChanged it\n\n>> +sub ask_login {\n>> +       run_credential(\"fill\");\n>> +\n>> +       if (!$mediawiki->login( {\n>> +               lgname => $wiki_login,\n>> +               lgpassword => $wiki_passwd,\n>> +               lgdomain => $wiki_domain,\n>> +               } )) {\n>> +                       print STDERR \"Failed to log in mediawiki \n>> user\n>> \\\"$wiki_login\\\" on $url\\n\";\n>\n> Is there a reason for escaping $wiki_login alone ?\n>\n\nOk, i have changed the message now there is no quotes\n\n>> +                       print STDERR \"URL:$wiki_domain $url\\n\";\n>\n> Space after :\n>\n\nSpace added\n\n>> +                       print STDERR \"(error \" .\n>> +                           $mediawiki->{error}->{code} . ': ' .\n>> +                           $mediawiki->{error}->{details} . \")\\n\";\n>\n> Broken indentation\n>\n\nindentation changed\n\n>> +               if (!$wiki_passwd) {\n>> +                       #user knows, password not.\n>> +                       ask_login();\n>\n> know*n (other instances below)\n> and don't forget space after # ;)\n>\n>\n> Best regards.\n\nSpace added\n\n\nThanks\n"}]}