Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic HTTP authentication support to Trac backend and a new backend to support WordPress authentication #152

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions bicho/backends/trac.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ class TracRPC(object):

def __init__(self, url):
self.url = url
self.backend_user = None
self.backend_password = None
self.requests = requests

if hasattr(Config, 'backend_user') and hasattr(Config, 'backend_password'):
self.backend_user = Config.backend_user
self.backend_password = Config.backend_password

def tickets(self, since=None):
"""Returns a list of IDs of tickets that have changed since timestamp."""
Expand Down Expand Up @@ -288,10 +295,19 @@ def call(self, method, params):
# POST parameters
data = {'method': method, 'params': params}
data = json.dumps(data)
auth = None

if self.backend_user and self.backend_password:
auth = (self.backend_user, self.backend_password)
url = '%s/login/jsonrpc' % self.url
else:
url = '%s/jsonrpc' % self.url

res = requests.post('%s/jsonrpc' % self.url,
res = self.requests.post(url,
headers=self.HEADERS,
data=data)
data=data,
auth=auth)

printdbg("Trac RPC %s method called: %s" % (method, res.url))

# Raise HTTP errors, if any
Expand Down
44 changes: 44 additions & 0 deletions bicho/backends/trac_wordpress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015 Bitergia
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Authors: Santiago Dueñas <[email protected]>
#

import requests

from bicho.backends import Backend
from bicho.backends.trac import Trac, TracRPC


class TracWordPress(Trac):
def __init__(self):
Trac.__init__(self)

self.trac_rpc = TracRPCWordPress(self.url)

class TracRPCWordPress(TracRPC):
def __init__(self, url):
TracRPC.__init__(self, url)

self.requests = requests.Session()
login_url = 'https://wordpress.org/support/bb-login.php'
login_data = {'password': self.backend_password, 'user_login': self.backend_user}

self.requests.post(login_url, login_data)

Backend.register_backend('trac_wordpress', TracWordPress)