{"thread":{"id":"30780","subject":"[PATCH/RFC] add git credential login to remote mediawiki","startedAt":"2012-06-12T14:42:05Z","lastAt":"2012-06-12T15:21:47Z","messageCount":4,"participants":["javier.roucher-iglesias@ensimag.imag.fr","Matthieu Moy","roucherj"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"193445","messageId":"1339512125-32761-1-git-send-email-Javier.Roucher-Iglesias@ensimag.imag.fr","threadId":"30780","inReplyTo":null,"subject":"[PATCH/RFC] add git credential login to remote mediawiki","fromName":"","fromEmail":"javier.roucher-iglesias@ensimag.imag.fr","sentAt":"2012-06-12T14:42:05Z","receivedAt":"2012-06-12T14:42:05Z","isPatch":true,"sender":{"key":"javier.roucher-iglesias@ensimag.imag.fr","avatar":null},"body":"From: Javier Roucher <jroucher@gmail.com>\n\n\nThis path uses git credential to store the login/password of the mediawiki.\n\n\n---\n contrib/mw-to-git/git-remote-mediawiki | 96 ++++++++++++++++++++++++++++------\n 1 file changed, 81 insertions(+), 15 deletions(-)\n\ndiff --git a/contrib/mw-to-git/git-remote-mediawiki b/contrib/mw-to-git/git-remote-mediawiki\nindex c18bfa1..4dcc189 100755\n--- a/contrib/mw-to-git/git-remote-mediawiki\n+++ b/contrib/mw-to-git/git-remote-mediawiki\n@@ -152,29 +152,95 @@ while (<STDIN>) {\n ########################## Functions ##############################\n \n # MediaWiki API instance, created lazily.\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+\tif ($wiki_login ne \"\") {\n+\t\t$msg .= \"username=$wiki_login\\n\";\n+\t}\n+\tif ($wiki_passwd ne \"\") {\n+\t\t$msg .= \"password=$wiki_passwd\\n\";\n+\t}\n+\tif ($cre_protocol ne \"\") {\n+\t\t$msg .= \"protocol=$cre_protocol\\n\";\n+\t}\n+\tif ($cre_host ne \"\") {\n+\t\t$msg .= \"host=$cre_host\\n\";\n+\t}\n+\tif ($cre_path ne \"\") {\n+\t\t$msg .= \"path=$cre_path\\n\";\n+\t}\n+\t$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\tif (not defined $key) {\n+\t\t\t\tprint STDERR \"ERROR receiving response git credential fill\\n Reponse: $_\\n\";\n+\t\t\t\t# exit 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_credential {\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\\n on: $url\\n\";\n+\t\t\tprint STDERR \"URL: $wiki_domain $url\\n\";\n+\t\t\tprint STDERR \"(error \" .\n+\t\t\t\t$mediawiki->{error}->{code} . ': ' .\n+\t\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\t} else {\n-\t\t\tprint STDERR \"Logged in with user \\\"$wiki_login\\\".\\n\";\n-\t\t}\n-\t}\n+\task_credential();\n }\n \n sub get_mw_first_pages {\n-- \n1.7.10.2.573.ged8bfa6\n"},{"id":"193448","messageId":"vpq8vfsoa6x.fsf@bauges.imag.fr","threadId":"30780","inReplyTo":"1339512125-32761-1-git-send-email-Javier.Roucher-Iglesias@ensimag.imag.fr","subject":"Re: [PATCH/RFC] add git credential login to remote mediawiki","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2012-06-12T14:51:18Z","receivedAt":"2012-06-12T14:51:18Z","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>  # MediaWiki API instance, created lazily.\n> +sub run_credential {\n\nHow is the code related to the comment right above?\n\n> +\tmy $Prog = \"git credential $op\";\n> +\topen2 (*Reader, *Writer, $Prog);\n> +\tprint Writer $msg;\n> +\tclose (Writer);\n\nNo space before \"(\" for function calls (already mentionned twice).\n\n>  my $mediawiki;\n\nDidn't I already mention (twice?) that this declaration was meant to\nstay right above mw_connect_maybe?\n\n> +\t\t\trun_credential(\"reject\");\n> +#\t\t\texit 1;\n\nDo you, or do you not want to \"exit 1\". Either remove this, or uncomment\nit.\n\n>  sub mw_connect_maybe {\n> +\n>  \tif ($mediawiki) {\n\nWhy do you add this blank line? (already mentionned)\n\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\t} else {\n> -\t\t\tprint STDERR \"Logged in with user \\\"$wiki_login\\\".\\n\";\n> -\t\t}\n> -\t}\n> +\task_credential();\n\nThis means you can't use the wiki anonymously anymore. This is an\nunacceptable regression.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"193451","messageId":"303c1249341d6f305d315b0a8d9cd20c@telesun.imag.fr","threadId":"30780","inReplyTo":"vpq8vfsoa6x.fsf@bauges.imag.fr","subject":"Re: [PATCH/RFC] add git credential login to remote mediawiki","fromName":"roucherj","fromEmail":"roucherj@telesun.imag.fr","sentAt":"2012-06-12T15:10:05Z","receivedAt":"2012-06-12T15:10:05Z","isPatch":true,"sender":{"key":"roucherj@telesun.imag.fr","avatar":null},"body":"On Tue, 12 Jun 2012 16:51:18 +0200, Matthieu Moy wrote:\n> Javier.Roucher-Iglesias@ensimag.imag.fr writes:\n>\n>>  # MediaWiki API instance, created lazily.\n>> +sub run_credential {\n>\n> How is the code related to the comment right above?\n>\n\nSorry a old comment, i think it's a cause of git rebase i will erase.\n\n>> +\tmy $Prog = \"git credential $op\";\n>> +\topen2 (*Reader, *Writer, $Prog);\n>> +\tprint Writer $msg;\n>> +\tclose (Writer);\n>\n> No space before \"(\" for function calls (already mentionned twice).\n>\n\nsorry but before it's like:\n+\tmy $Prog = \"git credential $op\";\n+\topen2(*Reader, *Writer, $Prog);\n+\tprint Writer $msg;\n+\tclose(Writer);\n\ni have add one space, but the have to be like that?:\n+\tmy $Prog = \"git credential $op\";\n+\topen2 ( *Reader, *Writer, $Prog );\n+\tprint Writer $msg;\n+\tclose ( Writer );\n\n>>  my $mediawiki;\n>\n> Didn't I already mention (twice?) that this declaration was meant to\n> stay right above mw_connect_maybe?\n>\n\nyes but 'ask_credential' used $mediawiki then i think i have to declare \nbefore 'ask_credential'\n\n>> +\t\t\trun_credential(\"reject\");\n>> +#\t\t\texit 1;\n>\n> Do you, or do you not want to \"exit 1\". Either remove this, or \n> uncomment\n> it.\n>\n\ni have comment this line to see the opinion of the community, because i \nask all the time to authenticate\nbut there are few operations who we don't have to authenticate it.\n\nnow if we comment this line the login will fail but they will continue \nwith the operation (like, git clone)\nand try to do it, if the wiki need to be authenticate will refuse the \noperation if not they will continue.\n\n>>  sub mw_connect_maybe {\n>> +\n>>  \tif ($mediawiki) {\n>\n> Why do you add this blank line? (already mentionned)\n>\n\nbecause we need the structure $mediawiki to get the url if is not \ndeclare it will return with out doing the operation\n\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 \n>> $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\t} else {\n>> -\t\t\tprint STDERR \"Logged in with user \\\"$wiki_login\\\".\\n\";\n>> -\t\t}\n>> -\t}\n>> +\task_credential();\n>\n> This means you can't use the wiki anonymously anymore. This is an\n> unacceptable regression.\n\nyes you can use anonymously but login will fail and try to the \noperation, this is the reason because i have comment the 'exit 1'.\n"},{"id":"193452","messageId":"vpqsje0mu7o.fsf@bauges.imag.fr","threadId":"30780","inReplyTo":"303c1249341d6f305d315b0a8d9cd20c@telesun.imag.fr","subject":"Re: [PATCH/RFC] add git credential login to remote mediawiki","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2012-06-12T15:21:47Z","receivedAt":"2012-06-12T15:21:47Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"roucherj <roucherj@telesun.imag.fr> writes:\n\n> On Tue, 12 Jun 2012 16:51:18 +0200, Matthieu Moy wrote:\n>> Javier.Roucher-Iglesias@ensimag.imag.fr writes:\n>>\n>>>  # MediaWiki API instance, created lazily.\n>>> +sub run_credential {\n>>\n>> How is the code related to the comment right above?\n>>\n>\n> Sorry a old comment, i think it's a cause of git rebase i will erase.\n\nThe comment was already there in the code, but it was right above\n\nmy $mediawiki;\n\nand therefore meaningful.\n\n> sorry but before it's like:\n> +\tmy $Prog = \"git credential $op\";\n> +\topen2(*Reader, *Writer, $Prog);\n> +\tprint Writer $msg;\n> +\tclose(Writer);\n\nNo it wasn't (this is the expected version). It was \"close (Writer);\"\nwith an extra space.\n\n>> Didn't I already mention (twice?) that this declaration was meant to\n>> stay right above mw_connect_maybe?\n>\n> yes but 'ask_credential' used $mediawiki then i think i have to\n> declare before 'ask_credential'\n\nBut do you have any reason not to declare ask_credential after\nmw_connect_maybe?\n\n>>> +\t\t\trun_credential(\"reject\");\n>>> +#\t\t\texit 1;\n>>\n>> Do you, or do you not want to \"exit 1\". Either remove this, or\n>> uncomment\n>> it.\n>>\n>\n> i have comment this line to see the opinion of the community, because\n> i ask all the time to authenticate\n> but there are few operations who we don't have to authenticate it.\n>\n> now if we comment this line the login will fail but they will continue\n> with the operation (like, git clone)\n> and try to do it, if the wiki need to be authenticate will refuse the\n> operation if not they will continue.\n[...]\n>> This means you can't use the wiki anonymously anymore. This is an\n>> unacceptable regression.\n>\n> yes you can use anonymously but login will fail and try to the\n> operation, this is the reason because i have comment the 'exit 1'.\n\nBut in this case, you still prompt for login and password, right?.\nThat's weird for the user to have to type a dummy login/password and see\nan error message to use a wiki anonymously.\n\n>>>  sub mw_connect_maybe {\n>>> +\n>>>  \tif ($mediawiki) {\n>>\n>> Why do you add this blank line? (already mentionned)\n>>\n>\n> because we need the structure $mediawiki to get the url if is not\n> declare it will return with out doing the operation\n\nI'm talking about the blank line, not the if.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"}]}