From 926b9c61e34b804ec46b869c218ba828636a9c4e Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Mon, 24 Nov 2014 22:01:20 +0000 Subject: Add support for authenticated bugzilla in QA mode. This will allow QA team to post automated messages to BZ when trying to assign IDs and the cross check fails for whatever reason (typically deependent bugs or SRPM check failures). --- config_default | 1 + lib/MGA/Advisories.pm | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/config_default b/config_default index fbcd072..9e2ef03 100644 --- a/config_default +++ b/config_default @@ -23,3 +23,4 @@ advisory_types: bugzilla_url: https://bugs.mageia.org/ bugzilla_login: bugzilla_password: +bugzilla_tokenfile: ~/.mga-advisories/bugzilla.token diff --git a/lib/MGA/Advisories.pm b/lib/MGA/Advisories.pm index 482bf43..0cf72d3 100644 --- a/lib/MGA/Advisories.pm +++ b/lib/MGA/Advisories.pm @@ -70,6 +70,16 @@ sub init_bz { $bz{proxy} = XMLRPC::Lite->proxy( $config->{bugzilla_url} . "xmlrpc.cgi" ); + if ($config->{bugzilla_tokenfile} && -f glob($config->{bugzilla_tokenfile})) { + if (open(my $fh, '<', glob($config->{bugzilla_tokenfile}))) { + while (my $row = <$fh>) { + chomp($bz{token} = $row); + last; + } + close $fh; + } + } + #$bz{proxy}->import(+trace => 'debug'); return 1; @@ -106,13 +116,25 @@ sub call_bz { } sub login_bz { + my ($login, $password); if ($config->{bugzilla_login} && $config->{bugzilla_password}) { - my $password = $config->{bugzilla_password}; + $login = $config->{bugzilla_login}; + $password = $config->{bugzilla_password}; + } elsif ($config->{mode} eq 'qa') { + print "Please enter your bugzilla user name (email address): "; + chomp($login = ); + print "Please now enter your bugzilla password: "; + ReadMode('noecho'); + chomp($password = ); + ReadMode(0); # back to normal + print "\n"; + } + + if ($login && $password) { if ( $password =~ /^file:\/\// ) { if (open(my $fh, '<:encoding(UTF-8)', substr $password, 7)) { while (my $row = <$fh>) { - chomp $row; - $password = $row; + chomp($password = $row); last; } close $fh; @@ -124,13 +146,20 @@ sub login_bz { my $soapresult = $bz{proxy}->call( 'User.login', { - login => $config->{bugzilla_login}, + login => $login, password => $password, remember => 1 } ); if ($soapresult->result && $soapresult->result->{token}) { $bz{token} = $soapresult->result->{token}; + if ($config->{bugzilla_tokenfile}) { + if (open(my $fh, '>', glob($config->{bugzilla_tokenfile}))) { + print $fh $bz{token}; + close $fh; + chmod 0600, glob($config->{bugzilla_tokenfile}); + } + } } return 1 unless $soapresult->fault; } -- cgit v1.2.1