[bugzilla-gnome-org-extensions] Add a Splinter web-service module to the extension
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bugzilla-gnome-org-extensions] Add a Splinter web-service module to the extension
- Date: Thu, 20 Nov 2014 22:20:40 +0000 (UTC)
commit 7f8bd891a7669aa9e5ddb6ab42eb81b51799070c
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Sun Sep 27 17:03:09 2009 -0400
Add a Splinter web-service module to the extension
Add a webservice module 'Splinter' with (so far) one method:
Splinter.info() =>
{
version: <version integer, currently 1>,
logged_in: [true|false],
login: <login if logged in>,
name: <name if logged in>
}
Use this in splinter_proxy.py to add a config variable
configHaveExtension.
Makefile | 2 +
extension/code/webservice.pl | 26 ++++++++
extension/lib/WSSplinter.pm | 48 +++++++++++++++
.../en/default/pages/splinter.html.tmpl.in | 7 ++-
proxy/splinter_proxy.py | 61 +++++++++++++++++---
5 files changed, 133 insertions(+), 11 deletions(-)
---
diff --git a/Makefile b/Makefile
index 256d796..47b2c3a 100644
--- a/Makefile
+++ b/Makefile
@@ -40,8 +40,10 @@ EXTENSION_FILES = \
extension/code/bug-format_comment.pl \
extension/code/config-add_panels.pl \
extension/code/page-before_template.pl \
+ extension/code/webservice.pl \
extension/info.pl \
extension/lib/ConfigSplinter.pm \
+ extension/lib/WSSplinter.pm \
extension/template/en/attachment/list-action.html.tmpl \
extension/template/en/default/admin/params/splinter.html.tmpl \
extension/template/en/default/pages/splinter.html.tmpl
diff --git a/extension/code/webservice.pl b/extension/code/webservice.pl
new file mode 100644
index 0000000..f5bf4ad
--- /dev/null
+++ b/extension/code/webservice.pl
@@ -0,0 +1,26 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Bugzilla BugBuddy Plugin.
+#
+# The Initial Developer of the Original Code is Canonical Ltd.
+# Portions created by Canonical Ltd. are Copyright (C) 2009
+# Canonical Ltd. All Rights Reserved.
+#
+# Contributor(s): Bradley Baetz <bbaetz acm org>
+# Owen Taylor <otaylor redhat com>
+
+use strict;
+use warnings;
+use Bugzilla;
+my $dispatch = Bugzilla->hook_args->{dispatch};
+$dispatch->{Splinter} = "extensions::splinter::lib::WSSplinter";
diff --git a/extension/lib/WSSplinter.pm b/extension/lib/WSSplinter.pm
new file mode 100644
index 0000000..3c3d3f4
--- /dev/null
+++ b/extension/lib/WSSplinter.pm
@@ -0,0 +1,48 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Splinter Bugzilla Extension.
+#
+# The Initial Developer of the Original Code is Red Hat, Inc.
+# Portions created by Red Hat, Inc. are Copyright (C) 2009
+# Red Hat Inc. All Rights Reserved.
+#
+# Contributor(s):
+# Owen Taylor <otaylor fishsoup net>
+
+package extensions::splinter::lib::WSSplinter;
+use strict;
+use warnings;
+
+use Bugzilla;
+
+use base qw(Bugzilla::WebService);
+
+sub info {
+ my $user = Bugzilla->login;
+
+ my $results = {
+ version => 1
+ };
+
+ if ($user->login ne '') {
+ $results->{'logged_in'} = 1;
+ $results->{'login'} = $user->login;
+ $results->{'name'} = $user->name;
+ } else {
+ $results->{'logged_in'} = 0;
+ }
+
+ return $results;
+}
+
+1;
diff --git a/extension/template/en/default/pages/splinter.html.tmpl.in
b/extension/template/en/default/pages/splinter.html.tmpl.in
index b665422..5e59b33 100644
--- a/extension/template/en/default/pages/splinter.html.tmpl.in
+++ b/extension/template/en/default/pages/splinter.html.tmpl.in
@@ -31,12 +31,15 @@
<script type="text/javascript">
configAttachmentStatuses = [
[% FOREACH status = attachment_statuses %]
- '[% status FILTER js %]',
+ '[% status FILTER js %]',
[% END %]
];
- configBugzillaUrl = '/';
+
configBase = '[% Param('splinter_base') FILTER js %]';
$(function() { init(); });
+ configBugzillaUrl = '/';
+ configHaveExtension = true;
+ configNote = '';
</script>
@@BODY@@
diff --git a/proxy/splinter_proxy.py b/proxy/splinter_proxy.py
index adf7c7d..15d9031 100755
--- a/proxy/splinter_proxy.py
+++ b/proxy/splinter_proxy.py
@@ -316,6 +316,11 @@ class LoginTransport(xmlrpclib.Transport):
else:
return LoginConnectionS(self.hostname, self.port)
+ def send_request(self, connection, handler, request_body):
+ xmlrpclib.Transport.send_request(self, connection, handler, request_body)
+ if login_cookie_header is not None:
+ connection.putheader('Cookie', login_cookie_header)
+
class LoginConnection(httplib.HTTP):
def getreply(self):
errcode, errmsg, headers = httplib.HTTP.getreply(self)
@@ -331,10 +336,7 @@ class LoginConnectionS(httplib.HTTPS):
# Try to log in; we log in once every time the proxy is started, and don't
# try to remember our cookies. Cookies will be deleted from the server
# after 30 days of non-use.
-def login():
- proxy_scheme, proxy_hostname, proxy_port, proxy_path, proxy_url = get_proxy_info("/xmlrpc.cgi")
- transport = LoginTransport(proxy_scheme, proxy_hostname, proxy_port)
- xmlrpc = xmlrpclib.ServerProxy(proxy_url, transport)
+def login(xmlrpc):
try:
# 'remember: 0' basically just causes the server not to send an
# Expires: parameter with the cookie, but it serves as a hint
@@ -354,19 +356,36 @@ def login():
print >>sys.stderr, "Can't log in to %s: %s" % (current_config['bugzilla_url'],
e.args[1])
+def get_splinter_info(xmlrpc):
+ try:
+ return xmlrpc.Splinter.info()
+ except xmlrpclib.Fault, e:
+ # Probably simply no extension
+ pass
+ except xmlrpclib.ProtocolError, e:
+ print >>sys.stderr, "Can't get splinter extension info: %d %s" % (e.errcode,
+ e.errmsg)
+ except (socket.error, socket.herror, socket.gaierror), e:
+ print >>sys.stderr, "Can't get splinter extension info %s: %s" % (current_config['bugzilla_url'],
+ e.args[1])
+
+ return None
+
def make_config_js():
if 'bugzilla_login' in current_config and 'bugzilla_login' in current_config:
note = ''
else:
note = 'This is a read-only demo instance of Splinter; you will not be able to publish your reviews'
+ if have_extension:
+ have_extension_value = 'true';
+ else:
+ have_extension_value = 'false';
+
# configAttachmentStatuses is just hardcoded here to the values for bugzilla.gnome.org
# which is the only Bugzilla instance I'm aware of using attachment statuses. It
# could be added to config.py if needed.
return """\
-configBugzillaUrl = '%(bugzilla_url)s';
-configNote = '%(note)s';
-
configAttachmentStatuses = [
'none',
'accepted-commit_now',
@@ -376,6 +395,11 @@ configAttachmentStatuses = [
'rejected',
'reviewed'
];
+
+configBase = 'index.html';
+configBugzillaUrl = '%(bugzilla_url)s';
+configHaveExtension = %(have_extension)s;
+configNote = '%(note)s';
""" % {
'bugzilla_url': current_config['bugzilla_url'],
'have_extension': have_extension_value,
@@ -456,7 +480,9 @@ if not config_name in config.configs:
current_config = config.configs[config_name]
-config_js_content = make_config_js()
+proxy_scheme, proxy_hostname, proxy_port, proxy_path, proxy_url = get_proxy_info("/xmlrpc.cgi")
+transport = LoginTransport(proxy_scheme, proxy_hostname, proxy_port)
+xmlrpc = xmlrpclib.ServerProxy(proxy_url, transport)
if 'bugzilla_login' in current_config and 'bugzilla_login' in current_config:
if 'proxy_bind' in current_config and current_config['proxy_bind'] != '127.0.0.1':
@@ -465,11 +491,28 @@ if 'bugzilla_login' in current_config and 'bugzilla_login' in current_config:
print >>sys.stderr, "proxy_bind is '%s' not '127.0.0.1" % current_config['proxy_bind']
print >>sys.stderr, "Refusing to log in with private login/password"
else:
- login()
+ login(xmlrpc)
if login_cookie_header is None:
print >>sys.stderr, "Proxying to %s anonymously" % (current_config['bugzilla_url'])
+have_extension = False
+splinter_info = get_splinter_info(xmlrpc)
+if splinter_info:
+ extension_version = splinter_info['version']
+
+ if extension_version < 1:
+ print >>sys.stderr, "Too old splinter extension found"
+ else:
+ print >>sys.stderr, "Splinter extension found, version %d" % extension_version
+ have_extension = True
+ if splinter_info['logged_in']:
+ print "Login=%s, Name=%s" % (splinter_info['login'], splinter_info['name'])
+else:
+ print >>sys.stderr, "No Splinter extension found"
+
+config_js_content = make_config_js()
+
proxy_bind = '127.0.0.1'
proxy_port = 23080
if 'proxy_bind' in current_config:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]