~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/launchpad/lp_registration.py

  • Committer: James Henstridge
  • Date: 2007-10-10 01:25:42 UTC
  • mto: This revision was merged to the branch mainline in revision 2980.
  • Revision ID: james@jamesh.id.au-20071010012542-d0cq7ttawfhptlve
Make it possible to make unauthenticated XML-RPC requests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
        else:
70
70
            return self.DEFAULT_SERVICE_URL
71
71
 
72
 
    def get_proxy(self):
 
72
    def get_proxy(self, authenticated):
73
73
        """Return the proxy for XMLRPC requests."""
74
 
        # auth info must be in url
75
 
        # TODO: if there's no registrant email perhaps we should just connect
76
 
        # anonymously?
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
82
 
        # obscured
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),
89
 
                                 hostinfo)
90
 
        url = urlunsplit((scheme, hostinfo, path, '', ''))
 
74
        if authenticated:
 
75
            # auth info must be in url
 
76
            # TODO: if there's no registrant email perhaps we should
 
77
            # just connect anonymously?
 
78
            scheme, hostinfo, path = urlsplit(self.service_url)[:3]
 
79
            assert '@' not in hostinfo
 
80
            assert self.registrant_email is not None
 
81
            assert self.registrant_password is not None
 
82
            # TODO: perhaps fully quote the password to make it very slightly
 
83
            # obscured
 
84
            # TODO: can we perhaps add extra Authorization headers
 
85
            # directly to the request, rather than putting this into
 
86
            # the url?  perhaps a bit more secure against accidentally
 
87
            # revealing it.  std66 s3.2.1 discourages putting the
 
88
            # password in the url.
 
89
            hostinfo = '%s:%s@%s' % (urllib.quote(self.registrant_email),
 
90
                                     urllib.quote(self.registrant_password),
 
91
                                     hostinfo)
 
92
            url = urlunsplit((scheme, hostinfo, path, '', ''))
 
93
        else:
 
94
            url = self.service_url
91
95
        return xmlrpclib.ServerProxy(url, transport=self.transport)
92
96
 
93
97
    def gather_user_credentials(self):
99
103
                    self.registrant_email
100
104
            self.registrant_password = getpass(prompt)
101
105
 
102
 
    def send_request(self, method_name, method_params):
103
 
        proxy = self.get_proxy()
 
106
    def send_request(self, method_name, method_params, authenticated):
 
107
        proxy = self.get_proxy(authenticated)
104
108
        assert method_name
105
109
        method = getattr(proxy, method_name)
106
110
        try:
126
130
 
127
131
    # Set this to the XMLRPC method name.
128
132
    _methodname = None
 
133
    _authenticated = True
129
134
 
130
135
    def _request_params(self):
131
136
        """Return the arguments to pass to the method"""
137
142
        :param service: LaunchpadService indicating where to send
138
143
            the request and the authentication credentials.
139
144
        """
140
 
        return service.send_request(self._methodname, self._request_params())
 
145
        return service.send_request(self._methodname, self._request_params(),
 
146
                                    self._authenticated)
141
147
 
142
148
 
143
149
class DryRunLaunchpadService(LaunchpadService):
146
152
    The dummy service does not need authentication.
147
153
    """
148
154
 
149
 
    def send_request(self, method_name, method_params):
 
155
    def send_request(self, method_name, method_params, authenticated):
150
156
        pass
151
157
 
152
158
    def gather_user_credentials(self):