27
__version__ as _bzrlib_version,
25
import bzrlib.errors as errors
32
29
export BZR_LP_XMLRPC_URL=http://xmlrpc.staging.launchpad.net/bazaar/
35
class InvalidLaunchpadInstance(errors.BzrError):
37
_fmt = "%(lp_instance)s is not a valid Launchpad instance."
39
def __init__(self, lp_instance):
40
errors.BzrError.__init__(self, lp_instance=lp_instance)
43
32
class LaunchpadService(object):
44
33
"""A service to talk to Launchpad via XMLRPC.
46
35
See http://bazaar-vcs.org/Specs/LaunchpadRpc for the methods we can call.
49
# NB: these should always end in a slash to avoid xmlrpclib appending
38
# NB: this should always end in a slash to avoid xmlrpclib appending
51
# We use edge as the default because:
52
# Beta users get redirected to it
53
# All users can use it
54
# There is a bug in the launchpad side where redirection causes an OOPS.
55
LAUNCHPAD_INSTANCE = {
56
'production': 'https://xmlrpc.launchpad.net/bazaar/',
57
'edge': 'https://xmlrpc.edge.launchpad.net/bazaar/',
58
'staging': 'https://xmlrpc.staging.launchpad.net/bazaar/',
59
'demo': 'https://xmlrpc.demo.launchpad.net/bazaar/',
60
'dev': 'http://xmlrpc.launchpad.dev/bazaar/',
62
DEFAULT_SERVICE_URL = LAUNCHPAD_INSTANCE['edge']
40
DEFAULT_SERVICE_URL = 'https://xmlrpc.launchpad.net/bazaar/'
65
43
registrant_email = None
66
44
registrant_password = None
69
def __init__(self, transport=None, lp_instance=None):
47
def __init__(self, transport=None):
70
48
"""Construct a new service talking to the launchpad rpc server"""
71
self._lp_instance = lp_instance
72
49
if transport is None:
73
50
uri_type = urllib.splittype(self.service_url)[0]
74
51
if uri_type == 'https':
89
66
key = 'BZR_LP_XMLRPC_URL'
90
67
if key in os.environ:
91
68
return os.environ[key]
92
elif self._lp_instance is not None:
94
return self.LAUNCHPAD_INSTANCE[self._lp_instance]
96
raise InvalidLaunchpadInstance(self._lp_instance)
98
70
return self.DEFAULT_SERVICE_URL
100
def get_proxy(self, authenticated):
101
73
"""Return the proxy for XMLRPC requests."""
103
# auth info must be in url
104
# TODO: if there's no registrant email perhaps we should
105
# just connect anonymously?
106
scheme, hostinfo, path = urlsplit(self.service_url)[:3]
107
assert '@' not in hostinfo
108
assert self.registrant_email is not None
109
assert self.registrant_password is not None
110
# TODO: perhaps fully quote the password to make it very slightly
112
# TODO: can we perhaps add extra Authorization headers
113
# directly to the request, rather than putting this into
114
# the url? perhaps a bit more secure against accidentally
115
# revealing it. std66 s3.2.1 discourages putting the
116
# password in the url.
117
hostinfo = '%s:%s@%s' % (urllib.quote(self.registrant_email),
118
urllib.quote(self.registrant_password),
120
url = urlunsplit((scheme, hostinfo, path, '', ''))
122
url = self.service_url
74
# auth info must be in url
75
# TODO: if there's no registrant email perhaps we should just connect
77
scheme, hostinfo, path = urlsplit(self.service_url)[:3]
78
assert '@' not in hostinfo
79
assert self.registrant_email is not None
80
assert self.registrant_password is not None
81
# TODO: perhaps fully quote the password to make it very slightly
83
# TODO: can we perhaps add extra Authorization headers directly to the
84
# request, rather than putting this into the url? perhaps a bit more
85
# secure against accidentally revealing it. std66 s3.2.1 discourages putting
86
# the password in the url.
87
hostinfo = '%s:%s@%s' % (urllib.quote(self.registrant_email),
88
urllib.quote(self.registrant_password),
90
url = urlunsplit((scheme, hostinfo, path, '', ''))
123
91
return xmlrpclib.ServerProxy(url, transport=self.transport)
125
93
def gather_user_credentials(self):
126
94
"""Get the password from the user."""
127
the_config = config.GlobalConfig()
128
self.registrant_email = the_config.user_email()
95
config = bzrlib.config.GlobalConfig()
96
self.registrant_email = config.user_email()
129
97
if self.registrant_password is None:
130
auth = config.AuthenticationConfig()
131
scheme, hostinfo = urlsplit(self.service_url)[:2]
132
98
prompt = 'launchpad.net password for %s: ' % \
133
99
self.registrant_email
134
# We will reuse http[s] credentials if we can, prompt user
136
self.registrant_password = auth.get_password(scheme, hostinfo,
137
self.registrant_email,
100
self.registrant_password = getpass(prompt)
140
def send_request(self, method_name, method_params, authenticated):
141
proxy = self.get_proxy(authenticated)
102
def send_request(self, method_name, method_params):
103
proxy = self.get_proxy()
142
104
assert method_name
143
105
method = getattr(proxy, method_name)
249
208
# This must match the parameter tuple expected by Launchpad for this
251
210
return (self.branch_url, self.bug_id, '')
254
class ResolveLaunchpadPathRequest(BaseRequest):
255
"""Request to resolve the path component of an lp: URL."""
257
_methodname = 'resolve_lp_path'
258
_authenticated = False
260
def __init__(self, path):
262
raise errors.InvalidURL(path=path,
263
extra="You must specify a product.")
266
def _request_params(self):
267
"""Return xmlrpc request parameters"""