comparison doc/xmlrpc.txt @ 6342:31bac6f2dd8b

Update advanced script to python3; other doc updates
author John Rouillard <rouilj@ieee.org>
date Sat, 13 Mar 2021 21:48:59 -0500
parents 81ae33038ec5
children 45e8d10a9609
comparison
equal deleted inserted replaced
6341:35a162c8977c 6342:31bac6f2dd8b
77 passed in cleartext unless the server is being proxied behind another 77 passed in cleartext unless the server is being proxied behind another
78 server (such as Apache or lighttpd) that provide SSL. 78 server (such as Apache or lighttpd) that provide SSL.
79 79
80 Client API 80 Client API
81 ---------- 81 ----------
82 The server currently implements four methods. Each method requires 82 The server currently implements seven methods/commands. Each method
83 that the user provide a username and password in the HTTP 83 requires that the user provide a username and password in the HTTP
84 authorization header in order to authenticate the request against the 84 authorization header in order to authenticate the request against the
85 tracker. 85 tracker.
86 86
87 ======= ==================================================================== 87 ======= ====================================================================
88 Command Description 88 Command Description
126 filter arguments: *classname, list or None, attributes* 126 filter arguments: *classname, list or None, attributes*
127 127
128 ``list`` is a list of ids to filter. It can be set to None to run 128 ``list`` is a list of ids to filter. It can be set to None to run
129 filter over all values (requires ``allow_none=True`` when 129 filter over all values (requires ``allow_none=True`` when
130 instantiating the ServerProxy). The ``attributes`` are given as a 130 instantiating the ServerProxy). The ``attributes`` are given as a
131 dictionary of name value pairs to search for. See also :ref:`query-tracker`. 131 dictionary of name value pairs to search for. See also
132 :ref:`query-tracker`.
132 ======= ==================================================================== 133 ======= ====================================================================
133 134
134 sample python client 135 sample python client
135 ==================== 136 ====================
136 137
171 The one below adds Referer and X-Requested-With headers so it can pass 172 The one below adds Referer and X-Requested-With headers so it can pass
172 stronger CSRF detection methods. It also generates a fault message 173 stronger CSRF detection methods. It also generates a fault message
173 from the server and reports it. Note if you are using http rather than 174 from the server and reports it. Note if you are using http rather than
174 https, replace xmlrpclib.SafeTransport with xmlrpclib.Transport:: 175 https, replace xmlrpclib.SafeTransport with xmlrpclib.Transport::
175 176
176 import xmlrpclib 177 try:
178 from xmlrpc import client as xmlrpclib # python 3
179 except ImportError:
180 import xmlrpclib # python 2
181
182 hostname="localhost"
183 path="/demo"
184 user_pw="admin:admin"
177 185
178 class SpecialTransport(xmlrpclib.SafeTransport): 186 class SpecialTransport(xmlrpclib.SafeTransport):
179 187
180 def send_content(self, connection, request_body): 188 def send_content(self, connection, request_body):
181 189
182 connection.putheader("Referer", "https://localhost/demo/") 190 connection.putheader("Referer", "https://%s%s/"%(hostname, path))
183 connection.putheader("Origin", "https://localhost") 191 connection.putheader("Origin", "https://%s"%hostname)
184 connection.putheader("X-Requested-With", "XMLHttpRequest") 192 connection.putheader("X-Requested-With", "XMLHttpRequest")
185 193
186 connection.putheader("Content-Type", "text/xml") 194 connection.putheader("Content-Type", "text/xml")
187 connection.putheader("Content-Length", str(len(request_body))) 195 connection.putheader("Content-Length", str(len(request_body)))
188 connection.endheaders() 196 connection.endheaders()
189 if request_body: 197 if request_body:
190 connection.send(request_body) 198 connection.send(request_body)
191 199
192 roundup_server = xmlrpclib.ServerProxy( 200 roundup_server = xmlrpclib.ServerProxy(
193 'https://admin:admin@localhost/demo/xmlrpc', 201 'https://%s@%s%s/xmlrpc'%(user_pw,hostname,path),
194 transport=SpecialTransport(), 202 transport=SpecialTransport(),
195 verbose=False, 203 verbose=False,
196 allow_none=True) 204 allow_none=True)
197 205
198 print(roundup_server.schema()) 206 print(roundup_server.schema())
199 print(roundup_server.display('user2', 'username')) 207 print(roundup_server.display('user2', 'username'))
200 print(roundup_server.display('issue1', 'status')) 208 print(roundup_server.display('issue1', 'status'))
201 print(roundup_server.filter('user',['1','2','3'],{'username':'demo'})) 209 print(roundup_server.filter('user',['1','2','3'],{'username':'demo'}))
202 210
203 # this will fail with a fault 211 # this will fail with a fault
204 try: 212 try:
205 print(roundup_server.filter('usr',['0','2','3'],{'username':'demo'})) 213 print(roundup_server.filter('usr',['0','2','3'],{'username':'demo'}))
206 except Exception as msg: 214 except Exception as msg:
207 print(msg) 215 print(msg)
216
217 modify this script replacing the hostname, path and user_pw with those
218 for your tracker.

Roundup Issue Tracker: http://roundup-tracker.org/